Skip to content

Commit 8d08b44

Browse files
authored
Merge pull request #1932 from dscho/prepare-for-2.20.0-rc0
Prepare for v2.20.0-rc0
2 parents 2d3b493 + 6a07e39 commit 8d08b44

20 files changed

+692
-816
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ phases:
164164
displayName: Windows
165165
condition: succeeded()
166166
queue:
167-
name: Hosted VS2017
167+
name: Hosted
168168
timeoutInMinutes: 240
169169
steps:
170170
- powershell: |
@@ -215,7 +215,7 @@ phases:
215215
. ci/lib.sh
216216
217217
make -j10 DEVELOPER=1 NO_PERL=1 || exit 1
218-
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"--quiet --write-junit-xml\" time make -j15 -k DEVELOPER=1 test || {
218+
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"--no-chain-lint --no-bin-wrappers --quiet --write-junit-xml\" time make -j15 -k DEVELOPER=1 test || {
219219
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"-i -v -x\" make -k -C t failed; exit 1
220220
}
221221

builtin/rebase.c

Lines changed: 136 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "wt-status.h"
2323
#include "revision.h"
2424
#include "rerere.h"
25+
#include "branch.h"
2526

2627
static char const * const builtin_rebase_usage[] = {
2728
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -54,7 +55,7 @@ static int use_builtin_rebase(void)
5455
cp.git_cmd = 1;
5556
if (capture_command(&cp, &out, 6)) {
5657
strbuf_release(&out);
57-
return 0;
58+
return 1;
5859
}
5960

6061
strbuf_trim(&out);
@@ -281,8 +282,10 @@ static int apply_autostash(struct rebase_options *opts)
281282
if (!file_exists(path))
282283
return 0;
283284

284-
if (read_one(state_dir_path("autostash", opts), &autostash))
285+
if (read_one(path, &autostash))
285286
return error(_("Could not read '%s'"), path);
287+
/* Ensure that the hash is not mistaken for a number */
288+
strbuf_addstr(&autostash, "^0");
286289
argv_array_pushl(&stash_apply.args,
287290
"stash", "apply", autostash.buf, NULL);
288291
stash_apply.git_cmd = 1;
@@ -364,9 +367,124 @@ N_("Resolve all conflicts manually, mark them as resolved with\n"
364367
"To abort and get back to the state before \"git rebase\", run "
365368
"\"git rebase --abort\".");
366369

370+
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
371+
372+
#define RESET_HEAD_DETACH (1<<0)
373+
#define RESET_HEAD_HARD (1<<1)
374+
367375
static int reset_head(struct object_id *oid, const char *action,
368-
const char *switch_to_branch, int detach_head,
369-
const char *reflog_orig_head, const char *reflog_head);
376+
const char *switch_to_branch, unsigned flags,
377+
const char *reflog_orig_head, const char *reflog_head)
378+
{
379+
unsigned detach_head = flags & RESET_HEAD_DETACH;
380+
unsigned reset_hard = flags & RESET_HEAD_HARD;
381+
struct object_id head_oid;
382+
struct tree_desc desc[2] = { { NULL }, { NULL } };
383+
struct lock_file lock = LOCK_INIT;
384+
struct unpack_trees_options unpack_tree_opts;
385+
struct tree *tree;
386+
const char *reflog_action;
387+
struct strbuf msg = STRBUF_INIT;
388+
size_t prefix_len;
389+
struct object_id *orig = NULL, oid_orig,
390+
*old_orig = NULL, oid_old_orig;
391+
int ret = 0, nr = 0;
392+
393+
if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
394+
BUG("Not a fully qualified branch: '%s'", switch_to_branch);
395+
396+
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
397+
ret = -1;
398+
goto leave_reset_head;
399+
}
400+
401+
if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) {
402+
ret = error(_("could not determine HEAD revision"));
403+
goto leave_reset_head;
404+
}
405+
406+
if (!oid)
407+
oid = &head_oid;
408+
409+
memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
410+
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
411+
unpack_tree_opts.head_idx = 1;
412+
unpack_tree_opts.src_index = the_repository->index;
413+
unpack_tree_opts.dst_index = the_repository->index;
414+
unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;
415+
unpack_tree_opts.update = 1;
416+
unpack_tree_opts.merge = 1;
417+
if (!detach_head)
418+
unpack_tree_opts.reset = 1;
419+
420+
if (read_index_unmerged(the_repository->index) < 0) {
421+
ret = error(_("could not read index"));
422+
goto leave_reset_head;
423+
}
424+
425+
if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
426+
ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
427+
goto leave_reset_head;
428+
}
429+
430+
if (!fill_tree_descriptor(&desc[nr++], oid)) {
431+
ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
432+
goto leave_reset_head;
433+
}
434+
435+
if (unpack_trees(nr, desc, &unpack_tree_opts)) {
436+
ret = -1;
437+
goto leave_reset_head;
438+
}
439+
440+
tree = parse_tree_indirect(oid);
441+
prime_cache_tree(the_repository->index, tree);
442+
443+
if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
444+
ret = error(_("could not write index"));
445+
goto leave_reset_head;
446+
}
447+
448+
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
449+
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
450+
prefix_len = msg.len;
451+
452+
if (!get_oid("ORIG_HEAD", &oid_old_orig))
453+
old_orig = &oid_old_orig;
454+
if (!get_oid("HEAD", &oid_orig)) {
455+
orig = &oid_orig;
456+
if (!reflog_orig_head) {
457+
strbuf_addstr(&msg, "updating ORIG_HEAD");
458+
reflog_orig_head = msg.buf;
459+
}
460+
update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
461+
UPDATE_REFS_MSG_ON_ERR);
462+
} else if (old_orig)
463+
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
464+
if (!reflog_head) {
465+
strbuf_setlen(&msg, prefix_len);
466+
strbuf_addstr(&msg, "updating HEAD");
467+
reflog_head = msg.buf;
468+
}
469+
if (!switch_to_branch)
470+
ret = update_ref(reflog_head, "HEAD", oid, orig,
471+
detach_head ? REF_NO_DEREF : 0,
472+
UPDATE_REFS_MSG_ON_ERR);
473+
else {
474+
ret = create_symref("HEAD", switch_to_branch, msg.buf);
475+
if (!ret)
476+
ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
477+
UPDATE_REFS_MSG_ON_ERR);
478+
}
479+
480+
leave_reset_head:
481+
strbuf_release(&msg);
482+
rollback_lock_file(&lock);
483+
while (nr)
484+
free((void *)desc[--nr].buffer);
485+
return ret;
486+
}
487+
370488

371489
static int move_to_original_branch(struct rebase_options *opts)
372490
{
@@ -697,112 +815,6 @@ static int run_specific_rebase(struct rebase_options *opts)
697815
return status ? -1 : 0;
698816
}
699817

700-
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
701-
702-
static int reset_head(struct object_id *oid, const char *action,
703-
const char *switch_to_branch, int detach_head,
704-
const char *reflog_orig_head, const char *reflog_head)
705-
{
706-
struct object_id head_oid;
707-
struct tree_desc desc;
708-
struct lock_file lock = LOCK_INIT;
709-
struct unpack_trees_options unpack_tree_opts;
710-
struct tree *tree;
711-
const char *reflog_action;
712-
struct strbuf msg = STRBUF_INIT;
713-
size_t prefix_len;
714-
struct object_id *orig = NULL, oid_orig,
715-
*old_orig = NULL, oid_old_orig;
716-
int ret = 0;
717-
718-
if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
719-
BUG("Not a fully qualified branch: '%s'", switch_to_branch);
720-
721-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)
722-
return -1;
723-
724-
if (!oid) {
725-
if (get_oid("HEAD", &head_oid)) {
726-
rollback_lock_file(&lock);
727-
return error(_("could not determine HEAD revision"));
728-
}
729-
oid = &head_oid;
730-
}
731-
732-
memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
733-
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
734-
unpack_tree_opts.head_idx = 1;
735-
unpack_tree_opts.src_index = the_repository->index;
736-
unpack_tree_opts.dst_index = the_repository->index;
737-
unpack_tree_opts.fn = oneway_merge;
738-
unpack_tree_opts.update = 1;
739-
unpack_tree_opts.merge = 1;
740-
if (!detach_head)
741-
unpack_tree_opts.reset = 1;
742-
743-
if (read_index_unmerged(the_repository->index) < 0) {
744-
rollback_lock_file(&lock);
745-
return error(_("could not read index"));
746-
}
747-
748-
if (!fill_tree_descriptor(&desc, oid)) {
749-
error(_("failed to find tree of %s"), oid_to_hex(oid));
750-
rollback_lock_file(&lock);
751-
free((void *)desc.buffer);
752-
return -1;
753-
}
754-
755-
if (unpack_trees(1, &desc, &unpack_tree_opts)) {
756-
rollback_lock_file(&lock);
757-
free((void *)desc.buffer);
758-
return -1;
759-
}
760-
761-
tree = parse_tree_indirect(oid);
762-
prime_cache_tree(the_repository->index, tree);
763-
764-
if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0)
765-
ret = error(_("could not write index"));
766-
free((void *)desc.buffer);
767-
768-
if (ret)
769-
return ret;
770-
771-
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
772-
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
773-
prefix_len = msg.len;
774-
775-
if (!get_oid("ORIG_HEAD", &oid_old_orig))
776-
old_orig = &oid_old_orig;
777-
if (!get_oid("HEAD", &oid_orig)) {
778-
orig = &oid_orig;
779-
if (!reflog_orig_head) {
780-
strbuf_addstr(&msg, "updating ORIG_HEAD");
781-
reflog_orig_head = msg.buf;
782-
}
783-
update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
784-
UPDATE_REFS_MSG_ON_ERR);
785-
} else if (old_orig)
786-
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
787-
if (!reflog_head) {
788-
strbuf_setlen(&msg, prefix_len);
789-
strbuf_addstr(&msg, "updating HEAD");
790-
reflog_head = msg.buf;
791-
}
792-
if (!switch_to_branch)
793-
ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF,
794-
UPDATE_REFS_MSG_ON_ERR);
795-
else {
796-
ret = create_symref("HEAD", switch_to_branch, msg.buf);
797-
if (!ret)
798-
ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
799-
UPDATE_REFS_MSG_ON_ERR);
800-
}
801-
802-
strbuf_release(&msg);
803-
return ret;
804-
}
805-
806818
static int rebase_config(const char *var, const char *value, void *data)
807819
{
808820
struct rebase_options *opts = data;
@@ -1177,8 +1189,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11771189
rerere_clear(&merge_rr);
11781190
string_list_clear(&merge_rr, 1);
11791191

1180-
if (reset_head(NULL, "reset", NULL, 0, NULL, NULL) < 0)
1192+
if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
1193+
NULL, NULL) < 0)
11811194
die(_("could not discard worktree changes"));
1195+
remove_branch_state();
11821196
if (read_basic_state(&options))
11831197
exit(1);
11841198
goto run_rebase;
@@ -1193,9 +1207,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11931207
if (read_basic_state(&options))
11941208
exit(1);
11951209
if (reset_head(&options.orig_head, "reset",
1196-
options.head_name, 0, NULL, NULL) < 0)
1210+
options.head_name, RESET_HEAD_HARD,
1211+
NULL, NULL) < 0)
11971212
die(_("could not move back to %s"),
11981213
oid_to_hex(&options.orig_head));
1214+
remove_branch_state();
11991215
ret = finish_rebase(&options);
12001216
goto cleanup;
12011217
}
@@ -1395,15 +1411,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13951411
* git-rebase.txt caveats with "unless you know what you are doing"
13961412
*/
13971413
if (options.rebase_merges)
1398-
die(_("error: cannot combine '--preserve_merges' with "
1414+
die(_("error: cannot combine '--preserve-merges' with "
13991415
"'--rebase-merges'"));
14001416

14011417
if (options.rebase_merges) {
14021418
if (strategy_options.nr)
1403-
die(_("error: cannot combine '--rebase_merges' with "
1419+
die(_("error: cannot combine '--rebase-merges' with "
14041420
"'--strategy-option'"));
14051421
if (options.strategy)
1406-
die(_("error: cannot combine '--rebase_merges' with "
1422+
die(_("error: cannot combine '--rebase-merges' with "
14071423
"'--strategy'"));
14081424
}
14091425

@@ -1528,7 +1544,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15281544
update_index_if_able(&the_index, &lock_file);
15291545
rollback_lock_file(&lock_file);
15301546

1531-
if (has_unstaged_changes(0) || has_uncommitted_changes(0)) {
1547+
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
15321548
const char *autostash =
15331549
state_dir_path("autostash", &options);
15341550
struct child_process stash = CHILD_PROCESS_INIT;
@@ -1554,10 +1570,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15541570
if (safe_create_leading_directories_const(autostash))
15551571
die(_("Could not create directory for '%s'"),
15561572
options.state_dir);
1557-
write_file(autostash, "%s", buf.buf);
1573+
write_file(autostash, "%s", oid_to_hex(&oid));
15581574
printf(_("Created autostash: %s\n"), buf.buf);
15591575
if (reset_head(&head->object.oid, "reset --hard",
1560-
NULL, 0, NULL, NULL) < 0)
1576+
NULL, RESET_HEAD_HARD, NULL, NULL) < 0)
15611577
die(_("could not reset --hard"));
15621578
printf(_("HEAD is now at %s"),
15631579
find_unique_abbrev(&head->object.oid,
@@ -1677,8 +1693,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
16771693
"it...\n"));
16781694

16791695
strbuf_addf(&msg, "rebase: checkout %s", options.onto_name);
1680-
if (reset_head(&options.onto->object.oid, "checkout", NULL, 1,
1681-
NULL, msg.buf))
1696+
if (reset_head(&options.onto->object.oid, "checkout", NULL,
1697+
RESET_HEAD_DETACH, NULL, msg.buf))
16821698
die(_("Could not detach HEAD"));
16831699
strbuf_release(&msg);
16841700

0 commit comments

Comments
 (0)