5 #include "parse-options.h"
6 #include "string-list.h"
8 #include "xdiff/xdiff.h"
9 #include "xdiff-interface.h"
12 static const char * const rerere_usage
[] = {
13 N_("git rerere [clear | forget <path>... | status | remaining | diff | gc]"),
17 static int outf(void *dummy
, mmbuffer_t
*ptr
, int nbuf
)
20 for (i
= 0; i
< nbuf
; i
++)
21 if (write_in_full(1, ptr
[i
].ptr
, ptr
[i
].size
) < 0)
26 static int diff_two(const char *file1
, const char *label1
,
27 const char *file2
, const char *label2
)
35 if (read_mmfile(&minus
, file1
) || read_mmfile(&plus
, file2
))
38 printf("--- a/%s\n+++ b/%s\n", label1
, label2
);
40 memset(&xpp
, 0, sizeof(xpp
));
42 memset(&xecfg
, 0, sizeof(xecfg
));
46 ret
= xdi_diff(&minus
, &plus
, &xpp
, &xecfg
, &ecb
);
53 int cmd_rerere(int argc
, const char **argv
, const char *prefix
)
55 struct string_list merge_rr
= STRING_LIST_INIT_DUP
;
56 int i
, autoupdate
= -1, flags
= 0;
58 struct option options
[] = {
59 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate
,
60 N_("register clean resolutions in index"), 1),
64 argc
= parse_options(argc
, argv
, prefix
, options
, rerere_usage
, 0);
66 git_config(git_xmerge_config
, NULL
);
69 flags
= RERERE_AUTOUPDATE
;
71 flags
= RERERE_NOAUTOUPDATE
;
74 return repo_rerere(the_repository
, flags
);
76 if (!strcmp(argv
[0], "forget")) {
77 struct pathspec pathspec
;
79 warning(_("'git rerere forget' without paths is deprecated"));
80 parse_pathspec(&pathspec
, 0, PATHSPEC_PREFER_CWD
,
82 return rerere_forget(the_repository
, &pathspec
);
85 if (!strcmp(argv
[0], "clear")) {
86 rerere_clear(the_repository
, &merge_rr
);
87 } else if (!strcmp(argv
[0], "gc"))
88 rerere_gc(the_repository
, &merge_rr
);
89 else if (!strcmp(argv
[0], "status")) {
90 if (setup_rerere(the_repository
, &merge_rr
,
91 flags
| RERERE_READONLY
) < 0)
93 for (i
= 0; i
< merge_rr
.nr
; i
++)
94 printf("%s\n", merge_rr
.items
[i
].string
);
95 } else if (!strcmp(argv
[0], "remaining")) {
96 rerere_remaining(the_repository
, &merge_rr
);
97 for (i
= 0; i
< merge_rr
.nr
; i
++) {
98 if (merge_rr
.items
[i
].util
!= RERERE_RESOLVED
)
99 printf("%s\n", merge_rr
.items
[i
].string
);
101 /* prepare for later call to
102 * string_list_clear() */
103 merge_rr
.items
[i
].util
= NULL
;
105 } else if (!strcmp(argv
[0], "diff")) {
106 if (setup_rerere(the_repository
, &merge_rr
,
107 flags
| RERERE_READONLY
) < 0)
109 for (i
= 0; i
< merge_rr
.nr
; i
++) {
110 const char *path
= merge_rr
.items
[i
].string
;
111 const struct rerere_id
*id
= merge_rr
.items
[i
].util
;
112 if (diff_two(rerere_path(id
, "preimage"), path
, path
, path
))
113 die(_("unable to generate diff for '%s'"), rerere_path(id
, NULL
));
116 usage_with_options(rerere_usage
, options
);
118 string_list_clear(&merge_rr
, 1);