largefiles: fix path handling for cp/mv (issue3516) stable
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 22 Jul 2012 23:37:53 -0400
branchstable
changeset 17245 6e84171a61c8
parent 17244 483aa765f6c4
child 17246 bf5bb38bcc7c
largefiles: fix path handling for cp/mv (issue3516) Previously, a copy or a move of a largefile only worked if the cwd was the root of the repository. The first issue was that the destination path passed to os.mkdirs() chopped the absolute path to the standin after '.hglf/', which essentially created a path relative to the repository root. Similarly, the second issue was that the source and dest paths for copyfile() were relative to the repo root. This converts these three paths to absolute paths. Some notable issues, regardless of the directory in which the cp/mv is executed: 1) The copy is not being recorded in lfdirstate, but it is in dirstate for the standins. I'm not sure if this is by design (i.e. minimal info in lfdirstate). 2) status -C doesn't behave as expected. Using the testcase as an example: # after mv + ci $ hg status -C -v --rev '.^' # expected to see 'A' and ' ' lines too R dira\dirb\largefile $ hg status -C -v --rev '.^' foo/largefile # no output # expected to see 'A' and ' ' lines only $ hg status -C -v --rev '.^' foo/ # no output # expected to see 'A', ' ' and 'R' lines $ hg status -C -v --rev '.^' ./ # expected to see 'A' and ' ' lines too R dirb\largefile $ hg status -C -v --rev '.^' ../.hglf/dira/foo/largefile A ..\.hglf\dira\foo\largefile ..\.hglf\dira\dirb\largefile # no 'R' expected when new file is specified $ hg status -C -v --rev '.^' ../.hglf # OK A ..\.hglf\dira\foo\largefile ..\.hglf\dira\dirb\largefile R ..\.hglf\dira\dirb\largefile
hgext/largefiles/overrides.py
tests/test-largefiles.t
--- a/hgext/largefiles/overrides.py	Wed Jul 25 16:15:28 2012 +0900
+++ b/hgext/largefiles/overrides.py	Sun Jul 22 23:37:53 2012 -0400
@@ -515,14 +515,16 @@
                     dest.startswith(repo.wjoin(lfutil.shortname))):
                     srclfile = src.replace(repo.wjoin(lfutil.standin('')), '')
                     destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '')
-                    destlfiledir = os.path.dirname(destlfile) or '.'
+                    destlfiledir = os.path.dirname(repo.wjoin(destlfile)) or '.'
                     if not os.path.isdir(destlfiledir):
                         os.makedirs(destlfiledir)
                     if rename:
                         os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile))
                         lfdirstate.remove(srclfile)
                     else:
-                        util.copyfile(srclfile, destlfile)
+                        util.copyfile(repo.wjoin(srclfile),
+                                      repo.wjoin(destlfile))
+
                     lfdirstate.add(destlfile)
             lfdirstate.write()
         except util.Abort, e:
--- a/tests/test-largefiles.t	Wed Jul 25 16:15:28 2012 +0900
+++ b/tests/test-largefiles.t	Sun Jul 22 23:37:53 2012 -0400
@@ -141,6 +141,43 @@
   $ cat sub/large4
   large22
 
+Test copies and moves from a directory other than root (issue3516)
+
+  $ cd ..
+  $ hg init lf_cpmv
+  $ cd lf_cpmv
+  $ mkdir dira
+  $ mkdir dira/dirb
+  $ touch dira/dirb/largefile
+  $ hg add --large dira/dirb/largefile
+  $ hg commit -m "added"
+  Invoking status precommit hook
+  A dira/dirb/largefile
+  $ cd dira
+  $ hg cp dirb/largefile foo/largefile
+  $ hg ci -m "deep copy"
+  Invoking status precommit hook
+  A dira/foo/largefile
+  $ find . | sort
+  .
+  ./dirb
+  ./dirb/largefile
+  ./foo
+  ./foo/largefile
+  $ hg mv foo/largefile baz/largefile
+  $ hg ci -m "moved"
+  Invoking status precommit hook
+  A dira/baz/largefile
+  R dira/foo/largefile
+  $ find . | sort
+  .
+  ./baz
+  ./baz/largefile
+  ./dirb
+  ./dirb/largefile
+  ./foo
+  $ cd ../../a
+
 #if hgweb
 Test display of largefiles in hgweb