Skip to content

Commit 1946d45

Browse files
phillipwoodgitster
authored andcommitted
reset_head(): remove action parameter
The only use of the action parameter is to setup the error messages for unpack_trees(). All but two cases pass either "checkout" or "reset". The case that passes "reset --hard" would be better passing "reset" so that the error messages match the builtin reset command like all the other callers that are doing a reset. The case that passes "Fast-forwarded" is only updating HEAD and so the parameter is unused in that case as it does not call unpack_trees(). The value to pass to setup_unpack_trees_porcelain() can be determined by checking whether flags contains RESET_HEAD_HARD without the caller having to specify it. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4840002 commit 1946d45

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

builtin/rebase.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static int move_to_original_branch(struct rebase_options *opts)
583583
opts->head_name, oid_to_hex(&opts->onto->object.oid));
584584
strbuf_addf(&head_reflog, "rebase finished: returning to %s",
585585
opts->head_name);
586-
ret = reset_head(the_repository, NULL, "", opts->head_name,
586+
ret = reset_head(the_repository, NULL, opts->head_name,
587587
RESET_HEAD_REFS_ONLY,
588588
orig_head_reflog.buf, head_reflog.buf,
589589
DEFAULT_REFLOG_ACTION);
@@ -674,7 +674,7 @@ static int run_am(struct rebase_options *opts)
674674
free(rebased_patches);
675675
strvec_clear(&am.args);
676676

677-
reset_head(the_repository, &opts->orig_head, "checkout",
677+
reset_head(the_repository, &opts->orig_head,
678678
opts->head_name, 0,
679679
"HEAD", NULL, DEFAULT_REFLOG_ACTION);
680680
error(_("\ngit encountered an error while preparing the "
@@ -820,7 +820,7 @@ static int checkout_up_to_date(struct rebase_options *options)
820820
strbuf_addf(&buf, "%s: checkout %s",
821821
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
822822
options->switch_to);
823-
if (reset_head(the_repository, &options->orig_head, "checkout",
823+
if (reset_head(the_repository, &options->orig_head,
824824
options->head_name, RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
825825
NULL, buf.buf, DEFAULT_REFLOG_ACTION) < 0)
826826
ret = error(_("could not switch to %s"), options->switch_to);
@@ -1272,7 +1272,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12721272
rerere_clear(the_repository, &merge_rr);
12731273
string_list_clear(&merge_rr, 1);
12741274

1275-
if (reset_head(the_repository, NULL, "reset", NULL, RESET_HEAD_HARD,
1275+
if (reset_head(the_repository, NULL, NULL, RESET_HEAD_HARD,
12761276
NULL, NULL, DEFAULT_REFLOG_ACTION) < 0)
12771277
die(_("could not discard worktree changes"));
12781278
remove_branch_state(the_repository, 0);
@@ -1290,7 +1290,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12901290

12911291
if (read_basic_state(&options))
12921292
exit(1);
1293-
if (reset_head(the_repository, &options.orig_head, "reset",
1293+
if (reset_head(the_repository, &options.orig_head,
12941294
options.head_name, RESET_HEAD_HARD,
12951295
NULL, NULL, DEFAULT_REFLOG_ACTION) < 0)
12961296
die(_("could not move back to %s"),
@@ -1759,7 +1759,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17591759

17601760
strbuf_addf(&msg, "%s: checkout %s",
17611761
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
1762-
if (reset_head(the_repository, &options.onto->object.oid, "checkout", NULL,
1762+
if (reset_head(the_repository, &options.onto->object.oid, NULL,
17631763
RESET_HEAD_DETACH | RESET_ORIG_HEAD |
17641764
RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
17651765
NULL, msg.buf, DEFAULT_REFLOG_ACTION))
@@ -1777,7 +1777,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17771777
strbuf_addf(&msg, "rebase finished: %s onto %s",
17781778
options.head_name ? options.head_name : "detached HEAD",
17791779
oid_to_hex(&options.onto->object.oid));
1780-
reset_head(the_repository, NULL, "Fast-forwarded", options.head_name,
1780+
reset_head(the_repository, NULL, options.head_name,
17811781
RESET_HEAD_REFS_ONLY, "HEAD", msg.buf,
17821782
DEFAULT_REFLOG_ACTION);
17831783
strbuf_release(&msg);

reset.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "tree.h"
99
#include "unpack-trees.h"
1010

11-
int reset_head(struct repository *r, struct object_id *oid, const char *action,
11+
int reset_head(struct repository *r, struct object_id *oid,
1212
const char *switch_to_branch, unsigned flags,
1313
const char *reflog_orig_head, const char *reflog_head,
1414
const char *default_reflog_action)
@@ -23,7 +23,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action,
2323
struct lock_file lock = LOCK_INIT;
2424
struct unpack_trees_options unpack_tree_opts = { 0 };
2525
struct tree *tree;
26-
const char *reflog_action;
26+
const char *action, *reflog_action;
2727
struct strbuf msg = STRBUF_INIT;
2828
size_t prefix_len;
2929
struct object_id *old_orig = NULL, oid_old_orig;
@@ -50,6 +50,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action,
5050
if (refs_only)
5151
goto reset_head_refs;
5252

53+
action = reset_hard ? "reset" : "checkout";
5354
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
5455
unpack_tree_opts.head_idx = 1;
5556
unpack_tree_opts.src_index = r->index;

reset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define RESET_HEAD_REFS_ONLY (1<<3)
1313
#define RESET_ORIG_HEAD (1<<4)
1414

15-
int reset_head(struct repository *r, struct object_id *oid, const char *action,
15+
int reset_head(struct repository *r, struct object_id *oid,
1616
const char *switch_to_branch, unsigned flags,
1717
const char *reflog_orig_head, const char *reflog_head,
1818
const char *default_reflog_action);

sequencer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,8 +4137,7 @@ void create_autostash(struct repository *r, const char *path,
41374137
path);
41384138
write_file(path, "%s", oid_to_hex(&oid));
41394139
printf(_("Created autostash: %s\n"), buf.buf);
4140-
if (reset_head(r, NULL, "reset --hard",
4141-
NULL, RESET_HEAD_HARD, NULL, NULL,
4140+
if (reset_head(r, NULL, NULL, RESET_HEAD_HARD, NULL, NULL,
41424141
default_reflog_action) < 0)
41434142
die(_("could not reset --hard"));
41444143

0 commit comments

Comments
 (0)