зеркало из https://github.com/microsoft/git.git
built-in rebase: set ORIG_HEAD just once, before the rebase
Technically, the scripted version set ORIG_HEAD only in two spots (which really could have been one, because it called `git checkout $onto^0` to start the rebase and also if it could take a shortcut, and in both cases it called `git update-ref $orig_head`). Practically, it *implicitly* reset ORIG_HEAD whenever `git reset --hard` was called. However, what we really want is that it is set exactly once, at the beginning of the rebase. So let's do that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
c2d9629360
Коммит
cbd29ead92
|
@ -369,6 +369,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
|
||||||
#define RESET_HEAD_DETACH (1<<0)
|
#define RESET_HEAD_DETACH (1<<0)
|
||||||
#define RESET_HEAD_HARD (1<<1)
|
#define RESET_HEAD_HARD (1<<1)
|
||||||
#define RESET_HEAD_REFS_ONLY (1<<2)
|
#define RESET_HEAD_REFS_ONLY (1<<2)
|
||||||
|
#define RESET_ORIG_HEAD (1<<3)
|
||||||
|
|
||||||
static int reset_head(struct object_id *oid, const char *action,
|
static int reset_head(struct object_id *oid, const char *action,
|
||||||
const char *switch_to_branch, unsigned flags,
|
const char *switch_to_branch, unsigned flags,
|
||||||
|
@ -377,6 +378,7 @@ static int reset_head(struct object_id *oid, const char *action,
|
||||||
unsigned detach_head = flags & RESET_HEAD_DETACH;
|
unsigned detach_head = flags & RESET_HEAD_DETACH;
|
||||||
unsigned reset_hard = flags & RESET_HEAD_HARD;
|
unsigned reset_hard = flags & RESET_HEAD_HARD;
|
||||||
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
|
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
|
||||||
|
unsigned update_orig_head = flags & RESET_ORIG_HEAD;
|
||||||
struct object_id head_oid;
|
struct object_id head_oid;
|
||||||
struct tree_desc desc[2] = { { NULL }, { NULL } };
|
struct tree_desc desc[2] = { { NULL }, { NULL } };
|
||||||
struct lock_file lock = LOCK_INIT;
|
struct lock_file lock = LOCK_INIT;
|
||||||
|
@ -453,18 +455,21 @@ reset_head_refs:
|
||||||
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
|
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
|
||||||
prefix_len = msg.len;
|
prefix_len = msg.len;
|
||||||
|
|
||||||
if (!get_oid("ORIG_HEAD", &oid_old_orig))
|
if (update_orig_head) {
|
||||||
old_orig = &oid_old_orig;
|
if (!get_oid("ORIG_HEAD", &oid_old_orig))
|
||||||
if (!get_oid("HEAD", &oid_orig)) {
|
old_orig = &oid_old_orig;
|
||||||
orig = &oid_orig;
|
if (!get_oid("HEAD", &oid_orig)) {
|
||||||
if (!reflog_orig_head) {
|
orig = &oid_orig;
|
||||||
strbuf_addstr(&msg, "updating ORIG_HEAD");
|
if (!reflog_orig_head) {
|
||||||
reflog_orig_head = msg.buf;
|
strbuf_addstr(&msg, "updating ORIG_HEAD");
|
||||||
}
|
reflog_orig_head = msg.buf;
|
||||||
update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
|
}
|
||||||
UPDATE_REFS_MSG_ON_ERR);
|
update_ref(reflog_orig_head, "ORIG_HEAD", orig,
|
||||||
} else if (old_orig)
|
old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
|
||||||
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
|
} else if (old_orig)
|
||||||
|
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!reflog_head) {
|
if (!reflog_head) {
|
||||||
strbuf_setlen(&msg, prefix_len);
|
strbuf_setlen(&msg, prefix_len);
|
||||||
strbuf_addstr(&msg, "updating HEAD");
|
strbuf_addstr(&msg, "updating HEAD");
|
||||||
|
@ -1725,7 +1730,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||||
strbuf_addf(&msg, "%s: checkout %s",
|
strbuf_addf(&msg, "%s: checkout %s",
|
||||||
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
|
||||||
if (reset_head(&options.onto->object.oid, "checkout", NULL,
|
if (reset_head(&options.onto->object.oid, "checkout", NULL,
|
||||||
RESET_HEAD_DETACH, NULL, msg.buf))
|
RESET_HEAD_DETACH | RESET_ORIG_HEAD, NULL, msg.buf))
|
||||||
die(_("Could not detach HEAD"));
|
die(_("Could not detach HEAD"));
|
||||||
strbuf_release(&msg);
|
strbuf_release(&msg);
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ test_expect_success 'rebase against master' '
|
||||||
git rebase master
|
git rebase master
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'rebase sets ORIG_HEAD to pre-rebase state' '
|
test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
|
||||||
git checkout -b orig-head topic &&
|
git checkout -b orig-head topic &&
|
||||||
pre="$(git rev-parse --verify HEAD)" &&
|
pre="$(git rev-parse --verify HEAD)" &&
|
||||||
git rebase master &&
|
git rebase master &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче