o.usage()
hashsplit.split_verbosely = opt.verbose
+if opt.verbose >= 2:
+ git.verbose = opt.verbose - 1
start_time = time.time()
(shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
+if opt.verbose:
+ log('\n')
if opt.blobs:
- for (mode,name,sum) in shalist:
- print sum
+ for (mode,name,bin) in shalist:
+ print bin.encode('hex')
if opt.tree:
- print tree
+ print tree.encode('hex')
if opt.commit or opt.name:
msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
ref = opt.name and ('refs/heads/%s' % opt.name) or None
commit = git.gen_commit_easy(ref, tree, msg)
if opt.commit:
- print commit
+ print commit.encode('hex')
secs = time.time() - start_time
size = hashsplit.total_split
import os, errno, zlib, time, sha, subprocess, struct, mmap
from helpers import *
+verbose = 0
+
class PackIndex:
def __init__(self, filename):
else: # got it!
return mid
return None
+
def find_offset(self, hash):
idx = self._idx_from_hash(hash)
if idx != None:
class MultiPackIndex:
def __init__(self, dir):
self.packs = []
+ self.also = {}
for f in os.listdir(dir):
if f.endswith('.idx'):
self.packs.append(PackIndex(os.path.join(dir, f)))
def exists(self, hash):
+ if hash in self.also:
+ return True
for i in range(len(self.packs)):
p = self.packs[i]
if p.exists(hash):
return True
return None
-
-def _old_write_object(bin, type, content):
- hex = bin.encode('hex')
- header = '%s %d\0' % (type, len(content))
- dir = '.git/objects/%s' % hex[0:2]
- fn = '%s/%s' % (dir, hex[2:])
- if not os.path.exists(fn):
- #log('creating %s' % fn)
- try:
- os.mkdir(dir)
- except OSError, e:
- if e.errno != errno.EEXIST:
- raise
- tfn = '.git/objects/bup%d.tmp' % os.getpid()
- f = open(tfn, 'w')
- z = zlib.compressobj(1)
- f.write(z.compress(header))
- f.write(z.compress(content))
- f.write(z.flush())
- f.close()
- os.rename(tfn, fn)
+ def add(self, hash):
+ self.also[hash] = 1
def calc_hash(type, content):
global _typemap
f = self.file
+ if verbose:
+ log('>')
+
sz = len(content)
szbits = (sz & 0x0f) | (_typemap[type]<<4)
sz >>= 4
def easy_write(self, type, content):
return self.write(calc_hash(type, content), type, content)
+ def abort(self):
+ self.file.close()
+ os.unlink(self.filename + '.pack')
+
def close(self):
f = self.file
global _packout
if _packout:
_packout.close()
+ _packout = None
+
+def abort_pack():
+ global _packout
+ if _packout:
+ _packout.abort()
+ _packout = None
-_objcache = {}
+
+_objcache = None
def hash_raw(type, s):
global _objcache
+ if not _objcache:
+ _objcache = MultiPackIndex('.git/objects/pack')
bin = calc_hash(type, s)
- hex = bin.encode('hex')
- if bin in _objcache:
- return hex
+ if _objcache.exists(bin):
+ return bin
else:
_write_object(bin, type, s)
- _objcache[bin] = 1
- return hex
+ _objcache.add(bin)
+ return bin
def hash_blob(blob):
def gen_tree(shalist):
shalist = sorted(shalist, key = lambda x: x[1])
- l = ['%s %s\0%s' % (mode,name,hex.decode('hex'))
- for (mode,name,hex) in shalist]
+ l = ['%s %s\0%s' % (mode,name,bin)
+ for (mode,name,bin) in shalist]
return hash_raw('tree', ''.join(l))
def gen_commit(tree, parent, author, adate, committer, cdate, msg):
l = []
- if tree: l.append('tree %s' % tree)
+ if tree: l.append('tree %s' % tree.encode('hex'))
if parent: l.append('parent %s' % parent)
if author: l.append('author %s %s' % (author, _git_date(adate)))
if committer: l.append('committer %s %s' % (committer, _git_date(cdate)))