#include "attr.h"
#include "run-command.h"
#include "utf8.h"
+#include "object-store.h"
#include "userdiff.h"
#include "submodule-config.h"
#include "submodule.h"
#include "argv-array.h"
#include "graph.h"
#include "packfile.h"
+#include "help.h"
#ifdef NO_FAST_WORKING_DIRECTORY
#define FAST_WORKING_DIRECTORY 0
GIT_COLOR_FAINT_ITALIC, /* NEW_MOVED_ALTERNATIVE_DIM */
};
+static const char *color_diff_slots[] = {
+ [DIFF_CONTEXT] = "context",
+ [DIFF_METAINFO] = "meta",
+ [DIFF_FRAGINFO] = "frag",
+ [DIFF_FILE_OLD] = "old",
+ [DIFF_FILE_NEW] = "new",
+ [DIFF_COMMIT] = "commit",
+ [DIFF_WHITESPACE] = "whitespace",
+ [DIFF_FUNCINFO] = "func",
+ [DIFF_FILE_OLD_MOVED] = "oldMoved",
+ [DIFF_FILE_OLD_MOVED_ALT] = "oldMovedAlternative",
+ [DIFF_FILE_OLD_MOVED_DIM] = "oldMovedDimmed",
+ [DIFF_FILE_OLD_MOVED_ALT_DIM] = "oldMovedAlternativeDimmed",
+ [DIFF_FILE_NEW_MOVED] = "newMoved",
+ [DIFF_FILE_NEW_MOVED_ALT] = "newMovedAlternative",
+ [DIFF_FILE_NEW_MOVED_DIM] = "newMovedDimmed",
+ [DIFF_FILE_NEW_MOVED_ALT_DIM] = "newMovedAlternativeDimmed",
+};
+
static NORETURN void die_want_option(const char *option_name)
{
die(_("option '%s' requires a value"), option_name);
}
+define_list_config_array_extra(color_diff_slots, {"plain"});
+
static int parse_diff_color_slot(const char *var)
{
- if (!strcasecmp(var, "context") || !strcasecmp(var, "plain"))
+ if (!strcasecmp(var, "plain"))
return DIFF_CONTEXT;
- if (!strcasecmp(var, "meta"))
- return DIFF_METAINFO;
- if (!strcasecmp(var, "frag"))
- return DIFF_FRAGINFO;
- if (!strcasecmp(var, "old"))
- return DIFF_FILE_OLD;
- if (!strcasecmp(var, "new"))
- return DIFF_FILE_NEW;
- if (!strcasecmp(var, "commit"))
- return DIFF_COMMIT;
- if (!strcasecmp(var, "whitespace"))
- return DIFF_WHITESPACE;
- if (!strcasecmp(var, "func"))
- return DIFF_FUNCINFO;
- if (!strcasecmp(var, "oldmoved"))
- return DIFF_FILE_OLD_MOVED;
- if (!strcasecmp(var, "oldmovedalternative"))
- return DIFF_FILE_OLD_MOVED_ALT;
- if (!strcasecmp(var, "oldmoveddimmed"))
- return DIFF_FILE_OLD_MOVED_DIM;
- if (!strcasecmp(var, "oldmovedalternativedimmed"))
- return DIFF_FILE_OLD_MOVED_ALT_DIM;
- if (!strcasecmp(var, "newmoved"))
- return DIFF_FILE_NEW_MOVED;
- if (!strcasecmp(var, "newmovedalternative"))
- return DIFF_FILE_NEW_MOVED_ALT;
- if (!strcasecmp(var, "newmoveddimmed"))
- return DIFF_FILE_NEW_MOVED_DIM;
- if (!strcasecmp(var, "newmovedalternativedimmed"))
- return DIFF_FILE_NEW_MOVED_ALT_DIM;
- return -1;
+ return LOOKUP_CONFIG(color_diff_slots, var);
}
static int parse_dirstat_params(struct diff_options *options, const char *params_string,
return 0;
}
-static int git_config_rename(const char *var, const char *value)
+int git_config_rename(const char *var, const char *value)
{
if (!value)
return DIFF_DETECT_RENAME;
fputs(o->stat_sep, o->file);
break;
default:
- die("BUG: unknown diff symbol");
+ BUG("unknown diff symbol");
}
strbuf_release(&sb);
}
for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
if (!diff_temp[i].name)
return diff_temp + i;
- die("BUG: diff is failing to clean up its tempfiles");
+ BUG("diff is failing to clean up its tempfiles");
}
static void remove_tempfile(void)
* objects however would tend to be slower as they need
* to be individually opened and inflated.
*/
- if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(oid->hash))
+ if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
return 0;
/*
if (abbrev < 0)
abbrev = FALLBACK_DEFAULT_ABBREV;
if (abbrev > GIT_SHA1_HEXSZ)
- die("BUG: oid abbreviation out of range: %d", abbrev);
+ BUG("oid abbreviation out of range: %d", abbrev);
if (abbrev)
hex[abbrev] = '\0';
return hex;
*must_show_header = 0;
}
if (one && two && oidcmp(&one->oid, &two->oid)) {
- int abbrev = o->flags.full_index ? 40 : DEFAULT_ABBREV;
+ const unsigned hexsz = the_hash_algo->hexsz;
+ int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;
if (o->flags.binary) {
mmfile_t mf;
if ((!fill_mmfile(&mf, one) && diff_filespec_is_binary(one)) ||
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
- abbrev = 40;
+ abbrev = hexsz;
}
strbuf_addf(msg, "%s%sindex %s..%s", line_prefix, set,
diff_abbrev_oid(&one->oid, abbrev),
DIFF_FORMAT_NAME_STATUS |
DIFF_FORMAT_CHECKDIFF |
DIFF_FORMAT_NO_OUTPUT;
+ /*
+ * This must be signed because we're comparing against a potentially
+ * negative value.
+ */
+ const int hexsz = the_hash_algo->hexsz;
if (options->set_default)
options->set_default(options);
*/
read_cache();
}
- if (40 < options->abbrev)
- options->abbrev = 40; /* full */
+ if (hexsz < options->abbrev)
+ options->abbrev = hexsz; /* full */
/*
* It does not make sense to show the first hit we happened
int argcount = 1;
if (!skip_prefix(arg, "--stat", &arg))
- die("BUG: stat option does not begin with --stat: %s", arg);
+ BUG("stat option does not begin with --stat: %s", arg);
end = (char *)arg;
switch (*arg) {
options->abbrev = strtoul(arg, NULL, 10);
if (options->abbrev < MINIMUM_ABBREV)
options->abbrev = MINIMUM_ABBREV;
- else if (40 < options->abbrev)
- options->abbrev = 40;
+ else if (the_hash_algo->hexsz < options->abbrev)
+ options->abbrev = the_hash_algo->hexsz;
}
else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
options->a_prefix = optarg;
struct diff_queue_struct *q = &diff_queued_diff;
if (WSEH_NEW & WS_RULE_MASK)
- die("BUG: WS rules bit mask overlaps with diff symbol flags");
+ BUG("WS rules bit mask overlaps with diff symbol flags");
if (o->color_moved)
o->emitted_symbols = &esm;
}
if (!driver->textconv)
- die("BUG: fill_textconv called with non-textconv driver");
+ BUG("fill_textconv called with non-textconv driver");
if (driver->textconv_cache && df->oid_valid) {
*outbuf = notes_cache_get(driver->textconv_cache,