+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:
+ new_blob = pack_writer.new_blob
+ new_tree = pack_writer.new_tree
+elif opt.blobs or opt.tree:
+ # --noop mode
+ new_blob = lambda content: git.calc_hash('blob', content)
+ new_tree = lambda shalist: git.calc_hash('tree', git.tree_encode(shalist))
+
+if opt.blobs:
+ shalist = hashsplit.split_to_blobs(new_blob, files,
+ keep_boundaries=opt.keep_boundaries,
+ progress=prog)
+ for (sha, size, level) in shalist:
+ print sha.encode('hex')
+ reprogress()
+elif opt.tree or opt.commit or opt.name:
+ if opt.name: # insert dummy_name which may be used as a restore target
+ mode, sha = \
+ hashsplit.split_to_blob_or_tree(new_blob, 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(
+ new_blob, new_tree, files,
+ keep_boundaries=opt.keep_boundaries, progress=prog)
+ tree = new_tree(shalist)