Commit 94b1ee9d authored by maruel@chromium.org's avatar maruel@chromium.org

Factor out gcl.GetRepositoryRoot() into scm.SVN.GetCheckoutRoot()

This is to reduce trychange.py dependency on gcl.py

Review URL: http://codereview.chromium.org/502085

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35055 0039d316-1c4b-4281-b951-d872f2087c98
parent 9a2f37ea
......@@ -65,18 +65,9 @@ def GetRepositoryRoot():
"""
global REPOSITORY_ROOT
if not REPOSITORY_ROOT:
infos = SVN.CaptureInfo(os.getcwd(), print_error=False)
cur_dir_repo_root = infos.get("Repository Root")
if not cur_dir_repo_root:
REPOSITORY_ROOT = SVN.GetCheckoutRoot(os.getcwd())
if not REPOSITORY_ROOT:
raise gclient_utils.Error("gcl run outside of repository")
REPOSITORY_ROOT = os.getcwd()
while True:
parent = os.path.dirname(REPOSITORY_ROOT)
if (SVN.CaptureInfo(parent, print_error=False).get(
"Repository Root") != cur_dir_repo_root):
break
REPOSITORY_ROOT = parent
return REPOSITORY_ROOT
......
......@@ -486,3 +486,22 @@ class SVN(object):
break
values[key] = value
return values
@staticmethod
def GetCheckoutRoot(directory):
"""Returns the top level directory of the current repository.
The directory is returned as an absolute path.
"""
infos = SVN.CaptureInfo(directory, print_error=False)
cur_dir_repo_root = infos.get("Repository Root")
if not cur_dir_repo_root:
return None
while True:
parent = os.path.dirname(directory)
if (SVN.CaptureInfo(parent, print_error=False).get(
"Repository Root") != cur_dir_repo_root):
break
directory = parent
return directory
......@@ -75,7 +75,6 @@ class GclUnittest(GclTestsBase):
gcl.os.getcwd().AndReturn(root_path)
result1 = { "Repository Root": "Some root" }
gcl.SVN.CaptureInfo(root_path, print_error=False).AndReturn(result1)
gcl.os.getcwd().AndReturn(root_path)
results2 = { "Repository Root": "A different root" }
gcl.SVN.CaptureInfo(gcl.os.path.dirname(root_path),
print_error=False).AndReturn(results2)
......
......@@ -65,7 +65,7 @@ class SVNWrapperTestCase(BaseTestCase):
def testDir(self):
members = [
'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
'CaptureStatus', 'DiffItem', 'GetEmail',
'CaptureStatus', 'DiffItem', 'GetCheckoutRoot', 'GetEmail',
'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run',
'RunAndFilterOutput', 'RunAndGetFileList',
'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
......
......@@ -139,7 +139,8 @@ class SVNTestCase(BaseSCMTestCase):
self.mox.ReplayAll()
members = [
'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
'CaptureStatus', 'DiffItem', 'GetEmail', 'GetFileProperty', 'IsMoved',
'CaptureStatus', 'DiffItem', 'GetCheckoutRoot', 'GetEmail',
'GetFileProperty', 'IsMoved',
'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList',
]
# If this test fails, you should add the relevant test.
......
......@@ -138,10 +138,7 @@ class SVN(SCM):
used.
"""
previous_cwd = os.getcwd()
if root is None:
os.chdir(gcl.GetRepositoryRoot())
else:
os.chdir(root)
os.chdir(root or scm.SVN.GetCheckoutRoot(previous_cwd))
# Directories will return None so filter them out.
diff = filter(None, [scm.SVN.DiffItem(f) for f in files])
......@@ -157,19 +154,23 @@ class SVN(SCM):
return self.change_info.GetLocalRoot()
def ProcessOptions(self):
checkout_root = None
if not self.options.diff:
# Generate the diff with svn and write it to the submit queue path. The
# files are relative to the repository root, but we need patches relative
# to one level up from there (i.e., 'src'), so adjust both the file
# paths and the root of the diff.
# TODO(maruel): Remove this hack.
source_root = GetSourceRoot()
prefix = PathDifference(source_root, gcl.GetRepositoryRoot())
checkout_root = scm.SVN.GetCheckoutRoot(os.getcwd())
prefix = PathDifference(source_root, checkout_root)
adjusted_paths = [os.path.join(prefix, x) for x in self.options.files]
self.options.diff = self.GenerateDiff(adjusted_paths, root=source_root)
self.change_info = gcl.LoadChangelistInfoForMultiple(self.options.name,
gcl.GetRepositoryRoot(), True, True)
if not self.options.email:
self.options.email = scm.SVN.GetEmail(gcl.GetRepositoryRoot())
checkout_root = checkout_root or scm.SVN.GetCheckoutRoot(os.getcwd())
self.options.email = scm.SVN.GetEmail(checkout_root)
class GIT(SCM):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment