6 #include "parse-options.h"
7 #include "repository.h"
8 #include "string-list.h"
11 #include "xdiff/xdiff.h"
12 #include "xdiff-interface.h"
15 static const char * const rerere_usage
[] = {
16 N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
20 static int outf(void *dummy UNUSED
, mmbuffer_t
*ptr
, int nbuf
)
23 for (i
= 0; i
< nbuf
; i
++)
24 if (write_in_full(1, ptr
[i
].ptr
, ptr
[i
].size
) < 0)
29 static int diff_two(const char *file1
, const char *label1
,
30 const char *file2
, const char *label2
)
34 xdemitcb_t ecb
= { .out_line
= outf
};
38 if (read_mmfile(&minus
, file1
) || read_mmfile(&plus
, file2
))
41 printf("--- a/%s\n+++ b/%s\n", label1
, label2
);
43 memset(&xpp
, 0, sizeof(xpp
));
45 memset(&xecfg
, 0, sizeof(xecfg
));
47 ret
= xdi_diff(&minus
, &plus
, &xpp
, &xecfg
, &ecb
);
54 int cmd_rerere(int argc
, const char **argv
, const char *prefix
)
56 struct string_list merge_rr
= STRING_LIST_INIT_DUP
;
57 int i
, autoupdate
= -1, flags
= 0;
59 struct option options
[] = {
60 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate
,
61 N_("register clean resolutions in index"), 1),
65 argc
= parse_options(argc
, argv
, prefix
, options
, rerere_usage
, 0);
67 git_config(git_xmerge_config
, NULL
);
70 flags
= RERERE_AUTOUPDATE
;
72 flags
= RERERE_NOAUTOUPDATE
;
75 return repo_rerere(the_repository
, flags
);
77 if (!strcmp(argv
[0], "forget")) {
78 struct pathspec pathspec
;
80 warning(_("'git rerere forget' without paths is deprecated"));
81 parse_pathspec(&pathspec
, 0, PATHSPEC_PREFER_CWD
,
83 return rerere_forget(the_repository
, &pathspec
);
86 if (!strcmp(argv
[0], "clear")) {
87 rerere_clear(the_repository
, &merge_rr
);
88 } else if (!strcmp(argv
[0], "gc"))
89 rerere_gc(the_repository
, &merge_rr
);
90 else if (!strcmp(argv
[0], "status")) {
91 if (setup_rerere(the_repository
, &merge_rr
,
92 flags
| RERERE_READONLY
) < 0)
94 for (i
= 0; i
< merge_rr
.nr
; i
++)
95 printf("%s\n", merge_rr
.items
[i
].string
);
96 } else if (!strcmp(argv
[0], "remaining")) {
97 rerere_remaining(the_repository
, &merge_rr
);
98 for (i
= 0; i
< merge_rr
.nr
; i
++) {
99 if (merge_rr
.items
[i
].util
!= RERERE_RESOLVED
)
100 printf("%s\n", merge_rr
.items
[i
].string
);
102 /* prepare for later call to
103 * string_list_clear() */
104 merge_rr
.items
[i
].util
= NULL
;
106 } else if (!strcmp(argv
[0], "diff")) {
107 if (setup_rerere(the_repository
, &merge_rr
,
108 flags
| RERERE_READONLY
) < 0)
110 for (i
= 0; i
< merge_rr
.nr
; i
++) {
111 const char *path
= merge_rr
.items
[i
].string
;
112 const struct rerere_id
*id
= merge_rr
.items
[i
].util
;
113 if (diff_two(rerere_path(id
, "preimage"), path
, path
, path
))
114 die(_("unable to generate diff for '%s'"), rerere_path(id
, NULL
));
117 usage_with_options(rerere_usage
, options
);
119 string_list_clear(&merge_rr
, 1);