# HG changeset patch # User Alexis S. L. Carvalho # Date 1174015378 10800 # Node ID c93562fb12cc5cc56b71515504ec714c3a3b9096 # Parent 24c22a3f2ef86ad759d28bc3c826ca8d28927b87 Fix handling of paths when run outside the repo. The main problem was that dirstate.getcwd() returned just "", which was interpreted as "we're at the repo root". It now returns an absolute path. The util.pathto function was also changed to deal with the "cwd is an absolute path" case. diff -r 24c22a3f2ef8 -r c93562fb12cc mercurial/dirstate.py --- a/mercurial/dirstate.py Fri Mar 16 00:22:57 2007 -0300 +++ b/mercurial/dirstate.py Fri Mar 16 00:22:58 2007 -0300 @@ -34,10 +34,14 @@ cwd = os.getcwd() if cwd == self.root: return '' # self.root ends with a path separator if self.root is '/' or 'C:\' - common_prefix_len = len(self.root) - if not self.root.endswith(os.sep): - common_prefix_len += 1 - return cwd[common_prefix_len:] + rootsep = self.root + if not rootsep.endswith(os.sep): + rootsep += os.sep + if cwd.startswith(rootsep): + return cwd[len(rootsep):] + else: + # we're outside the repo. return an absolute path. + return cwd def hgignore(self): '''return the contents of .hgignore files as a list of patterns. diff -r 24c22a3f2ef8 -r c93562fb12cc mercurial/util.py --- a/mercurial/util.py Fri Mar 16 00:22:57 2007 -0300 +++ b/mercurial/util.py Fri Mar 16 00:22:58 2007 -0300 @@ -326,6 +326,10 @@ n2 should always be relative to root. ''' if not n1: return localpath(n2) + if os.path.isabs(n1): + if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]: + return os.path.join(root, localpath(n2)) + n2 = '/'.join((pconvert(root), n2)) a, b = n1.split(os.sep), n2.split('/') a.reverse() b.reverse() diff -r 24c22a3f2ef8 -r c93562fb12cc tests/test-import --- a/tests/test-import Fri Mar 16 00:22:57 2007 -0300 +++ b/tests/test-import Fri Mar 16 00:22:58 2007 -0300 @@ -32,6 +32,17 @@ hg --cwd b import -mpatch ../tip.patch rm -r b +echo % hg -R repo import +# put the clone in a subdir - having a directory named "a" +# used to hide a bug. +mkdir dir +hg clone -r0 a dir/b +hg --cwd a export tip > dir/tip.patch +cd dir +hg -R b import tip.patch +cd .. +rm -r dir + echo % import from stdin hg clone -r0 a b hg --cwd a export tip | hg --cwd b import - diff -r 24c22a3f2ef8 -r c93562fb12cc tests/test-import.out --- a/tests/test-import.out Fri Mar 16 00:22:57 2007 -0300 +++ b/tests/test-import.out Fri Mar 16 00:22:58 2007 -0300 @@ -30,6 +30,14 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch +% hg -R repo import +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 2 changes to 2 files +2 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying tip.patch % import from stdin requesting all changes adding changesets diff -r 24c22a3f2ef8 -r c93562fb12cc tests/test-walk --- a/tests/test-walk Fri Mar 16 00:22:57 2007 -0300 +++ b/tests/test-walk Fri Mar 16 00:22:58 2007 -0300 @@ -59,3 +59,9 @@ hg debugwalk fenugreek touch new hg debugwalk new +cd .. +hg -R t debugwalk t/mammals/skunk +mkdir t2 +cd t2 +hg -R ../t debugwalk ../t/mammals/skunk +hg --cwd ../t debugwalk mammals/skunk diff -r 24c22a3f2ef8 -r c93562fb12cc tests/test-walk.out --- a/tests/test-walk.out Fri Mar 16 00:22:57 2007 -0300 +++ b/tests/test-walk.out Fri Mar 16 00:22:58 2007 -0300 @@ -95,3 +95,6 @@ m fenugreek fenugreek exact m fenugreek fenugreek exact f new new exact +f mammals/skunk t/mammals/skunk exact +f mammals/skunk ../t/mammals/skunk exact +f mammals/skunk mammals/skunk exact