diff options
Diffstat (limited to 'morphlib/gitindex.py')
-rw-r--r-- | morphlib/gitindex.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/morphlib/gitindex.py b/morphlib/gitindex.py index 7cac2311..62e6838f 100644 --- a/morphlib/gitindex.py +++ b/morphlib/gitindex.py @@ -101,3 +101,24 @@ class GitIndex(object): def set_to_tree(self, treeish): '''Modify the index to contain the contents of the treeish.''' self._run_git('read-tree', treeish) + + def add_files_from_index_info(self, infos): + '''Add files without interacting with the working tree. + + `infos` is an iterable of (file mode string, object sha1, path) + There are no constraints on the size of the iterable + + ''' + + # update-index may take NUL terminated input lines of the entries + # to add so we generate a string for the input, rather than + # having many command line arguments, since for a large amount + # of entries, this can be too many arguments to process and the + # exec will fail. + # Generating the input as a string uses more memory than using + # subprocess.Popen directly and using .communicate, but is much + # less verbose. + feed_stdin = '\0'.join('%o %s\t%s' % (mode, sha1, path) + for mode, sha1, path in infos) + '\0' + self._run_git('update-index', '--add', '-z', '--index-info', + feed_stdin=feed_stdin) |