From: Junio C Hamano Date: Thu, 12 Sep 2024 18:02:16 +0000 (-0700) Subject: Merge branch 'jc/patch-id' into maint-2.46 X-Git-Tag: v2.46.1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41c952ebacf7e3369e7bee721f768114d65e50c4;p=thirdparty%2Fgit.git Merge branch 'jc/patch-id' into maint-2.46 The patch parser in "git patch-id" has been tightened to avoid getting confused by lines that look like a patch header in the log message. cf. * jc/patch-id: patch-id: tighten code to detect the patch header patch-id: rewrite code that detects the beginning of a patch patch-id: make get_one_patchid() more extensible patch-id: call flush_current_id() only when needed t4204: patch-id supports various input format --- 41c952ebacf7e3369e7bee721f768114d65e50c4 diff --cc builtin/patch-id.c index d790ae6354,f2e8feb6d3..35c1179f7e --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@@ -5,12 -5,10 +5,11 @@@ #include "hash.h" #include "hex.h" #include "parse-options.h" +#include "setup.h" - static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result) + static void flush_current_id(struct object_id *id, struct object_id *result) { - if (patchlen) - printf("%s %s\n", oid_to_hex(result), oid_to_hex(id)); + printf("%s %s\n", oid_to_hex(result), oid_to_hex(id)); } static int remove_space(char *line) @@@ -179,11 -221,14 +222,14 @@@ static void generate_id_list(unsigned f int patchlen; struct strbuf line_buf = STRBUF_INIT; - oidclr(&oid); + oidclr(&oid, the_repository->hash_algo); + flags |= GOPID_FIND_HEADER; while (!feof(stdin)) { - patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim); - flush_current_id(patchlen, &oid, &result); + patchlen = get_one_patchid(&n, &result, &line_buf, flags); + if (patchlen) + flush_current_id(&oid, &result); oidcpy(&oid, &n); + flags &= ~GOPID_FIND_HEADER; } strbuf_release(&line_buf); } @@@ -238,19 -284,11 +285,23 @@@ int cmd_patch_id(int argc, const char * argc = parse_options(argc, argv, prefix, builtin_patch_id_options, patch_id_usage, 0); + /* + * We rely on `the_hash_algo` to compute patch IDs. This is dubious as + * it means that the hash algorithm now depends on the object hash of + * the repository, even though git-patch-id(1) clearly defines that + * patch IDs always use SHA1. + * + * NEEDSWORK: This hack should be removed in favor of converting + * the code that computes patch IDs to always use SHA1. + */ + if (!the_hash_algo) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + - generate_id_list(opts ? opts > 1 : config.stable, - opts ? opts == 3 : config.verbatim); + if (opts ? opts > 1 : config.stable) + flags |= GOPID_STABLE; + if (opts ? opts == 3 : config.verbatim) + flags |= GOPID_VERBATIM; + generate_id_list(flags); + return 0; }