Merge branch 'jk/common-main'
authorJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 20:22:13 +0000 (12:22 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 20:22:13 +0000 (12:22 -0800)
Fix for a small regression in a topic already in 'master'.

* jk/common-main:
common-main: stop munging argv[0] path

1  2 
git.c
diff --combined git.c
index e8b2baf2d15c8a68553780c3137c55c3fea99b11,5e50a41285bd7129aa1e1373276a6f22206831a5..dce529fcbfd6e5d8526b0e88b43f6c568876ce9d
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -35,7 -35,8 +35,7 @@@ static void save_env_before_alias(void
        orig_cwd = xgetcwd();
        for (i = 0; i < ARRAY_SIZE(env_names); i++) {
                orig_env[i] = getenv(env_names[i]);
 -              if (orig_env[i])
 -                      orig_env[i] = xstrdup(orig_env[i]);
 +              orig_env[i] = xstrdup_or_null(orig_env[i]);
        }
  }
  
@@@ -163,20 -164,6 +163,20 @@@ static int handle_options(const char **
                        setenv(GIT_WORK_TREE_ENVIRONMENT, cmd, 1);
                        if (envchanged)
                                *envchanged = 1;
 +              } else if (!strcmp(cmd, "--super-prefix")) {
 +                      if (*argc < 2) {
 +                              fprintf(stderr, "No prefix given for --super-prefix.\n" );
 +                              usage(git_usage_string);
 +                      }
 +                      setenv(GIT_SUPER_PREFIX_ENVIRONMENT, (*argv)[1], 1);
 +                      if (envchanged)
 +                              *envchanged = 1;
 +                      (*argv)++;
 +                      (*argc)--;
 +              } else if (skip_prefix(cmd, "--super-prefix=", &cmd)) {
 +                      setenv(GIT_SUPER_PREFIX_ENVIRONMENT, cmd, 1);
 +                      if (envchanged)
 +                              *envchanged = 1;
                } else if (!strcmp(cmd, "--bare")) {
                        char *cwd = xgetcwd();
                        is_bare_repository_cfg = 1;
@@@ -323,7 -310,6 +323,7 @@@ static int handle_alias(int *argcp, con
   * RUN_SETUP for reading from the configuration file.
   */
  #define NEED_WORK_TREE                (1<<3)
 +#define SUPPORT_SUPER_PREFIX  (1<<4)
  
  struct cmd_struct {
        const char *cmd;
@@@ -358,13 -344,6 +358,13 @@@ static int run_builtin(struct cmd_struc
        }
        commit_pager_choice();
  
 +      if (!help && get_super_prefix()) {
 +              if (!(p->option & SUPPORT_SUPER_PREFIX))
 +                      die("%s doesn't support --super-prefix", p->cmd);
 +              if (prefix)
 +                      die("can't use --super-prefix from a subdirectory");
 +      }
 +
        if (!help && p->option & NEED_WORK_TREE)
                setup_work_tree();
  
@@@ -396,7 -375,7 +396,7 @@@ static struct cmd_struct commands[] = 
        { "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
        { "annotate", cmd_annotate, RUN_SETUP },
        { "apply", cmd_apply, RUN_SETUP_GENTLY },
 -      { "archive", cmd_archive },
 +      { "archive", cmd_archive, RUN_SETUP_GENTLY },
        { "bisect--helper", cmd_bisect__helper, RUN_SETUP },
        { "blame", cmd_blame, RUN_SETUP },
        { "branch", cmd_branch, RUN_SETUP },
        { "init-db", cmd_init_db },
        { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY },
        { "log", cmd_log, RUN_SETUP },
 -      { "ls-files", cmd_ls_files, RUN_SETUP },
 +      { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX },
        { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
        { "ls-tree", cmd_ls_tree, RUN_SETUP },
 -      { "mailinfo", cmd_mailinfo },
 +      { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
        { "mailsplit", cmd_mailsplit },
        { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
        { "merge-base", cmd_merge_base, RUN_SETUP },
        { "pack-objects", cmd_pack_objects, RUN_SETUP },
        { "pack-redundant", cmd_pack_redundant, RUN_SETUP },
        { "pack-refs", cmd_pack_refs, RUN_SETUP },
 -      { "patch-id", cmd_patch_id },
 +      { "patch-id", cmd_patch_id, RUN_SETUP_GENTLY },
        { "pickaxe", cmd_blame, RUN_SETUP },
        { "prune", cmd_prune, RUN_SETUP },
        { "prune-packed", cmd_prune_packed, RUN_SETUP },
@@@ -543,34 -522,21 +543,34 @@@ static void strip_extension(const char 
  
  static void handle_builtin(int argc, const char **argv)
  {
 +      struct argv_array args = ARGV_ARRAY_INIT;
        const char *cmd;
        struct cmd_struct *builtin;
  
        strip_extension(argv);
        cmd = argv[0];
  
 -      /* Turn "git cmd --help" into "git help cmd" */
 +      /* Turn "git cmd --help" into "git help --exclude-guides cmd" */
        if (argc > 1 && !strcmp(argv[1], "--help")) {
 +              int i;
 +
                argv[1] = argv[0];
                argv[0] = cmd = "help";
 +
 +              for (i = 0; i < argc; i++) {
 +                      argv_array_push(&args, argv[i]);
 +                      if (!i)
 +                              argv_array_push(&args, "--exclude-guides");
 +              }
 +
 +              argc++;
 +              argv = args.argv;
        }
  
        builtin = get_builtin(cmd);
        if (builtin)
                exit(run_builtin(builtin, argc, argv));
 +      argv_array_clear(&args);
  }
  
  static void execv_dashed_external(const char **argv)
        const char *tmp;
        int status;
  
 +      if (get_super_prefix())
 +              die("%s doesn't support --super-prefix", argv[0]);
 +
        if (use_pager == -1)
                use_pager = check_pager_config(argv[0]);
        commit_pager_choice();
@@@ -654,6 -617,11 +654,11 @@@ int cmd_main(int argc, const char **arg
        cmd = argv[0];
        if (!cmd)
                cmd = "git-help";
+       else {
+               const char *slash = find_last_dir_sep(cmd);
+               if (slash)
+                       cmd = slash + 1;
+       }
  
        trace_command_performance(argv);