Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a performance regression in the built-in rebase #1983

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,15 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)

#define RESET_HEAD_DETACH (1<<0)
#define RESET_HEAD_HARD (1<<1)
#define RESET_HEAD_REFS_ONLY (1<<2)

static int reset_head(struct object_id *oid, const char *action,
const char *switch_to_branch, unsigned flags,
const char *reflog_orig_head, const char *reflog_head)
{
unsigned detach_head = flags & RESET_HEAD_DETACH;
unsigned reset_hard = flags & RESET_HEAD_HARD;
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
struct object_id head_oid;
struct tree_desc desc[2] = { { NULL }, { NULL } };
struct lock_file lock = LOCK_INIT;
Expand All @@ -390,7 +392,7 @@ static int reset_head(struct object_id *oid, const char *action,
if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
BUG("Not a fully qualified branch: '%s'", switch_to_branch);

if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
ret = -1;
goto leave_reset_head;
}
Expand All @@ -403,6 +405,9 @@ static int reset_head(struct object_id *oid, const char *action,
if (!oid)
oid = &head_oid;

if (flags & RESET_HEAD_REFS_ONLY)
goto reset_head_refs;

memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
unpack_tree_opts.head_idx = 1;
Expand Down Expand Up @@ -443,6 +448,7 @@ static int reset_head(struct object_id *oid, const char *action,
goto leave_reset_head;
}

reset_head_refs:
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
prefix_len = msg.len;
Expand Down Expand Up @@ -499,7 +505,8 @@ static int move_to_original_branch(struct rebase_options *opts)
opts->head_name, oid_to_hex(&opts->onto->object.oid));
strbuf_addf(&head_reflog, "rebase finished: returning to %s",
opts->head_name);
ret = reset_head(NULL, "checkout", opts->head_name, 0,
ret = reset_head(NULL, "checkout", opts->head_name,
RESET_HEAD_REFS_ONLY,
orig_head_reflog.buf, head_reflog.buf);

strbuf_release(&orig_head_reflog);
Expand Down