Commit 2dc8a4d3 authored by maruel@chromium.org's avatar maruel@chromium.org

Change CaptureSVNInfo() to return a dictionary instead of a object.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@15750 0039d316-1c4b-4281-b951-d872f2087c98
parent 25b438de
......@@ -557,19 +557,18 @@ def RunSVNAndGetFileList(options, args, in_directory, file_list):
def CaptureSVNInfo(options, relpath, in_directory):
"""Runs 'svn info' on an existing path.
"""Returns a dictionary from the svn info output for the given file.
Args:
relpath: The directory where the working copy resides relative to
the directory given by in_directory.
in_directory: The directory where svn is to be run.
Returns:
An object with fields corresponding to the output of 'svn info'
"""
dom = ParseXML(CaptureSVN(options, ["info", "--xml", relpath], in_directory))
result = PrintableObject()
result = {}
if dom:
def C(item, f):
if item is not None: return f(item)
# /info/entry/
# url
# reposityory/(root|uuid)
......@@ -578,11 +577,18 @@ def CaptureSVNInfo(options, relpath, in_directory):
# str() the results because they may be returned as Unicode, which
# interferes with the higher layers matching up things in the deps
# dictionary.
result = PrintableObject()
result.root = str(GetNamedNodeText(dom, 'root'))
result.url = str(GetNamedNodeText(dom, 'url'))
result.uuid = str(GetNamedNodeText(dom, 'uuid'))
result.revision = int(GetNodeNamedAttributeText(dom, 'entry', 'revision'))
# TODO(maruel): Fix at higher level instead (!)
result['Repository Root'] = C(GetNamedNodeText(dom, 'root'), str)
result['URL'] = C(GetNamedNodeText(dom, 'url'), str)
result['UUID'] = C(GetNamedNodeText(dom, 'uuid'), str)
result['Revision'] = C(GetNodeNamedAttributeText(dom, 'entry', 'revision'),
int)
result['Node Kind'] = C(GetNodeNamedAttributeText(dom, 'entry', 'kind'),
str)
result['Schedule'] = C(GetNamedNodeText(dom, 'schedule'), str)
result['Path'] = C(GetNodeNamedAttributeText(dom, 'entry', 'path'), str)
result['Copied From URL'] = C(GetNamedNodeText(dom, 'copy-from-url'), str)
result['Copied From Rev'] = C(GetNamedNodeText(dom, 'copy-from-rev'), str)
return result
......@@ -781,17 +787,21 @@ class SCMWrapper(object):
if options.manually_grab_svn_rev:
# Retrieve the current HEAD version because svn is slow at null updates.
if not revision:
from_info_live = CaptureSVNInfo(options, from_info.url, '.')
revision = int(from_info_live.revision)
from_info_live = CaptureSVNInfo(options, from_info['URL'], '.')
revision = int(from_info_live['Revision'])
rev_str = ' at %d' % revision
if from_info.url != components[0]:
if from_info['URL'] != components[0]:
to_info = CaptureSVNInfo(options, url, '.')
if from_info.root != to_info.root:
if from_info['Repository Root'] != to_info['Repository Root']:
# We have different roots, so check if we can switch --relocate.
# Subversion only permits this if the repository UUIDs match.
if from_info.uuid != to_info.uuid:
raise Error("Can't switch the checkout to %s; UUID don't match" % url)
if from_info['UUID'] != to_info['UUID']:
raise Error("Can't switch the checkout to %s; UUID don't match. That "
"simply means in theory, gclient should verify you don't "
"have a local change, remove the old checkout and do a "
"fresh new checkout of the new repo. Contributions are "
"welcome." % url)
# Perform the switch --relocate, then rewrite the from_url
# to reflect where we "are now." (This is the same way that
......@@ -800,14 +810,18 @@ class SCMWrapper(object):
# can update to a revision or have to switch to a different
# branch work as expected.
# TODO(maruel): TEST ME !
command = ["switch", "--relocate", from_info.root, to_info.root,
command = ["switch", "--relocate",
from_info['Repository Root'],
to_info['Repository Root'],
self.relpath]
RunSVN(options, command, self._root_dir)
from_info.url = from_info.url.replace(from_info.root, to_info.root)
from_info['URL'] = from_info['URL'].replace(
from_info['Repository Root'],
to_info['Repository Root'])
# If the provided url has a revision number that matches the revision
# number of the existing directory, then we don't need to bother updating.
if not options.force and from_info.revision == revision:
if not options.force and from_info['Revision'] == revision:
if options.verbose or not forced_revision:
print >>options.stdout, ("\n_____ %s%s" % (
self.relpath, rev_str))
......
......@@ -1220,21 +1220,22 @@ class SCMWrapperTestCase(BaseTestCase):
options = self.Options(verbose=True)
base_path = os.path.join(self.root_dir, self.relpath)
options.force = True
file_info = gclient.PrintableObject()
file_info.root = 'blah'
file_info.url = self.url
file_info.uuid = 'ABC'
file_info.revision = 42
file_info = {
'Repository Root': 'blah',
'URL': self.url,
'UUID': 'ABC',
'Revision': 42,
}
options.path_exists(os.path.join(base_path, '.git')).AndReturn(False)
# Checkout or update.
options.path_exists(base_path).AndReturn(True)
gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.'
).AndReturn(file_info)
# Cheat a bit here.
gclient.CaptureSVNInfo(options, file_info.url, '.').AndReturn(file_info)
gclient.CaptureSVNInfo(options, file_info['URL'], '.').AndReturn(file_info)
additional_args = []
if options.manually_grab_svn_rev:
additional_args = ['--revision', str(file_info.revision)]
additional_args = ['--revision', str(file_info['Revision'])]
files_list = []
gclient.RunSVNAndGetFileList(options, ['update', base_path] + additional_args,
self.root_dir, files_list)
......@@ -1259,6 +1260,41 @@ class SCMWrapperTestCase(BaseTestCase):
scm.update(options, self.args, file_list)
self.mox.VerifyAll()
def testGetSVNFileInfo(self):
xml_text = r"""<?xml version="1.0"?>
<info>
<entry kind="file" path="%s" revision="14628">
<url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
<repository><root>http://src.chromium.org/svn</root></repository>
<wc-info>
<schedule>add</schedule>
<depth>infinity</depth>
<copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-url>
<copy-from-rev>14628</copy-from-rev>
<checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
</wc-info>
</entry>
</info>
""" % self.url
options = self.Options(verbose=True)
gclient.CaptureSVN(options, ['info', '--xml', self.url],
'.').AndReturn(xml_text)
expected = {
'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
'UUID': None,
'Repository Root': 'http://src.chromium.org/svn',
'Schedule': 'add',
'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
'Copied From Rev': '14628',
'Path': self.url,
'Revision': 14628,
'Node Kind': 'file',
}
self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(options, self.url, '.')
self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
self.mox.VerifyAll()
def testCaptureSvnInfo(self):
xml_text = """<?xml version="1.0"?>
<info>
......@@ -1288,10 +1324,18 @@ class SCMWrapperTestCase(BaseTestCase):
'.').AndReturn(xml_text)
self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(options, self.url, '.')
self.failUnless(file_info.root == self.root_dir)
self.failUnless(file_info.url == self.url)
self.failUnless(file_info.uuid == '7b9385f5-0452-0410-af26-ad4892b7a1fb')
self.failUnless(file_info.revision == 35)
expected = {
'URL': self.url,
'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
'Revision': 35,
'Repository Root': self.root_dir,
'Schedule': 'normal',
'Copied From URL': None,
'Copied From Rev': None,
'Path': '.',
'Node Kind': 'dir',
}
self.assertEqual(file_info, expected)
self.mox.VerifyAll()
......
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