3 static void flush_current_id(int patchlen
, unsigned char *id
, git_SHA_CTX
*c
)
5 unsigned char result
[20];
11 git_SHA1_Final(result
, c
);
12 memcpy(name
, sha1_to_hex(id
), 41);
13 printf("%s %s\n", sha1_to_hex(result
), name
);
17 static int remove_space(char *line
)
23 while ((c
= *src
++) != '\0') {
30 static void generate_id_list(void)
32 static unsigned char sha1
[20];
33 static char line
[1000];
38 while (fgets(line
, sizeof(line
), stdin
) != NULL
) {
43 if (!memcmp(line
, "diff-tree ", 10))
45 else if (!memcmp(line
, "commit ", 7))
48 if (!get_sha1_hex(p
, n
)) {
49 flush_current_id(patchlen
, sha1
, &ctx
);
55 /* Ignore commit comments */
56 if (!patchlen
&& memcmp(line
, "diff ", 5))
59 /* Ignore git-diff index header */
60 if (!memcmp(line
, "index ", 6))
63 /* Ignore line numbers when computing the SHA1 of the patch */
64 if (!memcmp(line
, "@@ -", 4))
67 /* Compute the sha without whitespace */
68 len
= remove_space(line
);
70 git_SHA1_Update(&ctx
, line
, len
);
72 flush_current_id(patchlen
, sha1
, &ctx
);
75 static const char patch_id_usage
[] = "git-patch-id < patch";
77 int main(int argc
, char **argv
)
80 usage(patch_id_usage
);