4 static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
6 unsigned char result[20];
12 git_SHA1_Final(result, c);
13 memcpy(name, sha1_to_hex(id), 41);
14 printf("%s %s\n", sha1_to_hex(result), name);
18 static int remove_space(char *line)
24 while ((c = *src++) != '\0') {
31 int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
33 static char line[1000];
34 int patchlen = 0, found_next = 0;
36 while (fgets(line, sizeof(line), stdin) != NULL) {
40 if (!memcmp(line, "diff-tree ", 10))
42 else if (!memcmp(line, "commit ", 7))
45 if (!get_sha1_hex(p, next_sha1)) {
50 /* Ignore commit comments */
51 if (!patchlen && memcmp(line, "diff ", 5))
54 /* Ignore git-diff index header */
55 if (!memcmp(line, "index ", 6))
58 /* Ignore line numbers when computing the SHA1 of the patch */
59 if (!memcmp(line, "@@ -", 4))
62 /* Compute the sha without whitespace */
63 len = remove_space(line);
65 git_SHA1_Update(ctx, line, len);
74 static void generate_id_list(void)
76 unsigned char sha1[20], n[20];
82 while (!feof(stdin)) {
83 patchlen = get_one_patchid(n, &ctx);
84 flush_current_id(patchlen, sha1, &ctx);
89 static const char patch_id_usage[] = "git patch-id < patch";
91 int cmd_patch_id(int argc, const char **argv, const char *prefix)
94 usage(patch_id_usage);