Add explanation why we do not allow to sparse checkout to empty working tree
[git/jrn.git] / builtin / rerere.c
blob08213c7c0bc6fa5d649a38520dc87222019babe2
1 #include "builtin.h"
2 #include "cache.h"
3 #include "dir.h"
4 #include "parse-options.h"
5 #include "string-list.h"
6 #include "rerere.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]",
12 NULL,
15 static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
17 int i;
18 for (i = 0; i < nbuf; i++)
19 if (write_in_full(1, ptr[i].ptr, ptr[i].size) != ptr[i].size)
20 return -1;
21 return 0;
24 static int diff_two(const char *file1, const char *label1,
25 const char *file2, const char *label2)
27 xpparam_t xpp;
28 xdemitconf_t xecfg;
29 xdemitcb_t ecb;
30 mmfile_t minus, plus;
32 if (read_mmfile(&minus, file1) || read_mmfile(&plus, file2))
33 return 1;
35 printf("--- a/%s\n+++ b/%s\n", label1, label2);
36 fflush(stdout);
37 memset(&xpp, 0, sizeof(xpp));
38 xpp.flags = 0;
39 memset(&xecfg, 0, sizeof(xecfg));
40 xecfg.ctxlen = 3;
41 ecb.outf = outf;
42 xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);
44 free(minus.ptr);
45 free(plus.ptr);
46 return 0;
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),
57 OPT_END(),
60 argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
62 if (autoupdate == 1)
63 flags = RERERE_AUTOUPDATE;
64 if (autoupdate == 0)
65 flags = RERERE_NOAUTOUPDATE;
67 if (argc < 1)
68 return rerere(flags);
70 if (!strcmp(argv[0], "forget")) {
71 const char **pathspec;
72 if (argc < 2)
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);
79 if (fd < 0)
80 return 0;
82 if (!strcmp(argv[0], "clear")) {
83 rerere_clear(&merge_rr);
84 } else if (!strcmp(argv[0], "gc"))
85 rerere_gc(&merge_rr);
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);
94 else
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);
105 else
106 usage_with_options(rerere_usage, options);
108 string_list_clear(&merge_rr, 1);
109 return 0;