[PATCH 1 of 1 STABLE] largefiles: fix path handling for cp/mv (issue3516)

Matt Harbison matt_harbison at yahoo.com
Wed Jul 25 11:17:09 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1343014673 14400
# Branch stable
# Node ID 2f4c6e61c190c126ba6203877dc278803d0c108e
# Parent  ffc49100151b68c0bcd061b900d9993e9e1a0d7d
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

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -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:
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -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
 


More information about the Mercurial-devel mailing list