From 18b1504d064220edf169db8738fe561cb16e6d4b Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 17 Feb 2011 23:36:49 -0800 Subject: [PATCH] Add git.shorten_hash(), printing only the first few bytes of a sha1. The full name is rarely needed and clutters the output. Let's try this instead in a few places. Signed-off-by: Avery Pennarun --- cmd/server-cmd.py | 3 ++- lib/bup/client.py | 6 ++++-- lib/bup/git.py | 7 ++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/server-cmd.py b/cmd/server-cmd.py index ff4db47..acd6119 100755 --- a/cmd/server-cmd.py +++ b/cmd/server-cmd.py @@ -101,7 +101,8 @@ def receive_objects_v2(conn, junk): assert(oldpack.endswith('.idx')) (dir,name) = os.path.split(oldpack) if not (name in suggested): - debug1("bup server: suggesting index %s\n" % name) + debug1("bup server: suggesting index %s\n" + % git.shorten_hash(name)) debug1("bup server: because of object %s\n" % shar.encode('hex')) conn.write('index %s\n' % name) diff --git a/lib/bup/client.py b/lib/bup/client.py index 22fa38d..f941067 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -216,11 +216,13 @@ class Client: debug2('%s\n' % line) if line.startswith('index '): idx = line[6:] - debug1('client: received index suggestion: %s\n' % idx) + debug1('client: received index suggestion: %s\n' + % git.shorten_hash(idx)) suggested.append(idx) else: assert(line.endswith('.idx')) - debug1('client: completed writing pack, idx: %s\n' % line) + debug1('client: completed writing pack, idx: %s\n' + % git.shorten_hash(line)) suggested.append(line) self.check_ok() if ob: diff --git a/lib/bup/git.py b/lib/bup/git.py index 79df185..ace4e4c 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -38,6 +38,11 @@ def repo(sub = ''): return os.path.join(repodir, sub) +def shorten_hash(s): + return re.sub(r'([^0-9a-z]|\b)([0-9a-z]{7})[0-9a-z]{33}([^0-9a-z]|\b)', + r'\1\2*\3', s) + + def repo_rel(path): full = os.path.abspath(path) fullrepo = os.path.abspath(repo('')) @@ -47,7 +52,7 @@ def repo_rel(path): path = full[len(fullrepo):] if path.startswith('index-cache/'): path = path[len('index-cache/'):] - return path + return shorten_hash(path) def all_packdirs(): -- 2.39.2