]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/patch-id' into maint-2.46
authorJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 18:02:16 +0000 (11:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 18:02:16 +0000 (11:02 -0700)
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. <Zqh2T_2RLt0SeKF7@tanuki>

* 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

1  2 
builtin/patch-id.c
t/t4204-patch-id.sh

index d790ae6354b415a1101b8b1de3d3fe5d7bbf27c5,f2e8feb6d3dff232882c842d5be27576d0bac534..35c1179f7e94ba055e40f45c775bcda008632068
@@@ -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);
  
-       generate_id_list(opts ? opts > 1 : config.stable,
-                        opts ? opts == 3 : config.verbatim);
 +      /*
 +       * 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);
 +
+       if (opts ? opts > 1 : config.stable)
+               flags |= GOPID_STABLE;
+       if (opts ? opts == 3 : config.verbatim)
+               flags |= GOPID_VERBATIM;
+       generate_id_list(flags);
        return 0;
  }
Simple merge