diff --git a/hgitaly/git.py b/hgitaly/git.py index b7902fb8dc5b9ebb73fd5e466cf475417f992597_aGdpdGFseS9naXQucHk=..5cc001bbfa070d471e1da1de3d5be5ce8e46b5ca_aGdpdGFseS9naXQucHk= 100644 --- a/hgitaly/git.py +++ b/hgitaly/git.py @@ -14,4 +14,6 @@ # from `sha1-file.c` in Git 2.28 sources # we're not dealing for now with the fact that there will be # two kinds of OIDs with SHA-1 and SHA-256 soon. + +# The Git tree object hash that corresponds to an empty tree (directory) EMPTY_TREE_OID = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' @@ -17,4 +19,6 @@ EMPTY_TREE_OID = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' + +# The Git blob object hash that corresponds to an empty blob (file) EMPTY_BLOB_OID = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' OBJECT_MODE_LINK = 0o120000 # symlink to file or directory diff --git a/hgitaly/service/diff.py b/hgitaly/service/diff.py index b7902fb8dc5b9ebb73fd5e466cf475417f992597_aGdpdGFseS9zZXJ2aWNlL2RpZmYucHk=..5cc001bbfa070d471e1da1de3d5be5ce8e46b5ca_aGdpdGFseS9zZXJ2aWNlL2RpZmYucHk= 100644 --- a/hgitaly/service/diff.py +++ b/hgitaly/service/diff.py @@ -213,4 +213,5 @@ # For explicitness, let's instantiate a new BytesIO obj for each file self.curr_diff.patch = BytesIO() for diffhunk in iter_file_hunks: + self.curr_diff.patch.write(diffhunk) if diffhunk.startswith(b'@@'): @@ -216,8 +217,7 @@ if diffhunk.startswith(b'@@'): - newdiffhunk = diffhunk.split(b'\n', 1)[-1] - lines = newdiffhunk.splitlines(True) - self.curr_diff.patch.write(diffhunk) - self.curr_diff.bytes_count += len(newdiffhunk) + diffhunk = diffhunk.split(b'\n', 1)[-1] + lines = diffhunk.splitlines(True) + self.curr_diff.bytes_count += len(diffhunk) self.curr_diff.line_count += len(lines) if self.limits.collapse_diffs: diff --git a/hgitaly/tests/test_diff.py b/hgitaly/tests/test_diff.py new file mode 100644 index 0000000000000000000000000000000000000000..5cc001bbfa070d471e1da1de3d5be5ce8e46b5ca_aGdpdGFseS90ZXN0cy90ZXN0X2RpZmYucHk= --- /dev/null +++ b/hgitaly/tests/test_diff.py @@ -0,0 +1,17 @@ +# Copyright 2021 Georges Racinet <georges.racinet@octobus.net> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from hgitaly.service.diff import ( + CurrDiff, + Limits, + Parser, +) + + +def test_parser_corner_cases(): + parser = Parser(Limits(), CurrDiff()) + parser.parse([b""])