mirror of
https://github.com/git/git
synced 2024-10-30 14:03:28 +00:00
d1cbe1e6d8
hash.h depends upon and includes repository.h, due to the definition and use of the_hash_algo (defined as the_repository->hash_algo). However, most headers trying to include hash.h are only interested in the layout of the structs like object_id. Move the parts of hash.h that do not depend upon repository.h into a new file hash-ll.h (the "low level" parts of hash.h), and adjust other files to use this new header where the convenience inline functions aren't needed. This allows hash.h and object.h to be fairly small, minimal headers. It also exposes a lot of hidden dependencies on both path.h (which was brought in by repository.h) and repository.h (which was previously implicitly brought in by object.h), so also adjust other files to be more explicit about what they depend upon. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
121 lines
3.2 KiB
C
121 lines
3.2 KiB
C
#include "builtin.h"
|
|
#include "cache.h"
|
|
#include "config.h"
|
|
#include "dir.h"
|
|
#include "gettext.h"
|
|
#include "parse-options.h"
|
|
#include "repository.h"
|
|
#include "string-list.h"
|
|
#include "rerere.h"
|
|
#include "wrapper.h"
|
|
#include "xdiff/xdiff.h"
|
|
#include "xdiff-interface.h"
|
|
#include "pathspec.h"
|
|
|
|
static const char * const rerere_usage[] = {
|
|
N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
|
|
NULL,
|
|
};
|
|
|
|
static int outf(void *dummy UNUSED, mmbuffer_t *ptr, int nbuf)
|
|
{
|
|
int i;
|
|
for (i = 0; i < nbuf; i++)
|
|
if (write_in_full(1, ptr[i].ptr, ptr[i].size) < 0)
|
|
return -1;
|
|
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 = { .out_line = outf };
|
|
mmfile_t minus, plus;
|
|
int ret;
|
|
|
|
if (read_mmfile(&minus, file1) || read_mmfile(&plus, file2))
|
|
return -1;
|
|
|
|
printf("--- a/%s\n+++ b/%s\n", label1, label2);
|
|
fflush(stdout);
|
|
memset(&xpp, 0, sizeof(xpp));
|
|
xpp.flags = 0;
|
|
memset(&xecfg, 0, sizeof(xecfg));
|
|
xecfg.ctxlen = 3;
|
|
ret = xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);
|
|
|
|
free(minus.ptr);
|
|
free(plus.ptr);
|
|
return ret;
|
|
}
|
|
|
|
int cmd_rerere(int argc, const char **argv, const char *prefix)
|
|
{
|
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
|
int i, autoupdate = -1, flags = 0;
|
|
|
|
struct option options[] = {
|
|
OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
|
|
N_("register clean resolutions in index"), 1),
|
|
OPT_END(),
|
|
};
|
|
|
|
argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
|
|
|
|
git_config(git_xmerge_config, NULL);
|
|
|
|
if (autoupdate == 1)
|
|
flags = RERERE_AUTOUPDATE;
|
|
if (autoupdate == 0)
|
|
flags = RERERE_NOAUTOUPDATE;
|
|
|
|
if (argc < 1)
|
|
return repo_rerere(the_repository, flags);
|
|
|
|
if (!strcmp(argv[0], "forget")) {
|
|
struct pathspec pathspec;
|
|
if (argc < 2)
|
|
warning(_("'git rerere forget' without paths is deprecated"));
|
|
parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
|
|
prefix, argv + 1);
|
|
return rerere_forget(the_repository, &pathspec);
|
|
}
|
|
|
|
if (!strcmp(argv[0], "clear")) {
|
|
rerere_clear(the_repository, &merge_rr);
|
|
} else if (!strcmp(argv[0], "gc"))
|
|
rerere_gc(the_repository, &merge_rr);
|
|
else if (!strcmp(argv[0], "status")) {
|
|
if (setup_rerere(the_repository, &merge_rr,
|
|
flags | RERERE_READONLY) < 0)
|
|
return 0;
|
|
for (i = 0; i < merge_rr.nr; i++)
|
|
printf("%s\n", merge_rr.items[i].string);
|
|
} else if (!strcmp(argv[0], "remaining")) {
|
|
rerere_remaining(the_repository, &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")) {
|
|
if (setup_rerere(the_repository, &merge_rr,
|
|
flags | RERERE_READONLY) < 0)
|
|
return 0;
|
|
for (i = 0; i < merge_rr.nr; i++) {
|
|
const char *path = merge_rr.items[i].string;
|
|
const struct rerere_id *id = merge_rr.items[i].util;
|
|
if (diff_two(rerere_path(id, "preimage"), path, path, path))
|
|
die(_("unable to generate diff for '%s'"), rerere_path(id, NULL));
|
|
}
|
|
} else
|
|
usage_with_options(rerere_usage, options);
|
|
|
|
string_list_clear(&merge_rr, 1);
|
|
return 0;
|
|
}
|