4 static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
6 unsigned char result[20];
12 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))
47 if (!get_sha1_hex(p, n)) {
48 flush_current_id(patchlen, sha1, &ctx);
54 /* Ignore commit comments */
55 if (!patchlen && memcmp(line, "diff ", 5))
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 SHA1_Update(&ctx, line, len);
67 flush_current_id(patchlen, sha1, &ctx);
70 static const char patch_id_usage[] = "git-patch-id < patch";
72 int main(int argc, char **argv)
75 usage(patch_id_usage);