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): ...@@ -557,19 +557,18 @@ def RunSVNAndGetFileList(options, args, in_directory, file_list):
def CaptureSVNInfo(options, relpath, in_directory): 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: Args:
relpath: The directory where the working copy resides relative to relpath: The directory where the working copy resides relative to
the directory given by in_directory. the directory given by in_directory.
in_directory: The directory where svn is to be run. 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)) dom = ParseXML(CaptureSVN(options, ["info", "--xml", relpath], in_directory))
result = PrintableObject() result = {}
if dom: if dom:
def C(item, f):
if item is not None: return f(item)
# /info/entry/ # /info/entry/
# url # url
# reposityory/(root|uuid) # reposityory/(root|uuid)
...@@ -578,11 +577,18 @@ def CaptureSVNInfo(options, relpath, in_directory): ...@@ -578,11 +577,18 @@ def CaptureSVNInfo(options, relpath, in_directory):
# str() the results because they may be returned as Unicode, which # str() the results because they may be returned as Unicode, which
# interferes with the higher layers matching up things in the deps # interferes with the higher layers matching up things in the deps
# dictionary. # dictionary.
result = PrintableObject() # TODO(maruel): Fix at higher level instead (!)
result.root = str(GetNamedNodeText(dom, 'root')) result['Repository Root'] = C(GetNamedNodeText(dom, 'root'), str)
result.url = str(GetNamedNodeText(dom, 'url')) result['URL'] = C(GetNamedNodeText(dom, 'url'), str)
result.uuid = str(GetNamedNodeText(dom, 'uuid')) result['UUID'] = C(GetNamedNodeText(dom, 'uuid'), str)
result.revision = int(GetNodeNamedAttributeText(dom, 'entry', 'revision')) 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 return result
...@@ -781,17 +787,21 @@ class SCMWrapper(object): ...@@ -781,17 +787,21 @@ class SCMWrapper(object):
if options.manually_grab_svn_rev: if options.manually_grab_svn_rev:
# Retrieve the current HEAD version because svn is slow at null updates. # Retrieve the current HEAD version because svn is slow at null updates.
if not revision: if not revision:
from_info_live = CaptureSVNInfo(options, from_info.url, '.') from_info_live = CaptureSVNInfo(options, from_info['URL'], '.')
revision = int(from_info_live.revision) revision = int(from_info_live['Revision'])
rev_str = ' at %d' % revision rev_str = ' at %d' % revision
if from_info.url != components[0]: if from_info['URL'] != components[0]:
to_info = CaptureSVNInfo(options, url, '.') 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. # We have different roots, so check if we can switch --relocate.
# Subversion only permits this if the repository UUIDs match. # Subversion only permits this if the repository UUIDs match.
if from_info.uuid != to_info.uuid: if from_info['UUID'] != to_info['UUID']:
raise Error("Can't switch the checkout to %s; UUID don't match" % url) 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 # Perform the switch --relocate, then rewrite the from_url
# to reflect where we "are now." (This is the same way that # to reflect where we "are now." (This is the same way that
...@@ -800,14 +810,18 @@ class SCMWrapper(object): ...@@ -800,14 +810,18 @@ class SCMWrapper(object):
# can update to a revision or have to switch to a different # can update to a revision or have to switch to a different
# branch work as expected. # branch work as expected.
# TODO(maruel): TEST ME ! # 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] self.relpath]
RunSVN(options, command, self._root_dir) 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 # 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. # 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: if options.verbose or not forced_revision:
print >>options.stdout, ("\n_____ %s%s" % ( print >>options.stdout, ("\n_____ %s%s" % (
self.relpath, rev_str)) self.relpath, rev_str))
......
...@@ -1220,21 +1220,22 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1220,21 +1220,22 @@ class SCMWrapperTestCase(BaseTestCase):
options = self.Options(verbose=True) options = self.Options(verbose=True)
base_path = os.path.join(self.root_dir, self.relpath) base_path = os.path.join(self.root_dir, self.relpath)
options.force = True options.force = True
file_info = gclient.PrintableObject() file_info = {
file_info.root = 'blah' 'Repository Root': 'blah',
file_info.url = self.url 'URL': self.url,
file_info.uuid = 'ABC' 'UUID': 'ABC',
file_info.revision = 42 'Revision': 42,
}
options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) options.path_exists(os.path.join(base_path, '.git')).AndReturn(False)
# Checkout or update. # Checkout or update.
options.path_exists(base_path).AndReturn(True) options.path_exists(base_path).AndReturn(True)
gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.' gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.'
).AndReturn(file_info) ).AndReturn(file_info)
# Cheat a bit here. # Cheat a bit here.
gclient.CaptureSVNInfo(options, file_info.url, '.').AndReturn(file_info) gclient.CaptureSVNInfo(options, file_info['URL'], '.').AndReturn(file_info)
additional_args = [] additional_args = []
if options.manually_grab_svn_rev: if options.manually_grab_svn_rev:
additional_args = ['--revision', str(file_info.revision)] additional_args = ['--revision', str(file_info['Revision'])]
files_list = [] files_list = []
gclient.RunSVNAndGetFileList(options, ['update', base_path] + additional_args, gclient.RunSVNAndGetFileList(options, ['update', base_path] + additional_args,
self.root_dir, files_list) self.root_dir, files_list)
...@@ -1259,6 +1260,41 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1259,6 +1260,41 @@ class SCMWrapperTestCase(BaseTestCase):
scm.update(options, self.args, file_list) scm.update(options, self.args, file_list)
self.mox.VerifyAll() 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): def testCaptureSvnInfo(self):
xml_text = """<?xml version="1.0"?> xml_text = """<?xml version="1.0"?>
<info> <info>
...@@ -1288,10 +1324,18 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1288,10 +1324,18 @@ class SCMWrapperTestCase(BaseTestCase):
'.').AndReturn(xml_text) '.').AndReturn(xml_text)
self.mox.ReplayAll() self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(options, self.url, '.') file_info = self._CaptureSVNInfo(options, self.url, '.')
self.failUnless(file_info.root == self.root_dir) expected = {
self.failUnless(file_info.url == self.url) 'URL': self.url,
self.failUnless(file_info.uuid == '7b9385f5-0452-0410-af26-ad4892b7a1fb') 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
self.failUnless(file_info.revision == 35) '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() 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