Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-06-13 23:18:46 +0300
committerJunio C Hamano <gitster@pobox.com>2019-06-13 23:18:46 +0300
commit8202d12fca5d482640a51c663d4d556c46dbc6b8 (patch)
treef5440c439b27b06e00f5d0a5229e42bf7131c20e /diff.c
parentcf3269fba816d9b216b8b0d6e95ca6a345158de5 (diff)
parenta8f6855f48fd474719e92eecc66c29a28fdc0f46 (diff)
Merge branch 'sb/format-patch-base-patch-id-fix'
The "--base" option of "format-patch" computed the patch-ids for prerequisite patches in an unstable way, which has been updated to compute in a way that is compatible with "git patch-id --stable". * sb/format-patch-base-patch-id-fix: format-patch: make --base patch-id output stable format-patch: inform user that patch-id generation is unstable
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/diff.c b/diff.c
index a654d46f6a..1ee04e321b 100644
--- a/diff.c
+++ b/diff.c
@@ -5990,6 +5990,22 @@ static int remove_space(char *line, int len)
return dst - line;
}
+void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
+{
+ unsigned char hash[GIT_MAX_RAWSZ];
+ unsigned short carry = 0;
+ int i;
+
+ git_SHA1_Final(hash, ctx);
+ git_SHA1_Init(ctx);
+ /* 20-byte sum, with carry */
+ for (i = 0; i < GIT_SHA1_RAWSZ; ++i) {
+ carry += result->hash[i] + hash[i];
+ result->hash[i] = carry;
+ carry >>= 8;
+ }
+}
+
static void patch_id_consume(void *priv, char *line, unsigned long len)
{
struct patch_id_t *data = priv;
@@ -6014,8 +6030,8 @@ static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)
git_SHA1_Update(ctx, buf, len);
}
-/* returns 0 upon success, and writes result into sha1 */
-static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
+/* returns 0 upon success, and writes result into oid */
+static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only, int stable)
{
struct diff_queue_struct *q = &diff_queued_diff;
int i;
@@ -6025,6 +6041,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
git_SHA1_Init(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
+ oidclr(oid);
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;
@@ -6100,17 +6117,22 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
patch_id_consume, &data, &xpp, &xecfg))
return error("unable to generate patch-id diff for %s",
p->one->path);
+
+ if (stable)
+ flush_one_hunk(oid, &ctx);
}
- git_SHA1_Final(oid->hash, &ctx);
+ if (!stable)
+ git_SHA1_Final(oid->hash, &ctx);
+
return 0;
}
-int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
+int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only, int stable)
{
struct diff_queue_struct *q = &diff_queued_diff;
int i;
- int result = diff_get_patch_id(options, oid, diff_header_only);
+ int result = diff_get_patch_id(options, oid, diff_header_only, stable);
for (i = 0; i < q->nr; i++)
diff_free_filepair(q->queue[i]);