提交 6b5ee137 编写于 作者: J Junio C Hamano

Diff clean-up.

This is a long overdue clean-up to the code for parsing and passing
diff options.  It also tightens some constness issues.
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 dbc37438
...@@ -143,9 +143,9 @@ extern char *get_graft_file(void); ...@@ -143,9 +143,9 @@ extern char *get_graft_file(void);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
extern const char **get_pathspec(const char *prefix, char **pathspec); extern const char **get_pathspec(const char *prefix, const char **pathspec);
extern const char *setup_git_directory(void); extern const char *setup_git_directory(void);
extern char *prefix_path(const char *prefix, int len, char *path); extern const char *prefix_path(const char *prefix, int len, const char *path);
#define alloc_nr(x) (((x)+16)*3/2) #define alloc_nr(x) (((x)+16)*3/2)
...@@ -158,7 +158,7 @@ extern int cache_name_pos(const char *name, int namelen); ...@@ -158,7 +158,7 @@ extern int cache_name_pos(const char *name, int namelen);
#define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
extern int add_cache_entry(struct cache_entry *ce, int option); extern int add_cache_entry(struct cache_entry *ce, int option);
extern int remove_cache_entry_at(int pos); extern int remove_cache_entry_at(int pos);
extern int remove_file_from_cache(char *path); extern int remove_file_from_cache(const char *path);
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
extern int ce_match_stat(struct cache_entry *ce, struct stat *st); extern int ce_match_stat(struct cache_entry *ce, struct stat *st);
extern int ce_modified(struct cache_entry *ce, struct stat *st); extern int ce_modified(struct cache_entry *ce, struct stat *st);
......
...@@ -11,87 +11,56 @@ static const char diff_files_usage[] = ...@@ -11,87 +11,56 @@ static const char diff_files_usage[] =
"[<common diff options>] [<path>...]" "[<common diff options>] [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;
static int diff_output_format = DIFF_FORMAT_RAW; static struct diff_options diff_options;
static int diff_line_termination = '\n';
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 int silent = 0; static int silent = 0;
static void show_unmerge(const char *path) static void show_unmerge(const char *path)
{ {
diff_unmerge(path); diff_unmerge(&diff_options, path);
} }
static void show_file(int pfx, struct cache_entry *ce) static void show_file(int pfx, struct cache_entry *ce)
{ {
diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL); diff_addremove(&diff_options, pfx, ntohl(ce->ce_mode),
ce->sha1, ce->name, NULL);
} }
static void show_modified(int oldmode, int mode, static void show_modified(int oldmode, int mode,
const unsigned char *old_sha1, const unsigned char *sha1, const unsigned char *old_sha1, const unsigned char *sha1,
char *path) char *path)
{ {
diff_change(oldmode, mode, old_sha1, sha1, path, NULL); diff_change(&diff_options, oldmode, mode, old_sha1, sha1, path, NULL);
} }
int main(int argc, char **argv) int main(int argc, const char **argv)
{ {
static const unsigned char null_sha1[20] = { 0, }; static const unsigned char null_sha1[20] = { 0, };
const char **pathspec; const char **pathspec;
const char *prefix = setup_git_directory(); const char *prefix = setup_git_directory();
int entries, i; int entries, i;
diff_setup(&diff_options);
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "-p") || !strcmp(argv[1], "-u")) if (!strcmp(argv[1], "-q"))
diff_output_format = DIFF_FORMAT_PATCH;
else if (!strcmp(argv[1], "-q"))
silent = 1; silent = 1;
else if (!strcmp(argv[1], "-r")) else if (!strcmp(argv[1], "-r"))
; /* no-op */ ; /* no-op */
else if (!strcmp(argv[1], "-s")) else if (!strcmp(argv[1], "-s"))
; /* no-op */ ; /* no-op */
else if (!strcmp(argv[1], "-z")) else {
diff_line_termination = 0; int diff_opt_cnt;
else if (!strcmp(argv[1], "--name-only")) diff_opt_cnt = diff_opt_parse(&diff_options,
diff_output_format = DIFF_FORMAT_NAME; argv+1, argc-1);
else if (!strcmp(argv[1], "-R")) if (diff_opt_cnt < 0)
diff_setup_opt |= DIFF_SETUP_REVERSE;
else if (!strncmp(argv[1], "-S", 2))
pickaxe = argv[1] + 2;
else if (!strncmp(argv[1], "-O", 2))
orderfile = argv[1] + 2;
else if (!strncmp(argv[1], "--diff-filter=", 14))
diff_filter = argv[1] + 14;
else if (!strcmp(argv[1], "--pickaxe-all"))
pickaxe_opts = DIFF_PICKAXE_ALL;
else if (!strncmp(argv[1], "-B", 2)) {
if ((diff_break_opt =
diff_scoreopt_parse(argv[1])) == -1)
usage(diff_files_usage); usage(diff_files_usage);
} else if (diff_opt_cnt) {
else if (!strncmp(argv[1], "-M", 2)) { argv += diff_opt_cnt;
if ((diff_score_opt = argc -= diff_opt_cnt;
diff_scoreopt_parse(argv[1])) == -1) continue;
usage(diff_files_usage); }
detect_rename = DIFF_DETECT_RENAME; else
}
else if (!strncmp(argv[1], "-C", 2)) {
if ((diff_score_opt =
diff_scoreopt_parse(argv[1])) == -1)
usage(diff_files_usage); usage(diff_files_usage);
detect_rename = DIFF_DETECT_COPY;
} }
else if (!strcmp(argv[1], "--find-copies-harder"))
find_copies_harder = 1;
else
usage(diff_files_usage);
argv++; argc--; argv++; argc--;
} }
...@@ -99,7 +68,7 @@ int main(int argc, char **argv) ...@@ -99,7 +68,7 @@ int main(int argc, char **argv)
pathspec = get_pathspec(prefix, argv + 1); pathspec = get_pathspec(prefix, argv + 1);
entries = read_cache(); entries = read_cache();
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY) if (diff_setup_done(&diff_options) < 0)
usage(diff_files_usage); usage(diff_files_usage);
/* At this point, if argc == 1, then we are doing everything. /* At this point, if argc == 1, then we are doing everything.
...@@ -110,8 +79,6 @@ int main(int argc, char **argv) ...@@ -110,8 +79,6 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
diff_setup(diff_setup_opt);
for (i = 0; i < entries; i++) { for (i = 0; i < entries; i++) {
struct stat st; struct stat st;
unsigned int oldmode; unsigned int oldmode;
...@@ -141,18 +108,14 @@ int main(int argc, char **argv) ...@@ -141,18 +108,14 @@ int main(int argc, char **argv)
continue; continue;
} }
changed = ce_match_stat(ce, &st); changed = ce_match_stat(ce, &st);
if (!changed && !find_copies_harder) if (!changed && !diff_options.find_copies_harder)
continue; continue;
oldmode = ntohl(ce->ce_mode); oldmode = ntohl(ce->ce_mode);
show_modified(oldmode, DIFF_FILE_CANON_MODE(st.st_mode), show_modified(oldmode, DIFF_FILE_CANON_MODE(st.st_mode),
ce->sha1, (changed ? null_sha1 : ce->sha1), ce->sha1, (changed ? null_sha1 : ce->sha1),
ce->name); ce->name);
} }
diffcore_std(pathspec, diffcore_std(&diff_options);
detect_rename, diff_score_opt, diff_flush(&diff_options);
pickaxe, pickaxe_opts,
diff_break_opt,
orderfile, diff_filter);
diff_flush(diff_output_format, diff_line_termination);
return 0; return 0;
} }
...@@ -2,26 +2,20 @@ ...@@ -2,26 +2,20 @@
#include "diff.h" #include "diff.h"
static int cached_only = 0; 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 match_nonexisting = 0;
static int detect_rename = 0; static struct diff_options diff_options;
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;
/* A file entry went away or appeared */ /* 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 char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode; unsigned int mode = ce->ce_mode;
...@@ -77,13 +71,13 @@ static int show_modified(struct cache_entry *old, ...@@ -77,13 +71,13 @@ static int show_modified(struct cache_entry *old,
oldmode = old->ce_mode; oldmode = old->ce_mode;
if (mode == oldmode && !memcmp(sha1, old->sha1, 20) && if (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&
!find_copies_harder) !diff_options.find_copies_harder)
return 0; return 0;
mode = ntohl(mode); mode = ntohl(mode);
oldmode = ntohl(oldmode); oldmode = ntohl(oldmode);
diff_change(oldmode, mode, diff_change(&diff_options, oldmode, mode,
old->sha1, sha1, old->name, NULL); old->sha1, sha1, old->name, NULL);
return 0; return 0;
} }
...@@ -127,7 +121,7 @@ static int diff_cache(struct cache_entry **ac, int entries, const char **pathspe ...@@ -127,7 +121,7 @@ static int diff_cache(struct cache_entry **ac, int entries, const char **pathspe
break; break;
/* fallthru */ /* fallthru */
case 3: case 3:
diff_unmerge(ce->name); diff_unmerge(&diff_options, ce->name);
break; break;
default: default:
...@@ -168,7 +162,7 @@ static const char diff_cache_usage[] = ...@@ -168,7 +162,7 @@ static const char diff_cache_usage[] =
"[<common diff options>] <tree-ish> [<path>...]" "[<common diff options>] <tree-ish> [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;
int main(int argc, char **argv) int main(int argc, const char **argv)
{ {
const char *tree_name = NULL; const char *tree_name = NULL;
unsigned char sha1[20]; unsigned char sha1[20];
...@@ -180,8 +174,10 @@ int main(int argc, char **argv) ...@@ -180,8 +174,10 @@ int main(int argc, char **argv)
int allow_options = 1; int allow_options = 1;
int i; int i;
diff_setup(&diff_options);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
int diff_opt_cnt;
if (!allow_options || *arg != '-') { if (!allow_options || *arg != '-') {
if (tree_name) if (tree_name)
...@@ -198,60 +194,15 @@ int main(int argc, char **argv) ...@@ -198,60 +194,15 @@ int main(int argc, char **argv)
/* We accept the -r flag just to look like git-diff-tree */ /* We accept the -r flag just to look like git-diff-tree */
continue; continue;
} }
/* We accept the -u flag as a synonym for "-p" */ diff_opt_cnt = diff_opt_parse(&diff_options, argv + i,
if (!strcmp(arg, "-p") || !strcmp(arg, "-u")) { argc - i);
diff_output_format = DIFF_FORMAT_PATCH; if (diff_opt_cnt < 0)
continue; usage(diff_cache_usage);
} else if (diff_opt_cnt) {
if (!strncmp(arg, "-B", 2)) { i += diff_opt_cnt - 1;
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;
continue; continue;
} }
if (!strcmp(arg, "-m")) { if (!strcmp(arg, "-m")) {
match_nonexisting = 1; match_nonexisting = 1;
continue; continue;
...@@ -265,7 +216,7 @@ int main(int argc, char **argv) ...@@ -265,7 +216,7 @@ int main(int argc, char **argv)
pathspec = get_pathspec(prefix, argv + i); 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); usage(diff_cache_usage);
if (!tree_name || get_sha1(tree_name, sha1)) if (!tree_name || get_sha1(tree_name, sha1))
...@@ -273,9 +224,6 @@ int main(int argc, char **argv) ...@@ -273,9 +224,6 @@ int main(int argc, char **argv)
read_cache(); read_cache();
/* The rest is for paths restriction. */
diff_setup(diff_setup_opt);
mark_merge_entries(); mark_merge_entries();
tree = read_object_with_reference(sha1, "tree", &size, NULL); tree = read_object_with_reference(sha1, "tree", &size, NULL);
...@@ -286,11 +234,7 @@ int main(int argc, char **argv) ...@@ -286,11 +234,7 @@ int main(int argc, char **argv)
ret = diff_cache(active_cache, active_nr, pathspec); ret = diff_cache(active_cache, active_nr, pathspec);
diffcore_std(pathspec, diffcore_std(&diff_options);
detect_rename, diff_score_opt, diff_flush(&diff_options);
pickaxe, pickaxe_opts,
diff_break_opt,
orderfile, diff_filter);
diff_flush(diff_output_format, diff_line_termination);
return ret; return ret;
} }
...@@ -5,17 +5,7 @@ ...@@ -5,17 +5,7 @@
#include "cache.h" #include "cache.h"
#include "diff.h" #include "diff.h"
static int diff_output_format = DIFF_FORMAT_RAW; static struct diff_options diff_options;
static int diff_line_termination = '\n';
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 const char diff_stages_usage[] = static const char diff_stages_usage[] =
"git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]" "git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
...@@ -47,15 +37,16 @@ static void diff_stages(int stage1, int stage2) ...@@ -47,15 +37,16 @@ static void diff_stages(int stage1, int stage2)
if (!one && !two) if (!one && !two)
continue; continue;
if (!one) if (!one)
diff_addremove('+', ntohl(two->ce_mode), diff_addremove(&diff_options, '+', ntohl(two->ce_mode),
two->sha1, name, NULL); two->sha1, name, NULL);
else if (!two) else if (!two)
diff_addremove('-', ntohl(one->ce_mode), diff_addremove(&diff_options, '-', ntohl(one->ce_mode),
one->sha1, name, NULL); one->sha1, name, NULL);
else if (memcmp(one->sha1, two->sha1, 20) || else if (memcmp(one->sha1, two->sha1, 20) ||
(one->ce_mode != two->ce_mode) || (one->ce_mode != two->ce_mode) ||
find_copies_harder) diff_options.find_copies_harder)
diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode), diff_change(&diff_options,
ntohl(one->ce_mode), ntohl(two->ce_mode),
one->sha1, two->sha1, name, NULL); one->sha1, two->sha1, name, NULL);
} }
} }
...@@ -65,44 +56,25 @@ int main(int ac, const char **av) ...@@ -65,44 +56,25 @@ int main(int ac, const char **av)
int stage1, stage2; int stage1, stage2;
read_cache(); read_cache();
diff_setup(&diff_options);
while (1 < ac && av[1][0] == '-') { while (1 < ac && av[1][0] == '-') {
const char *arg = av[1]; const char *arg = av[1];
if (!strcmp(arg, "-r")) if (!strcmp(arg, "-r"))
; /* as usual */ ; /* as usual */
else if (!strcmp(arg, "-p") || !strcmp(arg, "-u")) else {
diff_output_format = DIFF_FORMAT_PATCH; int diff_opt_cnt;
else if (!strncmp(arg, "-B", 2)) { diff_opt_cnt = diff_opt_parse(&diff_options,
if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1) av+1, ac-1);
if (diff_opt_cnt < 0)
usage(diff_stages_usage); usage(diff_stages_usage);
} else if (diff_opt_cnt) {
else if (!strncmp(arg, "-M", 2)) { av += diff_opt_cnt;
detect_rename = DIFF_DETECT_RENAME; ac -= diff_opt_cnt;
if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1) continue;
usage(diff_stages_usage); }
} else
else if (!strncmp(arg, "-C", 2)) {
detect_rename = DIFF_DETECT_COPY;
if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
usage(diff_stages_usage); usage(diff_stages_usage);
} }
else if (!strcmp(arg, "--find-copies-harder"))
find_copies_harder = 1;
else if (!strcmp(arg, "-z"))
diff_line_termination = 0;
else if (!strcmp(arg, "--name-only"))
diff_output_format = DIFF_FORMAT_NAME;
else if (!strcmp(arg, "-R"))
diff_setup_opt |= DIFF_SETUP_REVERSE;
else if (!strncmp(arg, "-S", 2))
pickaxe = arg + 2;
else if (!strncmp(arg, "-O", 2))
orderfile = arg + 2;
else if (!strncmp(arg, "--diff-filter=", 14))
diff_filter = arg + 14;
else if (!strcmp(arg, "--pickaxe-all"))
pickaxe_opts = DIFF_PICKAXE_ALL;
else
usage(diff_stages_usage);
ac--; av++; ac--; av++;
} }
...@@ -110,21 +82,17 @@ int main(int ac, const char **av) ...@@ -110,21 +82,17 @@ int main(int ac, const char **av)
sscanf(av[1], "%d", &stage1) != 1 || sscanf(av[1], "%d", &stage1) != 1 ||
! (0 <= stage1 && stage1 <= 3) || ! (0 <= stage1 && stage1 <= 3) ||
sscanf(av[2], "%d", &stage2) != 1 || sscanf(av[2], "%d", &stage2) != 1 ||
! (0 <= stage2 && stage2 <= 3) || ! (0 <= stage2 && stage2 <= 3))
(find_copies_harder && detect_rename != DIFF_DETECT_COPY))
usage(diff_stages_usage); usage(diff_stages_usage);
av += 3; /* The rest from av[0] are for paths restriction. */ av += 3; /* The rest from av[0] are for paths restriction. */
diff_setup(diff_setup_opt); diff_options.paths = av;
diff_stages(stage1, stage2); if (diff_setup_done(&diff_options) < 0)
usage(diff_stages_usage);
diffcore_std(av, diff_stages(stage1, stage2);
detect_rename, diff_score_opt, diffcore_std(&diff_options);
pickaxe, pickaxe_opts, diff_flush(&diff_options);
diff_break_opt,
orderfile,
diff_filter);
diff_flush(diff_output_format, diff_line_termination);
return 0; return 0;
} }
...@@ -9,17 +9,9 @@ static int ignore_merges = 1; ...@@ -9,17 +9,9 @@ static int ignore_merges = 1;
static int recursive = 0; static int recursive = 0;
static int show_tree_entry_in_recursive = 0; static int show_tree_entry_in_recursive = 0;
static int read_stdin = 0; static int read_stdin = 0;
static int diff_output_format = DIFF_FORMAT_RAW;
static int diff_line_termination = '\n'; static struct diff_options diff_options;
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 const char *header = NULL; static const char *header = NULL;
static const char *header_prefix = ""; static const char *header_prefix = "";
static enum cmit_fmt commit_format = CMIT_FMT_RAW; static enum cmit_fmt commit_format = CMIT_FMT_RAW;
...@@ -94,7 +86,7 @@ static void show_file(const char *prefix, void *tree, unsigned long size, const ...@@ -94,7 +86,7 @@ static void show_file(const char *prefix, void *tree, unsigned long size, const
return; return;
} }
diff_addremove(prefix[0], mode, sha1, base, path); diff_addremove(&diff_options, prefix[0], mode, sha1, base, path);
} }
static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base)
...@@ -118,7 +110,8 @@ static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, uns ...@@ -118,7 +110,8 @@ static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, uns
show_file("+", tree2, size2, base); show_file("+", tree2, size2, base);
return 1; return 1;
} }
if (!find_copies_harder && !memcmp(sha1, sha2, 20) && mode1 == mode2) if (!diff_options.find_copies_harder &&
!memcmp(sha1, sha2, 20) && mode1 == mode2)
return 0; return 0;
/* /*
...@@ -135,13 +128,14 @@ static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, uns ...@@ -135,13 +128,14 @@ static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, uns
int retval; int retval;
char *newbase = malloc_base(base, path1, pathlen1); char *newbase = malloc_base(base, path1, pathlen1);
if (show_tree_entry_in_recursive) if (show_tree_entry_in_recursive)
diff_change(mode1, mode2, sha1, sha2, base, path1); diff_change(&diff_options, mode1, mode2,
sha1, sha2, base, path1);
retval = diff_tree_sha1(sha1, sha2, newbase); retval = diff_tree_sha1(sha1, sha2, newbase);
free(newbase); free(newbase);
return retval; return retval;
} }
diff_change(mode1, mode2, sha1, sha2, base, path1); diff_change(&diff_options, mode1, mode2, sha1, sha2, base, path1);
return 0; return 0;
} }
...@@ -263,28 +257,26 @@ static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, co ...@@ -263,28 +257,26 @@ static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, co
return retval; return retval;
} }
static void call_diff_setup(void) static void call_diff_setup_done(void)
{ {
diff_setup(diff_setup_opt); diff_setup_done(&diff_options);
} }
static int call_diff_flush(void) static int call_diff_flush(void)
{ {
diffcore_std(NULL, diffcore_std(&diff_options);
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
orderfile,
diff_filter);
if (diff_queue_is_empty()) { if (diff_queue_is_empty()) {
diff_flush(DIFF_FORMAT_NO_OUTPUT, diff_line_termination); int saved_fmt = diff_options.output_format;
diff_options.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_flush(&diff_options);
diff_options.output_format = saved_fmt;
return 0; return 0;
} }
if (header) { if (header) {
printf("%s%c", header, diff_line_termination); printf("%s%c", header, diff_options.line_termination);
header = NULL; header = NULL;
} }
diff_flush(diff_output_format, diff_line_termination); diff_flush(&diff_options);
return 1; return 1;
} }
...@@ -293,7 +285,7 @@ static int diff_tree_sha1_top(const unsigned char *old, ...@@ -293,7 +285,7 @@ static int diff_tree_sha1_top(const unsigned char *old,
{ {
int ret; int ret;
call_diff_setup(); call_diff_setup_done();
ret = diff_tree_sha1(old, new, base); ret = diff_tree_sha1(old, new, base);
call_diff_flush(); call_diff_flush();
return ret; return ret;
...@@ -305,7 +297,7 @@ static int diff_root_tree(const unsigned char *new, const char *base) ...@@ -305,7 +297,7 @@ static int diff_root_tree(const unsigned char *new, const char *base)
void *tree; void *tree;
unsigned long size; unsigned long size;
call_diff_setup(); call_diff_setup_done();
tree = read_object_with_reference(new, "tree", &size, NULL); tree = read_object_with_reference(new, "tree", &size, NULL);
if (!tree) if (!tree)
die("unable to read root tree (%s)", sha1_to_hex(new)); die("unable to read root tree (%s)", sha1_to_hex(new));
...@@ -409,7 +401,7 @@ static const char diff_tree_usage[] = ...@@ -409,7 +401,7 @@ static const char diff_tree_usage[] =
"[<common diff options>] <tree-ish> <tree-ish>" "[<common diff options>] <tree-ish> <tree-ish>"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;
int main(int argc, char **argv) int main(int argc, const char **argv)
{ {
int nr_sha1; int nr_sha1;
char line[1000]; char line[1000];
...@@ -417,7 +409,10 @@ int main(int argc, char **argv) ...@@ -417,7 +409,10 @@ int main(int argc, char **argv)
const char *prefix = setup_git_directory(); const char *prefix = setup_git_directory();
nr_sha1 = 0; nr_sha1 = 0;
diff_setup(&diff_options);
for (;;) { for (;;) {
int diff_opt_cnt;
const char *arg; const char *arg;
argv++; argv++;
...@@ -434,6 +429,16 @@ int main(int argc, char **argv) ...@@ -434,6 +429,16 @@ int main(int argc, char **argv)
break; break;
} }
diff_opt_cnt = diff_opt_parse(&diff_options, argv, argc);
if (diff_opt_cnt < 0)
usage(diff_tree_usage);
else if (diff_opt_cnt) {
argv += diff_opt_cnt - 1;
argc -= diff_opt_cnt - 1;
continue;
}
if (!strcmp(arg, "--")) { if (!strcmp(arg, "--")) {
argv++; argv++;
argc--; argc--;
...@@ -447,68 +452,10 @@ int main(int argc, char **argv) ...@@ -447,68 +452,10 @@ int main(int argc, char **argv)
recursive = show_tree_entry_in_recursive = 1; recursive = show_tree_entry_in_recursive = 1;
continue; continue;
} }
if (!strcmp(arg, "-R")) {
diff_setup_opt |= DIFF_SETUP_REVERSE;
continue;
}
if (!strcmp(arg, "-p") || !strcmp(arg, "-u")) {
diff_output_format = DIFF_FORMAT_PATCH;
recursive = 1;
continue;
}
if (!strncmp(arg, "-S", 2)) {
pickaxe = arg + 2;
continue;
}
if (!strncmp(arg, "-O", 2)) {
orderfile = arg + 2;
continue;
}
if (!strncmp(arg, "--diff-filter=", 14)) {
diff_filter = arg + 14;
continue;
}
if (!strcmp(arg, "--pickaxe-all")) {
pickaxe_opts = DIFF_PICKAXE_ALL;
continue;
}
if (!strncmp(arg, "-M", 2)) {
detect_rename = DIFF_DETECT_RENAME;
if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
usage(diff_tree_usage);
continue;
}
if (!strncmp(arg, "-C", 2)) {
detect_rename = DIFF_DETECT_COPY;
if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
usage(diff_tree_usage);
continue;
}
if (!strncmp(arg, "-B", 2)) {
if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
usage(diff_tree_usage);
continue;
}
if (!strcmp(arg, "--find-copies-harder")) {
find_copies_harder = 1;
continue;
}
if (!strcmp(arg, "--name-only")) {
diff_output_format = DIFF_FORMAT_NAME;
continue;
}
if (!strcmp(arg, "-z")) {
diff_line_termination = 0;
continue;
}
if (!strcmp(arg, "-m")) { if (!strcmp(arg, "-m")) {
ignore_merges = 0; ignore_merges = 0;
continue; continue;
} }
if (!strcmp(arg, "-s")) {
diff_output_format = DIFF_FORMAT_NO_OUTPUT;
continue;
}
if (!strcmp(arg, "-v")) { if (!strcmp(arg, "-v")) {
verbose_header = 1; verbose_header = 1;
header_prefix = "diff-tree "; header_prefix = "diff-tree ";
...@@ -530,8 +477,8 @@ int main(int argc, char **argv) ...@@ -530,8 +477,8 @@ int main(int argc, char **argv)
} }
usage(diff_tree_usage); usage(diff_tree_usage);
} }
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY) if (diff_options.output_format == DIFF_FORMAT_PATCH)
usage(diff_tree_usage); recursive = 1;
paths = get_pathspec(prefix, argv); paths = get_pathspec(prefix, argv);
if (paths) { if (paths) {
...@@ -559,9 +506,9 @@ int main(int argc, char **argv) ...@@ -559,9 +506,9 @@ int main(int argc, char **argv)
if (!read_stdin) if (!read_stdin)
return 0; return 0;
if (detect_rename) if (diff_options.detect_rename)
diff_setup_opt |= (DIFF_SETUP_USE_SIZE_CACHE | diff_options.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
DIFF_SETUP_USE_CACHE); DIFF_SETUP_USE_CACHE);
while (fgets(line, sizeof(line), stdin)) while (fgets(line, sizeof(line), stdin))
diff_tree_stdin(line); diff_tree_stdin(line);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
static const char *diff_opts = "-pu"; static const char *diff_opts = "-pu";
static unsigned char null_sha1[20] = { 0, }; static unsigned char null_sha1[20] = { 0, };
static int reverse_diff;
static int use_size_cache; static int use_size_cache;
static const char *external_diff(void) static const char *external_diff(void)
...@@ -669,11 +668,20 @@ static void run_diff(struct diff_filepair *p) ...@@ -669,11 +668,20 @@ static void run_diff(struct diff_filepair *p)
complete_rewrite); complete_rewrite);
} }
void diff_setup(int flags) void diff_setup(struct diff_options *options)
{ {
if (flags & DIFF_SETUP_REVERSE) memset(options, 0, sizeof(*options));
reverse_diff = 1; options->output_format = DIFF_FORMAT_RAW;
if (flags & DIFF_SETUP_USE_CACHE) { options->line_termination = '\n';
options->break_opt = -1;
}
int diff_setup_done(struct diff_options *options)
{
if (options->find_copies_harder &&
options->detect_rename != DIFF_DETECT_COPY)
return -1;
if (options->setup & DIFF_SETUP_USE_CACHE) {
if (!active_cache) if (!active_cache)
/* read-cache does not die even when it fails /* read-cache does not die even when it fails
* so it is safe for us to do this here. Also * so it is safe for us to do this here. Also
...@@ -683,9 +691,55 @@ void diff_setup(int flags) ...@@ -683,9 +691,55 @@ void diff_setup(int flags)
*/ */
read_cache(); read_cache();
} }
if (flags & DIFF_SETUP_USE_SIZE_CACHE) if (options->setup & DIFF_SETUP_USE_SIZE_CACHE)
use_size_cache = 1; use_size_cache = 1;
return 0;
}
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
{
const char *arg = av[0];
if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
options->output_format = DIFF_FORMAT_PATCH;
else if (!strcmp(arg, "-z"))
options->line_termination = 0;
else if (!strcmp(arg, "--name-only"))
options->output_format = DIFF_FORMAT_NAME;
else if (!strcmp(arg, "-R"))
options->reverse_diff = 1;
else if (!strncmp(arg, "-S", 2))
options->pickaxe = arg + 2;
else if (!strcmp(arg, "-s"))
options->output_format = DIFF_FORMAT_NO_OUTPUT;
else if (!strncmp(arg, "-O", 2))
options->orderfile = arg + 2;
else if (!strncmp(arg, "--diff-filter=", 14))
options->filter = arg + 14;
else if (!strcmp(arg, "--pickaxe-all"))
options->pickaxe_opts = DIFF_PICKAXE_ALL;
else if (!strncmp(arg, "-B", 2)) {
if ((options->break_opt =
diff_scoreopt_parse(arg)) == -1)
return -1;
}
else if (!strncmp(arg, "-M", 2)) {
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
options->detect_rename = DIFF_DETECT_RENAME;
}
else if (!strncmp(arg, "-C", 2)) {
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
options->detect_rename = DIFF_DETECT_COPY;
}
else if (!strcmp(arg, "--find-copies-harder"))
options->find_copies_harder = 1;
else
return 0;
return 1;
} }
static int parse_num(const char **cp_p) static int parse_num(const char **cp_p)
...@@ -987,23 +1041,25 @@ static void diff_resolve_rename_copy(void) ...@@ -987,23 +1041,25 @@ static void diff_resolve_rename_copy(void)
diff_debug_queue("resolve-rename-copy done", q); diff_debug_queue("resolve-rename-copy done", q);
} }
void diff_flush(int diff_output_style, int line_termination) void diff_flush(struct diff_options *options)
{ {
struct diff_queue_struct *q = &diff_queued_diff; struct diff_queue_struct *q = &diff_queued_diff;
int i; int i;
int inter_name_termination = '\t'; int inter_name_termination = '\t';
int diff_output_format = options->output_format;
int line_termination = options->line_termination;
if (!line_termination) if (!line_termination)
inter_name_termination = 0; inter_name_termination = 0;
for (i = 0; i < q->nr; i++) { for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i]; struct diff_filepair *p = q->queue[i];
if ((diff_output_style == DIFF_FORMAT_NO_OUTPUT) || if ((diff_output_format == DIFF_FORMAT_NO_OUTPUT) ||
(p->status == DIFF_STATUS_UNKNOWN)) (p->status == DIFF_STATUS_UNKNOWN))
continue; continue;
if (p->status == 0) if (p->status == 0)
die("internal error in diff-resolve-rename-copy"); die("internal error in diff-resolve-rename-copy");
switch (diff_output_style) { switch (diff_output_format) {
case DIFF_FORMAT_PATCH: case DIFF_FORMAT_PATCH:
diff_flush_patch(p); diff_flush_patch(p);
break; break;
...@@ -1078,45 +1134,36 @@ static void diffcore_apply_filter(const char *filter) ...@@ -1078,45 +1134,36 @@ static void diffcore_apply_filter(const char *filter)
*q = outq; *q = outq;
} }
void diffcore_std(const char **paths, void diffcore_std(struct diff_options *options)
int detect_rename, int rename_score,
const char *pickaxe, int pickaxe_opts,
int break_opt,
const char *orderfile,
const char *filter)
{ {
if (paths && paths[0]) if (options->paths && options->paths[0])
diffcore_pathspec(paths); diffcore_pathspec(options->paths);
if (break_opt != -1) if (options->break_opt != -1)
diffcore_break(break_opt); diffcore_break(options->break_opt);
if (detect_rename) if (options->detect_rename)
diffcore_rename(detect_rename, rename_score); diffcore_rename(options->detect_rename, options->rename_score);
if (break_opt != -1) if (options->break_opt != -1)
diffcore_merge_broken(); diffcore_merge_broken();
if (pickaxe) if (options->pickaxe)
diffcore_pickaxe(pickaxe, pickaxe_opts); diffcore_pickaxe(options->pickaxe, options->pickaxe_opts);
if (orderfile) if (options->orderfile)
diffcore_order(orderfile); diffcore_order(options->orderfile);
diff_resolve_rename_copy(); diff_resolve_rename_copy();
diffcore_apply_filter(filter); diffcore_apply_filter(options->filter);
} }
void diffcore_std_no_resolve(const char **paths, void diffcore_std_no_resolve(struct diff_options *options)
const char *pickaxe, int pickaxe_opts,
const char *orderfile,
const char *filter)
{ {
if (paths && paths[0]) if (options->pickaxe)
diffcore_pathspec(paths); diffcore_pickaxe(options->pickaxe, options->pickaxe_opts);
if (pickaxe) if (options->orderfile)
diffcore_pickaxe(pickaxe, pickaxe_opts); diffcore_order(options->orderfile);
if (orderfile) diffcore_apply_filter(options->filter);
diffcore_order(orderfile);
diffcore_apply_filter(filter);
} }
void diff_addremove(int addremove, unsigned mode, void diff_addremove(struct diff_options *options,
int addremove, unsigned mode,
const unsigned char *sha1, const unsigned char *sha1,
const char *base, const char *path) const char *base, const char *path)
{ {
...@@ -1135,7 +1182,7 @@ void diff_addremove(int addremove, unsigned mode, ...@@ -1135,7 +1182,7 @@ void diff_addremove(int addremove, unsigned mode,
* Before the final output happens, they are pruned after * Before the final output happens, they are pruned after
* merged into rename/copy pairs as appropriate. * merged into rename/copy pairs as appropriate.
*/ */
if (reverse_diff) if (options->reverse_diff)
addremove = (addremove == '+' ? '-' : addremove = (addremove == '+' ? '-' :
addremove == '-' ? '+' : addremove); addremove == '-' ? '+' : addremove);
...@@ -1152,7 +1199,8 @@ void diff_addremove(int addremove, unsigned mode, ...@@ -1152,7 +1199,8 @@ void diff_addremove(int addremove, unsigned mode,
diff_queue(&diff_queued_diff, one, two); diff_queue(&diff_queued_diff, one, two);
} }
void diff_change(unsigned old_mode, unsigned new_mode, void diff_change(struct diff_options *options,
unsigned old_mode, unsigned new_mode,
const unsigned char *old_sha1, const unsigned char *old_sha1,
const unsigned char *new_sha1, const unsigned char *new_sha1,
const char *base, const char *path) const char *base, const char *path)
...@@ -1160,7 +1208,7 @@ void diff_change(unsigned old_mode, unsigned new_mode, ...@@ -1160,7 +1208,7 @@ void diff_change(unsigned old_mode, unsigned new_mode,
char concatpath[PATH_MAX]; char concatpath[PATH_MAX];
struct diff_filespec *one, *two; struct diff_filespec *one, *two;
if (reverse_diff) { if (options->reverse_diff) {
unsigned tmp; unsigned tmp;
const unsigned char *tmp_c; const unsigned char *tmp_c;
tmp = old_mode; old_mode = new_mode; new_mode = tmp; tmp = old_mode; old_mode = new_mode; new_mode = tmp;
...@@ -1176,7 +1224,8 @@ void diff_change(unsigned old_mode, unsigned new_mode, ...@@ -1176,7 +1224,8 @@ void diff_change(unsigned old_mode, unsigned new_mode,
diff_queue(&diff_queued_diff, one, two); diff_queue(&diff_queued_diff, one, two);
} }
void diff_unmerge(const char *path) void diff_unmerge(struct diff_options *options,
const char *path)
{ {
struct diff_filespec *one, *two; struct diff_filespec *one, *two;
one = alloc_filespec(path); one = alloc_filespec(path);
......
...@@ -8,18 +8,37 @@ ...@@ -8,18 +8,37 @@
(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
S_ISLNK(mode) ? S_IFLNK : S_IFDIR) S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
extern void diff_addremove(int addremove, struct diff_options {
const char **paths;
const char *filter;
const char *orderfile;
const char *pickaxe;
int break_opt;
int detect_rename;
int find_copies_harder;
int line_termination;
int output_format;
int pickaxe_opts;
int rename_score;
int reverse_diff;
int setup;
};
extern void diff_addremove(struct diff_options *,
int addremove,
unsigned mode, unsigned mode,
const unsigned char *sha1, const unsigned char *sha1,
const char *base, const char *base,
const char *path); const char *path);
extern void diff_change(unsigned mode1, unsigned mode2, extern void diff_change(struct diff_options *,
const unsigned char *sha1, unsigned mode1, unsigned mode2,
const unsigned char *sha2, const unsigned char *sha1,
const char *base, const char *path); const unsigned char *sha2,
const char *base, const char *path);
extern void diff_unmerge(const char *path); extern void diff_unmerge(struct diff_options *,
const char *path);
extern int diff_scoreopt_parse(const char *opt); extern int diff_scoreopt_parse(const char *opt);
...@@ -27,22 +46,18 @@ extern int diff_scoreopt_parse(const char *opt); ...@@ -27,22 +46,18 @@ extern int diff_scoreopt_parse(const char *opt);
#define DIFF_SETUP_USE_CACHE 2 #define DIFF_SETUP_USE_CACHE 2
#define DIFF_SETUP_USE_SIZE_CACHE 4 #define DIFF_SETUP_USE_SIZE_CACHE 4
extern void diff_setup(int flags); extern void diff_setup(struct diff_options *);
extern int diff_opt_parse(struct diff_options *, const char **, int);
extern int diff_setup_done(struct diff_options *);
#define DIFF_DETECT_RENAME 1 #define DIFF_DETECT_RENAME 1
#define DIFF_DETECT_COPY 2 #define DIFF_DETECT_COPY 2
#define DIFF_PICKAXE_ALL 1 #define DIFF_PICKAXE_ALL 1
extern void diffcore_std(const char **paths, extern void diffcore_std(struct diff_options *);
int detect_rename, int rename_score,
const char *pickaxe, int pickaxe_opts,
int break_opt,
const char *orderfile, const char *filter);
extern void diffcore_std_no_resolve(const char **paths, extern void diffcore_std_no_resolve(struct diff_options *);
const char *pickaxe, int pickaxe_opts,
const char *orderfile, const char *filter);
#define COMMON_DIFF_OPTIONS_HELP \ #define COMMON_DIFF_OPTIONS_HELP \
"\ncommon diff options:\n" \ "\ncommon diff options:\n" \
...@@ -71,7 +86,7 @@ extern int diff_queue_is_empty(void); ...@@ -71,7 +86,7 @@ extern int diff_queue_is_empty(void);
#define DIFF_FORMAT_NO_OUTPUT 3 #define DIFF_FORMAT_NO_OUTPUT 3
#define DIFF_FORMAT_NAME 4 #define DIFF_FORMAT_NAME 4
extern void diff_flush(int output_style, int line_terminator); extern void diff_flush(struct diff_options*);
/* diff-raw status letters */ /* diff-raw status letters */
#define DIFF_STATUS_ADDED 'A' #define DIFF_STATUS_ADDED 'A'
......
...@@ -31,7 +31,7 @@ static const char *tag_other = ""; ...@@ -31,7 +31,7 @@ static const char *tag_other = "";
static const char *tag_killed = ""; static const char *tag_killed = "";
static const char *tag_modified = ""; static const char *tag_modified = "";
static char *exclude_per_dir = NULL; static const char *exclude_per_dir = NULL;
/* We maintain three exclude pattern lists: /* We maintain three exclude pattern lists:
* EXC_CMDL lists patterns explicitly given on the command line. * EXC_CMDL lists patterns explicitly given on the command line.
...@@ -532,7 +532,7 @@ static const char ls_files_usage[] = ...@@ -532,7 +532,7 @@ static const char ls_files_usage[] =
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] " "[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
"[ --exclude-per-directory=<filename> ]"; "[ --exclude-per-directory=<filename> ]";
int main(int argc, char **argv) int main(int argc, const char **argv)
{ {
int i; int i;
int exc_given = 0; int exc_given = 0;
...@@ -542,7 +542,7 @@ int main(int argc, char **argv) ...@@ -542,7 +542,7 @@ int main(int argc, char **argv)
prefix_offset = strlen(prefix); prefix_offset = strlen(prefix);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
char *arg = argv[i]; const char *arg = argv[i];
if (!strcmp(arg, "-z")) { if (!strcmp(arg, "-z")) {
line_terminator = 0; line_terminator = 0;
......
...@@ -232,7 +232,7 @@ int remove_cache_entry_at(int pos) ...@@ -232,7 +232,7 @@ int remove_cache_entry_at(int pos)
return 1; return 1;
} }
int remove_file_from_cache(char *path) int remove_file_from_cache(const char *path)
{ {
int pos = cache_name_pos(path, strlen(path)); int pos = cache_name_pos(path, strlen(path));
if (pos < 0) if (pos < 0)
......
#include "cache.h" #include "cache.h"
char *prefix_path(const char *prefix, int len, char *path) const char *prefix_path(const char *prefix, int len, const char *path)
{ {
char *orig = path; const char *orig = path;
for (;;) { for (;;) {
char c; char c;
if (*path != '.') if (*path != '.')
...@@ -47,10 +47,10 @@ char *prefix_path(const char *prefix, int len, char *path) ...@@ -47,10 +47,10 @@ char *prefix_path(const char *prefix, int len, char *path)
return path; return path;
} }
const char **get_pathspec(const char *prefix, char **pathspec) const char **get_pathspec(const char *prefix, const char **pathspec)
{ {
char *entry = *pathspec; const char *entry = *pathspec;
char **p; const char **p;
int prefixlen; int prefixlen;
if (!prefix && !entry) if (!prefix && !entry)
......
...@@ -31,7 +31,7 @@ static inline long IS_ERR(const void *ptr) ...@@ -31,7 +31,7 @@ static inline long IS_ERR(const void *ptr)
return (unsigned long)ptr > (unsigned long)-1000L; return (unsigned long)ptr > (unsigned long)-1000L;
} }
static int add_file_to_cache(char *path) static int add_file_to_cache(const char *path)
{ {
int size, namelen, option, status; int size, namelen, option, status;
struct cache_entry *ce; struct cache_entry *ce;
...@@ -221,7 +221,7 @@ static int verify_dotfile(const char *rest) ...@@ -221,7 +221,7 @@ static int verify_dotfile(const char *rest)
return 1; return 1;
} }
static int verify_path(char *path) static int verify_path(const char *path)
{ {
char c; char c;
...@@ -247,7 +247,7 @@ static int verify_path(char *path) ...@@ -247,7 +247,7 @@ static int verify_path(char *path)
} }
} }
static int add_cacheinfo(char *arg1, char *arg2, char *arg3) static int add_cacheinfo(const char *arg1, const char *arg2, const char *arg3)
{ {
int size, len, option; int size, len, option;
unsigned int mode; unsigned int mode;
...@@ -277,7 +277,7 @@ static int add_cacheinfo(char *arg1, char *arg2, char *arg3) ...@@ -277,7 +277,7 @@ static int add_cacheinfo(char *arg1, char *arg2, char *arg3)
static struct cache_file cache_file; static struct cache_file cache_file;
int main(int argc, char **argv) int main(int argc, const char **argv)
{ {
int i, newfd, entries, has_errors = 0; int i, newfd, entries, has_errors = 0;
int allow_options = 1; int allow_options = 1;
...@@ -292,7 +292,7 @@ int main(int argc, char **argv) ...@@ -292,7 +292,7 @@ int main(int argc, char **argv)
die("cache corrupted"); die("cache corrupted");
for (i = 1 ; i < argc; i++) { for (i = 1 ; i < argc; i++) {
char *path = argv[i]; const char *path = argv[i];
if (allow_options && *path == '-') { if (allow_options && *path == '-') {
if (!strcmp(path, "--")) { if (!strcmp(path, "--")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册