builtin: patch-id: fix patch-id with binary diffs
commit0df19eb9d905ff9b6115139106d98d8f0a8a9046
authorJerry Zhang <Jerry@skydio.com>
Mon, 24 Oct 2022 20:07:41 +0000 (24 20:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Oct 2022 22:44:19 +0000 (24 15:44 -0700)
treee2cdfe24c753499b667fabf17b5e344411d3f173
parent51276c1832d64d3b8f4dfc06c3ef21bf74f1916e
builtin: patch-id: fix patch-id with binary diffs

"git patch-id" currently doesn't produce correct output if the
incoming diff has any binary files. Add logic to get_one_patchid
to handle the different possible styles of binary diff. This
attempts to keep resulting patch-ids identical to what would be
produced by the counterpart logic in diff.c, that is it produces
the id by hashing the a and b oids in succession.

In general we handle binary diffs by first caching the object ids from
the "index" line and using those if we then find an indication
that the diff is binary.

The input could contain patches generated with "git diff --binary". This
currently breaks the parse logic and results in multiple patch-ids
output for a single commit. Here we have to skip the contents of the
patch itself since those do not go into the patch id. --binary
implies --full-index so the object ids are always available.

When the diff is generated with --full-index there is no patch content
to skip over.

When a diff is generated without --full-index or --binary, it will
contain abbreviated object ids. This will still result in a sufficiently
unique patch-id when hashed, but does not match internal patch id
output. We'll call this ok for now as we already need specialized
arguments to diff in order to match internal patch id (namely -U3).

Signed-off-by: Jerry Zhang <Jerry@skydio.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/patch-id.c
t/t4204-patch-id.sh