MCPcopy Create free account
hub / github.com/git/git / get_one_patchid

Function get_one_patchid

builtin/patch-id.c:66–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66static size_t get_one_patchid(struct object_id *next_oid, struct object_id *result,
67 struct strbuf *line_buf, int stable, int verbatim)
68{
69 size_t patchlen = 0;
70 int found_next = 0;
71 int before = -1, after = -1;
72 int diff_is_binary = 0;
73 char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1];
74 struct git_hash_ctx ctx;
75
76 the_hash_algo->init_fn(&ctx);
77 oidclr(result, the_repository->hash_algo);
78
79 while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
80 char *line = line_buf->buf;
81 const char *p = line;
82 size_t len;
83
84 /* Possibly skip over the prefix added by "log" or "format-patch" */
85 if (!skip_prefix(line, "commit ", &p) &&
86 !skip_prefix(line, "From ", &p) &&
87 starts_with(line, "\\ ") && 12 < strlen(line)) {
88 if (verbatim)
89 git_hash_update(&ctx, line, strlen(line));
90 continue;
91 }
92
93 if (!get_oid_hex(p, next_oid)) {
94 found_next = 1;
95 break;
96 }
97
98 /* Ignore commit comments */
99 if (!patchlen && !starts_with(line, "diff "))
100 continue;
101
102 /* Parsing diff header? */
103 if (before == -1) {
104 if (starts_with(line, "GIT binary patch") ||
105 starts_with(line, "Binary files")) {
106 diff_is_binary = 1;
107 before = 0;
108 git_hash_update(&ctx, pre_oid_str,
109 strlen(pre_oid_str));
110 git_hash_update(&ctx, post_oid_str,
111 strlen(post_oid_str));
112 if (stable)
113 flush_one_hunk(result, &ctx);
114 continue;
115 } else if (skip_prefix(line, "index ", &p)) {
116 char *oid1_end = strstr(line, "..");
117 char *oid2_end = NULL;
118 if (oid1_end)
119 oid2_end = strstr(oid1_end, " ");
120 if (!oid2_end)
121 oid2_end = line + strlen(line) - 1;
122 if (oid1_end != NULL && oid2_end != NULL) {
123 *oid1_end = *oid2_end = '\0';

Callers 1

generate_id_listFunction · 0.85

Calls 8

oidclrFunction · 0.85
strbuf_getwholelineFunction · 0.85
starts_withFunction · 0.85
git_hash_updateFunction · 0.85
get_oid_hexFunction · 0.85
flush_one_hunkFunction · 0.85
scan_hunk_headerFunction · 0.85
remove_spaceFunction · 0.70

Tested by

no test coverage detected