Skip to content

Commit 7c9fbc0

Browse files
committed
Merge pull request #1983 from dscho/builtin-rebase-perf-fix
Fix a performance regression in the built-in rebase
2 parents 046627e + 27472d1 commit 7c9fbc0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

builtin/rebase.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
368368

369369
#define RESET_HEAD_DETACH (1<<0)
370370
#define RESET_HEAD_HARD (1<<1)
371+
#define RESET_HEAD_REFS_ONLY (1<<2)
371372

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

393-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
395+
if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
394396
ret = -1;
395397
goto leave_reset_head;
396398
}
@@ -403,6 +405,9 @@ static int reset_head(struct object_id *oid, const char *action,
403405
if (!oid)
404406
oid = &head_oid;
405407

408+
if (flags & RESET_HEAD_REFS_ONLY)
409+
goto reset_head_refs;
410+
406411
memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
407412
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
408413
unpack_tree_opts.head_idx = 1;
@@ -443,6 +448,7 @@ static int reset_head(struct object_id *oid, const char *action,
443448
goto leave_reset_head;
444449
}
445450

451+
reset_head_refs:
446452
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
447453
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
448454
prefix_len = msg.len;

0 commit comments

Comments
 (0)