merge & sequencer: unify codepaths that write "Conflicts:" hint
Two identical loops in suggest_conflicts() in merge, and do_recursive_merge() in sequencer, can use a single helper function extracted from the latter that prepares the "Conflicts:" hint that is meant to remind the user the paths for which merge conflicts had to be resolved to write a better commit log message. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 24, 2014 at 11:34 UTC
75c961b767ec061696634c1079dbe5f1a9e10f93
3 files changed
+26
-28
builtin/merge.c
+5
-13
@@ -28,6 +28,7 @@
28
#include "remote.h"
29
#include "fmt-merge-msg.h"
30
#include "gpg-interface.h"
31
+#include "sequencer.h"
32
33
#define DEFAULT_TWOHEAD (1<<0)
34
#define DEFAULT_OCTOPUS (1<<1)
@@ -888,24 +889,15 @@ static int suggest_conflicts(void)
889
{
890
const char *filename;
891
FILE *fp;
891
- int pos;
892
+ struct strbuf msgbuf = STRBUF_INIT;
893
894
filename = git_path("MERGE_MSG");
895
fp = fopen(filename, "a");
896
if (!fp)
897
die_errno(_("Could not open '%s' for writing"), filename);
897
- fprintf(fp, "\nConflicts:\n");
898
- for (pos = 0; pos < active_nr; pos++) {
899
- const struct cache_entry *ce = active_cache[pos];
900
-
901
- if (ce_stage(ce)) {
902
- fprintf(fp, "\t%s\n", ce->name);
903
- while (pos + 1 < active_nr &&
904
- !strcmp(ce->name,
905
- active_cache[pos + 1]->name))
906
- pos++;
907
- }
908
- }
898
+
899
+ append_conflicts_hint(&msgbuf);
900
+ fputs(msgbuf.buf, fp);
901
fclose(fp);
902
rerere(allow_rerere_auto);
903
printf(_("Automatic merge failed; "
sequencer.c
+20
-15
@@ -287,6 +287,24 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
287
return ret;
288
}
289
290
+void append_conflicts_hint(struct strbuf *msgbuf)
291
+{
292
+ int i;
293
+
294
+ strbuf_addstr(msgbuf, "\nConflicts:\n");
295
+ for (i = 0; i < active_nr;) {
296
+ const struct cache_entry *ce = active_cache[i++];
297
+ if (ce_stage(ce)) {
298
+ strbuf_addch(msgbuf, '\t');
299
+ strbuf_addstr(msgbuf, ce->name);
300
+ strbuf_addch(msgbuf, '\n');
301
+ while (i < active_nr && !strcmp(ce->name,
302
+ active_cache[i]->name))
303
+ i++;
304
+ }
305
+ }
306
+}
307
+
308
static int do_recursive_merge(struct commit *base, struct commit *next,
309
const char *base_label, const char *next_label,
310
unsigned char *head, struct strbuf *msgbuf,
@@ -328,21 +346,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
346
if (opts->signoff)
347
append_signoff(msgbuf, 0, 0);
348
331
- if (!clean) {
332
- int i;
333
- strbuf_addstr(msgbuf, "\nConflicts:\n");
334
- for (i = 0; i < active_nr;) {
335
- const struct cache_entry *ce = active_cache[i++];
336
- if (ce_stage(ce)) {
337
- strbuf_addch(msgbuf, '\t');
338
- strbuf_addstr(msgbuf, ce->name);
339
- strbuf_addch(msgbuf, '\n');
340
- while (i < active_nr && !strcmp(ce->name,
341
- active_cache[i]->name))
342
- i++;
343
- }
344
- }
345
- }
349
+ if (!clean)
350
+ append_conflicts_hint(msgbuf);
351
352
return !clean;
353
}
sequencer.h
+1
@@ -51,5 +51,6 @@ int sequencer_pick_revisions(struct replay_opts *opts);
51
extern const char sign_off_header[];
52
53
void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);
54
+void append_conflicts_hint(struct strbuf *msgbuf);
55
56
#endif