import glob, os, sys, tempfile
from bup import options, git, bloom
+from bup.compat import hexstr
from bup.helpers import (add_error, debug1, handle_ctrl_c, log, progress, qprogress,
saved_errors)
log("bloom: checking %s\n" % ridx)
for objsha in git.open_idx(idx):
if not b.exists(objsha):
- add_error("bloom: ERROR: object %s missing"
- % str(objsha).encode('hex'))
+ add_error('bloom: ERROR: object %s missing' % hexstr(objsha))
_first = None
from stat import S_ISDIR
from bup import git, client, helpers, vfs
-from bup.compat import wrap_main
+from bup.compat import hexstr, wrap_main
from bup.git import get_cat_data, parse_commit, walk_object
from bup.helpers import add_error, debug1, handle_ctrl_c, log, saved_errors
from bup.helpers import hostname, shstr, tty_width
def log_item(name, type, opt, tree=None, commit=None, tag=None):
if tag and opt.print_tags:
- print(tag.encode('hex'))
+ print(hexstr(tag))
if tree and opt.print_trees:
- print(tree.encode('hex'))
+ print(hexstr(tree))
if commit and opt.print_commits:
- print(commit.encode('hex'))
+ print(hexstr(commit))
if opt.verbose:
last = ''
if type in ('root', 'branch', 'save', 'commit', 'tree'):
import glob, math, os, resource, struct, sys, tempfile
from bup import options, git, midx, _helpers, xstat
-from bup.compat import range
+from bup.compat import hexstr, range
from bup.helpers import (Sha1, add_error, atomically_replaced_file, debug1, fdatasync,
handle_ctrl_c, log, mmap_readwrite, qprogress,
saved_errors, unlink)
git.shorten_hash(subname), ecount, len(sub)))
if not sub.exists(e):
add_error("%s: %s: %s missing from idx"
- % (nicename, git.shorten_hash(subname),
- str(e).encode('hex')))
+ % (nicename, git.shorten_hash(subname), hexstr(e)))
if not ix.exists(e):
add_error("%s: %s: %s missing from midx"
- % (nicename, git.shorten_hash(subname),
- str(e).encode('hex')))
+ % (nicename, git.shorten_hash(subname), hexstr(e)))
prev = None
for ecount,e in enumerate(ix):
if not (ecount % 1234):
qprogress(' Ordering: %d/%d\r' % (ecount, len(ix)))
if not e >= prev:
add_error('%s: ordering error: %s < %s'
- % (nicename,
- str(e).encode('hex'), str(prev).encode('hex')))
+ % (nicename, hexstr(e), hexstr(prev)))
prev = e
import os, sys, struct, subprocess
from bup import options, git, vfs, vint
+from bup.compat import hexstr
from bup.git import MissingObject
from bup.helpers import (Conn, debug1, debug2, linereader, lines_until_sentinel,
log)
debug1("bup server: suggesting index %s\n"
% git.shorten_hash(name))
debug1("bup server: because of object %s\n"
- % shar.encode('hex'))
+ % hexstr(shar))
conn.write('index %s\n' % name)
suggested.add(name)
continue
from __future__ import absolute_import, print_function
from array import array
+from binascii import hexlify
from traceback import print_exception
import sys
str_type = str
int_types = (int,)
+ def hexstr(b):
+ """Return hex string (not bytes as with hexlify) representation of b."""
+ return b.hex()
+
def add_ex_tb(ex):
"""Do nothing (already handled by Python 3 infrastructure)."""
return ex
str_type = basestring
int_types = (int, long)
+ hexstr = hexlify
+
def add_ex_tb(ex):
"""Add a traceback to ex if it doesn't already have one. Return ex.
from __future__ import absolute_import
import glob, os, subprocess, sys, tempfile
from bup import bloom, git, midx
-from bup.compat import range
+from bup.compat import hexstr, range
from bup.git import MissingObject, walk_object
from bup.helpers import Nonlocal, log, progress, qprogress
from os.path import basename
def report_live_item(n, total, ref_name, ref_id, item, verbosity):
status = 'scanned %02.2f%%' % (n * 100.0 / total)
- hex_id = ref_id.encode('hex')
+ hex_id = hexstr(ref_id)
dirslash = '/' if item.type == 'tree' else ''
chunk_path = item.chunk_path
live_objects = find_live_objects(existing_count, cat_pipe,
verbosity=verbosity)
except MissingObject as ex:
- log('bup: missing object %r \n' % ex.oid.encode('hex'))
+ log('bup: missing object %s \n' % hexstr(ex.oid))
sys.exit(1)
try:
# FIXME: just rename midxes and bloom, and restore them at the end if
from bup import compat, git, vfs
from bup.client import ClientError
+from bup.compat import hexstr
from bup.git import get_commit_items
from bup.helpers import add_error, die_if_errors, log, saved_errors
else:
git.update_ref(ref_name, new_ref, orig_ref)
if verbosity:
- new_hex = new_ref.encode('hex')
- if orig_ref:
- orig_hex = orig_ref.encode('hex')
- log('updated %r (%s -> %s)\n'
- % (ref_name, orig_hex, new_hex))
- else:
- log('updated %r (%s)\n' % (ref_name, new_hex))
+ log('updated %r (%s%s)\n'
+ % (ref_name,
+ hexstr(orig_ref) + ' -> ' if orig_ref else '',
+ hexstr(new_ref)))
except (git.GitError, ClientError) as ex:
if new_ref:
- add_error('while trying to update %r (%s -> %s): %s'
- % (ref_name, orig_ref, new_ref, ex))
+ add_error('while trying to update %r (%s%s): %s'
+ % (ref_name,
+ hexstr(orig_ref) + ' -> ' if orig_ref else '',
+ hexstr(new_ref),
+ ex))
else:
add_error('while trying to delete %r (%s): %s'
- % (ref_name, orig_ref, ex))
+ % (ref_name, hexstr(orig_ref), ex))
import re, sys
from bup import git, metadata, vint
-from bup.compat import range
+from bup.compat import hexstr, range
from bup.git import BUP_CHUNKED, cp, get_commit_items, parse_commit, tree_decode
from bup.helpers import debug2, last
from bup.metadata import Metadata
data = ''.join(it)
assert item_t == 'tree'
elif item_t != 'tree':
- raise Exception('%r is not a tree or commit' % oid.encode('hex'))
+ raise Exception('%s is not a tree or commit' % hexstr(oid))
for _, mangled_name, sub_oid in tree_decode(data):
if mangled_name == '.bupm':
return data, sub_oid