# HG changeset patch # User Benjamin Pollack # Date 1319131449 14400 # Node ID c65f5b6e26d4e382aeb36640f4f7d631aa450802 # Parent ca51a5dd5d0b75c7cba3fe07ec9f58452f125394 largefiles: rename functions and methods to match desired behavior The original intent was that the largefiles would primarily be in the repository, with the global cache being only that--a cache. The naming conventions and actual intent have both strayed. In this first patch, the naming conventions are switched to match the actual intent, as are the configuration options. diff -r ca51a5dd5d0b -r c65f5b6e26d4 hgext/largefiles/basestore.py --- a/hgext/largefiles/basestore.py Thu Oct 20 13:24:08 2011 -0400 +++ b/hgext/largefiles/basestore.py Thu Oct 20 13:24:09 2011 -0400 @@ -74,13 +74,13 @@ at += 1 ui.note(_('getting %s:%s\n') % (filename, hash)) - cachefilename = lfutil.cachepath(self.repo, hash) - cachedir = os.path.dirname(cachefilename) + storefilename = lfutil.storepath(self.repo, hash) + storedir = os.path.dirname(storefilename) # No need to pass mode='wb' to fdopen(), since mkstemp() already # opened the file in binary mode. (tmpfd, tmpfilename) = tempfile.mkstemp( - dir=cachedir, prefix=os.path.basename(filename)) + dir=storedir, prefix=os.path.basename(filename)) tmpfile = os.fdopen(tmpfd, 'w') try: @@ -98,10 +98,10 @@ missing.append(filename) continue - if os.path.exists(cachefilename): # Windows - os.remove(cachefilename) - os.rename(tmpfilename, cachefilename) - lfutil.linktosystemcache(self.repo, hash) + if os.path.exists(storefilename): # Windows + os.remove(storefilename) + os.rename(tmpfilename, storefilename) + lfutil.linktousercache(self.repo, hash) success.append((filename, hhash)) ui.progress(_('getting largefiles'), None) diff -r ca51a5dd5d0b -r c65f5b6e26d4 hgext/largefiles/lfutil.py --- a/hgext/largefiles/lfutil.py Thu Oct 20 13:24:08 2011 -0400 +++ b/hgext/largefiles/lfutil.py Thu Oct 20 13:24:09 2011 -0400 @@ -80,8 +80,8 @@ shutil.copyfile(src, dest) os.chmod(dest, os.stat(src).st_mode) -def systemcachepath(ui, hash): - path = ui.config(longname, 'systemcache', None) +def usercachepath(ui, hash): + path = ui.config(longname, 'usercache', None) if path: path = os.path.join(path, hash) else: @@ -94,16 +94,16 @@ raise util.Abort(_('unknown operating system: %s\n') % os.name) return path -def insystemcache(ui, hash): - return os.path.exists(systemcachepath(ui, hash)) +def inusercache(ui, hash): + return os.path.exists(usercachepath(ui, hash)) def findfile(repo, hash): - if incache(repo, hash): - repo.ui.note(_('Found %s in cache\n') % hash) - return cachepath(repo, hash) - if insystemcache(repo.ui, hash): + if instore(repo, hash): + repo.ui.note(_('Found %s in store\n') % hash) + return storepath(repo, hash) + if inusercache(repo.ui, hash): repo.ui.note(_('Found %s in system cache\n') % hash) - return systemcachepath(repo.ui, hash) + return usercachepath(repo.ui, hash) return None class largefiles_dirstate(dirstate.dirstate): @@ -188,14 +188,14 @@ for f in repo[rev].walk(matcher) if rev is not None or repo.dirstate[f] != '?'] -def incache(repo, hash): - return os.path.exists(cachepath(repo, hash)) +def instore(repo, hash): + return os.path.exists(storepath(repo, hash)) def createdir(dir): if not os.path.exists(dir): os.makedirs(dir) -def cachepath(repo, hash): +def storepath(repo, hash): return repo.join(os.path.join(longname, hash)) def copyfromcache(repo, hash, filename): @@ -211,24 +211,24 @@ shutil.copy(path, repo.wjoin(filename)) return True -def copytocache(repo, rev, file, uploaded=False): +def copytostore(repo, rev, file, uploaded=False): hash = readstandin(repo, file) - if incache(repo, hash): + if instore(repo, hash): return - copytocacheabsolute(repo, repo.wjoin(file), hash) + copytostoreabsolute(repo, repo.wjoin(file), hash) -def copytocacheabsolute(repo, file, hash): - createdir(os.path.dirname(cachepath(repo, hash))) - if insystemcache(repo.ui, hash): - link(systemcachepath(repo.ui, hash), cachepath(repo, hash)) +def copytostoreabsolute(repo, file, hash): + createdir(os.path.dirname(storepath(repo, hash))) + if inusercache(repo.ui, hash): + link(usercachepath(repo.ui, hash), storepath(repo, hash)) else: - shutil.copyfile(file, cachepath(repo, hash)) - os.chmod(cachepath(repo, hash), os.stat(file).st_mode) - linktosystemcache(repo, hash) + shutil.copyfile(file, storepath(repo, hash)) + os.chmod(storepath(repo, hash), os.stat(file).st_mode) + linktousercache(repo, hash) -def linktosystemcache(repo, hash): - createdir(os.path.dirname(systemcachepath(repo.ui, hash))) - link(cachepath(repo, hash), systemcachepath(repo.ui, hash)) +def linktousercache(repo, hash): + createdir(os.path.dirname(usercachepath(repo.ui, hash))) + link(storepath(repo, hash), usercachepath(repo.ui, hash)) def getstandinmatcher(repo, pats=[], opts={}): '''Return a match object that applies pats to the standin directory''' diff -r ca51a5dd5d0b -r c65f5b6e26d4 hgext/largefiles/localstore.py --- a/hgext/largefiles/localstore.py Thu Oct 20 13:24:08 2011 -0400 +++ b/hgext/largefiles/localstore.py Thu Oct 20 13:24:09 2011 -0400 @@ -31,11 +31,11 @@ return def exists(self, hash): - return lfutil.insystemcache(self.repo.ui, hash) + return lfutil.inusercache(self.repo.ui, hash) def _getfile(self, tmpfile, filename, hash): - if lfutil.insystemcache(self.ui, hash): - return lfutil.systemcachepath(self.ui, hash) + if lfutil.inusercache(self.ui, hash): + return lfutil.usercachepath(self.ui, hash) raise basestore.StoreError(filename, hash, '', _("Can't get file locally")) @@ -50,7 +50,7 @@ expecthash = fctx.data()[0:40] verified.add(key) - if not lfutil.insystemcache(self.ui, expecthash): + if not lfutil.inusercache(self.ui, expecthash): self.ui.warn( _('changeset %s: %s missing\n' ' (looked for hash %s)\n') @@ -58,7 +58,7 @@ return True # failed if contents: - storepath = lfutil.systemcachepath(self.ui, expecthash) + storepath = lfutil.usercachepath(self.ui, expecthash) actualhash = lfutil.hashfile(storepath) if actualhash != expecthash: self.ui.warn( diff -r ca51a5dd5d0b -r c65f5b6e26d4 hgext/largefiles/proto.py --- a/hgext/largefiles/proto.py Thu Oct 20 13:24:08 2011 -0400 +++ b/hgext/largefiles/proto.py Thu Oct 20 13:24:09 2011 -0400 @@ -28,7 +28,7 @@ f.seek(0) if sha != lfutil.hexsha1(f): return wireproto.pushres(1) - lfutil.copytocacheabsolute(repo, f.name, sha) + lfutil.copytostoreabsolute(repo, f.name, sha) except IOError: repo.ui.warn( _('error: could not put received data into largefile store')) diff -r ca51a5dd5d0b -r c65f5b6e26d4 hgext/largefiles/reposetup.py --- a/hgext/largefiles/reposetup.py Thu Oct 20 13:24:08 2011 -0400 +++ b/hgext/largefiles/reposetup.py Thu Oct 20 13:24:09 2011 -0400 @@ -228,7 +228,7 @@ for filename in ctx.files(): if lfutil.isstandin(filename) and filename in ctx.manifest(): realfile = lfutil.splitstandin(filename) - lfutil.copytocache(self, ctx.node(), realfile) + lfutil.copytostore(self, ctx.node(), realfile) return node