max_pack_size = 1000*1000*1000 # larger packs will slow down pruning
max_pack_objects = 200*1000 # cache memory usage is about 83 bytes per object
-SEEK_END=2 # os.SEEK_END is not defined in python 2.4
verbose = 0
ignore_midx = 0
-home_repodir = os.path.expanduser('~/.bup')
repodir = None
_typemap = { 'blob':3, 'tree':2, 'commit':1, 'tag':4 }
return sum.digest()
-def _shalist_sort_key(ent):
+def shalist_item_sort_key(ent):
(mode, name, id) = ent
assert(mode+0 == mode)
if stat.S_ISDIR(mode):
def tree_encode(shalist):
"""Generate a git tree object from (mode,name,hash) tuples."""
- shalist = sorted(shalist, key = _shalist_sort_key)
+ shalist = sorted(shalist, key = shalist_item_sort_key)
l = []
for (mode,name,bin) in shalist:
assert(mode)
return self._end(run_midx=run_midx)
def _write_pack_idx_v2(self, filename, idx, packbin):
+ ofs64_count = 0
+ for section in idx:
+ for entry in section:
+ if entry[2] >= 2**31:
+ ofs64_count += 1
+
+ # Length: header + fan-out + shas-and-crcs + overflow-offsets
+ index_len = 8 + (4 * 256) + (28 * self.count) + (8 * ofs64_count)
+ idx_map = None
idx_f = open(filename, 'w+b')
- idx_f.write('\377tOc\0\0\0\2')
-
- ofs64_ofs = 8 + 4*256 + 28*self.count
- idx_f.truncate(ofs64_ofs)
- idx_f.seek(0)
- idx_map = mmap_readwrite(idx_f, close=False)
- idx_f.seek(0, SEEK_END)
- count = _helpers.write_idx(idx_f, idx_map, idx, self.count)
- assert(count == self.count)
- idx_map.close()
- idx_f.write(packbin)
-
- idx_f.seek(0)
- idx_sum = Sha1()
- b = idx_f.read(8 + 4*256)
- idx_sum.update(b)
-
- obj_list_sum = Sha1()
- for b in chunkyreader(idx_f, 20*self.count):
+ try:
+ idx_f.truncate(index_len)
+ idx_map = mmap_readwrite(idx_f, close=False)
+ count = _helpers.write_idx(filename, idx_map, idx, self.count)
+ assert(count == self.count)
+ finally:
+ if idx_map: idx_map.close()
+ idx_f.close()
+
+ idx_f = open(filename, 'a+b')
+ try:
+ idx_f.write(packbin)
+ idx_f.seek(0)
+ idx_sum = Sha1()
+ b = idx_f.read(8 + 4*256)
idx_sum.update(b)
- obj_list_sum.update(b)
- namebase = obj_list_sum.hexdigest()
- for b in chunkyreader(idx_f):
- idx_sum.update(b)
- idx_f.write(idx_sum.digest())
- idx_f.close()
+ obj_list_sum = Sha1()
+ for b in chunkyreader(idx_f, 20*self.count):
+ idx_sum.update(b)
+ obj_list_sum.update(b)
+ namebase = obj_list_sum.hexdigest()
- return namebase
+ for b in chunkyreader(idx_f):
+ idx_sum.update(b)
+ idx_f.write(idx_sum.digest())
+ return namebase
+ finally:
+ idx_f.close()
def _git_date(date):
opts = []
if count:
opts += ['-n', str(atoi(count))]
- argv = ['git', 'rev-list', '--pretty=format:%ct'] + opts + [ref, '--']
+ argv = ['git', 'rev-list', '--pretty=format:%at'] + opts + [ref, '--']
p = subprocess.Popen(argv, preexec_fn = _gitenv, stdout = subprocess.PIPE)
commit = None
for row in p.stdout:
raise GitError, 'git rev-list returned error %d' % rv
-def rev_get_date(ref):
- """Get the date of the latest commit on the specified ref."""
- for (date, commit) in rev_list(ref, count=1):
- return date
- raise GitError, 'no such commit %r' % ref
+def get_commit_dates(refs):
+ """Get the dates for the specified commit refs."""
+ result = []
+ cmd = ['git', 'show', '-s', '--pretty=format:%ct']
+ for chunk in batchpipe(cmd, refs, preexec_fn=_gitenv):
+ result += chunk.splitlines()
+ return result
def rev_parse(committish):
os.stat(repo('objects/pack/.'))
except OSError, e:
if e.errno == errno.ENOENT:
- if repodir != home_repodir:
- log('error: %r is not a bup repository; run "bup init"\n'
- % repo())
- sys.exit(15)
- else:
- init_repo()
+ log('error: %r is not a bup repository; run "bup init"\n'
+ % repo())
+ sys.exit(15)
else:
log('error: %s\n' % e)
sys.exit(14)
if not self.p or self.p.poll() != None:
self._restart()
assert(self.p)
- assert(self.p.poll() == None)
+ poll_result = self.p.poll()
+ assert(poll_result == None)
if self.inprogress:
log('_fast_get: opening %r while %r is open\n'
% (id, self.inprogress))
yield type
for blob in it:
yield blob
- assert(self.p.stdout.readline() == '\n')
+ readline_result = self.p.stdout.readline()
+ assert(readline_result == '\n')
self.inprogress = None
except Exception, e:
it.abort()