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 static void generate_id_list(void)
33 static unsigned char sha1
[20];
34 static char line
[1000];
39 while (fgets(line
, sizeof(line
), stdin
) != NULL
) {
44 if (!memcmp(line
, "diff-tree ", 10))
46 else if (!memcmp(line
, "commit ", 7))
49 if (!get_sha1_hex(p
, n
)) {
50 flush_current_id(patchlen
, sha1
, &ctx
);
56 /* Ignore commit comments */
57 if (!patchlen
&& memcmp(line
, "diff ", 5))
60 /* Ignore git-diff index header */
61 if (!memcmp(line
, "index ", 6))
64 /* Ignore line numbers when computing the SHA1 of the patch */
65 if (!memcmp(line
, "@@ -", 4))
68 /* Compute the sha without whitespace */
69 len
= remove_space(line
);
71 git_SHA1_Update(&ctx
, line
, len
);
73 flush_current_id(patchlen
, sha1
, &ctx
);
76 static const char patch_id_usage
[] = "git patch-id < patch";
78 int cmd_patch_id(int argc
, const char **argv
, const char *prefix
)
81 usage(patch_id_usage
);