]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/patch-id.c
patch-id: make it stable against hunk reordering
authorMichael S. Tsirkin <mst@redhat.com>
Sun, 27 Apr 2014 18:15:44 +0000 (21:15 +0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Jun 2014 20:09:24 +0000 (13:09 -0700)
commit30e12b924b57b15e707f1749f2e5af15f1c7fe09
treeb1b51fe49bb067dd3d50c1ebd4dc26a3272283ab
parentbb98b01ee8c5c6f66a6d70aa453b70184dd3d96f
patch-id: make it stable against hunk reordering

Patch id changes if users reorder file diffs that make up a patch.

As the result is functionally equivalent, a different patch id is
surprising to many users.
In particular, reordering files using diff -O is helpful to make patches
more readable (e.g. API header diff before implementation diff).

Add an option to change patch-id behaviour making it stable against
these kinds of patch change:
calculate SHA1 hash for each hunk separately and sum all hashes
(using a symmetrical sum) to get patch id

We use a 20byte sum and not xor - since xor would give 0 output
for patches that have two identical diffs, which isn't all that
unlikely (e.g. append the same line in two places).

The new behaviour is enabled
- when patchid.stable is true
- when --stable flag is present

Using a new flag --unstable or setting patchid.stable to false force
the historical behaviour.

In the documentation, clarify that patch ID can now be a sum of hashes,
not a hash.
Document how command line and config options affect the
behaviour.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-patch-id.txt
builtin/patch-id.c