2007-07-15 07:14:45 +08:00
|
|
|
#include "builtin.h"
|
2006-12-21 00:39:41 +08:00
|
|
|
#include "cache.h"
|
2009-01-10 20:07:50 +08:00
|
|
|
#include "dir.h"
|
2010-08-05 19:28:37 +08:00
|
|
|
#include "parse-options.h"
|
2008-07-22 02:03:49 +08:00
|
|
|
#include "string-list.h"
|
2008-07-09 20:58:57 +08:00
|
|
|
#include "rerere.h"
|
2006-12-21 00:39:41 +08:00
|
|
|
#include "xdiff/xdiff.h"
|
|
|
|
#include "xdiff-interface.h"
|
2013-07-14 16:35:40 +08:00
|
|
|
#include "pathspec.h"
|
2006-12-21 00:39:41 +08:00
|
|
|
|
2010-08-05 19:28:37 +08:00
|
|
|
static const char * const rerere_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git rerere [clear | forget <path>... | status | remaining | diff | gc]"),
|
2010-08-05 19:28:37 +08:00
|
|
|
NULL,
|
|
|
|
};
|
2006-12-21 00:39:41 +08:00
|
|
|
|
|
|
|
static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < nbuf; i++)
|
2007-01-08 23:58:23 +08:00
|
|
|
if (write_in_full(1, ptr[i].ptr, ptr[i].size) != ptr[i].size)
|
|
|
|
return -1;
|
2006-12-21 00:39:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int diff_two(const char *file1, const char *label1,
|
|
|
|
const char *file2, const char *label2)
|
|
|
|
{
|
|
|
|
xpparam_t xpp;
|
|
|
|
xdemitconf_t xecfg;
|
|
|
|
xdemitcb_t ecb;
|
|
|
|
mmfile_t minus, plus;
|
|
|
|
|
|
|
|
if (read_mmfile(&minus, file1) || read_mmfile(&plus, file2))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
printf("--- a/%s\n+++ b/%s\n", label1, label2);
|
|
|
|
fflush(stdout);
|
2008-10-25 21:30:37 +08:00
|
|
|
memset(&xpp, 0, sizeof(xpp));
|
2010-05-02 21:04:41 +08:00
|
|
|
xpp.flags = 0;
|
2007-07-05 02:05:46 +08:00
|
|
|
memset(&xecfg, 0, sizeof(xecfg));
|
2006-12-21 00:39:41 +08:00
|
|
|
xecfg.ctxlen = 3;
|
|
|
|
ecb.outf = outf;
|
2007-12-14 05:25:07 +08:00
|
|
|
xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);
|
2006-12-21 00:39:41 +08:00
|
|
|
|
|
|
|
free(minus.ptr);
|
|
|
|
free(plus.ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-18 08:06:47 +08:00
|
|
|
int cmd_rerere(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2010-07-05 03:46:19 +08:00
|
|
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
2010-08-05 19:28:37 +08:00
|
|
|
int i, fd, autoupdate = -1, flags = 0;
|
|
|
|
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
|
2012-08-20 20:32:38 +08:00
|
|
|
N_("register clean resolutions in index"), 1),
|
2010-08-05 19:28:37 +08:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
|
|
|
|
|
2014-04-30 12:08:29 +08:00
|
|
|
git_config(git_xmerge_config, NULL);
|
|
|
|
|
2010-08-05 19:28:37 +08:00
|
|
|
if (autoupdate == 1)
|
|
|
|
flags = RERERE_AUTOUPDATE;
|
|
|
|
if (autoupdate == 0)
|
|
|
|
flags = RERERE_NOAUTOUPDATE;
|
|
|
|
|
|
|
|
if (argc < 1)
|
2009-12-04 16:20:48 +08:00
|
|
|
return rerere(flags);
|
2009-11-09 23:05:01 +08:00
|
|
|
|
2010-08-05 19:28:37 +08:00
|
|
|
if (!strcmp(argv[0], "forget")) {
|
2013-07-14 16:35:40 +08:00
|
|
|
struct pathspec pathspec;
|
2011-03-01 21:21:05 +08:00
|
|
|
if (argc < 2)
|
|
|
|
warning("'git rerere forget' without paths is deprecated");
|
2013-07-14 16:35:40 +08:00
|
|
|
parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
|
|
|
|
prefix, argv + 1);
|
|
|
|
return rerere_forget(&pathspec);
|
2010-01-21 16:23:48 +08:00
|
|
|
}
|
2009-11-09 23:05:01 +08:00
|
|
|
|
2009-12-04 16:20:48 +08:00
|
|
|
fd = setup_rerere(&merge_rr, flags);
|
2007-09-18 08:06:47 +08:00
|
|
|
if (fd < 0)
|
|
|
|
return 0;
|
2006-12-21 00:39:41 +08:00
|
|
|
|
2010-08-05 19:28:37 +08:00
|
|
|
if (!strcmp(argv[0], "clear")) {
|
2011-05-09 03:55:34 +08:00
|
|
|
rerere_clear(&merge_rr);
|
2010-08-05 19:28:37 +08:00
|
|
|
} else if (!strcmp(argv[0], "gc"))
|
2011-05-09 03:55:34 +08:00
|
|
|
rerere_gc(&merge_rr);
|
2010-08-05 19:28:37 +08:00
|
|
|
else if (!strcmp(argv[0], "status"))
|
2006-12-21 00:39:41 +08:00
|
|
|
for (i = 0; i < merge_rr.nr; i++)
|
2008-07-22 02:03:49 +08:00
|
|
|
printf("%s\n", merge_rr.items[i].string);
|
2011-02-16 18:47:44 +08:00
|
|
|
else if (!strcmp(argv[0], "remaining")) {
|
|
|
|
rerere_remaining(&merge_rr);
|
|
|
|
for (i = 0; i < merge_rr.nr; i++) {
|
|
|
|
if (merge_rr.items[i].util != RERERE_RESOLVED)
|
|
|
|
printf("%s\n", merge_rr.items[i].string);
|
|
|
|
else
|
|
|
|
/* prepare for later call to
|
|
|
|
* string_list_clear() */
|
|
|
|
merge_rr.items[i].util = NULL;
|
|
|
|
}
|
|
|
|
} else if (!strcmp(argv[0], "diff"))
|
2006-12-21 00:39:41 +08:00
|
|
|
for (i = 0; i < merge_rr.nr; i++) {
|
2008-07-22 02:03:49 +08:00
|
|
|
const char *path = merge_rr.items[i].string;
|
2006-12-21 00:39:41 +08:00
|
|
|
const char *name = (const char *)merge_rr.items[i].util;
|
2009-02-15 06:21:04 +08:00
|
|
|
diff_two(rerere_path(name, "preimage"), path, path, path);
|
2006-12-21 00:39:41 +08:00
|
|
|
}
|
|
|
|
else
|
2010-08-05 19:28:37 +08:00
|
|
|
usage_with_options(rerere_usage, options);
|
2006-12-21 00:39:41 +08:00
|
|
|
|
2008-07-22 02:03:49 +08:00
|
|
|
string_list_clear(&merge_rr, 1);
|
2006-12-21 00:39:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|