4 #include "parse-options.h"
5 #include "string-list.h"
7 #include "xdiff/xdiff.h"
8 #include "xdiff-interface.h"
10 static const char * const rerere_usage
[] = {
11 "git rerere [clear | forget path... | status | remaining | diff | gc]",
15 static int outf(void *dummy
, mmbuffer_t
*ptr
, int nbuf
)
18 for (i
= 0; i
< nbuf
; i
++)
19 if (write_in_full(1, ptr
[i
].ptr
, ptr
[i
].size
) != ptr
[i
].size
)
24 static int diff_two(const char *file1
, const char *label1
,
25 const char *file2
, const char *label2
)
32 if (read_mmfile(&minus
, file1
) || read_mmfile(&plus
, file2
))
35 printf("--- a/%s\n+++ b/%s\n", label1
, label2
);
37 memset(&xpp
, 0, sizeof(xpp
));
39 memset(&xecfg
, 0, sizeof(xecfg
));
42 xdi_diff(&minus
, &plus
, &xpp
, &xecfg
, &ecb
);
49 int cmd_rerere(int argc
, const char **argv
, const char *prefix
)
51 struct string_list merge_rr
= STRING_LIST_INIT_DUP
;
52 int i
, fd
, autoupdate
= -1, flags
= 0;
54 struct option options
[] = {
55 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate
,
56 "register clean resolutions in index", 1),
60 argc
= parse_options(argc
, argv
, prefix
, options
, rerere_usage
, 0);
63 flags
= RERERE_AUTOUPDATE
;
65 flags
= RERERE_NOAUTOUPDATE
;
70 if (!strcmp(argv
[0], "forget")) {
71 const char **pathspec
;
73 warning("'git rerere forget' without paths is deprecated");
74 pathspec
= get_pathspec(prefix
, argv
+ 1);
75 return rerere_forget(pathspec
);
78 fd
= setup_rerere(&merge_rr
, flags
);
82 if (!strcmp(argv
[0], "clear")) {
83 rerere_clear(&merge_rr
);
84 } else if (!strcmp(argv
[0], "gc"))
86 else if (!strcmp(argv
[0], "status"))
87 for (i
= 0; i
< merge_rr
.nr
; i
++)
88 printf("%s\n", merge_rr
.items
[i
].string
);
89 else if (!strcmp(argv
[0], "remaining")) {
90 rerere_remaining(&merge_rr
);
91 for (i
= 0; i
< merge_rr
.nr
; i
++) {
92 if (merge_rr
.items
[i
].util
!= RERERE_RESOLVED
)
93 printf("%s\n", merge_rr
.items
[i
].string
);
95 /* prepare for later call to
96 * string_list_clear() */
97 merge_rr
.items
[i
].util
= NULL
;
99 } else if (!strcmp(argv
[0], "diff"))
100 for (i
= 0; i
< merge_rr
.nr
; i
++) {
101 const char *path
= merge_rr
.items
[i
].string
;
102 const char *name
= (const char *)merge_rr
.items
[i
].util
;
103 diff_two(rerere_path(name
, "preimage"), path
, path
, path
);
106 usage_with_options(rerere_usage
, options
);
108 string_list_clear(&merge_rr
, 1);