Code

Merge branch 'jn/fix-abbrev'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 19:28:58 +0000 (12:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 19:28:58 +0000 (12:28 -0700)
* jn/fix-abbrev:
  examples/commit: use --abbrev for commit summary
  checkout, commit: remove confusing assignments to rev.abbrev
  archive: abbreviate substituted commit ids again

1  2 
builtin/checkout.c
builtin/commit.c

diff --combined builtin/checkout.c
index 4ad74270cf1ae8be73372f8511f21ed1b14efdb4,eef2b48d9856c90b2d8fd7b2e06f8179c08faeac..1f7e1546f69acaef5e3c5cca1476acec972cb334
@@@ -32,11 -32,7 +32,11 @@@ struct checkout_opts 
        int writeout_stage;
        int writeout_error;
  
 +      /* not set by parse_options */
 +      int branch_exists;
 +
        const char *new_branch;
 +      const char *new_branch_force;
        const char *new_orphan_branch;
        int new_branch_log;
        enum branch_track track;
@@@ -283,7 -279,6 +283,6 @@@ static void show_local_changes(struct o
        struct rev_info rev;
        /* I think we want full paths, even if we're in a subdirectory. */
        init_revisions(&rev, NULL);
-       rev.abbrev = 0;
        rev.diffopt.output_format |= DIFF_FORMAT_NAME_STATUS;
        if (diff_setup_done(&rev.diffopt) < 0)
                die("diff_setup_done failed");
@@@ -515,8 -510,7 +514,8 @@@ static void update_refs_for_switch(stru
                        }
                }
                else
 -                      create_branch(old->name, opts->new_branch, new->name, 0,
 +                      create_branch(old->name, opts->new_branch, new->name,
 +                                    opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_log, opts->track);
                new->name = opts->new_branch;
                setup_branch_path(new);
                                        new->name);
                        else
                                fprintf(stderr, "Switched to%s branch '%s'\n",
 -                                      opts->new_branch ? " a new" : "",
 +                                      opts->branch_exists ? " and reset" : " a new",
                                        new->name);
                }
                if (old->path && old->name) {
@@@ -662,10 -656,7 +661,10 @@@ int cmd_checkout(int argc, const char *
        int dwim_new_local_branch = 1;
        struct option options[] = {
                OPT__QUIET(&opts.quiet),
 -              OPT_STRING('b', NULL, &opts.new_branch, "new branch", "branch"),
 +              OPT_STRING('b', NULL, &opts.new_branch, "branch",
 +                         "create and checkout a new branch"),
 +              OPT_STRING('B', NULL, &opts.new_branch_force, "branch",
 +                         "create/reset and checkout a branch"),
                OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
                OPT_SET_INT('t', "track",  &opts.track, "track",
                        BRANCH_TRACK_EXPLICIT),
        argc = parse_options(argc, argv, prefix, options, checkout_usage,
                             PARSE_OPT_KEEP_DASHDASH);
  
 +      /* we can assume from now on new_branch = !new_branch_force */
 +      if (opts.new_branch && opts.new_branch_force)
 +              die("-B cannot be used with -b");
 +
 +      /* copy -B over to -b, so that we can just check the latter */
 +      if (opts.new_branch_force)
 +              opts.new_branch = opts.new_branch_force;
 +
        if (patch_mode && (opts.track > 0 || opts.new_branch
                           || opts.new_branch_log || opts.merge || opts.force))
                die ("--patch is incompatible with all other options");
  
        if (opts.new_orphan_branch) {
                if (opts.new_branch)
 -                      die("--orphan and -b are mutually exclusive");
 +                      die("--orphan and -b|-B are mutually exclusive");
                if (opts.track > 0)
                        die("--orphan cannot be used with -t");
                opts.new_branch = opts.new_orphan_branch;
@@@ -874,12 -857,8 +873,12 @@@ no_reference
                if (strbuf_check_branch_ref(&buf, opts.new_branch))
                        die("git checkout: we do not like '%s' as a branch name.",
                            opts.new_branch);
 -              if (!get_sha1(buf.buf, rev))
 -                      die("git checkout: branch %s already exists", opts.new_branch);
 +              if (!get_sha1(buf.buf, rev)) {
 +                      opts.branch_exists = 1;
 +                      if (!opts.new_branch_force)
 +                              die("git checkout: branch %s already exists",
 +                                  opts.new_branch);
 +              }
                strbuf_release(&buf);
        }
  
diff --combined builtin/commit.c
index 2bb30c0e80f8948b28599da06c94c8c66b5733c7,279cfc1b5df89d8a58a25ecf5a9098cb761a91bf..c4a577d5c5595a6c50ecaaba90690c286d30b7e2
@@@ -147,7 -147,7 +147,7 @@@ static struct option builtin_commit_opt
                    "terminate entries with NUL"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
        OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
 -      { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 +      { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
        /* end commit contents options */
  
        { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
@@@ -1163,7 -1163,6 +1163,6 @@@ static void print_summary(const char *p
        init_revisions(&rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
  
-       rev.abbrev = 0;
        rev.diff = 1;
        rev.diffopt.output_format =
                DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY;