Merge branch 'jk/create-branch-remove-unused-param' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:28:02 +0000 (13:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:28:02 +0000 (13:28 -0800)
Code clean-up.

* jk/create-branch-remove-unused-param:
create_branch: drop unused "head" parameter

1  2 
builtin/branch.c
builtin/checkout.c
diff --combined builtin/branch.c
index 7df05437f11f76fb3a6c2c879fbb88fb63e71eac,6c3b570cf7a68839793d4a15b856fe4b65263e57..6810c3ac447a3078681c60f1e72bb008e5961bcf
@@@ -212,7 -212,7 +212,7 @@@ static int delete_branches(int argc, co
                        die(_("Couldn't look up commit object for HEAD"));
        }
        for (i = 0; i < argc; i++, strbuf_release(&bname)) {
 -              const char *target;
 +              char *target = NULL;
                int flags = 0;
  
                strbuf_branchname(&bname, argv[i]);
                        }
                }
  
 -              target = resolve_ref_unsafe(name,
 -                                          RESOLVE_REF_READING
 -                                          | RESOLVE_REF_NO_RECURSE
 -                                          | RESOLVE_REF_ALLOW_BAD_NAME,
 -                                          sha1, &flags);
 +              target = resolve_refdup(name,
 +                                      RESOLVE_REF_READING
 +                                      | RESOLVE_REF_NO_RECURSE
 +                                      | RESOLVE_REF_ALLOW_BAD_NAME,
 +                                      sha1, &flags);
                if (!target) {
                        error(remote_branch
                              ? _("remote-tracking branch '%s' not found.")
                    check_branch_commit(bname.buf, name, sha1, head_rev, kinds,
                                        force)) {
                        ret = 1;
 -                      continue;
 +                      goto next;
                }
  
                if (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,
                              : _("Error deleting branch '%s'"),
                              bname.buf);
                        ret = 1;
 -                      continue;
 +                      goto next;
                }
                if (!quiet) {
                        printf(remote_branch
                               : find_unique_abbrev(sha1, DEFAULT_ABBREV));
                }
                delete_branch_config(bname.buf);
 +
 +      next:
 +              free(target);
        }
  
        free(name);
@@@ -617,11 -614,14 +617,11 @@@ static int edit_branch_description(cons
        if (!buf.len || buf.buf[buf.len-1] != '\n')
                strbuf_addch(&buf, '\n');
        strbuf_commented_addf(&buf,
 -                  "Please edit the description for the branch\n"
 -                  "  %s\n"
 -                  "Lines starting with '%c' will be stripped.\n",
 +                  _("Please edit the description for the branch\n"
 +                    "  %s\n"
 +                    "Lines starting with '%c' will be stripped.\n"),
                    branch_name, comment_line_char);
 -      if (write_file_gently(git_path(edit_description), "%s", buf.buf)) {
 -              strbuf_release(&buf);
 -              return error_errno(_("could not write branch description template"));
 -      }
 +      write_file_buf(git_path(edit_description), buf.buf, buf.len);
        strbuf_reset(&buf);
        if (launch_editor(git_path(edit_description), &buf, NULL)) {
                strbuf_release(&buf);
@@@ -807,7 -807,7 +807,7 @@@ int cmd_branch(int argc, const char **a
                 * create_branch takes care of setting up the tracking
                 * info and making sure new_upstream is correct
                 */
-               create_branch(head, branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
+               create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
        } else if (unset_upstream) {
                struct branch *branch = branch_get(argv[0]);
                struct strbuf buf = STRBUF_INIT;
                strbuf_release(&buf);
  
                branch_existed = ref_exists(branch->refname);
-               create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
+               create_branch(argv[0], (argc == 2) ? argv[1] : head,
                              force, reflog, 0, quiet, track);
  
                /*
diff --combined builtin/checkout.c
index 32cf317ec244f0f08d2a2174e3e5b6279cde5b85,d561f7491d55c0b49224fa6c47222fb901bf18fe..899bd8db0b50d8d8a1cb00a9432692d9b898980d
@@@ -154,8 -154,8 +154,8 @@@ static int check_stages(unsigned stages
        return 0;
  }
  
 -static int checkout_stage(int stage, struct cache_entry *ce, int pos,
 -                        struct checkout *state)
 +static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
 +                        const struct checkout *state)
  {
        while (pos < active_nr &&
               !strcmp(active_cache[pos]->name, ce->name)) {
                return error(_("path '%s' does not have their version"), ce->name);
  }
  
 -static int checkout_merged(int pos, struct checkout *state)
 +static int checkout_merged(int pos, const struct checkout *state)
  {
        struct cache_entry *ce = active_cache[pos];
        const char *path = ce->name;
@@@ -276,7 -276,7 +276,7 @@@ static int checkout_paths(const struct 
  
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(&opts->pathspec) < 0)
 -              return error(_("corrupt index file"));
 +              return error(_("index file corrupt"));
  
        if (opts->source_tree)
                read_tree_some(opts->source_tree, &opts->pathspec);
@@@ -470,7 -470,7 +470,7 @@@ static int merge_working_tree(const str
  
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(NULL) < 0)
 -              return error(_("corrupt index file"));
 +              return error(_("index file corrupt"));
  
        resolve_undo_clear();
        if (opts->force) {
                         * entries in the index.
                         */
  
 -                      add_files_to_cache(NULL, NULL, 0, 0);
 +                      add_files_to_cache(NULL, NULL, 0);
                        /*
                         * NEEDSWORK: carrying over local changes
                         * when branches have different end-of-line
                        o.ancestor = old->name;
                        o.branch1 = new->name;
                        o.branch2 = "local";
 -                      merge_trees(&o, new->commit->tree, work,
 +                      ret = merge_trees(&o, new->commit->tree, work,
                                old->commit->tree, &result);
 +                      if (ret < 0)
 +                              exit(128);
                        ret = reset_tree(new->commit->tree, opts, 0,
                                         writeout_error);
 +                      strbuf_release(&o.obuf);
                        if (ret)
                                return ret;
                }
@@@ -631,7 -628,7 +631,7 @@@ static void update_refs_for_switch(cons
                        }
                }
                else
-                       create_branch(old->name, opts->new_branch, new->name,
+                       create_branch(opts->new_branch, new->name,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_log,
                                      opts->new_branch_force ? 1 : 0,
@@@ -985,7 -982,7 +985,7 @@@ static int parse_branchname_arg(int arg
                int recover_with_dwim = dwim_new_local_branch_ok;
  
                if (!has_dash_dash &&
 -                  (check_filename(NULL, arg) || !no_wildcard(arg)))
 +                  (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
                        recover_with_dwim = 0;
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
  
        if (!*source_tree)                   /* case (1): want a tree */
                die(_("reference is not a tree: %s"), arg);
 -      if (!has_dash_dash) {/* case (3).(d) -> (1) */
 +      if (!has_dash_dash) {   /* case (3).(d) -> (1) */
                /*
                 * Do not complain the most common case
                 *      git checkout branch
                 * it would be extremely annoying.
                 */
                if (argc)
 -                      verify_non_filename(NULL, arg);
 +                      verify_non_filename(opts->prefix, arg);
        } else {
                argcount++;
                argv++;
@@@ -1141,7 -1138,7 +1141,7 @@@ int cmd_checkout(int argc, const char *
                OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"),
                           N_("create/reset and checkout a branch")),
                OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")),
 -              OPT_BOOL(0, "detach", &opts.force_detach, N_("detach the HEAD at named commit")),
 +              OPT_BOOL(0, "detach", &opts.force_detach, N_("detach HEAD at named commit")),
                OPT_SET_INT('t', "track",  &opts.track, N_("set upstream info for new branch"),
                        BRANCH_TRACK_EXPLICIT),
                OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")),