##// END OF EJS Templates
largefiles: rename functions and methods to match desired behavior...
Benjamin Pollack -
r15316:c65f5b6e stable
parent child Browse files
Show More
@@ -74,13 +74,13 b' class basestore(object):'
74 at += 1
74 at += 1
75 ui.note(_('getting %s:%s\n') % (filename, hash))
75 ui.note(_('getting %s:%s\n') % (filename, hash))
76
76
77 cachefilename = lfutil.cachepath(self.repo, hash)
77 storefilename = lfutil.storepath(self.repo, hash)
78 cachedir = os.path.dirname(cachefilename)
78 storedir = os.path.dirname(storefilename)
79
79
80 # No need to pass mode='wb' to fdopen(), since mkstemp() already
80 # No need to pass mode='wb' to fdopen(), since mkstemp() already
81 # opened the file in binary mode.
81 # opened the file in binary mode.
82 (tmpfd, tmpfilename) = tempfile.mkstemp(
82 (tmpfd, tmpfilename) = tempfile.mkstemp(
83 dir=cachedir, prefix=os.path.basename(filename))
83 dir=storedir, prefix=os.path.basename(filename))
84 tmpfile = os.fdopen(tmpfd, 'w')
84 tmpfile = os.fdopen(tmpfd, 'w')
85
85
86 try:
86 try:
@@ -98,10 +98,10 b' class basestore(object):'
98 missing.append(filename)
98 missing.append(filename)
99 continue
99 continue
100
100
101 if os.path.exists(cachefilename): # Windows
101 if os.path.exists(storefilename): # Windows
102 os.remove(cachefilename)
102 os.remove(storefilename)
103 os.rename(tmpfilename, cachefilename)
103 os.rename(tmpfilename, storefilename)
104 lfutil.linktosystemcache(self.repo, hash)
104 lfutil.linktousercache(self.repo, hash)
105 success.append((filename, hhash))
105 success.append((filename, hhash))
106
106
107 ui.progress(_('getting largefiles'), None)
107 ui.progress(_('getting largefiles'), None)
@@ -80,8 +80,8 b' def link(src, dest):'
80 shutil.copyfile(src, dest)
80 shutil.copyfile(src, dest)
81 os.chmod(dest, os.stat(src).st_mode)
81 os.chmod(dest, os.stat(src).st_mode)
82
82
83 def systemcachepath(ui, hash):
83 def usercachepath(ui, hash):
84 path = ui.config(longname, 'systemcache', None)
84 path = ui.config(longname, 'usercache', None)
85 if path:
85 if path:
86 path = os.path.join(path, hash)
86 path = os.path.join(path, hash)
87 else:
87 else:
@@ -94,16 +94,16 b' def systemcachepath(ui, hash):'
94 raise util.Abort(_('unknown operating system: %s\n') % os.name)
94 raise util.Abort(_('unknown operating system: %s\n') % os.name)
95 return path
95 return path
96
96
97 def insystemcache(ui, hash):
97 def inusercache(ui, hash):
98 return os.path.exists(systemcachepath(ui, hash))
98 return os.path.exists(usercachepath(ui, hash))
99
99
100 def findfile(repo, hash):
100 def findfile(repo, hash):
101 if incache(repo, hash):
101 if instore(repo, hash):
102 repo.ui.note(_('Found %s in cache\n') % hash)
102 repo.ui.note(_('Found %s in store\n') % hash)
103 return cachepath(repo, hash)
103 return storepath(repo, hash)
104 if insystemcache(repo.ui, hash):
104 if inusercache(repo.ui, hash):
105 repo.ui.note(_('Found %s in system cache\n') % hash)
105 repo.ui.note(_('Found %s in system cache\n') % hash)
106 return systemcachepath(repo.ui, hash)
106 return usercachepath(repo.ui, hash)
107 return None
107 return None
108
108
109 class largefiles_dirstate(dirstate.dirstate):
109 class largefiles_dirstate(dirstate.dirstate):
@@ -188,14 +188,14 b' def listlfiles(repo, rev=None, matcher=N'
188 for f in repo[rev].walk(matcher)
188 for f in repo[rev].walk(matcher)
189 if rev is not None or repo.dirstate[f] != '?']
189 if rev is not None or repo.dirstate[f] != '?']
190
190
191 def incache(repo, hash):
191 def instore(repo, hash):
192 return os.path.exists(cachepath(repo, hash))
192 return os.path.exists(storepath(repo, hash))
193
193
194 def createdir(dir):
194 def createdir(dir):
195 if not os.path.exists(dir):
195 if not os.path.exists(dir):
196 os.makedirs(dir)
196 os.makedirs(dir)
197
197
198 def cachepath(repo, hash):
198 def storepath(repo, hash):
199 return repo.join(os.path.join(longname, hash))
199 return repo.join(os.path.join(longname, hash))
200
200
201 def copyfromcache(repo, hash, filename):
201 def copyfromcache(repo, hash, filename):
@@ -211,24 +211,24 b' def copyfromcache(repo, hash, filename):'
211 shutil.copy(path, repo.wjoin(filename))
211 shutil.copy(path, repo.wjoin(filename))
212 return True
212 return True
213
213
214 def copytocache(repo, rev, file, uploaded=False):
214 def copytostore(repo, rev, file, uploaded=False):
215 hash = readstandin(repo, file)
215 hash = readstandin(repo, file)
216 if incache(repo, hash):
216 if instore(repo, hash):
217 return
217 return
218 copytocacheabsolute(repo, repo.wjoin(file), hash)
218 copytostoreabsolute(repo, repo.wjoin(file), hash)
219
219
220 def copytocacheabsolute(repo, file, hash):
220 def copytostoreabsolute(repo, file, hash):
221 createdir(os.path.dirname(cachepath(repo, hash)))
221 createdir(os.path.dirname(storepath(repo, hash)))
222 if insystemcache(repo.ui, hash):
222 if inusercache(repo.ui, hash):
223 link(systemcachepath(repo.ui, hash), cachepath(repo, hash))
223 link(usercachepath(repo.ui, hash), storepath(repo, hash))
224 else:
224 else:
225 shutil.copyfile(file, cachepath(repo, hash))
225 shutil.copyfile(file, storepath(repo, hash))
226 os.chmod(cachepath(repo, hash), os.stat(file).st_mode)
226 os.chmod(storepath(repo, hash), os.stat(file).st_mode)
227 linktosystemcache(repo, hash)
227 linktousercache(repo, hash)
228
228
229 def linktosystemcache(repo, hash):
229 def linktousercache(repo, hash):
230 createdir(os.path.dirname(systemcachepath(repo.ui, hash)))
230 createdir(os.path.dirname(usercachepath(repo.ui, hash)))
231 link(cachepath(repo, hash), systemcachepath(repo.ui, hash))
231 link(storepath(repo, hash), usercachepath(repo.ui, hash))
232
232
233 def getstandinmatcher(repo, pats=[], opts={}):
233 def getstandinmatcher(repo, pats=[], opts={}):
234 '''Return a match object that applies pats to the standin directory'''
234 '''Return a match object that applies pats to the standin directory'''
@@ -31,11 +31,11 b' class localstore(basestore.basestore):'
31 return
31 return
32
32
33 def exists(self, hash):
33 def exists(self, hash):
34 return lfutil.insystemcache(self.repo.ui, hash)
34 return lfutil.inusercache(self.repo.ui, hash)
35
35
36 def _getfile(self, tmpfile, filename, hash):
36 def _getfile(self, tmpfile, filename, hash):
37 if lfutil.insystemcache(self.ui, hash):
37 if lfutil.inusercache(self.ui, hash):
38 return lfutil.systemcachepath(self.ui, hash)
38 return lfutil.usercachepath(self.ui, hash)
39 raise basestore.StoreError(filename, hash, '',
39 raise basestore.StoreError(filename, hash, '',
40 _("Can't get file locally"))
40 _("Can't get file locally"))
41
41
@@ -50,7 +50,7 b' class localstore(basestore.basestore):'
50
50
51 expecthash = fctx.data()[0:40]
51 expecthash = fctx.data()[0:40]
52 verified.add(key)
52 verified.add(key)
53 if not lfutil.insystemcache(self.ui, expecthash):
53 if not lfutil.inusercache(self.ui, expecthash):
54 self.ui.warn(
54 self.ui.warn(
55 _('changeset %s: %s missing\n'
55 _('changeset %s: %s missing\n'
56 ' (looked for hash %s)\n')
56 ' (looked for hash %s)\n')
@@ -58,7 +58,7 b' class localstore(basestore.basestore):'
58 return True # failed
58 return True # failed
59
59
60 if contents:
60 if contents:
61 storepath = lfutil.systemcachepath(self.ui, expecthash)
61 storepath = lfutil.usercachepath(self.ui, expecthash)
62 actualhash = lfutil.hashfile(storepath)
62 actualhash = lfutil.hashfile(storepath)
63 if actualhash != expecthash:
63 if actualhash != expecthash:
64 self.ui.warn(
64 self.ui.warn(
@@ -28,7 +28,7 b' def putlfile(repo, proto, sha):'
28 f.seek(0)
28 f.seek(0)
29 if sha != lfutil.hexsha1(f):
29 if sha != lfutil.hexsha1(f):
30 return wireproto.pushres(1)
30 return wireproto.pushres(1)
31 lfutil.copytocacheabsolute(repo, f.name, sha)
31 lfutil.copytostoreabsolute(repo, f.name, sha)
32 except IOError:
32 except IOError:
33 repo.ui.warn(
33 repo.ui.warn(
34 _('error: could not put received data into largefile store'))
34 _('error: could not put received data into largefile store'))
@@ -228,7 +228,7 b' def reposetup(ui, repo):'
228 for filename in ctx.files():
228 for filename in ctx.files():
229 if lfutil.isstandin(filename) and filename in ctx.manifest():
229 if lfutil.isstandin(filename) and filename in ctx.manifest():
230 realfile = lfutil.splitstandin(filename)
230 realfile = lfutil.splitstandin(filename)
231 lfutil.copytocache(self, ctx.node(), realfile)
231 lfutil.copytostore(self, ctx.node(), realfile)
232
232
233 return node
233 return node
234
234
General Comments 0
You need to be logged in to leave comments. Login now