largefiles: treat status of cache missed largefiles as "missing" correctly
"hg status" may treat cache missed largefiles as "removed" incorrectly.
assumptions for problem case:
- there is no cache for largefile "L"
- at first, update working directory to the revision in which "L" is
not yet added,
- then, update working directory to the revision in which "L" is
already added
and now, "hg status" treats "L" as "removed".
current implementation does not allocate entry for cache missed
largefile in ".hg/largefiles/dirstate", but files without
".hg/largefiles/dirstate" entry are treated as "removed" by largefiles
extension.
"hg revert" can not recover from this situation, but "rm -rf
.hg/largefiles", because it causes dirstate rebuilding.
this patch invokes normallookup() for cache missed largefiles to
allocate entry in ".hg/largefiles/dirstate", so "hg status" can treat
it as "missing" correctly.
--- a/hgext/largefiles/lfcommands.py Thu Nov 10 11:00:02 2011 -0600
+++ b/hgext/largefiles/lfcommands.py Fri Nov 11 02:33:01 2011 +0900
@@ -437,7 +437,11 @@
(not os.path.exists(abslfile) or
expecthash != lfutil.hashfile(abslfile))):
if not lfutil.copyfromcache(repo, expecthash, lfile):
- return None # don't try to set the mode or update the dirstate
+ # use normallookup() to allocate entry in largefiles dirstate,
+ # because lack of it misleads lfiles_repo.status() into
+ # recognition that such cache missing files are REMOVED.
+ lfdirstate.normallookup(lfile)
+ return None # don't try to set the mode
ret = 1
mode = os.stat(absstandin).st_mode
if mode != os.stat(abslfile).st_mode:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-largefiles-cache.t Fri Nov 11 02:33:01 2011 +0900
@@ -0,0 +1,70 @@
+Create user cache directory
+
+ $ USERCACHE=`pwd`/cache; export USERCACHE
+ $ cat <<EOF >> ${HGRCPATH}
+ > [extensions]
+ > hgext.largefiles=
+ > [largefiles]
+ > usercache=${USERCACHE}
+ > EOF
+ $ mkdir -p ${USERCACHE}
+
+Create source repo, and commit adding largefile.
+
+ $ hg init src
+ $ cd src
+ $ echo large > large
+ $ hg add --large large
+ $ hg commit -m 'add largefile'
+ $ cd ..
+
+Discard all cached largefiles in USERCACHE
+
+ $ rm -rf ${USERCACHE}
+
+Create mirror repo, and pull from source without largefile:
+"pull" is used instead of "clone" for suppression of (1) updating to
+tip (= cahcing largefile from source repo), and (2) recording source
+repo as "default" path in .hg/hgrc.
+
+ $ hg init mirror
+ $ cd mirror
+ $ hg pull ../src
+ pulling from ../src
+ requesting all changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+ (run 'hg update' to get a working copy)
+
+Update working directory to "tip", which requires largefile("large"),
+but there is no cache file for it. So, hg must treat it as
+"missing"(!) file.
+
+ $ hg update
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ getting changed largefiles
+ large: Can't get file locally
+ (no default or default-push path set in hgrc)
+ 0 largefiles updated, 0 removed
+ $ hg status
+ ! large
+
+Update working directory to null: this cleanup .hg/largefiles/dirstate
+
+ $ hg update null
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ getting changed largefiles
+ 0 largefiles updated, 0 removed
+
+Update working directory to tip, again.
+
+ $ hg update
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ getting changed largefiles
+ large: Can't get file locally
+ (no default or default-push path set in hgrc)
+ 0 largefiles updated, 0 removed
+ $ hg status
+ ! large