Changeset 3d9fcccc0ee8…
Parent f5d8843a249a…
by Andrew Pritchard <andrewp@fogcreek.com>
Changes to 4 files · Browse files at 3d9fcccc0ee8 Showing diff from parent f5d8843a249a Diff from another changeset...
@@ -11,6 +11,7 @@ import tempfile
import binascii
import re
+import shutil
from mercurial import util, node, error, url as url_, hg
from mercurial.i18n import _
@@ -71,18 +72,15 @@ ui.progress(_('getting largefiles'), at, unit='lfile',
total=len(files))
at += 1
- ui.note(_('getting %s\n') % filename)
- outfilename = self.repo.wjoin(filename)
- destdir = os.path.dirname(outfilename)
- util.makedirs(destdir)
- if not os.path.isdir(destdir):
- self.abort(error.RepoError(_('cannot create dest directory %s')
- % destdir))
+ ui.note(_('getting %s:%s\n') % (filename, hash))
+
+ cachefilename = lfutil.cachepath(self.repo, hash)
+ cachedir = os.path.dirname(cachefilename)
# No need to pass mode='wb' to fdopen(), since mkstemp() already
# opened the file in binary mode.
(tmpfd, tmpfilename) = tempfile.mkstemp(
- dir=destdir, prefix=os.path.basename(filename))
+ dir=cachedir, prefix=os.path.basename(filename))
tmpfile = os.fdopen(tmpfd, 'w')
try:
@@ -100,13 +98,13 @@ % (filename, hash, hhash))
os.remove(tmpfilename)
missing.append(filename)
- else:
- if os.path.exists(outfilename): # for windows
- os.remove(outfilename)
- os.rename(tmpfilename, outfilename)
- lfutil.copytocache(self.repo, self.repo['.'].node(), filename,
- True)
- success.append((filename, hhash))
+ continue
+
+ if os.path.exists(cachefilename): # Windows
+ os.remove(cachefilename)
+ os.rename(tmpfilename, cachefilename)
+ lfutil.linktosystemcache(self.repo, hash)
+ success.append((filename, hhash))
ui.progress(_('getting largefiles'), None)
return (success, missing)
|
|
|
@@ -389,7 +389,10 @@ unsure, modified, added, removed, missing, unknown, ignored, clean = s
lfiles = lfutil.listlfiles(repo)
- toget = []
+
+ if lfiles:
+ cachelfiles(ui, repo, '.')
+
at = 0
updated = 0
for lfile in lfiles:
@@ -398,7 +401,7 @@ lfdirstate.remove(lfile)
continue
if os.path.exists(repo.wjoin(lfutil.standin(os.path.join(lfile\
- + '.orig')))):
+ + '.orig')))):
shutil.copyfile(repo.wjoin(lfile), repo.wjoin(lfile + \
'.orig'))
at += 1
@@ -407,9 +410,7 @@ if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \
lfutil.hashfile(repo.wjoin(lfile)):
path = lfutil.findfile(repo, expectedhash)
- if path is None:
- toget.append((lfile, expectedhash))
- else:
+ if path is not None:
util.makedirs(os.path.dirname(repo.wjoin(lfile)))
shutil.copy(path, repo.wjoin(lfile))
os.chmod(repo.wjoin(lfile), mode)
@@ -435,24 +436,6 @@ lfutil.dirstate_normaldirty(lfdirstate,
lfutil.unixpath(lfile))
- if toget:
- store = basestore._openstore(repo)
- success, missing = store.get(toget)
- else:
- success, missing = [], []
-
- for (filename, hash) in success:
- mode = os.stat(repo.wjoin(lfutil.standin(filename))).st_mode
- os.chmod(repo.wjoin(filename), mode)
- updated += 1
- if lfutil.standin(filename) not in repo['.']:
- lfdirstate.add(lfutil.unixpath(filename))
- elif hash == repo['.'][lfutil.standin(filename)].data().strip():
- lfdirstate.normal(lfutil.unixpath(filename))
- else:
- lfutil.dirstate_normaldirty(lfdirstate,
- lfutil.unixpath(filename))
-
removed = 0
for lfile in lfdirstate:
if filelist is None or lfile in filelist:
@@ -483,6 +466,33 @@ finally:
wlock.release()
+def cachelfiles(ui, repo, node):
+ '''cachelfiles ensures that all largefiles needed by the specified revision
+ are present in the repository's largefile cache.
+
+ returns a tuple (cached, missing). cached is the list of files downloaded
+ by this operation; missing is the list of files that were needed but could
+ not be found.'''
+ lfiles = lfutil.listlfiles(repo, node)
+ toget = []
+
+ for lfile in lfiles:
+ expectedhash = repo[node][lfutil.standin(lfile)].data().strip()
+ # if it exists and its hash matches, it might have been locally
+ # modified before updating and the user chose 'local'. in this case,
+ # it will not be in any store, so don't look for it.
+ if (not os.path.exists(repo.wjoin(lfile)) \
+ or expectedhash != lfutil.hashfile(repo.wjoin(lfile))) and \
+ not lfutil.findfile(repo, expectedhash):
+ toget.append((lfile, expectedhash))
+
+ if toget:
+ store = basestore._openstore(repo)
+ ret = store.get(toget)
+ return ret
+
+ return ([], [])
+
def updatelfiles(ui, repo):
wlock = repo.wlock()
try:
@@ -492,7 +502,6 @@ unsure, modified, added, removed, missing, unknown, ignored, clean = s
lfiles = lfutil.listlfiles(repo)
- toget = []
at = 0
updated = 0
removed = 0
@@ -501,6 +510,8 @@ ui.status(_('getting changed largefiles\n'))
printed = True
+ success, missing = cachelfiles(ui, repo, None)
+
for lfile in lfiles:
at += 1
if os.path.exists(repo.wjoin(lfile)) and not \
@@ -514,9 +525,7 @@ if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \
lfutil.hashfile(repo.wjoin(lfile)):
path = lfutil.findfile(repo, expectedhash)
- if not path:
- toget.append((lfile, expectedhash))
- else:
+ if path:
util.makedirs(os.path.dirname(repo.wjoin(lfile)))
shutil.copy(path, repo.wjoin(lfile))
os.chmod(repo.wjoin(lfile), mode)
@@ -528,18 +537,6 @@ updated += 1
lfdirstate.normal(lfutil.unixpath(lfile))
- if toget:
- store = basestore._openstore(repo)
- (success, missing) = store.get(toget)
- else:
- success, missing = [],[]
-
- for (filename, hash) in success:
- mode = os.stat(repo.wjoin(lfutil.standin(filename))).st_mode
- os.chmod(repo.wjoin(filename), mode)
- updated += 1
- lfdirstate.normal(lfutil.unixpath(filename))
-
for lfile in lfdirstate:
if lfile not in lfiles:
if os.path.exists(repo.wjoin(lfile)):
|
@@ -265,8 +265,11 @@ else:
shutil.copyfile(file, cachepath(repo, hash))
os.chmod(cachepath(repo, hash), os.stat(file).st_mode)
- createdir(os.path.dirname(systemcachepath(repo.ui, hash)))
- link(cachepath(repo, hash), systemcachepath(repo.ui, hash))
+ linktosystemcache(repo, hash)
+
+def linktosystemcache(repo, hash):
+ createdir(os.path.dirname(systemcachepath(repo.ui, hash)))
+ link(cachepath(repo, hash), systemcachepath(repo.ui, hash))
def getstandinmatcher(repo, pats=[], opts={}):
'''Return a match object that applies pats to the standin directory'''
|
@@ -685,6 +685,8 @@ # No need to lock because we are only reading history and lfile caches
# neither of which are modified
+ lfcommands.cachelfiles(repo.ui, repo, node)
+
if kind not in archival.archivers:
raise util.Abort(_("unknown archive type '%s'") % kind)
|
Loading...