localrepo: break out the repo-finding walk into its own function
authorMatt Mackall <mpm@selenic.com>
Mon, 11 Jun 2007 21:09:23 -0500
changeset 4541 3f4555babe74
parent 4540 133a52d70958
child 4542 af02e6078d08
localrepo: break out the repo-finding walk into its own function
mercurial/localrepo.py
--- 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")