changeset 4541:3f4555babe74

localrepo: break out the repo-finding walk into its own function
author Matt Mackall <mpm@selenic.com>
date Mon, 11 Jun 2007 21:09:23 -0500
parents 133a52d70958
children af02e6078d08
files mercurial/localrepo.py
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Mon Jun 11 12:14:31 2007 -0700
+++ b/mercurial/localrepo.py	Mon Jun 11 21:09:23 2007 -0500
@@ -12,6 +12,15 @@
 import re, lock, transaction, tempfile, stat, mdiff, errno, ui
 import os, revlog, time, util
 
+def findrepo():
+    p = os.getcwd()
+    while not os.path.isdir(os.path.join(p, ".hg")):
+        oldp, p = p, os.path.dirname(p)
+        if p == oldp:
+            return None
+
+    return p
+
 class localrepository(repo.repository):
     capabilities = ('lookup', 'changegroupsubset')
     supported = ('revlogv1', 'store')
@@ -21,14 +30,10 @@
     def __init__(self, parentui, path=None, create=0):
         repo.repository.__init__(self)
         if not path:
-            p = os.getcwd()
-            while not os.path.isdir(os.path.join(p, ".hg")):
-                oldp = p
-                p = os.path.dirname(p)
-                if p == oldp:
-                    raise repo.RepoError(_("There is no Mercurial repository"
-                                           " here (.hg not found)"))
-            path = p
+            path = findrepo()
+            if not path:
+                raise repo.RepoError(_("There is no Mercurial repository"
+                                       " here (.hg not found)"))
 
         self.root = os.path.realpath(path)
         self.path = os.path.join(self.root, ".hg")