MCPcopy Create free account
hub / github.com/git/git / get_rebase_fork_point

Function get_rebase_fork_point

builtin/pull.c:646–684  ·  view source on GitHub ↗

* Given the repo and refspecs, sets fork_point to the point at which the * current branch forked from its remote-tracking branch. Returns 0 on success, * -1 on failure. */

Source from the content-addressed store, hash-verified

644 * -1 on failure.
645 */
646static int get_rebase_fork_point(struct object_id *fork_point, const char *repo,
647 const char *refspec)
648{
649 int ret;
650 struct branch *curr_branch;
651 const char *remote_branch;
652 struct child_process cp = CHILD_PROCESS_INIT;
653 struct strbuf sb = STRBUF_INIT;
654
655 curr_branch = branch_get("HEAD");
656 if (!curr_branch)
657 return -1;
658
659 if (refspec)
660 remote_branch = get_tracking_branch(repo, refspec);
661 else
662 remote_branch = get_upstream_branch(repo);
663
664 if (!remote_branch)
665 return -1;
666
667 strvec_pushl(&cp.args, "merge-base", "--fork-point",
668 remote_branch, curr_branch->name, NULL);
669 cp.no_stdin = 1;
670 cp.no_stderr = 1;
671 cp.git_cmd = 1;
672
673 ret = capture_command(&cp, &sb, GIT_MAX_HEXSZ);
674 if (ret)
675 goto cleanup;
676
677 ret = get_oid_hex(sb.buf, fork_point);
678 if (ret)
679 goto cleanup;
680
681cleanup:
682 strbuf_release(&sb);
683 return ret ? -1 : 0;
684}
685
686/**
687 * Sets merge_base to the octopus merge base of curr_head, merge_head and

Callers 1

cmd_pullFunction · 0.85

Calls 7

branch_getFunction · 0.85
get_tracking_branchFunction · 0.85
get_upstream_branchFunction · 0.85
strvec_pushlFunction · 0.85
capture_commandFunction · 0.85
get_oid_hexFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected