Skip to content

Commit

Permalink
index: index-add fixed to always append a newline after each item. In…
Browse files Browse the repository at this point in the history
… git has unified its way it reads from stdin, now it wants all items to be terminated by a newline usually. Previously, it could have been that it really didn't want to have a termination character when the last item was written to the file. Bumped the minimum requirements to 1.7.0 to be sure it is working as I think it will.

Still, I have to admit that sometime it just appears the closed pipe will not stop git from waiting for more input, at least with the previous implementation
  • Loading branch information
Byron committed May 26, 2010
1 parent de84cbd commit ecf37a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requirements
============

* Git_ tested with 1.5.3.7
* Requires Git_ 1.6.5.4 or newer if index.add function is to be used
* Requires Git_ 1.7.0 or newer
* `Python Nose`_ - used for running the tests
* `Mock by Michael Foord`_ used for tests. Requires 0.5

Expand Down
33 changes: 10 additions & 23 deletions lib/git/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,11 @@ def raise_exc(e):
# END path exception handling
# END for each path

def _write_path_to_stdin(self, proc, filepath, item, append_or_prepend_nl,
fmakeexc, fprogress, read_from_stdout=True):
def _write_path_to_stdin(self, proc, filepath, item, fmakeexc, fprogress,
read_from_stdout=True):
"""Write path to proc.stdin and make sure it processes the item, including progress.
:return: stdout string
:param append_or_prepend_nl:
* if -1, a newline will be sent before the filepath is printed.
* If 1, a newline will be appended after the filepath was printed.
* If 0, no additional newline will be sent.
:param read_from_stdout: if True, proc.stdout will be read after the item
was sent to stdin. In that case, it will return None
:note: There is a bug in git-update-index that prevents it from sending
Expand All @@ -684,11 +680,7 @@ def _write_path_to_stdin(self, proc, filepath, item, append_or_prepend_nl,
fprogress(filepath, False, item)
rval = None
try:
if append_or_prepend_nl < 0:
proc.stdin.write('\n')
proc.stdin.write("%s" % filepath)
if append_or_prepend_nl > 0:
proc.stdin.write('\n')
proc.stdin.write("%s\n" % filepath)
except IOError:
# pipe broke, usually because some error happend
raise fmakeexc()
Expand Down Expand Up @@ -980,10 +972,9 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
make_exc = lambda : GitCommandError(("git-update-index",)+args, 128, proc.stderr.read())
added_files = list()

prepend_newline = 0
for filepath in self._iter_expand_paths(paths):
self._write_path_to_stdin(proc, filepath, filepath, prepend_newline, make_exc, fprogress, read_from_stdout=False)
prepend_newline = -1
self._write_path_to_stdin(proc, filepath, filepath, make_exc,
fprogress, read_from_stdout=False)
added_files.append(filepath)
# END for each filepath
self._flush_stdin_and_wait(proc, ignore_stdout=True) # ignore stdout
Expand All @@ -1010,10 +1001,9 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
proc = self.repo.git.hash_object(*args, **{'istream':subprocess.PIPE, 'as_process':True})
make_exc = lambda : GitCommandError(("git-hash-object",)+args, 128, proc.stderr.read())
obj_ids = list()
append_newline = 1
for ei in null_entries_indices:
entry = entries[ei]
obj_ids.append(self._write_path_to_stdin(proc, entry.path, entry, append_newline,
obj_ids.append(self._write_path_to_stdin(proc, entry.path, entry,
make_exc, fprogress, read_from_stdout=True))
# END for each entry index
assert len(obj_ids) == len(null_entries_indices), "git-hash-object did not produce all requested objects: want %i, got %i" % ( len(null_entries_indices), len(obj_ids) )
Expand Down Expand Up @@ -1329,7 +1319,6 @@ def handle_stderr(proc, iter_checked_out_files):
proc = self.repo.git.checkout_index(args, **kwargs)
make_exc = lambda : GitCommandError(("git-checkout-index",)+tuple(args), 128, proc.stderr.read())
checked_out_files = list()
prepend_newline = 0

for path in paths:
path = self._to_relative_path(path)
Expand All @@ -1345,19 +1334,17 @@ def handle_stderr(proc, iter_checked_out_files):
for entry in self.entries.itervalues():
if entry.path.startswith(dir):
p = entry.path
self._write_path_to_stdin(proc, p, p, prepend_newline,
make_exc, fprogress, read_from_stdout=False)
prepend_newline = -1
self._write_path_to_stdin(proc, p, p, make_exc,
fprogress, read_from_stdout=False)
checked_out_files.append(p)
path_is_directory = True
# END if entry is in directory
# END for each entry
# END path exception handlnig

if not path_is_directory:
self._write_path_to_stdin(proc, path, path, prepend_newline,
make_exc, fprogress, read_from_stdout=False)
prepend_newline = -1
self._write_path_to_stdin(proc, path, path, make_exc,
fprogress, read_from_stdout=False)
checked_out_files.append(path)
# END path is a file
# END for each path
Expand Down

0 comments on commit ecf37a1

Please sign in to comment.