Skip to content

Commit 4f66d79

Browse files
phil-blaingitster
authored andcommitted
pull --rebase: compute rebase arguments in separate function
The function 'run_rebase' is responsible for constructing the command line to be passed to 'git rebase'. This includes both forwarding pass-through options given to 'git pull' as well computing the <newbase> and <upstream> arguments to 'git rebase'. A following commit will need to access the <upstream> argument in 'cmd_pull' to fix a bug with 'git pull --rebase --recurse-submodules'. In order to do so, refactor the code so that the <newbase> and <upstream> commits are computed in a new, separate function, 'get_rebase_newbase_and_upstream'. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit 4f66d79

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

builtin/pull.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,21 +852,42 @@ static int get_octopus_merge_base(struct object_id *merge_base,
852852

853853
/**
854854
* Given the current HEAD oid, the merge head returned from git-fetch and the
855-
* fork point calculated by get_rebase_fork_point(), runs git-rebase with the
856-
* appropriate arguments and returns its exit status.
855+
* fork point calculated by get_rebase_fork_point(), compute the <newbase> and
856+
* <upstream> arguments to use for the upcoming git-rebase invocation.
857857
*/
858-
static int run_rebase(const struct object_id *curr_head,
858+
static int get_rebase_newbase_and_upstream(struct object_id *newbase,
859+
struct object_id *upstream,
860+
const struct object_id *curr_head,
859861
const struct object_id *merge_head,
860862
const struct object_id *fork_point)
861863
{
862-
int ret;
863864
struct object_id oct_merge_base;
864-
struct strvec args = STRVEC_INIT;
865865

866866
if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
867867
if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))
868868
fork_point = NULL;
869869

870+
if (fork_point && !is_null_oid(fork_point))
871+
oidcpy(upstream, fork_point);
872+
else
873+
oidcpy(upstream, merge_head);
874+
875+
oidcpy(newbase, merge_head);
876+
877+
return 0;
878+
}
879+
880+
/**
881+
* Given the <newbase> and <upstream> calculated by
882+
* get_rebase_newbase_and_upstream(), runs git-rebase with the
883+
* appropriate arguments and returns its exit status.
884+
*/
885+
static int run_rebase(const struct object_id *newbase,
886+
const struct object_id *upstream)
887+
{
888+
int ret;
889+
struct strvec args = STRVEC_INIT;
890+
870891
strvec_push(&args, "rebase");
871892

872893
/* Shared options */
@@ -894,12 +915,9 @@ static int run_rebase(const struct object_id *curr_head,
894915
warning(_("ignoring --verify-signatures for rebase"));
895916

896917
strvec_push(&args, "--onto");
897-
strvec_push(&args, oid_to_hex(merge_head));
918+
strvec_push(&args, oid_to_hex(newbase));
898919

899-
if (fork_point && !is_null_oid(fork_point))
900-
strvec_push(&args, oid_to_hex(fork_point));
901-
else
902-
strvec_push(&args, oid_to_hex(merge_head));
920+
strvec_push(&args, oid_to_hex(upstream));
903921

904922
ret = run_command_v_opt(args.v, RUN_GIT_CMD);
905923
strvec_clear(&args);
@@ -1011,6 +1029,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10111029
if (opt_rebase) {
10121030
int ret = 0;
10131031
int ran_ff = 0;
1032+
1033+
struct object_id newbase;
1034+
struct object_id upstream;
1035+
get_rebase_newbase_and_upstream(&newbase, &upstream, &curr_head,
1036+
merge_heads.oid, &rebase_fork_point);
1037+
10141038
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
10151039
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
10161040
submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head))
@@ -1034,7 +1058,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10341058
free_commit_list(list);
10351059
}
10361060
if (!ran_ff)
1037-
ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);
1061+
ret = run_rebase(&newbase, &upstream);
10381062

10391063
if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
10401064
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))

0 commit comments

Comments
 (0)