#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,
* 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;
/*
*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
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;