| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,6 +88,7 @@ def __del__(self): | |||
| 88 | 88 | # try to kill it | |
| 89 | 89 | try: | |
| 90 | 90 | os.kill(self.proc.pid, 2) # interrupt signal | |
| 91 | + self.proc.wait() # ensure process goes away | ||
| 91 | 92 | except OSError: | |
| 92 | 93 | pass # ignore error when process already died | |
| 93 | 94 | except AttributeError: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | Actor, | |
| 9 | 9 | Iterable, | |
| 10 | 10 | Stats, | |
| 11 | + finalize_process | ||
| 11 | 12 | ) | |
| 12 | 13 | from git.diff import Diffable | |
| 13 | 14 | from tree import Tree | |
@@ -65,7 +66,6 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut | |||
| 65 | 66 | message=None, parents=None, encoding=None, gpgsig=None): | |
| 66 | 67 | """Instantiate a new Commit. All keyword arguments taking None as default will | |
| 67 | 68 | be implicitly set on first query. | |
| 68 | - | ||
| 69 | 69 | :param binsha: 20 byte sha1 | |
| 70 | 70 | :param parents: tuple( Commit, ... ) | |
| 71 | 71 | is a tuple of commit ids or actual Commits | |
@@ -252,6 +252,10 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream): | |||
| 252 | 252 | assert len(hexsha) == 40, "Invalid line: %s" % hexsha | |
| 253 | 253 | yield Commit(repo, hex_to_bin(hexsha)) | |
| 254 | 254 | # END for each line in stream | |
| 255 | + # TODO: Review this - it seems process handling got a bit out of control | ||
| 256 | + # due to many developers trying to fix the open file handles issue | ||
| 257 | + if hasattr(proc_or_stream, 'wait'): | ||
| 258 | + finalize_process(proc_or_stream) | ||
| 255 | 259 | ||
| 256 | 260 | ||
| 257 | 261 | @classmethod | |
@@ -430,14 +434,21 @@ def _deserialize(self, stream): | |||
| 430 | 434 | ||
| 431 | 435 | self.author, self.authored_date, self.author_tz_offset = parse_actor_and_date(next_line) | |
| 432 | 436 | self.committer, self.committed_date, self.committer_tz_offset = parse_actor_and_date(readline()) | |
| 433 | - | ||
| 437 | + | ||
| 438 | + # we might run into one or more mergetag blocks, skip those for now | ||
| 439 | + next_line = readline() | ||
| 440 | + while next_line.startswith('mergetag '): | ||
| 441 | + next_line = readline() | ||
| 442 | + while next_line.startswith(' '): | ||
| 443 | + next_line = readline() | ||
| 434 | 444 | ||
| 435 | 445 | # now we can have the encoding line, or an empty line followed by the optional | |
| 436 | 446 | # message. | |
| 437 | 447 | self.encoding = self.default_encoding | |
| 438 | 448 | ||
| 439 | 449 | # read headers | |
| 440 | - buf = readline().strip() | ||
| 450 | + enc = next_line | ||
| 451 | + buf = enc.strip() | ||
| 441 | 452 | while buf != "": | |
| 442 | 453 | if buf[0:10] == "encoding ": | |
| 443 | 454 | self.encoding = buf[buf.find(' ')+1:] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,9 +70,13 @@ def tree_entries_from_data(data): | |||
| 70 | 70 | # default encoding for strings in git is utf8 | |
| 71 | 71 | # Only use the respective unicode object if the byte stream was encoded | |
| 72 | 72 | name = data[ns:i] | |
| 73 | - name_enc = name.decode("utf-8") | ||
| 74 | - if len(name) > len(name_enc): | ||
| 75 | - name = name_enc | ||
| 73 | + try: | ||
| 74 | + name_enc = name.decode("utf-8") | ||
| 75 | + except UnicodeDecodeError: | ||
| 76 | + pass | ||
| 77 | + else: | ||
| 78 | + if len(name) > len(name_enc): | ||
| 79 | + name = name_enc | ||
| 76 | 80 | # END handle encoding | |
| 77 | 81 | ||
| 78 | 82 | # byte is NULL, get next 20 | |
@@ -84,6 +88,7 @@ def tree_entries_from_data(data): | |||
| 84 | 88 | return out | |
| 85 | 89 | ||
| 86 | 90 | ||
| 91 | + | ||
| 87 | 92 | def _find_by_name(tree_data, name, is_dir, start_at): | |
| 88 | 93 | """return data entry matching the given name and tree mode | |
| 89 | 94 | or None. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,17 +167,22 @@ def parse_date(string_date): | |||
| 167 | 167 | ||
| 168 | 168 | # precompiled regex | |
| 169 | 169 | _re_actor_epoch = re.compile(r'^.+? (.*) (\d+) ([+-]\d+).*$') | |
| 170 | + _re_only_actor = re.compile(r'^.+? (.*)$') | ||
| 170 | 171 | ||
| 171 | 172 | def parse_actor_and_date(line): | |
| 172 | 173 | """Parse out the actor (author or committer) info from a line like:: | |
| 173 | 174 | ||
| 174 | 175 | author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700 | |
| 175 | 176 | ||
| 176 | 177 | :return: [Actor, int_seconds_since_epoch, int_timezone_offset]""" | |
| 178 | + actor, epoch, offset = '', 0, 0 | ||
| 177 | 179 | m = _re_actor_epoch.search(line) | |
| 178 | - actor, epoch, offset = m.groups() | ||
| 180 | + if m: | ||
| 181 | + actor, epoch, offset = m.groups() | ||
| 182 | + else: | ||
| 183 | + m = _re_only_actor.search(line) | ||
| 184 | + actor = m.group(1) if m else line or '' | ||
| 179 | 185 | return (Actor._from_string(actor), int(epoch), utctz_to_altz(offset)) | |
| 180 | - | ||
| 181 | 186 | ||
| 182 | 187 | #} END functions | |
| 183 | 188 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,10 @@ | |||
| 24 | 24 | TagReference | |
| 25 | 25 | ) | |
| 26 | 26 | ||
| 27 | - from git.util import join_path | ||
| 27 | + from git.util import ( | ||
| 28 | + join_path, | ||
| 29 | + finalize_process | ||
| 30 | + ) | ||
| 28 | 31 | from gitdb.util import join | |
| 29 | 32 | ||
| 30 | 33 | import re | |
@@ -58,18 +61,6 @@ def digest_process_messages(fh, progress): | |||
| 58 | 61 | # END while file is not done reading | |
| 59 | 62 | return dropped_lines | |
| 60 | 63 | ||
| 61 | - def finalize_process(proc): | ||
| 62 | - """Wait for the process (clone, fetch, pull or push) and handle its errors accordingly""" | ||
| 63 | - try: | ||
| 64 | - proc.wait() | ||
| 65 | - except GitCommandError,e: | ||
| 66 | - # if a push has rejected items, the command has non-zero return status | ||
| 67 | - # a return status of 128 indicates a connection error - reraise the previous one | ||
| 68 | - if proc.poll() == 128: | ||
| 69 | - raise | ||
| 70 | - pass | ||
| 71 | - # END exception handling | ||
| 72 | - | ||
| 73 | 64 | def add_progress(kwargs, git, progress): | |
| 74 | 65 | """Add the --progress flag to the given kwargs dict if supported by the | |
| 75 | 66 | git command. If the actual progress in the given progress instance is not | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,15 +6,17 @@ | |||
| 6 | 6 | ||
| 7 | 7 | from git.exc import InvalidGitRepositoryError, NoSuchPathError | |
| 8 | 8 | from git.cmd import Git | |
| 9 | - from git.util import Actor | ||
| 9 | + from git.util import ( | ||
| 10 | + Actor, | ||
| 11 | + finalize_process | ||
| 12 | + ) | ||
| 10 | 13 | from git.refs import * | |
| 11 | 14 | from git.index import IndexFile | |
| 12 | 15 | from git.objects import * | |
| 13 | 16 | from git.config import GitConfigParser | |
| 14 | 17 | from git.remote import ( | |
| 15 | 18 | Remote, | |
| 16 | 19 | digest_process_messages, | |
| 17 | - finalize_process, | ||
| 18 | 20 | add_progress | |
| 19 | 21 | ) | |
| 20 | 22 | ||
@@ -540,6 +542,7 @@ def untracked_files(self): | |||
| 540 | 542 | if filename[0] == filename[-1] == '"': | |
| 541 | 543 | filename = filename[1:-1].decode('string_escape') | |
| 542 | 544 | untracked_files.append(filename) | |
| 545 | + finalize_process(proc) | ||
| 543 | 546 | return untracked_files | |
| 544 | 547 | ||
| 545 | 548 | @property | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,7 +227,7 @@ class TestBase(TestCase): | |||
| 227 | 227 | """ | |
| 228 | 228 | ||
| 229 | 229 | @classmethod | |
| 230 | - def setUp(cls): | ||
| 230 | + def setUpClass(cls): | ||
| 231 | 231 | """ | |
| 232 | 232 | Dynamically add a read-only repository to our actual type. This way | |
| 233 | 233 | each test type has its own repository | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,8 @@ | |||
| 2 | 2 | from git.objects.fun import ( | |
| 3 | 3 | traverse_tree_recursive, | |
| 4 | 4 | traverse_trees_recursive, | |
| 5 | - tree_to_stream | ||
| 5 | + tree_to_stream, | ||
| 6 | + tree_entries_from_data | ||
| 6 | 7 | ) | |
| 7 | 8 | ||
| 8 | 9 | from git.index.fun import ( | |
@@ -249,3 +250,7 @@ def test_tree_traversal_single(self): | |||
| 249 | 250 | entries = traverse_tree_recursive(odb, commit.tree.binsha, '') | |
| 250 | 251 | assert entries | |
| 251 | 252 | # END for each commit | |
| 253 | + | ||
| 254 | + def test_tree_entries_from_data(self): | ||
| 255 | + r = tree_entries_from_data(b'100644 \x9f\0aaa') | ||
| 256 | + assert r == [('aaa', 33188, '\x9f')], r | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,8 @@ | |||
| 18 | 18 | class TestGit(TestBase): | |
| 19 | 19 | ||
| 20 | 20 | @classmethod | |
| 21 | - def setUp(cls): | ||
| 22 | - super(TestGit, cls).setUp() | ||
| 21 | + def setUpClass(cls): | ||
| 22 | + super(TestGit, cls).setUpClass() | ||
| 23 | 23 | cls.git = Git(cls.rorepo.working_dir) | |
| 24 | 24 | ||
| 25 | 25 | @patch.object(Git, 'execute') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | 16 | # NOTE: Some of the unused imports might be used/imported by others. | |
| 17 | 17 | # Handle once test-cases are back up and running. | |
| 18 | + from exc import GitCommandError | ||
| 19 | + | ||
| 18 | 20 | from gitdb.util import ( | |
| 19 | 21 | make_sha, | |
| 20 | 22 | LockedFD, | |
@@ -117,6 +119,18 @@ def get_user_id(): | |||
| 117 | 119 | """:return: string identifying the currently active system user as name@node""" | |
| 118 | 120 | return "%s@%s" % (getpass.getuser(), platform.node()) | |
| 119 | 121 | ||
| 122 | + def finalize_process(proc): | ||
| 123 | + """Wait for the process (clone, fetch, pull or push) and handle its errors accordingly""" | ||
| 124 | + try: | ||
| 125 | + proc.wait() | ||
| 126 | + except GitCommandError,e: | ||
| 127 | + # if a push has rejected items, the command has non-zero return status | ||
| 128 | + # a return status of 128 indicates a connection error - reraise the previous one | ||
| 129 | + if proc.poll() == 128: | ||
| 130 | + raise | ||
| 131 | + pass | ||
| 132 | + # END exception handling | ||
| 133 | + | ||
| 120 | 134 | #} END utilities | |
| 121 | 135 | ||
| 122 | 136 | #{ Classes | |
| Back | FazBrowse Home | New Git URL |
0 commit comments