Skip to content

Commit 1526d0f

Browse files
phillipwoodgitster
authored andcommitted
reset_head(): make default_reflog_action optional
This parameter is only needed when a ref is going to be updated and the caller does not pass an explicit reflog message. Callers that are only discarding uncommitted changes in the working tree such as such as "rebase --skip" or create_autostash() do not update any refs so should not have to worry about passing this parameter. This change is not intended to have any user visible changes. The pointer comparison between `oid` and `&head_oid` checks that the caller did not pass an oid to be checked out. As no callers pass RESET_HEAD_RUN_POST_CHECKOUT_HOOK without passing an oid there are no changes to when the post-checkout hook is run. As update_ref() only updates the ref if the oid passed to it differs from the current ref there are no changes to when HEAD is updated. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6a9f5e commit 1526d0f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

builtin/rebase.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ static int move_to_original_branch(struct rebase_options *opts)
585585
opts->head_name);
586586
ret = reset_head(the_repository, NULL, opts->head_name,
587587
RESET_HEAD_REFS_ONLY,
588-
orig_head_reflog.buf, head_reflog.buf,
589-
DEFAULT_REFLOG_ACTION);
588+
orig_head_reflog.buf, head_reflog.buf, NULL);
590589

591590
strbuf_release(&orig_head_reflog);
592591
strbuf_release(&head_reflog);
@@ -822,7 +821,7 @@ static int checkout_up_to_date(struct rebase_options *options)
822821
options->switch_to);
823822
if (reset_head(the_repository, &options->orig_head,
824823
options->head_name, RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
825-
NULL, buf.buf, DEFAULT_REFLOG_ACTION) < 0)
824+
NULL, buf.buf, NULL) < 0)
826825
ret = error(_("could not switch to %s"), options->switch_to);
827826
strbuf_release(&buf);
828827

@@ -1273,7 +1272,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12731272
string_list_clear(&merge_rr, 1);
12741273

12751274
if (reset_head(the_repository, NULL, NULL, RESET_HEAD_HARD,
1276-
NULL, NULL, DEFAULT_REFLOG_ACTION) < 0)
1275+
NULL, NULL, NULL) < 0)
12771276
die(_("could not discard worktree changes"));
12781277
remove_branch_state(the_repository, 0);
12791278
if (read_basic_state(&options))
@@ -1778,8 +1777,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17781777
options.head_name ? options.head_name : "detached HEAD",
17791778
oid_to_hex(&options.onto->object.oid));
17801779
reset_head(the_repository, NULL, options.head_name,
1781-
RESET_HEAD_REFS_ONLY, "HEAD", msg.buf,
1782-
DEFAULT_REFLOG_ACTION);
1780+
RESET_HEAD_REFS_ONLY, "HEAD", msg.buf, NULL);
17831781
strbuf_release(&msg);
17841782
ret = finish_rebase(&options);
17851783
goto cleanup;

reset.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ static int update_refs(const struct object_id *oid, const char *switch_to_branch
2222
size_t prefix_len;
2323
int ret;
2424

25-
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
26-
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action);
25+
if ((update_orig_head && !reflog_orig_head) || !reflog_head) {
26+
if (!default_reflog_action)
27+
BUG("default_reflog_action must be given when reflog messages are omitted");
28+
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
29+
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action :
30+
default_reflog_action);
31+
}
2732
prefix_len = msg.len;
2833

2934
if (update_orig_head) {
@@ -71,6 +76,7 @@ int reset_head(struct repository *r, struct object_id *oid,
7176
{
7277
unsigned reset_hard = flags & RESET_HEAD_HARD;
7378
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
79+
unsigned update_orig_head = flags & RESET_ORIG_HEAD;
7480
struct object_id *head = NULL, head_oid;
7581
struct tree_desc desc[2] = { { NULL }, { NULL } };
7682
struct lock_file lock = LOCK_INIT;
@@ -144,8 +150,10 @@ int reset_head(struct repository *r, struct object_id *oid,
144150
goto leave_reset_head;
145151
}
146152

147-
ret = update_refs(oid, switch_to_branch, head, reflog_head,
148-
reflog_orig_head, default_reflog_action, flags);
153+
if (oid != &head_oid || update_orig_head || switch_to_branch)
154+
ret = update_refs(oid, switch_to_branch, head, reflog_head,
155+
reflog_orig_head, default_reflog_action,
156+
flags);
149157

150158
leave_reset_head:
151159
rollback_lock_file(&lock);

0 commit comments

Comments
 (0)