Chromium Code Reviews| Index: trychange.py |
| =================================================================== |
| --- trychange.py (revision 104937) |
| +++ trychange.py (working copy) |
| @@ -91,12 +91,30 @@ |
| return re.sub(r'[^\w#-]', '_', name) |
| +def _FindRepoCheckoutRoot(path): |
| + """Find the equivalent of gclient root of a repo-managed directory. |
| + |
| + Assumes the equivalent of gclient root is a level below the repo root. |
| + |
| + Args: |
| + path: A path that is within the repo-managed directory. |
| + """ |
| + path = os.path.abspath(path) |
| + while True: |
| + if path == os.path.dirname(path): |
| + break |
| + if os.path.isdir(os.path.join(os.path.dirname(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 +127,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 +170,34 @@ |
| 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() |
| + # Try to find gclient root first. |
| + if not self.options.no_gclient: |
|
M-A Ruel
2011/10/11 19:50:36
I feel like --no_gclient should also affect the se
|
| + self.toplevel_root = gclient_utils.FindGclientRoot(self.checkout_root) |
| + if self.toplevel_root: |
| + logging.info('Found .gclient at %s' % self.toplevel_root) |
| + |
| + # If no gclient toplevel root found, treat it like a repo-managed checkout. |
| + if not self.toplevel_root: |
| + self.toplevel_root = _FindRepoCheckoutRoot(self.checkout_root) |
| + if self.toplevel_root: |
| + logging.info('Found .repo dir at %s' |
| + % os.path.dirname(self.toplevel_root)) |
| + |
| + assert os.path.abspath(self.toplevel_root) == self.toplevel_root |
| + if self.toplevel_root and not self.options.root: |
| + self.options.root = gclient_utils.PathDifference(self.toplevel_root, |
|
M-A Ruel
2011/10/11 19:50:36
It's needed? I feel like it's a bug. :/
|
| + 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 = self.checkout_root |
| + if self.toplevel_root: |
|
M-A Ruel
2011/10/11 19:50:36
cur = self.checkout_root
root = self.toplevel_root
rcui1
2011/10/11 21:26:49
Done.
|
| + root = self.toplevel_root |
| + |
| assert cur.startswith(root), (root, cur) |
| while cur.startswith(root): |
| filepath = os.path.join(cur, filename) |