60
61
/*
62
* flag bits to control get_one_patchid()'s behaviour.
63
+ *
64
+ * STABLE/VERBATIM are given from the command line option as
65
+ * --stable/--verbatim. FIND_HEADER conveys the internal state
66
+ * maintained by the caller to allow the function to avoid mistaking
67
+ * lines of log message before seeing the "diff" part as the beginning
68
+ * of the next patch.
69
*/
70
enum {
71
GOPID_STABLE = (1<<0), /* --stable */
72
GOPID_VERBATIM = (1<<1), /* --verbatim */
73
+ GOPID_FIND_HEADER = (1<<2), /* stop at the beginning of patch message */
74
};
75
76
static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
78
{
79
int stable = flags & GOPID_STABLE;
80
int verbatim = flags & GOPID_VERBATIM;
81
+ int find_header = flags & GOPID_FIND_HEADER;
82
int patchlen = 0, found_next = 0;
83
int before = -1, after = -1;
84
int diff_is_binary = 0;
94
int len;
95
96
/*
89
- * If we see a line that begins with "<object name>",
90
- * "commit <object name>" or "From <object name>", it is
91
- * the beginning of a patch. Return to the caller, as
92
- * we are done with the one we have been processing.
97
+ * The caller hasn't seen us find a patch header and
98
+ * return to it, or we have started processing patch
99
+ * and may encounter the beginning of the next patch.
100
*/
94
- if (skip_prefix(line, "commit ", &p))
95
- ;
96
- else if (skip_prefix(line, "From ", &p))
97
- ;
98
- if (!get_oid_hex(p, next_oid)) {
99
- if (verbatim)
100
- the_hash_algo->update_fn(&ctx, line, strlen(line));
101
- found_next = 1;
102
- break;
101
+ if (find_header) {
102
+ /*
103
+ * If we see a line that begins with "<object name>",
104
+ * "commit <object name>" or "From <object name>", it is
105
+ * the beginning of a patch. Return to the caller, as
106
+ * we are done with the one we have been processing.
107
+ */
108
+ if (skip_prefix(line, "commit ", &p))
109
+ ;
110
+ else if (skip_prefix(line, "From ", &p))
111
+ ;
112
+ if (!get_oid_hex(p, next_oid)) {
113
+ if (verbatim)
114
+ the_hash_algo->update_fn(&ctx, line, strlen(line));
115
+ found_next = 1;
116
+ break;
117
+ }
118
}
119
120
/* Ignore commit comments */
121
if (!patchlen && !starts_with(line, "diff "))
122
continue;
123
124
+ /*
125
+ * We are past the commit log message. Prepare to
126
+ * stop at the beginning of the next patch header.
127
+ */
128
+ find_header = 1;
129
+
130
/* Parsing diff header? */
131
if (before == -1) {
132
if (starts_with(line, "GIT binary patch") ||
222
struct strbuf line_buf = STRBUF_INIT;
223
224
oidclr(&oid);
225
+ flags |= GOPID_FIND_HEADER;
226
while (!feof(stdin)) {
227
patchlen = get_one_patchid(&n, &result, &line_buf, flags);
228
if (patchlen)
229
flush_current_id(&oid, &result);
230
oidcpy(&oid, &n);
231
+ flags &= ~GOPID_FIND_HEADER;
232
}
233
strbuf_release(&line_buf);
234
}