Move git-related functionality out of cros_build_lib (1 of 4).
cros_build_lib is starting to get really long -- it's now 2279 lines. This CL
moves git-related functionality out of cros_build_lib into git.py, reducing the
size and complexity of cros_build_lib by over 980 lines.
Note CL:*29160 and CL:*29161 should also be committed at the same time as this
CL, but CQ is not capable of handling external -> internal dependencies, so we
leave this dependency as implicit.
BUG=none
CQ-DEPEND=CL:38255
TEST=pylint, regexps, run_tests, and lots of trybot runs.
Change-Id: Id6c749df09862a724bef2eee84ca719ed461589c
Reviewed-on: https://gerrit.chromium.org/gerrit/38253
Commit-Ready: David James <davidjames@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/scripts/cros_merge_to_branch.py b/scripts/cros_merge_to_branch.py
index 1d81bd8..c5faed7 100644
--- a/scripts/cros_merge_to_branch.py
+++ b/scripts/cros_merge_to_branch.py
@@ -45,6 +45,7 @@
from chromite.lib import commandline
from chromite.lib import cros_build_lib
from chromite.lib import gerrit
+from chromite.lib import git
from chromite.lib import patch as cros_patch
@@ -88,7 +89,7 @@
patch.CherryPick(work_dir, inflight=True, leave_dirty=True)
# Get the new sha1 after apply.
- new_sha1 = cros_build_lib.GetGitRepoRevision(work_dir)
+ new_sha1 = git.GetGitRepoRevision(work_dir)
# Create and use a LocalPatch to Upload the change to Gerrit.
local_patch = cros_patch.LocalPatch(
@@ -112,22 +113,21 @@
manifest.GetProjectPath(patch.project))
# Use the email if email wasn't specified.
if not email:
- email = cros_build_lib.GetProjectUserEmail(reference)
+ email = git.GetProjectUserEmail(reference)
repository.CloneGitRepo(work_dir, patch.project_url, reference=reference)
# Set the git committer.
- cros_build_lib.RunGitCommand(work_dir,
- ['config', '--replace-all', 'user.email', email])
+ git.RunGit(work_dir, ['config', '--replace-all', 'user.email', email])
- mbranch = cros_build_lib.GitMatchSingleBranchName(
+ mbranch = git.MatchSingleBranchName(
work_dir, branch, namespace='refs/remotes/origin/')
logging.info('Auto resolved branch name "%s" to "%s"' % (branch, mbranch))
branch = mbranch
# Finally, create a local branch for uploading changes to the given remote
# branch.
- cros_build_lib.CreatePushBranch(
+ git.CreatePushBranch(
constants.PATCH_BRANCH, work_dir, sync=False,
remote_push_branch=('ignore', 'origin/%s' % branch))
@@ -138,7 +138,7 @@
"""Returns true if the given manifest contains all the patches.
Args:
- manifest - an instance of cros_build_lib.Manifest
+ manifest - an instance of git.Manifest
patches - a collection GerritPatch objects.
"""
for patch in patches:
@@ -174,7 +174,7 @@
# both email addresses and for using your checkout as a git mirror.
manifest = None
if options.mirror:
- manifest = cros_build_lib.ManifestCheckout.Cached(constants.SOURCE_ROOT)
+ manifest = git.ManifestCheckout.Cached(constants.SOURCE_ROOT)
if not _ManifestContainsAllPatches(manifest, patches):
return 1
else:
@@ -204,7 +204,7 @@
logging.info(' URL: %s', url)
except (cros_build_lib.RunCommandError, cros_patch.ApplyPatchException,
- cros_build_lib.AmbiguousBranchName) as e:
+ git.AmbiguousBranchName) as e:
# Tell the user how far we got.
good_changes = changes[:index]
bad_changes = changes[index:]