Merge branch 'sb/opt-filename'
authorJunio C Hamano <gitster@pobox.com>
Sun, 31 May 2009 23:57:42 +0000 (16:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 31 May 2009 23:57:42 +0000 (16:57 -0700)
* sb/opt-filename:
parse-opts: add OPT_FILENAME and transition builtins
parse-opts: prepare for OPT_FILENAME

Conflicts:
builtin-log.c

1  2 
builtin-apply.c
builtin-cat-file.c
builtin-fetch.c
builtin-log.c
builtin-remote.c
builtin-revert.c
diff --combined builtin-apply.c
index ebbf084639e07a398ea6de62d5d135faabbd1bd4,5329186266786b8bae5d9fcedc50ee0041733882..94ba2bdd5bdf0bc2f9924fc8f73c98f0bb159134
@@@ -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;
                                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);
                        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
        if (def) {
                int deflen = strlen(def);
                if (deflen < len && !strncmp(start, def, deflen))
 -                      return def;
 +                      return squash_slash(def);
                free(def);
        }
  
                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",
        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 43ffe7ffae90322d757e110d8693a936209236f0,991e40fb2e01155c2fb9bf875781a8222ddfc715..590684200854ad6a71653f30d494eb191fd4a324
@@@ -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|<type>] <sha1>",
 -      "git cat-file [--batch|--batch-check] < <list_of_sha1s>",
 +      "git cat-file (-t|-s|-e|-p|<type>) <object>",
 +      "git cat-file (--batch|--batch-check) < <list_of_objects>",
        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 1eec64e9c4f624f035dc8c155316964c3b87470f,0ed6016da190f421b79819d9d1545e061dbffbdf..cd5eb9aff530fcb9629bd561bc774e2b9ad69afc
@@@ -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)
        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 c8c620827587f14c4ff3314572c0dd01a4a4cfe3,ea8dbc869808d8fa80bcf5c46236273ff0a0ca8c..0d34050556855d6bab8b4c4121e833cc326324df
@@@ -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 fda9a54a0c2f31b1071e4c401a3707375fc7a10d,13d5db168a8ec58ce6f99742fc35e71949559a6d..f7d66189ccefe903588c7bbf044c2bc909c50b5a
@@@ -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/<name>/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 ae0139500a6b4226e8b38b580524c6273f69a8cb,fa4752fd205ea6b3e122756d6c0640f059795737..c87115af30abd9515599586af860ccd07b96b264
@@@ -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;