+if opt.git_ids:
+ # the input is actually a series of git object ids that we should retrieve
+ # and split.
+ #
+ # This is a bit messy, but basically it converts from a series of
+ # CatPipe.get() iterators into a series of file-type objects.
+ # It would be less ugly if either CatPipe.get() returned a file-like object
+ # (not very efficient), or split_to_shalist() expected an iterator instead
+ # of a file.
+ cp = git.CatPipe()
+ class IterToFile:
+ def __init__(self, it):
+ self.it = iter(it)
+ def read(self, size):
+ v = next(self.it, None)
+ return v or ''
+ def read_ids():
+ while 1:
+ line = sys.stdin.readline()
+ if not line:
+ break
+ if line:
+ line = line.strip()
+ try:
+ it = cp.get(line.strip())
+ next(it, None) # skip the file info
+ except KeyError as e:
+ add_error('error: %s' % e)
+ continue
+ yield IterToFile(it)
+ files = read_ids()
+else:
+ # the input either comes from a series of files or from stdin.
+ files = extra and (open(fn) for fn in extra) or [sys.stdin]
+
+if pack_writer and opt.blobs:
+ shalist = hashsplit.split_to_blobs(pack_writer.new_blob, files,
+ keep_boundaries=opt.keep_boundaries,
+ progress=prog)
+ for (sha, size, level) in shalist:
+ print sha.encode('hex')
+ reprogress()
+elif pack_writer: # tree or commit or name
+ if opt.name: # insert dummy_name which may be used as a restore target
+ mode, sha = \
+ hashsplit.split_to_blob_or_tree(pack_writer.new_blob,
+ pack_writer.new_tree,
+ files,
+ keep_boundaries=opt.keep_boundaries,
+ progress=prog)
+ splitfile_name = git.mangle_name('data', hashsplit.GIT_MODE_FILE, mode)
+ shalist = [(mode, splitfile_name, sha)]
+ else:
+ shalist = hashsplit.split_to_shalist(
+ pack_writer.new_blob, pack_writer.new_tree, files,
+ keep_boundaries=opt.keep_boundaries, progress=prog)