From 5d63eb83824129c492f3f30b7dff23e3cdbc3b7a Mon Sep 17 00:00:00 2001 From: "nasser@codeaurora.org" Date: Wed, 24 Mar 2010 23:22:09 +0000 Subject: [PATCH] revinfo: Properly use git HEAD or svn BASE revisions BUG=http://crosbug.com/1658 Review URL: http://codereview.chromium.org/1307001 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@42555 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 35 ++++++++++++++++------------------- gclient_scm.py | 2 +- scm.py | 11 +++++++++++ tests/scm_unittest.py | 6 +++--- 4 files changed, 31 insertions(+), 23 deletions(-) mode change 100755 => 100644 gclient.py diff --git a/gclient.py b/gclient.py old mode 100755 new mode 100644 index 1e58e031d..3d16aef5c --- a/gclient.py +++ b/gclient.py @@ -248,7 +248,7 @@ Valid options: """, "revinfo": """Outputs source path, server URL and revision information for every -dependency in all solutions (no local checkout required). +dependency in all solutions. usage: revinfo [options] """, @@ -798,14 +798,21 @@ class GClient(object): self._SaveEntries(entries) def PrintRevInfo(self): - """Output revision info mapping for the client and its dependencies. This - allows the capture of an overall "revision" for the source tree that can - be used to reproduce the same tree in the future. The actual output + """Output revision info mapping for the client and its dependencies. + + This allows the capture of an overall "revision" for the source tree that + can be used to reproduce the same tree in the future. The actual output contains enough information (source paths, svn server urls and revisions) - that it can be used either to generate external svn commands (without + that it can be used either to generate external svn/git commands (without gclient) or as input to gclient's --rev option (with some massaging of the data). + Since we care about the revision of the current source tree, for git + repositories this command uses the revision of the HEAD. For subversion we + use BASE. + + The --snapshot option allows creating a .gclient file to reproduce the tree. + Raises: Error: If the client has conflicting entries. """ @@ -827,21 +834,11 @@ class GClient(object): if not solutions: raise gclient_utils.Error("No solution specified") - # Inner helper to generate base url and rev tuple (including honoring - # |revision_overrides|) + # Inner helper to generate base url and rev tuple def GetURLAndRev(name, original_url): - url, revision = gclient_utils.SplitUrlRevision(original_url) - if not revision: - if revision_overrides.has_key(name): - return (url, revision_overrides[name]) - else: - scm = gclient_scm.CreateSCM(solution["url"], self._root_dir, name) - return (url, scm.revinfo(self._options, [], None)) - else: - if revision_overrides.has_key(name): - return (url, revision_overrides[name]) - else: - return (url, revision) + url, _ = gclient_utils.SplitUrlRevision(original_url) + scm = gclient_scm.CreateSCM(original_url, self._root_dir, name) + return (url, scm.revinfo(self._options, [], None)) # text of the snapshot gclient file new_gclient = "" diff --git a/gclient_scm.py b/gclient_scm.py index c65f48f94..4363763e7 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -806,7 +806,7 @@ class SVNWrapper(SCMWrapper): def revinfo(self, options, args, file_list): """Display revision""" __pychecker__ = 'unusednames=args,file_list,options' - return scm.SVN.CaptureHeadRevision(self.url) + return scm.SVN.CaptureBaseRevision(self.checkout_path) def runhooks(self, options, args, file_list): self.status(options, args, file_list) diff --git a/scm.py b/scm.py index 313ff7839..1b3b72f2c 100644 --- a/scm.py +++ b/scm.py @@ -493,6 +493,17 @@ class SVN(object): dom = xml.dom.minidom.parseString(info) return dom.getElementsByTagName('entry')[0].getAttribute('revision') + @staticmethod + def CaptureBaseRevision(cwd): + """Get the base revision of a SVN repository. + + Returns: + Int base revision + """ + info = SVN.Capture(["info", "--xml"], cwd) + dom = xml.dom.minidom.parseString(info) + return dom.getElementsByTagName('entry')[0].getAttribute('revision') + @staticmethod def CaptureStatus(files): """Returns the svn 1.5 svn status emulated output. diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 5f3ff5ef3..699039ebe 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -146,9 +146,9 @@ class SVNTestCase(BaseSCMTestCase): def testMembersChanged(self): self.mox.ReplayAll() members = [ - 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo', - 'CaptureStatus', 'DiffItem', 'GenerateDiff', 'GetCheckoutRoot', - 'GetEmail', 'GetFileProperty', 'IsMoved', + 'COMMAND', 'Capture', 'CaptureBaseRevision', 'CaptureHeadRevision', + 'CaptureInfo', 'CaptureStatus', 'DiffItem', 'GenerateDiff', + 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList', ] # If this test fails, you should add the relevant test.