Skip to content

Commit 28c5a85

Browse files
committed
review
- avoid extra calls via _date() in one more case.
1 parent e694e9b commit 28c5a85

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

‎git/_backend.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def object_metadata(command: Any, oid: str, kind: str) -> Any:
245245
else ((data.tagger, result["tagger"]),)
246246
)
247247
for raw, signature in signatures:
248-
# Gix reads a time zone of 0 when other fields follow the date (GIX-34).
249-
if signature is not None and not raw.endswith(b"> " + _date(signature)):
248+
# Gix reads a time zone of 0 with trailing fields (GIX-34); accept either UTC sign.
249+
if signature is not None and not raw.replace(b" -0000", b" +0000").endswith(b"> " + _date(signature)):
250250
raise _Unsupported("signature trailing fields (GIX-34)")
251251
except _Unsupported as exc:
252252
return _fallback(kind + ".decode", str(exc))

‎test/test_commit.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,32 @@ def test_deserialization_reads_date_after_email(self):
671671
key = (kind + ".decode", "CLI: signature trailing fields (GIX-34)")
672672
self.assertEqual(_backend.statistics().get(key, 0), before.get(key, 0) + 1)
673673

674+
def test_deserialization_negative_zero_offset_stays_native(self):
675+
with fixture_repo("commit.sh", "zero-offset") as repo:
676+
root = Path(repo.working_dir).parent
677+
oid = (root / "object-id").read_text().strip()
678+
tag_oid = (root / "tag-id").read_text().strip()
679+
repo.git.fsck("--strict", oid, tag_oid)
680+
self.assertTrue(repo.git.cat_file("-p", tag_oid).split("\n")[3].endswith(" -0000"))
681+
self.assertEqual(
682+
repo.git.show("--no-patch", "--format=%ad%n%cd", "--date=raw", oid, "--"),
683+
"1112591163 +0000\n1112591163 +0000",
684+
)
685+
self.assertEqual(repo.git.for_each_ref("--format=%(taggerdate:raw)", "refs/tags/v1"), "1112591163 +0000")
686+
before = _backend.statistics()
687+
cmt = Commit(repo, bytes.fromhex(oid))
688+
self.assertEqual((cmt.authored_date, cmt.author_tz_offset), (1112591163, 0))
689+
self.assertEqual((cmt.committed_date, cmt.committer_tz_offset), (1112591163, 0))
690+
tag = TagObject(repo, bytes.fromhex(tag_oid))
691+
self.assertEqual((tag.tagged_date, tag.tagger_tz_offset), (1112591163, 0))
692+
if _backend.name == "gix":
693+
after = _backend.statistics()
694+
for kind in ("commit", "tag"):
695+
key = (kind + ".decode", "native")
696+
self.assertEqual(after.get(key, 0), before.get(key, 0) + 1)
697+
key = ("Git.execute", "CLI process")
698+
self.assertEqual(after.get(key, 0), before.get(key, 0))
699+
674700
def test_identity_cannot_alter_headers(self):
675701
"""A name or email must not add header lines or present another identity."""
676702
with fixture_repo("commit.sh", "tree", write=True) as rw_repo:

‎tests/fixtures/commit.sh‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ case "$1" in
4747
raw)
4848
git hash-object --literally -w -t commit "$2" > ../object-id
4949
;;
50-
trailing-date)
50+
trailing-date|zero-offset)
51+
date='1112591163 +0200 1700000000 -0500'
52+
if [ "$1" = zero-offset ]; then date='1112591163 -0000'; fi
5153
tree=$(git mktree </dev/null)
5254
{
5355
printf 'tree %s\n' "$tree"
54-
printf 'author A <a@example.com> 1112591163 +0200 1700000000 -0500\n'
55-
printf 'committer C <c@example.com> 1112591163 +0200 1700000000 -0500\n'
56+
printf 'author A <a@example.com> %s\n' "$date"
57+
printf 'committer C <c@example.com> %s\n' "$date"
5658
printf '\nmessage\n'
5759
} | git hash-object --literally -w -t commit --stdin > ../object-id
5860
{
5961
printf 'object %s\ntype commit\ntag v1\n' "$(cat ../object-id)"
60-
printf 'tagger T <t@example.com> 1112591163 +0200 1700000000 -0500\n'
62+
printf 'tagger T <t@example.com> %s\n' "$date"
6163
printf '\nmessage\n'
6264
} | git hash-object --literally -w -t tag --stdin > ../tag-id
6365
git update-ref refs/tags/v1 "$(cat ../tag-id)"

0 commit comments

Comments
 (0)