Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 871 lines (763 sloc) 20.154 kB
8f1d2e6 [PATCH] Compilation: zero-length array declaration.
Junio C Hamano authored
1 #include "cache.h"
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
2 #include "tag.h"
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
3 #include "commit.h"
ed09aef @dscho support fetching into a shallow repository
dscho authored
4 #include "pkt-line.h"
52883fb Teach log family --encoding
Junio C Hamano authored
5 #include "utf8.h"
199c45b Add %m to '--pretty=format:'
Junio C Hamano authored
6 #include "diff.h"
7 #include "revision.h"
a97a746 @dscho Introduce commit notes
dscho authored
8 #include "notes.h"
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
9
60ab26d [PATCH] Avoid wasting memory in git-rev-list
Linus Torvalds authored
10 int save_commit_buffer = 1;
11
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
12 const char *commit_type = "commit";
13
f76412e [PATCH] Add 'git show-branch'.
Junio C Hamano authored
14 static struct commit *check_commit(struct object *obj,
15 const unsigned char *sha1,
16 int quiet)
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
17 {
1974632 Remove TYPE_* constant macros and use object_type enums consistently.
Linus Torvalds authored
18 if (obj->type != OBJ_COMMIT) {
f76412e [PATCH] Add 'git show-branch'.
Junio C Hamano authored
19 if (!quiet)
20 error("Object %s is a %s, not a commit",
885a86a Shrink "struct object" a bit
Linus Torvalds authored
21 sha1_to_hex(sha1), typename(obj->type));
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
22 return NULL;
23 }
24 return (struct commit *) obj;
25 }
26
f76412e [PATCH] Add 'git show-branch'.
Junio C Hamano authored
27 struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
28 int quiet)
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
29 {
9534f40 Be careful when dereferencing tags.
Junio C Hamano authored
30 struct object *obj = deref_tag(parse_object(sha1), NULL, 0);
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
31
32 if (!obj)
33 return NULL;
f76412e [PATCH] Add 'git show-branch'.
Junio C Hamano authored
34 return check_commit(obj, sha1, quiet);
35 }
36
37 struct commit *lookup_commit_reference(const unsigned char *sha1)
38 {
39 return lookup_commit_reference_gently(sha1, 0);
961784e commit: add "lookup_commit_reference()" helper function
Linus Torvalds authored
40 }
41
5d6ccf5 [PATCH] Anal retentive 'const unsigned char *sha1'
Jason McMullan authored
42 struct commit *lookup_commit(const unsigned char *sha1)
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
43 {
44 struct object *obj = lookup_object(sha1);
100c5f3 @torvalds Clean up object creation to use more common code
torvalds authored
45 if (!obj)
46 return create_object(sha1, OBJ_COMMIT, alloc_commit_node());
d1af002 [PATCH] delta check
Nicolas Pitre authored
47 if (!obj->type)
1974632 Remove TYPE_* constant macros and use object_type enums consistently.
Linus Torvalds authored
48 obj->type = OBJ_COMMIT;
f76412e [PATCH] Add 'git show-branch'.
Junio C Hamano authored
49 return check_commit(obj, sha1, 0);
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
50 }
51
a6fa599 @patnotz commit: helper methods to reduce redundant blocks of code
patnotz authored
52 struct commit *lookup_commit_reference_by_name(const char *name)
53 {
54 unsigned char sha1[20];
55 struct commit *commit;
56
57 if (get_sha1(name, sha1))
58 return NULL;
59 commit = lookup_commit_reference(sha1);
60 if (!commit || parse_commit(commit))
61 return NULL;
62 return commit;
63 }
64
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
65 static unsigned long parse_commit_date(const char *buf, const char *tail)
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
66 {
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
67 const char *dateptr;
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
68
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
69 if (buf + 6 >= tail)
70 return 0;
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
71 if (memcmp(buf, "author", 6))
72 return 0;
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
73 while (buf < tail && *buf++ != '\n')
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
74 /* nada */;
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
75 if (buf + 9 >= tail)
76 return 0;
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
77 if (memcmp(buf, "committer", 9))
78 return 0;
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
79 while (buf < tail && *buf++ != '>')
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
80 /* nada */;
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
81 if (buf >= tail)
82 return 0;
83 dateptr = buf;
84 while (buf < tail && *buf++ != '\n')
85 /* nada */;
86 if (buf >= tail)
87 return 0;
88 /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
f290974 Allow the Unix epoch to be a valid commit date
Eric Wong authored
89 return strtoul(dateptr, NULL, 10);
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
90 }
91
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
92 static struct commit_graft **commit_graft;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
93 static int commit_graft_alloc, commit_graft_nr;
94
95 static int commit_graft_pos(const unsigned char *sha1)
96 {
97 int lo, hi;
98 lo = 0;
99 hi = commit_graft_nr;
100 while (lo < hi) {
101 int mi = (lo + hi) / 2;
102 struct commit_graft *graft = commit_graft[mi];
a89fccd Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
David Rientjes authored
103 int cmp = hashcmp(sha1, graft->sha1);
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
104 if (!cmp)
105 return mi;
106 if (cmp < 0)
107 hi = mi;
108 else
109 lo = mi + 1;
110 }
111 return -lo - 1;
112 }
113
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
114 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
115 {
116 int pos = commit_graft_pos(graft->sha1);
a6080a0 @gitster War on whitespace
gitster authored
117
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
118 if (0 <= pos) {
119 if (ignore_dups)
120 free(graft);
121 else {
122 free(commit_graft[pos]);
123 commit_graft[pos] = graft;
124 }
125 return 1;
126 }
127 pos = -pos - 1;
128 if (commit_graft_alloc <= ++commit_graft_nr) {
129 commit_graft_alloc = alloc_nr(commit_graft_alloc);
130 commit_graft = xrealloc(commit_graft,
131 sizeof(*commit_graft) *
132 commit_graft_alloc);
133 }
134 if (pos < commit_graft_nr)
135 memmove(commit_graft + pos + 1,
136 commit_graft + pos,
137 (commit_graft_nr - pos - 1) *
138 sizeof(*commit_graft));
139 commit_graft[pos] = graft;
140 return 0;
141 }
142
143 struct commit_graft *read_graft_line(char *buf, int len)
144 {
145 /* The format is just "Commit Parent1 Parent2 ...\n" */
146 int i;
147 struct commit_graft *graft = NULL;
148
fe0a3cb @gitster info/grafts: allow trailing whitespaces at the end of line
gitster authored
149 while (len && isspace(buf[len-1]))
150 buf[--len] = '\0';
360204c @ydirson Allow empty lines in info/grafts
ydirson authored
151 if (buf[0] == '#' || buf[0] == '\0')
5bc4ce5 reading $GIT_DIR/info/graft - skip comments correctly.
Junio C Hamano authored
152 return NULL;
df5d43b @ralfth commit.c: Remove backward goto in read_craft_line()
ralfth authored
153 if ((len + 1) % 41)
154 goto bad_graft_data;
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
155 i = (len + 1) / 41 - 1;
156 graft = xmalloc(sizeof(*graft) + 20 * i);
157 graft->nr_parent = i;
158 if (get_sha1_hex(buf, graft->sha1))
159 goto bad_graft_data;
160 for (i = 40; i < len; i += 41) {
161 if (buf[i] != ' ')
162 goto bad_graft_data;
163 if (get_sha1_hex(buf + i + 1, graft->parent[i/41]))
164 goto bad_graft_data;
165 }
166 return graft;
df5d43b @ralfth commit.c: Remove backward goto in read_craft_line()
ralfth authored
167
168 bad_graft_data:
169 error("bad graft data: %s", buf);
170 free(graft);
171 return NULL;
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
172 }
173
c5ae643 commit.c: make read_graft_file() static
Nanako Shiraishi authored
174 static int read_graft_file(const char *graft_file)
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
175 {
176 FILE *fp = fopen(graft_file, "r");
177 char buf[1024];
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
178 if (!fp)
179 return -1;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
180 while (fgets(buf, sizeof(buf), fp)) {
181 /* The format is just "Commit Parent1 Parent2 ...\n" */
182 int len = strlen(buf);
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
183 struct commit_graft *graft = read_graft_line(buf, len);
5bc4ce5 reading $GIT_DIR/info/graft - skip comments correctly.
Junio C Hamano authored
184 if (!graft)
185 continue;
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
186 if (register_commit_graft(graft, 1))
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
187 error("duplicate graft data: %s", buf);
188 }
189 fclose(fp);
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
190 return 0;
191 }
192
193 static void prepare_commit_graft(void)
194 {
195 static int commit_graft_prepared;
196 char *graft_file;
197
198 if (commit_graft_prepared)
199 return;
200 graft_file = get_graft_file();
201 read_graft_file(graft_file);
ed09aef @dscho support fetching into a shallow repository
dscho authored
202 /* make sure shallows are read */
203 is_repository_shallow();
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
204 commit_graft_prepared = 1;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
205 }
206
4516338 builtin-fsck: reports missing parent commits
Martin Koegler authored
207 struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
208 {
209 int pos;
5040f17 blame -S <ancestry-file>
Junio C Hamano authored
210 prepare_commit_graft();
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
211 pos = commit_graft_pos(sha1);
212 if (pos < 0)
213 return NULL;
214 return commit_graft[pos];
215 }
216
09d4664 @pclouds Add for_each_commit_graft() to iterate all grafts
pclouds authored
217 int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
ed09aef @dscho support fetching into a shallow repository
dscho authored
218 {
09d4664 @pclouds Add for_each_commit_graft() to iterate all grafts
pclouds authored
219 int i, ret;
220 for (i = ret = 0; i < commit_graft_nr && !ret; i++)
221 ret = fn(commit_graft[i], cb_data);
222 return ret;
ed09aef @dscho support fetching into a shallow repository
dscho authored
223 }
224
f53514b @dscho allow deepening of a shallow repository
dscho authored
225 int unregister_shallow(const unsigned char *sha1)
226 {
227 int pos = commit_graft_pos(sha1);
228 if (pos < 0)
229 return -1;
230 if (pos + 1 < commit_graft_nr)
65d41d4 @peff fix memcpy of overlapping area
peff authored
231 memmove(commit_graft + pos, commit_graft + pos + 1,
f53514b @dscho allow deepening of a shallow repository
dscho authored
232 sizeof(struct commit_graft *)
233 * (commit_graft_nr - pos - 1));
234 commit_graft_nr--;
235 return 0;
236 }
237
cf7b1ca @pclouds Add const to parse_{commit,tag}_buffer()
pclouds authored
238 int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size)
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
239 {
cf7b1ca @pclouds Add const to parse_{commit,tag}_buffer()
pclouds authored
240 const char *tail = buffer;
241 const char *bufptr = buffer;
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
242 unsigned char parent[20];
6c88be1 Keep the parents in order when parsing commits
Linus Torvalds authored
243 struct commit_list **pptr;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
244 struct commit_graft *graft;
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
245
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
246 if (item->object.parsed)
247 return 0;
248 item->object.parsed = 1;
3b44f15 connect.c: check the commit buffer boundary while parsing.
Junio C Hamano authored
249 tail += size;
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
250 if (tail <= bufptr + 46 || memcmp(bufptr, "tree ", 5) || bufptr[45] != '\n')
f7cc77d Make "parse_commit()" be a lot more careful
Linus Torvalds authored
251 return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
252 if (get_sha1_hex(bufptr + 5, parent) < 0)
bd2afde Give no terminating LF to error() function.
Junio C Hamano authored
253 return error("bad tree pointer in commit %s",
254 sha1_to_hex(item->object.sha1));
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
255 item->tree = lookup_tree(parent);
256 bufptr += 46; /* "tree " + "hex sha1" + "\n" */
6c88be1 Keep the parents in order when parsing commits
Linus Torvalds authored
257 pptr = &item->parents;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
258
259 graft = lookup_commit_graft(item->object.sha1);
3b44f15 connect.c: check the commit buffer boundary while parsing.
Junio C Hamano authored
260 while (bufptr + 48 < tail && !memcmp(bufptr, "parent ", 7)) {
f7cc77d Make "parse_commit()" be a lot more careful
Linus Torvalds authored
261 struct commit *new_parent;
262
3b44f15 connect.c: check the commit buffer boundary while parsing.
Junio C Hamano authored
263 if (tail <= bufptr + 48 ||
264 get_sha1_hex(bufptr + 7, parent) ||
265 bufptr[47] != '\n')
f7cc77d Make "parse_commit()" be a lot more careful
Linus Torvalds authored
266 return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
267 bufptr += 48;
7f3140c @dscho git repack: keep commits hidden by a graft
dscho authored
268 /*
269 * The clone is shallow if nr_parent < 0, and we must
270 * not traverse its real parents even when we unhide them.
271 */
272 if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
273 continue;
f7cc77d Make "parse_commit()" be a lot more careful
Linus Torvalds authored
274 new_parent = lookup_commit(parent);
39468de Remove unused code in parse_commit_buffer()
Miklos Vajna authored
275 if (new_parent)
6c88be1 Keep the parents in order when parsing commits
Linus Torvalds authored
276 pptr = &commit_list_insert(new_parent, pptr)->next;
5da5c8f Teach parse_commit_buffer about grafting.
Junio C Hamano authored
277 }
278 if (graft) {
279 int i;
280 struct commit *new_parent;
281 for (i = 0; i < graft->nr_parent; i++) {
282 new_parent = lookup_commit(graft->parent[i]);
283 if (!new_parent)
284 continue;
285 pptr = &commit_list_insert(new_parent, pptr)->next;
286 }
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
287 }
0a61779 parse_commit_buffer: tighten checks while parsing
Martin Koegler authored
288 item->date = parse_commit_date(bufptr, tail);
27dedf0 GIT 0.99.9j aka 1.0rc3
Junio C Hamano authored
289
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
290 return 0;
291 }
292
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
293 int parse_commit(struct commit *item)
294 {
21666f1 convert object type handling from a string to a number
Nicolas Pitre authored
295 enum object_type type;
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
296 void *buffer;
297 unsigned long size;
298 int ret;
299
9786f68 parse_commit: don't fail, if object is NULL
Martin Koegler authored
300 if (!item)
301 return -1;
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
302 if (item->object.parsed)
303 return 0;
21666f1 convert object type handling from a string to a number
Nicolas Pitre authored
304 buffer = read_sha1_file(item->object.sha1, &type, &size);
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
305 if (!buffer)
306 return error("Could not read %s",
307 sha1_to_hex(item->object.sha1));
21666f1 convert object type handling from a string to a number
Nicolas Pitre authored
308 if (type != OBJ_COMMIT) {
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
309 free(buffer);
310 return error("Object %s not a commit",
311 sha1_to_hex(item->object.sha1));
312 }
313 ret = parse_commit_buffer(item, buffer, size);
60ab26d [PATCH] Avoid wasting memory in git-rev-list
Linus Torvalds authored
314 if (save_commit_buffer && !ret) {
3ff1fbb commit: save the commit buffer off when parsing a commit
Linus Torvalds authored
315 item->buffer = buffer;
316 return 0;
317 }
bd2c39f [PATCH] don't load and decompress objects twice with parse_object()
Nicolas Pitre authored
318 free(buffer);
319 return ret;
320 }
321
11af2aa @chriscool revert: refactor code to find commit subject in find_commit_subject()
chriscool authored
322 int find_commit_subject(const char *commit_buffer, const char **subject)
323 {
324 const char *eol;
325 const char *p = commit_buffer;
326
327 while (*p && (*p != '\n' || p[1] != '\n'))
328 p++;
329 if (*p) {
330 p += 2;
331 for (eol = p; *eol && *eol != '\n'; eol++)
332 ; /* do nothing */
333 } else
334 eol = p;
335
336 *subject = p;
337
338 return eol - p;
339 }
340
ac5155e commit_list_insert: return the new commit list entry
Linus Torvalds authored
341 struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
342 {
812666c [PATCH] introduce xmalloc and xrealloc
Christopher Li authored
343 struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
344 new_list->item = item;
345 new_list->next = *list_p;
346 *list_p = new_list;
ac5155e commit_list_insert: return the new commit list entry
Linus Torvalds authored
347 return new_list;
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
348 }
349
6531947 Move commit_list_count() to commit.c
Miklos Vajna authored
350 unsigned commit_list_count(const struct commit_list *l)
351 {
352 unsigned c = 0;
353 for (; l; l = l->next )
354 c++;
355 return c;
356 }
357
175785e [PATCH] Implementations of parsing functions
Daniel Barkalow authored
358 void free_commit_list(struct commit_list *list)
359 {
360 while (list) {
361 struct commit_list *temp = list;
362 list = temp->next;
363 free(temp);
364 }
365 }
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
366
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
367 struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list)
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
368 {
369 struct commit_list **pp = list;
370 struct commit_list *p;
371 while ((p = *pp) != NULL) {
372 if (p->item->date < item->date) {
373 break;
374 }
375 pp = &p->next;
376 }
f755494 Make "insert_by_date()" match "commit_list_insert()"
Linus Torvalds authored
377 return commit_list_insert(item, pp);
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
378 }
379
a6080a0 @gitster War on whitespace
gitster authored
380
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
381 void commit_list_sort_by_date(struct commit_list **list)
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
382 {
383 struct commit_list *ret = NULL;
384 while (*list) {
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
385 commit_list_insert_by_date((*list)->item, &ret);
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
386 *list = (*list)->next;
387 }
388 *list = ret;
389 }
390
58e28af [PATCH] Allow multiple date-ordered lists
Daniel Barkalow authored
391 struct commit *pop_most_recent_commit(struct commit_list **list,
392 unsigned int mark)
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
393 {
394 struct commit *ret = (*list)->item;
395 struct commit_list *parents = ret->parents;
396 struct commit_list *old = *list;
397
398 *list = (*list)->next;
399 free(old);
400
401 while (parents) {
4056c09 Don't add parents to the commit list if we have already
Linus Torvalds authored
402 struct commit *commit = parents->item;
dec38c8 check return value from parse_commit() in various functions
Martin Koegler authored
403 if (!parse_commit(commit) && !(commit->object.flags & mark)) {
58e28af [PATCH] Allow multiple date-ordered lists
Daniel Barkalow authored
404 commit->object.flags |= mark;
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
405 commit_list_insert_by_date(commit, list);
4056c09 Don't add parents to the commit list if we have already
Linus Torvalds authored
406 }
dd97f85 [PATCH] Add some functions for commit lists
Daniel Barkalow authored
407 parents = parents->next;
408 }
409 return ret;
410 }
e3bc7a3 Add generic commit "pretty print" function.
Linus Torvalds authored
411
f8f9c73 describe: allow more than one revs to be named.
Junio C Hamano authored
412 void clear_commit_marks(struct commit *commit, unsigned int mark)
413 {
60fcc2e @dscho clear_commit_marks(): avoid deep recursion
dscho authored
414 while (commit) {
415 struct commit_list *parents;
f8f9c73 describe: allow more than one revs to be named.
Junio C Hamano authored
416
60fcc2e @dscho clear_commit_marks(): avoid deep recursion
dscho authored
417 if (!(mark & commit->object.flags))
418 return;
58ecf5c Re-fix clear_commit_marks().
Junio C Hamano authored
419
60fcc2e @dscho clear_commit_marks(): avoid deep recursion
dscho authored
420 commit->object.flags &= ~mark;
421
422 parents = commit->parents;
423 if (!parents)
424 return;
425
426 while ((parents = parents->next))
427 clear_commit_marks(parents->item, mark);
428
429 commit = commit->parents->item;
f8f9c73 describe: allow more than one revs to be named.
Junio C Hamano authored
430 }
431 }
432
a3437b8 [PATCH] Modify git-rev-list to linearise the commit history in merge …
jon@blackcubes.dyndns.org authored
433 struct commit *pop_commit(struct commit_list **stack)
434 {
435 struct commit_list *top = *stack;
436 struct commit *item = top ? top->item : NULL;
437
438 if (top) {
439 *stack = top->next;
440 free(top);
441 }
442 return item;
443 }
444
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
445 /*
446 * Performs an in-place topological sort on the list supplied.
447 */
4c8725f topo-order: make --date-order optional.
Junio C Hamano authored
448 void sort_in_topological_order(struct commit_list ** list, int lifo)
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
449 {
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
450 struct commit_list *next, *orig = *list;
451 struct commit_list *work, **insert;
452 struct commit_list **pptr;
a6080a0 @gitster War on whitespace
gitster authored
453
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
454 if (!orig)
7d6fb37 short circuit out of a few places where we would allocate zero bytes
Eric Wong authored
455 return;
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
456 *list = NULL;
457
458 /* Mark them and clear the indegree */
459 for (next = orig; next; next = next->next) {
460 struct commit *commit = next->item;
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
461 commit->indegree = 1;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
462 }
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
463
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
464 /* update the indegree */
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
465 for (next = orig; next; next = next->next) {
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
466 struct commit_list * parents = next->item->parents;
467 while (parents) {
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
468 struct commit *parent = parents->item;
6b6dcfc Make it possible to not clobber object.util in sort_in_topological_or…
Fredrik Kuivinen authored
469
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
470 if (parent->indegree)
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
471 parent->indegree++;
472 parents = parents->next;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
473 }
474 }
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
475
a6080a0 @gitster War on whitespace
gitster authored
476 /*
674d172 @MadCoder Rework pretty_print_commit to use strbufs instead of custom buffers.
MadCoder authored
477 * find the tips
478 *
479 * tips are nodes not reachable from any other node in the list
480 *
481 * the tips serve as a starting set for the work queue.
482 */
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
483 work = NULL;
2ed0288 Fix git-rev-list "date order" with --topo-order
Linus Torvalds authored
484 insert = &work;
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
485 for (next = orig; next; next = next->next) {
486 struct commit *commit = next->item;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
487
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
488 if (commit->indegree == 1)
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
489 insert = &commit_list_insert(commit, insert)->next;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
490 }
4c8725f topo-order: make --date-order optional.
Junio C Hamano authored
491
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
492 /* process the list in topological order */
4c8725f topo-order: make --date-order optional.
Junio C Hamano authored
493 if (!lifo)
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
494 commit_list_sort_by_date(&work);
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
495
496 pptr = list;
497 *list = NULL;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
498 while (work) {
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
499 struct commit *commit;
500 struct commit_list *parents, *work_item;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
501
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
502 work_item = work;
503 work = work_item->next;
504 work_item->next = NULL;
505
506 commit = work_item->item;
507 for (parents = commit->parents; parents ; parents = parents->next) {
cd2b8ae @gitster whitespace: have SP on both sides of an assignment "="
gitster authored
508 struct commit *parent = parents->item;
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
509
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
510 if (!parent->indegree)
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
511 continue;
512
513 /*
514 * parents are only enqueued for emission
515 * when all their children have been emitted thereby
516 * guaranteeing topological order.
517 */
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
518 if (--parent->indegree == 1) {
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
519 if (!lifo)
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
520 commit_list_insert_by_date(parent, &work);
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
521 else
522 commit_list_insert(parent, &work);
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
523 }
524 }
525 /*
674d172 @MadCoder Rework pretty_print_commit to use strbufs instead of custom buffers.
MadCoder authored
526 * work_item is a commit all of whose children
527 * have already been emitted. we can emit it now.
528 */
e358f3c @dscho sort_in_topological_order(): avoid setting a commit flag
dscho authored
529 commit->indegree = 0;
23c17d4 @torvalds Simplify topo-sort logic
torvalds authored
530 *pptr = work_item;
531 pptr = &work_item->next;
ab580ac @jonseymour [PATCH] Add a topological sort procedure to commit.c
jonseymour authored
532 }
533 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
534
1295228 merge-base: do not leak commit list
Junio C Hamano authored
535 /* merge-base stuff */
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
536
577ed5c rev-list --left-right
Junio C Hamano authored
537 /* bits #0..15 in revision.h */
538 #define PARENT1 (1u<<16)
539 #define PARENT2 (1u<<17)
540 #define STALE (1u<<18)
541 #define RESULT (1u<<19)
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
542
1295228 merge-base: do not leak commit list
Junio C Hamano authored
543 static const unsigned all_flags = (PARENT1 | PARENT2 | STALE | RESULT);
544
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
545 static struct commit *interesting(struct commit_list *list)
546 {
547 while (list) {
548 struct commit *commit = list->item;
549 list = list->next;
542ccef commit.c: do not redefine UNINTERESTING bit.
Junio C Hamano authored
550 if (commit->object.flags & STALE)
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
551 continue;
552 return commit;
553 }
554 return NULL;
555 }
556
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
557 static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
558 {
559 struct commit_list *list = NULL;
560 struct commit_list *result = NULL;
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
561 int i;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
562
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
563 for (i = 0; i < n; i++) {
564 if (one == twos[i])
565 /*
566 * We do not mark this even with RESULT so we do not
567 * have to clean it up.
568 */
569 return commit_list_insert(one, &result);
570 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
571
172947e check results of parse_commit in merge_bases
Martin Koegler authored
572 if (parse_commit(one))
573 return NULL;
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
574 for (i = 0; i < n; i++) {
575 if (parse_commit(twos[i]))
576 return NULL;
577 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
578
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
579 one->object.flags |= PARENT1;
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
580 commit_list_insert_by_date(one, &list);
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
581 for (i = 0; i < n; i++) {
582 twos[i]->object.flags |= PARENT2;
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
583 commit_list_insert_by_date(twos[i], &list);
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
584 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
585
586 while (interesting(list)) {
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
587 struct commit *commit;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
588 struct commit_list *parents;
f203d69 @drafnel commit.c: rename variable named 'n' which masks previous declaration
drafnel authored
589 struct commit_list *next;
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
590 int flags;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
591
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
592 commit = list->item;
f203d69 @drafnel commit.c: rename variable named 'n' which masks previous declaration
drafnel authored
593 next = list->next;
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
594 free(list);
f203d69 @drafnel commit.c: rename variable named 'n' which masks previous declaration
drafnel authored
595 list = next;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
596
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
597 flags = commit->object.flags & (PARENT1 | PARENT2 | STALE);
598 if (flags == (PARENT1 | PARENT2)) {
599 if (!(commit->object.flags & RESULT)) {
600 commit->object.flags |= RESULT;
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
601 commit_list_insert_by_date(commit, &result);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
602 }
542ccef commit.c: do not redefine UNINTERESTING bit.
Junio C Hamano authored
603 /* Mark parents of a found merge stale */
604 flags |= STALE;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
605 }
606 parents = commit->parents;
607 while (parents) {
608 struct commit *p = parents->item;
609 parents = parents->next;
610 if ((p->object.flags & flags) == flags)
611 continue;
172947e check results of parse_commit in merge_bases
Martin Koegler authored
612 if (parse_commit(p))
613 return NULL;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
614 p->object.flags |= flags;
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
615 commit_list_insert_by_date(p, &list);
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
616 }
617 }
618
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
619 /* Clean up the result to remove stale ones */
1295228 merge-base: do not leak commit list
Junio C Hamano authored
620 free_commit_list(list);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
621 list = result; result = NULL;
622 while (list) {
f203d69 @drafnel commit.c: rename variable named 'n' which masks previous declaration
drafnel authored
623 struct commit_list *next = list->next;
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
624 if (!(list->item->object.flags & STALE))
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
625 commit_list_insert_by_date(list->item, &result);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
626 free(list);
f203d69 @drafnel commit.c: rename variable named 'n' which masks previous declaration
drafnel authored
627 list = next;
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
628 }
629 return result;
630 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
631
5240c9d Introduce get_octopus_merge_bases() in commit.c
Miklos Vajna authored
632 struct commit_list *get_octopus_merge_bases(struct commit_list *in)
633 {
634 struct commit_list *i, *j, *k, *ret = NULL;
635 struct commit_list **pptr = &ret;
636
637 for (i = in; i; i = i->next) {
638 if (!ret)
639 pptr = &commit_list_insert(i->item, pptr)->next;
640 else {
641 struct commit_list *new = NULL, *end = NULL;
642
643 for (j = ret; j; j = j->next) {
644 struct commit_list *bases;
645 bases = get_merge_bases(i->item, j->item, 1);
646 if (!new)
647 new = bases;
648 else
649 end->next = bases;
650 for (k = bases; k; k = k->next)
651 end = k;
652 }
653 ret = new;
654 }
655 }
656 return ret;
657 }
658
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
659 struct commit_list *get_merge_bases_many(struct commit *one,
660 int n,
661 struct commit **twos,
662 int cleanup)
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
663 {
664 struct commit_list *list;
665 struct commit **rslt;
666 struct commit_list *result;
667 int cnt, i, j;
668
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
669 result = merge_bases_many(one, n, twos);
670 for (i = 0; i < n; i++) {
671 if (one == twos[i])
672 return result;
673 }
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
674 if (!result || !result->next) {
675 if (cleanup) {
676 clear_commit_marks(one, all_flags);
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
677 for (i = 0; i < n; i++)
678 clear_commit_marks(twos[i], all_flags);
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
679 }
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
680 return result;
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
681 }
682
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
683 /* There are more than one */
684 cnt = 0;
685 list = result;
686 while (list) {
687 list = list->next;
688 cnt++;
689 }
690 rslt = xcalloc(cnt, sizeof(*rslt));
691 for (list = result, i = 0; list; list = list->next)
692 rslt[i++] = list->item;
693 free_commit_list(result);
694
695 clear_commit_marks(one, all_flags);
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
696 for (i = 0; i < n; i++)
697 clear_commit_marks(twos[i], all_flags);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
698 for (i = 0; i < cnt - 1; i++) {
699 for (j = i+1; j < cnt; j++) {
700 if (!rslt[i] || !rslt[j])
701 continue;
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
702 result = merge_bases_many(rslt[i], 1, &rslt[j]);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
703 clear_commit_marks(rslt[i], all_flags);
704 clear_commit_marks(rslt[j], all_flags);
705 for (list = result; list; list = list->next) {
706 if (rslt[i] == list->item)
707 rslt[i] = NULL;
708 if (rslt[j] == list->item)
709 rslt[j] = NULL;
710 }
711 }
58ecf5c Re-fix clear_commit_marks().
Junio C Hamano authored
712 }
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
713
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
714 /* Surviving ones in rslt[] are the independent results */
715 result = NULL;
716 for (i = 0; i < cnt; i++) {
717 if (rslt[i])
47e44ed commit: Add commit_list prefix in two function names.
Thiago Farina authored
718 commit_list_insert_by_date(rslt[i], &result);
f324943 merge-base: update the clean-up postprocessing
Junio C Hamano authored
719 }
720 free(rslt);
7c6f8aa @dscho move get_merge_bases() to core lib.
dscho authored
721 return result;
722 }
2ecd2bb Move in_merge_bases() to commit.c
Junio C Hamano authored
723
6a93864 @gitster Introduce get_merge_bases_many()
gitster authored
724 struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
725 int cleanup)
726 {
727 return get_merge_bases_many(one, 1, &two, cleanup);
728 }
729
7fcdb36 Make has_commit() non-static
Jake Goulding authored
730 int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
731 {
732 if (!with_commit)
733 return 1;
734 while (with_commit) {
735 struct commit *other;
736
737 other = with_commit->item;
738 with_commit = with_commit->next;
739 if (in_merge_bases(other, &commit, 1))
740 return 1;
741 }
742 return 0;
743 }
744
03840fc Allow in_merge_bases() to take more than one reference commits.
Junio C Hamano authored
745 int in_merge_bases(struct commit *commit, struct commit **reference, int num)
2ecd2bb Move in_merge_bases() to commit.c
Junio C Hamano authored
746 {
747 struct commit_list *bases, *b;
748 int ret = 0;
749
03840fc Allow in_merge_bases() to take more than one reference commits.
Junio C Hamano authored
750 if (num == 1)
751 bases = get_merge_bases(commit, *reference, 1);
752 else
753 die("not yet");
2ecd2bb Move in_merge_bases() to commit.c
Junio C Hamano authored
754 for (b = bases; b; b = b->next) {
03840fc Allow in_merge_bases() to take more than one reference commits.
Junio C Hamano authored
755 if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
2ecd2bb Move in_merge_bases() to commit.c
Junio C Hamano authored
756 ret = 1;
757 break;
758 }
759 }
760
761 free_commit_list(bases);
762 return ret;
763 }
98cf9c3 @gitster Introduce reduce_heads()
gitster authored
764
765 struct commit_list *reduce_heads(struct commit_list *heads)
766 {
767 struct commit_list *p;
768 struct commit_list *result = NULL, **tail = &result;
769 struct commit **other;
770 size_t num_head, num_other;
771
772 if (!heads)
773 return NULL;
774
775 /* Avoid unnecessary reallocations */
776 for (p = heads, num_head = 0; p; p = p->next)
777 num_head++;
778 other = xcalloc(sizeof(*other), num_head);
779
780 /* For each commit, see if it can be reached by others */
781 for (p = heads; p; p = p->next) {
782 struct commit_list *q, *base;
783
711f6b2 @gitster reduce_heads(): protect from duplicate input
gitster authored
784 /* Do we already have this in the result? */
785 for (q = result; q; q = q->next)
786 if (p->item == q->item)
787 break;
788 if (q)
789 continue;
790
98cf9c3 @gitster Introduce reduce_heads()
gitster authored
791 num_other = 0;
792 for (q = heads; q; q = q->next) {
3d1dd47 @hvammen reduce_heads(): thinkofix
hvammen authored
793 if (p->item == q->item)
98cf9c3 @gitster Introduce reduce_heads()
gitster authored
794 continue;
795 other[num_other++] = q->item;
796 }
711f6b2 @gitster reduce_heads(): protect from duplicate input
gitster authored
797 if (num_other)
98cf9c3 @gitster Introduce reduce_heads()
gitster authored
798 base = get_merge_bases_many(p->item, num_other, other, 1);
711f6b2 @gitster reduce_heads(): protect from duplicate input
gitster authored
799 else
98cf9c3 @gitster Introduce reduce_heads()
gitster authored
800 base = NULL;
801 /*
802 * If p->item does not have anything common with other
803 * commits, there won't be any merge base. If it is
804 * reachable from some of the others, p->item will be
805 * the merge base. If its history is connected with
806 * others, but p->item is not reachable by others, we
807 * will get something other than p->item back.
808 */
809 if (!base || (base->item != p->item))
810 tail = &(commit_list_insert(p->item, tail)->next);
811 free_commit_list(base);
812 }
813 free(other);
814 return result;
815 }
40d52ff @peff make commit_tree a library function
peff authored
816
817 static const char commit_utf8_warn[] =
818 "Warning: commit message does not conform to UTF-8.\n"
819 "You may want to amend it after fixing the message, or set the config\n"
820 "variable i18n.commitencoding to the encoding your project uses.\n";
821
822 int commit_tree(const char *msg, unsigned char *tree,
823 struct commit_list *parents, unsigned char *ret,
824 const char *author)
825 {
826 int result;
827 int encoding_is_utf8;
828 struct strbuf buffer;
829
830 assert_sha1_type(tree, OBJ_TREE);
831
832 /* Not having i18n.commitencoding is the same as having utf-8 */
833 encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
834
835 strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
836 strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
837
838 /*
839 * NOTE! This ordering means that the same exact tree merged with a
840 * different order of parents will be a _different_ changeset even
841 * if everything else stays the same.
842 */
843 while (parents) {
844 struct commit_list *next = parents->next;
845 strbuf_addf(&buffer, "parent %s\n",
846 sha1_to_hex(parents->item->object.sha1));
847 free(parents);
848 parents = next;
849 }
850
851 /* Person/date information */
852 if (!author)
853 author = git_author_info(IDENT_ERROR_ON_NO_NAME);
854 strbuf_addf(&buffer, "author %s\n", author);
855 strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
856 if (!encoding_is_utf8)
857 strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
858 strbuf_addch(&buffer, '\n');
859
860 /* And add the comment */
861 strbuf_addstr(&buffer, msg);
862
863 /* And check the encoding */
864 if (encoding_is_utf8 && !is_utf8(buffer.buf))
865 fprintf(stderr, commit_utf8_warn);
866
867 result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
868 strbuf_release(&buffer);
869 return result;
870 }
Something went wrong with that request. Please try again.