Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 26076:cebf7e48365e
paths: move path validation logic to its own function
Hard coding the '.hg' path in the paths class made it difficult for the hggit
extension to pull from gitrepos.
This patch moves the logic out to it's own function so extensions can add
additional checks to what is a valid path (i.e. a git repo is valid when hggit
is enabled).
author | Durham Goode <durham@fb.com> |
---|---|
date | Mon, 24 Aug 2015 19:33:36 -0700 |
parents | 1b1ab6ff58c4 |
children | 663fbc336e22 |
comparison
equal
deleted
inserted
replaced
26075:e7e7182564f6 | 26076:cebf7e48365e |
---|---|
1066 self.loc = str(u) | 1066 self.loc = str(u) |
1067 self._pushloc = pushloc | 1067 self._pushloc = pushloc |
1068 | 1068 |
1069 # When given a raw location but not a symbolic name, validate the | 1069 # When given a raw location but not a symbolic name, validate the |
1070 # location is valid. | 1070 # location is valid. |
1071 if (not name and not u.scheme | 1071 if not name and not u.scheme and not self._isvalidlocalpath(self.loc): |
1072 and not os.path.isdir(os.path.join(str(u), '.hg'))): | |
1073 raise ValueError('location is not a URL or path to a local ' | 1072 raise ValueError('location is not a URL or path to a local ' |
1074 'repo: %s' % rawloc) | 1073 'repo: %s' % rawloc) |
1074 | |
1075 def _isvalidlocalpath(self, path): | |
1076 """Returns True if the given path is a potentially valid repository. | |
1077 This is its own function so that extensions can change the definition of | |
1078 'valid' in this case (like when pulling from a git repo into a hg | |
1079 one).""" | |
1080 return os.path.isdir(os.path.join(path, '.hg')) | |
1075 | 1081 |
1076 @property | 1082 @property |
1077 def pushloc(self): | 1083 def pushloc(self): |
1078 return self._pushloc or self.loc | 1084 return self._pushloc or self.loc |
1079 | 1085 |