-#!/usr/bin/env python
-import sys, math, struct, glob, resource
-import tempfile
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+from __future__ import absolute_import
+import glob, math, os, resource, struct, sys, tempfile
+
from bup import options, git, midx, _helpers, xstat
-from bup.helpers import *
+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)
+
PAGE_SIZE=4096
SHA_PER_PAGE=PAGE_SIZE/20.
def _group(l, count):
- for i in xrange(0, len(l), count):
+ for i in range(0, len(l), count):
yield l[i:i+count]
-
-
+
+
def max_files():
mf = min(resource.getrlimit(resource.RLIMIT_NOFILE))
if mf > 32:
log('Checking %s.\n' % nicename)
try:
ix = git.open_idx(name)
- except git.GitError, e:
+ except git.GitError as e:
add_error('%s: %s' % (name, e))
return
for count,subname in enumerate(ix.idxnames):
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
for n in ix.idxnames:
allfilenames.append(os.path.basename(n))
total += len(ix)
- inp.sort(lambda x,y: cmp(str(y[0][y[2]:y[2]+20]),str(x[0][x[2]:x[2]+20])))
+ inp.sort(reverse=True, key=lambda x: str(x[0][x[2]:x[2]+20]))
if not _first: _first = outdir
dirprefix = (_first != outdir) and git.repo_rel(outdir)+': ' or ''
print p.idxnames
assert(len(p) == total)
for pe, e in p, git.idxmerge(inp, final_progress=False):
- pin = pi.next()
+ pin = next(pi)
assert(i == pin)
assert(p.exists(i))
print rv[1]
-def do_midx_dir(path):
+def do_midx_dir(path, outfilename):
already = {}
sizes = {}
if opt.force and not opt.auto:
all.sort()
part1 = [name for sz,name in all[:len(all)-DESIRED_LWM+1]]
part2 = all[len(all)-DESIRED_LWM+1:]
- all = list(do_midx_group(path, part1)) + part2
+ all = list(do_midx_group(path, outfilename, part1)) + part2
if len(all) > DESIRED_HWM:
debug1('\nStill too many indexes (%d > %d). Merging again.\n'
% (len(all), DESIRED_HWM))
print name
-def do_midx_group(outdir, infiles):
+def do_midx_group(outdir, outfilename, infiles):
groups = list(_group(infiles, opt.max_files))
gprefix = ''
for n,sublist in enumerate(groups):
if len(groups) != 1:
gprefix = 'Group %d: ' % (n+1)
- rv = _do_midx(outdir, None, sublist, gprefix)
+ rv = _do_midx(outdir, outfilename, sublist, gprefix)
if rv:
yield rv
paths = opt.dir and [opt.dir] or git.all_packdirs()
for path in paths:
debug1('midx: scanning %s\n' % path)
- do_midx_dir(path)
+ do_midx_dir(path, opt.output)
else:
o.fatal("you must use -f or -a or provide input filenames")