##// END OF EJS Templates
largefiles: add some docstrings
Mads Kiilerich -
r28576:33bd9544 default
parent child Browse files
Show More
@@ -39,6 +39,7 b' def getminsize(ui, assumelfiles, opt, de'
39 return lfsize
39 return lfsize
40
40
41 def link(src, dest):
41 def link(src, dest):
42 """Try to create hardlink - if that fails, efficiently make a copy."""
42 util.makedirs(os.path.dirname(dest))
43 util.makedirs(os.path.dirname(dest))
43 try:
44 try:
44 util.oslink(src, dest)
45 util.oslink(src, dest)
@@ -86,6 +87,9 b' def inusercache(ui, hash):'
86 return os.path.exists(path)
87 return os.path.exists(path)
87
88
88 def findfile(repo, hash):
89 def findfile(repo, hash):
90 '''Return store path of the largefile with the specified hash.
91 As a side effect, the file might be linked from user cache.
92 Return None if the file can't be found locally.'''
89 path, exists = findstorepath(repo, hash)
93 path, exists = findstorepath(repo, hash)
90 if exists:
94 if exists:
91 repo.ui.note(_('found %s in store\n') % hash)
95 repo.ui.note(_('found %s in store\n') % hash)
@@ -176,9 +180,13 b' def listlfiles(repo, rev=None, matcher=N'
176 if rev is not None or repo.dirstate[f] != '?']
180 if rev is not None or repo.dirstate[f] != '?']
177
181
178 def instore(repo, hash, forcelocal=False):
182 def instore(repo, hash, forcelocal=False):
183 '''Return true if a largefile with the given hash exists in the user
184 cache.'''
179 return os.path.exists(storepath(repo, hash, forcelocal))
185 return os.path.exists(storepath(repo, hash, forcelocal))
180
186
181 def storepath(repo, hash, forcelocal=False):
187 def storepath(repo, hash, forcelocal=False):
188 '''Return the correct location in the repository largefiles cache for a
189 file with the given hash.'''
182 if not forcelocal and repo.shared():
190 if not forcelocal and repo.shared():
183 return repo.vfs.reljoin(repo.sharedpath, longname, hash)
191 return repo.vfs.reljoin(repo.sharedpath, longname, hash)
184 return repo.join(longname, hash)
192 return repo.join(longname, hash)
@@ -257,6 +265,8 b' def copytostoreabsolute(repo, file, hash'
257 linktousercache(repo, hash)
265 linktousercache(repo, hash)
258
266
259 def linktousercache(repo, hash):
267 def linktousercache(repo, hash):
268 '''Link / copy the largefile with the specified hash from the store
269 to the cache.'''
260 path = usercachepath(repo.ui, hash)
270 path = usercachepath(repo.ui, hash)
261 link(storepath(repo, hash), path)
271 link(storepath(repo, hash), path)
262
272
@@ -394,6 +404,7 b' def unixpath(path):'
394 return util.pconvert(os.path.normpath(path))
404 return util.pconvert(os.path.normpath(path))
395
405
396 def islfilesrepo(repo):
406 def islfilesrepo(repo):
407 '''Return true if the repo is a largefile repo.'''
397 if ('largefiles' in repo.requirements and
408 if ('largefiles' in repo.requirements and
398 any(shortnameslash in f[0] for f in repo.store.datafiles())):
409 any(shortnameslash in f[0] for f in repo.store.datafiles())):
399 return True
410 return True
@@ -22,8 +22,8 b' ssholdcallstream = None'
22 httpoldcallstream = None
22 httpoldcallstream = None
23
23
24 def putlfile(repo, proto, sha):
24 def putlfile(repo, proto, sha):
25 '''Put a largefile into a repository's local store and into the
25 '''Server command for putting a largefile into a repository's local store
26 user cache.'''
26 and into the user cache.'''
27 proto.redirect()
27 proto.redirect()
28
28
29 path = lfutil.storepath(repo, sha)
29 path = lfutil.storepath(repo, sha)
@@ -47,8 +47,8 b' def putlfile(repo, proto, sha):'
47 return wireproto.pushres(0)
47 return wireproto.pushres(0)
48
48
49 def getlfile(repo, proto, sha):
49 def getlfile(repo, proto, sha):
50 '''Retrieve a largefile from the repository-local cache or system
50 '''Server command for retrieving a largefile from the repository-local
51 cache.'''
51 cache or user cache.'''
52 filename = lfutil.findfile(repo, sha)
52 filename = lfutil.findfile(repo, sha)
53 if not filename:
53 if not filename:
54 raise error.Abort(_('requested largefile %s not present in cache')
54 raise error.Abort(_('requested largefile %s not present in cache')
@@ -68,8 +68,8 b' def getlfile(repo, proto, sha):'
68 return wireproto.streamres(generator())
68 return wireproto.streamres(generator())
69
69
70 def statlfile(repo, proto, sha):
70 def statlfile(repo, proto, sha):
71 '''Return '2\n' if the largefile is missing, '0\n' if it seems to be in
71 '''Server command for checking if a largefile is present - returns '2\n' if
72 good condition.
72 the largefile is missing, '0\n' if it seems to be in good condition.
73
73
74 The value 1 is reserved for mismatched checksum, but that is too expensive
74 The value 1 is reserved for mismatched checksum, but that is too expensive
75 to be verified on every stat and must be caught be running 'hg verify'
75 to be verified on every stat and must be caught be running 'hg verify'
@@ -151,9 +151,12 b' def wirereposetup(ui, repo):'
151
151
152 # advertise the largefiles=serve capability
152 # advertise the largefiles=serve capability
153 def capabilities(repo, proto):
153 def capabilities(repo, proto):
154 '''Wrap server command to announce largefile server capability'''
154 return capabilitiesorig(repo, proto) + ' largefiles=serve'
155 return capabilitiesorig(repo, proto) + ' largefiles=serve'
155
156
156 def heads(repo, proto):
157 def heads(repo, proto):
158 '''Wrap server command - largefile capable clients will know to call
159 lheads instead'''
157 if lfutil.islfilesrepo(repo):
160 if lfutil.islfilesrepo(repo):
158 return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
161 return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
159 return wireproto.heads(repo, proto)
162 return wireproto.heads(repo, proto)
General Comments 0
You need to be logged in to leave comments. Login now