From: Junio C Hamano Date: Sun, 31 May 2009 23:57:42 +0000 (-0700) Subject: Merge branch 'sb/opt-filename' X-Git-Tag: v1.6.4-rc0~94 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f9275c68af58e0f65e1557b5109ccbfdbbbc384a?ds=inline;hp=-c Merge branch 'sb/opt-filename' * sb/opt-filename: parse-opts: add OPT_FILENAME and transition builtins parse-opts: prepare for OPT_FILENAME Conflicts: builtin-log.c --- f9275c68af58e0f65e1557b5109ccbfdbbbc384a diff --combined builtin-apply.c index ebbf084639,5329186266..94ba2bdd5b --- a/builtin-apply.c +++ b/builtin-apply.c @@@ -320,20 -320,6 +320,20 @@@ static int name_terminate(const char *n return 1; } +/* remove double slashes to make --index work with such filenames */ +static char *squash_slash(char *name) +{ + int i = 0, j = 0; + + while (name[i]) { + if ((name[j++] = name[i++]) == '/') + while (name[i] == '/') + i++; + } + name[j] = '\0'; + return name; +} + static char *find_name(const char *line, char *def, int p_value, int terminate) { int len; @@@ -363,7 -349,7 +363,7 @@@ free(def); if (root) strbuf_insert(&name, 0, root, root_len); - return strbuf_detach(&name, NULL); + return squash_slash(strbuf_detach(&name, NULL)); } } strbuf_release(&name); @@@ -383,10 -369,10 +383,10 @@@ start = line; } if (!start) - return def; + return squash_slash(def); len = line - start; if (!len) - return def; + return squash_slash(def); /* * Generally we prefer the shorter name, especially @@@ -397,7 -383,7 +397,7 @@@ if (def) { int deflen = strlen(def); if (deflen < len && !strncmp(start, def, deflen)) - return def; + return squash_slash(def); free(def); } @@@ -406,10 -392,10 +406,10 @@@ strcpy(ret, root); memcpy(ret + root_len, start, len); ret[root_len + len] = '\0'; - return ret; + return squash_slash(ret); } - return xmemdupz(start, len); + return squash_slash(xmemdupz(start, len)); } static int count_slashes(const char *cp) @@@ -3292,7 -3278,7 +3292,7 @@@ int cmd_apply(int argc, const char **ar "apply a patch without touching the working tree"), OPT_BOOLEAN(0, "apply", &force_apply, "also apply the patch (use with --stat/--summary/--check)"), - OPT_STRING(0, "build-fake-ancestor", &fake_ancestor, "file", + OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor, "build a temporary index based on embedded index information"), { OPTION_CALLBACK, 'z', NULL, NULL, NULL, "paths are separated with NUL character", @@@ -3327,11 -3313,8 +3327,8 @@@ if (apply_default_whitespace) parse_whitespace_option(apply_default_whitespace); - argc = parse_options(argc, argv, builtin_apply_options, + argc = parse_options(argc, argv, prefix, builtin_apply_options, apply_usage, 0); - fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor); - if (fake_ancestor) - fake_ancestor = xstrdup(fake_ancestor); if (apply_with_reject) apply = apply_verbosely = 1; diff --combined builtin-cat-file.c index 43ffe7ffae,991e40fb2e..5906842008 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@@ -201,8 -201,8 +201,8 @@@ static int batch_objects(int print_cont } static const char * const cat_file_usage[] = { - "git cat-file [-t|-s|-e|-p|] ", - "git cat-file [--batch|--batch-check] < ", + "git cat-file (-t|-s|-e|-p|) ", + "git cat-file (--batch|--batch-check) < ", NULL }; @@@ -231,7 -231,7 +231,7 @@@ int cmd_cat_file(int argc, const char * if (argc != 3 && argc != 2) usage_with_options(cat_file_usage, options); - argc = parse_options(argc, argv, options, cat_file_usage, 0); + argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0); if (opt) { if (argc == 1) diff --combined builtin-fetch.c index 1eec64e9c4,0ed6016da1..cd5eb9aff5 --- a/builtin-fetch.c +++ b/builtin-fetch.c @@@ -167,9 -167,6 +167,9 @@@ static struct ref *get_ref_map(struct t return ref_map; } +#define STORE_REF_ERROR_OTHER 1 +#define STORE_REF_ERROR_DF_CONFLICT 2 + static int s_update_ref(const char *action, struct ref *ref, int check_old) @@@ -184,11 -181,9 +184,11 @@@ lock = lock_any_ref_for_update(ref->name, check_old ? ref->old_sha1 : NULL, 0); if (!lock) - return 2; + return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT : + STORE_REF_ERROR_OTHER; if (write_ref_sha1(lock, ref->new_sha1, msg) < 0) - return 2; + return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT : + STORE_REF_ERROR_OTHER; return 0; } @@@ -391,7 -386,7 +391,7 @@@ static int store_updated_refs(const cha } free(url); fclose(fp); - if (rc & 2) + if (rc & STORE_REF_ERROR_DF_CONFLICT) error("some local refs could not be updated; try running\n" " 'git remote prune %s' to remove any old, conflicting " "branches", remote_name); @@@ -639,7 -634,7 +639,7 @@@ int cmd_fetch(int argc, const char **ar for (i = 1; i < argc; i++) strbuf_addf(&default_rla, " %s", argv[i]); - argc = parse_options(argc, argv, + argc = parse_options(argc, argv, prefix, builtin_fetch_options, builtin_fetch_usage, 0); if (argc == 0) diff --combined builtin-log.c index c8c6208275,ea8dbc8698..0d34050556 --- a/builtin-log.c +++ b/builtin-log.c @@@ -620,7 -620,7 +620,7 @@@ static void make_cover_letter(struct re struct shortlog log; struct strbuf sb = STRBUF_INIT; int i; - const char *encoding = "utf-8"; + const char *encoding = "UTF-8"; struct diff_options opts; int need_8bit_cte = 0; struct commit *commit = NULL; @@@ -936,7 -936,7 +936,7 @@@ int cmd_format_patch(int argc, const ch * like "git format-patch -o a123 HEAD^.." may fail; a123 is * possibly a valid SHA1. */ - argc = parse_options(argc, argv, builtin_format_patch_options, + argc = parse_options(argc, argv, prefix, builtin_format_patch_options, builtin_format_patch_usage, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); diff --combined builtin-remote.c index fda9a54a0c,13d5db168a..f7d66189cc --- a/builtin-remote.c +++ b/builtin-remote.c @@@ -79,7 -79,8 +79,8 @@@ static int add(int argc, const char **a OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 2) usage_with_options(builtin_remote_usage, options); @@@ -299,11 -300,11 +300,11 @@@ static int get_push_ref_states(const st return 0; local_refs = get_local_heads(); - ref = push_map = copy_ref_list(remote_refs); - while (ref->next) - ref = ref->next; - push_tail = &ref->next; + push_map = copy_ref_list(remote_refs); + push_tail = &push_map; + while (*push_tail) + push_tail = &((*push_tail)->next); match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr, remote->push_refspec, MATCH_REFS_NONE); @@@ -986,7 -987,8 +987,8 @@@ static int show(int argc, const char ** struct string_list info_list = { NULL, 0, 0, 0 }; struct show_info info; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 1) return show_all(); @@@ -1076,7 -1078,8 +1078,8 @@@ static int set_head(int argc, const cha "delete refs/remotes//HEAD"), OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc) strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]); @@@ -1130,7 -1133,8 +1133,8 @@@ static int prune(int argc, const char * OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 1) usage_with_options(builtin_remote_usage, options); @@@ -1220,7 -1224,7 +1224,7 @@@ static int update(int argc, const char OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, PARSE_OPT_KEEP_ARGV0); if (argc < 2) { argc = 2; @@@ -1306,7 -1310,7 +1310,7 @@@ int cmd_remote(int argc, const char **a }; int result; - argc = parse_options(argc, argv, options, builtin_remote_usage, + argc = parse_options(argc, argv, prefix, options, builtin_remote_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc < 1) diff --combined builtin-revert.c index ae0139500a,fa4752fd20..c87115af30 --- a/builtin-revert.c +++ b/builtin-revert.c @@@ -60,7 -60,7 +60,7 @@@ static void parse_args(int argc, const OPT_END(), }; - if (parse_options(argc, argv, options, usage_str, 0) != 1) + if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1) usage_with_options(usage_str, options); arg = argv[0]; @@@ -323,9 -323,9 +323,9 @@@ static int revert_or_cherry_pick(int ar encoding = get_encoding(message); if (!encoding) - encoding = "utf-8"; + encoding = "UTF-8"; if (!git_commit_encoding) - git_commit_encoding = "utf-8"; + git_commit_encoding = "UTF-8"; if ((reencoded_message = reencode_string(message, git_commit_encoding, encoding))) message = reencoded_message;