4 #include "parse-options.h"
5 #include "string-list.h"
7 #include "xdiff/xdiff.h"
8 #include "xdiff-interface.h"
11 static const char * const rerere_usage
[] = {
12 N_("git rerere [clear | forget path... | status | remaining | diff | gc]"),
16 static int outf(void *dummy
, mmbuffer_t
*ptr
, int nbuf
)
19 for (i
= 0; i
< nbuf
; i
++)
20 if (write_in_full(1, ptr
[i
].ptr
, ptr
[i
].size
) != ptr
[i
].size
)
25 static int diff_two(const char *file1
, const char *label1
,
26 const char *file2
, const char *label2
)
33 if (read_mmfile(&minus
, file1
) || read_mmfile(&plus
, file2
))
36 printf("--- a/%s\n+++ b/%s\n", label1
, label2
);
38 memset(&xpp
, 0, sizeof(xpp
));
40 memset(&xecfg
, 0, sizeof(xecfg
));
43 xdi_diff(&minus
, &plus
, &xpp
, &xecfg
, &ecb
);
50 int cmd_rerere(int argc
, const char **argv
, const char *prefix
)
52 struct string_list merge_rr
= STRING_LIST_INIT_DUP
;
53 int i
, fd
, autoupdate
= -1, flags
= 0;
55 struct option options
[] = {
56 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate
,
57 N_("register clean resolutions in index"), 1),
61 argc
= parse_options(argc
, argv
, prefix
, options
, rerere_usage
, 0);
64 flags
= RERERE_AUTOUPDATE
;
66 flags
= RERERE_NOAUTOUPDATE
;
71 if (!strcmp(argv
[0], "forget")) {
72 struct pathspec pathspec
;
74 warning("'git rerere forget' without paths is deprecated");
75 parse_pathspec(&pathspec
, 0, PATHSPEC_PREFER_CWD
,
77 return rerere_forget(&pathspec
);
80 fd
= setup_rerere(&merge_rr
, flags
);
84 if (!strcmp(argv
[0], "clear")) {
85 rerere_clear(&merge_rr
);
86 } else if (!strcmp(argv
[0], "gc"))
88 else if (!strcmp(argv
[0], "status"))
89 for (i
= 0; i
< merge_rr
.nr
; i
++)
90 printf("%s\n", merge_rr
.items
[i
].string
);
91 else if (!strcmp(argv
[0], "remaining")) {
92 rerere_remaining(&merge_rr
);
93 for (i
= 0; i
< merge_rr
.nr
; i
++) {
94 if (merge_rr
.items
[i
].util
!= RERERE_RESOLVED
)
95 printf("%s\n", merge_rr
.items
[i
].string
);
97 /* prepare for later call to
98 * string_list_clear() */
99 merge_rr
.items
[i
].util
= NULL
;
101 } else if (!strcmp(argv
[0], "diff"))
102 for (i
= 0; i
< merge_rr
.nr
; i
++) {
103 const char *path
= merge_rr
.items
[i
].string
;
104 const char *name
= (const char *)merge_rr
.items
[i
].util
;
105 diff_two(rerere_path(name
, "preimage"), path
, path
, path
);
108 usage_with_options(rerere_usage
, options
);
110 string_list_clear(&merge_rr
, 1);