def get_head_pseudo_revision(root, remote): """Returns the pseudo revision number and commit hash describing the base upstream commit this branch is based on. The base upstream commit hash is determined by 'git merge-base'. See the man page for more information. The pseudo revision is calculated by the number of commits separating the base upstream commit from the rootest commit. The earliest commit should be a root commit, e.g. a commit with no parent. A git tree can have multiple root commits when git repositories are merged together. The oldest one will be selected. The list of all root commits can be retrieved with: git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$" Returns: tuple of: - pseudo revision number as a int - upstream commit hash this branch is based of. """ mergebase = git(['merge-base', 'HEAD', remote], cwd=root).rstrip() with chdir(root): targets = git_common.parse_commitrefs(mergebase) git_number.load_generation_numbers(targets) git_number.finalize(targets) return git_number.get_num(targets[0]), mergebase
def get_pseudo_revision(root, remote): """Returns the pseudo revision number and commit hash describing the base upstream commit this branch is based on. The base upstream commit hash is determined by 'git merge-base'. See the man page for more information. The pseudo revision is calculated by the number of commits separating the base upstream commit from the rootest commit. The earliest commit should be a root commit, e.g. a commit with no parent. A git tree can have multiple root commits when git repositories are merged together. The oldest one will be selected. The list of all root commits can be retrieved with: git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$" Returns: tuple of: - pseudo revision number as a int - upstream commit hash this branch is based of. """ mergebase = git(['merge-base', 'HEAD', remote], cwd=root).rstrip() with chdir(root): targets = git_common.parse_commitrefs(mergebase) git_number.load_generation_numbers(targets) git_number.finalize(targets) return git_number.get_num(targets[0]), mergebase
def get_remote_pseudo_revision(root, remote): """Returns the pseudo revision number and commit hash describing the base upstream commit the remote branch is based on. The base upstream commit hash is determined by 'git rev-parse'. See the man page for more information. See get_head_pseudo_revision for more info about the pseudo revision. Returns: tuple of: - pseudo revision number as a int - upstream commit hash this branch is based of. """ mergebase = git(['rev-parse', remote], cwd=root).rstrip() with chdir(root): targets = git_common.parse_commitrefs(mergebase) git_number.load_generation_numbers(targets) git_number.finalize(targets) return git_number.get_num(targets[0]), mergebase