#include "cache.h"
+#include "tree.h"
#include "diff.h"
static int cached_only = 0;
-static int diff_output_format = DIFF_FORMAT_RAW;
-static int diff_line_termination = '\n';
static int match_nonexisting = 0;
-static int detect_rename = 0;
-static int find_copies_harder = 0;
-static int diff_setup_opt = 0;
-static int diff_score_opt = 0;
-static const char *pickaxe = NULL;
-static int pickaxe_opts = 0;
-static int diff_break_opt = -1;
-static const char *orderfile = NULL;
-static const char *diff_filter = NULL;
+static struct diff_options diff_options;
/* A file entry went away or appeared */
-static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode)
+static void show_file(const char *prefix,
+ struct cache_entry *ce,
+ unsigned char *sha1, unsigned int mode)
{
- diff_addremove(prefix[0], ntohl(mode), sha1, ce->name, NULL);
+ diff_addremove(&diff_options, prefix[0], ntohl(mode),
+ sha1, ce->name, NULL);
}
-static int get_stat_data(struct cache_entry *ce, unsigned char **sha1p, unsigned int *modep)
+static int get_stat_data(struct cache_entry *ce,
+ unsigned char ** sha1p, unsigned int *modep)
{
unsigned char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode;
}
return -1;
}
- changed = ce_match_stat(ce, &st);
+ changed = ce_match_stat(ce, &st, 0);
if (changed) {
mode = create_ce_mode(st.st_mode);
+ if (!trust_executable_bit &&
+ S_ISREG(mode) && S_ISREG(ce->ce_mode) &&
+ ((mode ^ ce->ce_mode) == 0111))
+ mode = ce->ce_mode;
sha1 = no_sha1;
}
}
unsigned char *sha1;
unsigned int mode;
- /* New file in the index: it might actually be different in the working copy */
+ /* New file in the index: it might actually be different in
+ * the working copy.
+ */
if (get_stat_data(new, &sha1, &mode) < 0)
return;
oldmode = old->ce_mode;
if (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&
- !find_copies_harder)
+ !diff_options.find_copies_harder)
return 0;
mode = ntohl(mode);
oldmode = ntohl(oldmode);
- diff_change(oldmode, mode,
+ diff_change(&diff_options, oldmode, mode,
old->sha1, sha1, old->name, NULL);
return 0;
}
/* We come here with ce pointing at stage 1
* (original tree) and ac[1] pointing at stage
* 3 (unmerged). show-modified with
- * report-mising set to false does not say the
+ * report-missing set to false does not say the
* file is deleted but reports true if work
* tree does not have it, in which case we
* fall through to report the unmerged state.
break;
/* fallthru */
case 3:
- diff_unmerge(ce->name);
+ diff_unmerge(&diff_options, ce->name);
break;
default:
"[<common diff options>] <tree-ish> [<path>...]"
COMMON_DIFF_OPTIONS_HELP;
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
{
const char *tree_name = NULL;
unsigned char sha1[20];
const char *prefix = setup_git_directory();
const char **pathspec = NULL;
- void *tree;
- unsigned long size;
+ struct tree *tree;
int ret;
int allow_options = 1;
int i;
+ git_config(git_diff_config);
+ diff_setup(&diff_options);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
+ int diff_opt_cnt;
if (!allow_options || *arg != '-') {
if (tree_name)
/* We accept the -r flag just to look like git-diff-tree */
continue;
}
- /* We accept the -u flag as a synonym for "-p" */
- if (!strcmp(arg, "-p") || !strcmp(arg, "-u")) {
- diff_output_format = DIFF_FORMAT_PATCH;
- continue;
- }
- if (!strncmp(arg, "-B", 2)) {
- if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
- usage(diff_cache_usage);
- continue;
- }
- if (!strncmp(arg, "-M", 2)) {
- detect_rename = DIFF_DETECT_RENAME;
- if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
- usage(diff_cache_usage);
- continue;
- }
- if (!strncmp(arg, "-C", 2)) {
- detect_rename = DIFF_DETECT_COPY;
- if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
- usage(diff_cache_usage);
- continue;
- }
- if (!strcmp(arg, "--find-copies-harder")) {
- find_copies_harder = 1;
- continue;
- }
- if (!strcmp(arg, "-z")) {
- diff_line_termination = 0;
- continue;
- }
- if (!strcmp(arg, "--name-only")) {
- diff_output_format = DIFF_FORMAT_NAME;
- continue;
- }
- if (!strcmp(arg, "-R")) {
- diff_setup_opt |= DIFF_SETUP_REVERSE;
- continue;
- }
- if (!strncmp(arg, "-S", 2)) {
- pickaxe = arg + 2;
- continue;
- }
- if (!strncmp(arg, "--diff-filter=", 14)) {
- diff_filter = arg + 14;
- continue;
- }
- if (!strncmp(arg, "-O", 2)) {
- orderfile = arg + 2;
- continue;
- }
- if (!strcmp(arg, "--pickaxe-all")) {
- pickaxe_opts = DIFF_PICKAXE_ALL;
+ if (!strcmp(arg, "--cc"))
+ /*
+ * I _think_ "diff-index --cached HEAD" with an
+ * unmerged index could show something else
+ * later, but pretend --cc is the same as -p for
+ * now. "git diff" uses --cc by default.
+ */
+ argv[i] = arg = "-p";
+ diff_opt_cnt = diff_opt_parse(&diff_options, argv + i,
+ argc - i);
+ if (diff_opt_cnt < 0)
+ usage(diff_cache_usage);
+ else if (diff_opt_cnt) {
+ i += diff_opt_cnt - 1;
continue;
}
+
if (!strcmp(arg, "-m")) {
match_nonexisting = 1;
continue;
pathspec = get_pathspec(prefix, argv + i);
- if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
+ if (diff_setup_done(&diff_options) < 0)
usage(diff_cache_usage);
if (!tree_name || get_sha1(tree_name, sha1))
read_cache();
- /* The rest is for paths restriction. */
- diff_setup(diff_setup_opt);
-
mark_merge_entries();
- tree = read_object_with_reference(sha1, "tree", &size, NULL);
+ tree = parse_tree_indirect(sha1);
if (!tree)
die("bad tree object %s", tree_name);
- if (read_tree(tree, size, 1, pathspec))
+ if (read_tree(tree, 1, pathspec))
die("unable to read tree object %s", tree_name);
ret = diff_cache(active_cache, active_nr, pathspec);
- diffcore_std(pathspec,
- detect_rename, diff_score_opt,
- pickaxe, pickaxe_opts,
- diff_break_opt,
- orderfile, diff_filter);
- diff_flush(diff_output_format, diff_line_termination);
+ diffcore_std(&diff_options);
+ diff_flush(&diff_options);
return ret;
}