Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Unified Diff: trychange.py

Issue 8174009: Add repo-managed checkout support to trychange.py (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trychange.py
===================================================================
--- trychange.py (revision 104320)
+++ trychange.py (working copy)
@@ -91,12 +91,26 @@
return re.sub(r'[^\w#-]', '_', name)
+def _FindRepoCheckoutRoot(path):
+ """Returns the nearest higher-level repo dir from the specified path.
+
+ Args:
+ path: The path to use. Defaults to cwd.
+ """
+ path = os.path.abspath(path)
+ while path != '/':
M-A Ruel 2011/10/10 18:16:06 I'd like it to be windows-compatible, so I'd use s
rcui1 2011/10/11 19:42:34 Done.
+ if os.path.isdir(os.path.join(path, '.repo')):
+ return path
+ path = os.path.dirname(path)
+ return None
+
+
class SCM(object):
"""Simplistic base class to implement one function: ProcessOptions."""
def __init__(self, options, path, file_list):
items = path.split('@')
assert len(items) <= 2
- self.checkout_root = items[0]
+ self.checkout_root = os.path.abspath(items[0])
items.append(None)
self.diff_against = items[1]
self.options = options
@@ -109,7 +123,7 @@
self.options.files = None
self.codereview_settings = None
self.codereview_settings_file = 'codereview.settings'
- self.gclient_root = None
+ self.toplevel_root = None
def GetFileNames(self):
"""Return the list of files in the diff."""
@@ -152,36 +166,37 @@
if v and getattr(self.options, k) is None:
setattr(self.options, k, v)
- def _GclientStyleSettings(self):
- """Find the root, assuming a gclient-style checkout."""
- if not self.options.no_gclient and not self.options.root:
- root = self.checkout_root
- self.gclient_root = gclient_utils.FindGclientRoot(root)
- if self.gclient_root:
- logging.info('Found .gclient at %s' % self.gclient_root)
- self.options.root = gclient_utils.PathDifference(self.gclient_root,
- root)
-
def AutomagicalSettings(self):
"""Determines settings based on supported code review and checkout tools.
"""
- self._GclientStyleSettings()
+ # If user did not provide toplevel root, try to find gclient root first.
+ if not self.toplevel_root and not self.options.no_gclient:
+ self.toplevel_root = gclient_utils.FindGclientRoot(self.checkout_root)
+ if self.toplevel_root:
+ logging.info('Found .gclient at %s' % self.toplevel_root)
M-A Ruel 2011/10/10 18:16:06 If you want, add: assert os.path.abspath(self.topl
rcui1 2011/10/11 19:42:34 Done.
+
+ # If still no toplevel root found, try to find repo-managed chromium root
+ if not self.toplevel_root:
+ repo_root = _FindRepoCheckoutRoot(self.checkout_root)
+ if repo_root:
+ chromium_root = os.path.join(repo_root,
M-A Ruel 2011/10/10 18:16:06 weird alignment, also I've refrained from hardcodi
rcui1 2011/10/11 19:42:34 Done.
+ 'chromium')
+ if self.checkout_root.startswith(chromium_root):
+ self.toplevel_root = chromium_root
+ logging.info('Found chromium checkout root at %s'
+ % self.toplevel_root)
+
+ if self.toplevel_root and not self.options.root:
+ self.options.root = gclient_utils.PathDifference(self.toplevel_root,
+ self.checkout_root)
+
self._GclStyleSettings()
def ReadRootFile(self, filename):
- if not self.options.root:
- filepath = os.path.join(self.checkout_root, filename)
- if os.path.isfile(filepath):
- logging.info('Found %s at %s' % (filename, self.checkout_root))
- return gclient_utils.FileRead(filepath)
- return None
- cur = os.path.abspath(self.checkout_root)
- if self.gclient_root:
- root = os.path.abspath(self.gclient_root)
- else:
- root = gclient_utils.FindGclientRoot(cur)
- if not root:
- root = cur
+ root = cur = os.path.abspath(self.checkout_root)
M-A Ruel 2011/10/10 18:16:06 self.checkout_root is guaranteed to be abspath so
rcui1 2011/10/11 19:42:34 Done.
+ if self.toplevel_root:
+ root = os.path.abspath(self.toplevel_root)
M-A Ruel 2011/10/10 18:16:06 If you also abspath toplevel_root, then you can do
rcui1 2011/10/11 19:42:34 I think the logic is pretty clear as it is. On 20
+
assert cur.startswith(root), (root, cur)
while cur.startswith(root):
filepath = os.path.join(cur, filename)
@@ -319,6 +334,7 @@
values['target'] = options.target
if options.project:
values['project'] = options.project
+
M-A Ruel 2011/10/10 18:16:06 bof, I'd revert this line
rcui1 2011/10/11 19:42:34 Done.
return values
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698