1 #define USE_THE_REPOSITORY_VARIABLE
5 #include "parse-options.h"
7 #include "string-list.h"
9 #include "xdiff/xdiff.h"
10 #include "xdiff-interface.h"
13 static const char * const rerere_usage
[] = {
14 N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
18 static int outf(void *dummy UNUSED
, mmbuffer_t
*ptr
, int nbuf
)
21 for (i
= 0; i
< nbuf
; i
++)
22 if (write_in_full(1, ptr
[i
].ptr
, ptr
[i
].size
) < 0)
27 static int diff_two(const char *file1
, const char *label1
,
28 const char *file2
, const char *label2
)
32 xdemitcb_t ecb
= { .out_line
= outf
};
36 if (read_mmfile(&minus
, file1
) || read_mmfile(&plus
, file2
))
39 printf("--- a/%s\n+++ b/%s\n", label1
, label2
);
41 memset(&xpp
, 0, sizeof(xpp
));
43 memset(&xecfg
, 0, sizeof(xecfg
));
45 ret
= xdi_diff(&minus
, &plus
, &xpp
, &xecfg
, &ecb
);
52 int cmd_rerere(int argc
,
55 struct repository
*repo UNUSED
)
57 struct string_list merge_rr
= STRING_LIST_INIT_DUP
;
58 int i
, autoupdate
= -1, flags
= 0;
60 struct option options
[] = {
61 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate
,
62 N_("register clean resolutions in index"), 1),
66 argc
= parse_options(argc
, argv
, prefix
, options
, rerere_usage
, 0);
68 git_config(git_xmerge_config
, NULL
);
71 flags
= RERERE_AUTOUPDATE
;
73 flags
= RERERE_NOAUTOUPDATE
;
76 return repo_rerere(the_repository
, flags
);
78 if (!strcmp(argv
[0], "forget")) {
79 struct pathspec pathspec
;
83 warning(_("'git rerere forget' without paths is deprecated"));
84 parse_pathspec(&pathspec
, 0, PATHSPEC_PREFER_CWD
,
87 ret
= rerere_forget(the_repository
, &pathspec
);
89 clear_pathspec(&pathspec
);
93 if (!strcmp(argv
[0], "clear")) {
94 rerere_clear(the_repository
, &merge_rr
);
95 } else if (!strcmp(argv
[0], "gc"))
96 rerere_gc(the_repository
, &merge_rr
);
97 else if (!strcmp(argv
[0], "status")) {
98 if (setup_rerere(the_repository
, &merge_rr
,
99 flags
| RERERE_READONLY
) < 0)
101 for (i
= 0; i
< merge_rr
.nr
; i
++)
102 printf("%s\n", merge_rr
.items
[i
].string
);
103 } else if (!strcmp(argv
[0], "remaining")) {
104 rerere_remaining(the_repository
, &merge_rr
);
105 for (i
= 0; i
< merge_rr
.nr
; i
++) {
106 if (merge_rr
.items
[i
].util
!= RERERE_RESOLVED
)
107 printf("%s\n", merge_rr
.items
[i
].string
);
109 /* prepare for later call to
110 * string_list_clear() */
111 merge_rr
.items
[i
].util
= NULL
;
113 } else if (!strcmp(argv
[0], "diff")) {
114 if (setup_rerere(the_repository
, &merge_rr
,
115 flags
| RERERE_READONLY
) < 0)
117 for (i
= 0; i
< merge_rr
.nr
; i
++) {
118 const char *path
= merge_rr
.items
[i
].string
;
119 const struct rerere_id
*id
= merge_rr
.items
[i
].util
;
120 if (diff_two(rerere_path(id
, "preimage"), path
, path
, path
))
121 die(_("unable to generate diff for '%s'"), rerere_path(id
, NULL
));
124 usage_with_options(rerere_usage
, options
);
126 string_list_clear(&merge_rr
, 1);