comparison hgext/largefiles/overrides.py @ 15252:6e809bb4f969

largefiles: improve comments, internal docstrings - fix some ungrammatical/unclear/incorrect comments/docstrings - rewrite some really unclear comments/docstrings - make formatting/style more consistent with the rest of Mercurial (lowercase without period unless it's really multiple sentences) - wrap to 75 columns - always say "largefile(s)", not "lfile(s)" (or "big files") - one space between sentences, not two
author Greg Ward <greg@gerg.ca>
date Wed, 12 Oct 2011 20:59:27 -0400
parents 89e19ca2a90e
children dd03d3a9f888
comparison
equal deleted inserted replaced
15251:173b00827279 15252:6e809bb4f969
57 restore matchfn to reverse''' 57 restore matchfn to reverse'''
58 scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match) 58 scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
59 59
60 # -- Wrappers: modify existing commands -------------------------------- 60 # -- Wrappers: modify existing commands --------------------------------
61 61
62 # Add works by going through the files that the user wanted to add 62 # Add works by going through the files that the user wanted to add and
63 # and checking if they should be added as lfiles. Then making a new 63 # checking if they should be added as largefiles. Then it makes a new
64 # matcher which matches only the normal files and running the original 64 # matcher which matches only the normal files and runs the original
65 # version of add. 65 # version of add.
66 def override_add(orig, ui, repo, *pats, **opts): 66 def override_add(orig, ui, repo, *pats, **opts):
67 large = opts.pop('large', None) 67 large = opts.pop('large', None)
68 lfsize = lfutil.getminsize( 68 lfsize = lfutil.getminsize(
69 ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None)) 69 ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
99 ui.status(_('adding %s as a largefile\n') % m.rel(f)) 99 ui.status(_('adding %s as a largefile\n') % m.rel(f))
100 100
101 bad = [] 101 bad = []
102 standins = [] 102 standins = []
103 103
104 # Need to lock otherwise there could be a race condition inbetween when 104 # Need to lock, otherwise there could be a race condition between
105 # standins are created and added to the repo 105 # when standins are created and added to the repo.
106 wlock = repo.wlock() 106 wlock = repo.wlock()
107 try: 107 try:
108 if not opts.get('dry_run'): 108 if not opts.get('dry_run'):
109 lfdirstate = lfutil.openlfdirstate(ui, repo) 109 lfdirstate = lfutil.openlfdirstate(ui, repo)
110 for f in lfnames: 110 for f in lfnames:
219 lfdirstate = lfutil.openlfdirstate(ui, repo) 219 lfdirstate = lfutil.openlfdirstate(ui, repo)
220 s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, 220 s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False,
221 False, False) 221 False, False)
222 (unsure, modified, added, removed, missing, unknown, ignored, clean) = s 222 (unsure, modified, added, removed, missing, unknown, ignored, clean) = s
223 223
224 # Need to lock between the standins getting updated and their lfiles 224 # Need to lock between the standins getting updated and their
225 # getting updated 225 # largefiles getting updated
226 wlock = repo.wlock() 226 wlock = repo.wlock()
227 try: 227 try:
228 if opts['check']: 228 if opts['check']:
229 mod = len(modified) > 0 229 mod = len(modified) > 0
230 for lfile in unsure: 230 for lfile in unsure:
243 lfutil.updatestandin(repo, lfutil.standin(lfile)) 243 lfutil.updatestandin(repo, lfutil.standin(lfile))
244 finally: 244 finally:
245 wlock.release() 245 wlock.release()
246 return orig(ui, repo, *pats, **opts) 246 return orig(ui, repo, *pats, **opts)
247 247
248 # Override filemerge to prompt the user about how they wish to merge lfiles. 248 # Override filemerge to prompt the user about how they wish to merge
249 # This will handle identical edits, and copy/rename + edit without prompting 249 # largefiles. This will handle identical edits, and copy/rename +
250 # the user. 250 # edit without prompting the user.
251 def override_filemerge(origfn, repo, mynode, orig, fcd, fco, fca): 251 def override_filemerge(origfn, repo, mynode, orig, fcd, fco, fca):
252 # Use better variable names here. Because this is a wrapper we cannot 252 # Use better variable names here. Because this is a wrapper we cannot
253 # change the variable names in the function declaration. 253 # change the variable names in the function declaration.
254 fcdest, fcother, fcancestor = fcd, fco, fca 254 fcdest, fcother, fcancestor = fcd, fco, fca
255 if not lfutil.isstandin(orig): 255 if not lfutil.isstandin(orig):
286 return 0 286 return 0
287 else: 287 else:
288 repo.wwrite(fcdest.path(), fcother.data(), fcother.flags()) 288 repo.wwrite(fcdest.path(), fcother.data(), fcother.flags())
289 return 0 289 return 0
290 290
291 # Copy first changes the matchers to match standins instead of lfiles. 291 # Copy first changes the matchers to match standins instead of
292 # Then it overrides util.copyfile in that function it checks if the destination 292 # largefiles. Then it overrides util.copyfile in that function it
293 # lfile already exists. It also keeps a list of copied files so that the lfiles 293 # checks if the destination largefile already exists. It also keeps a
294 # can be copied and the dirstate updated. 294 # list of copied files so that the largefiles can be copied and the
295 # dirstate updated.
295 def override_copy(orig, ui, repo, pats, opts, rename=False): 296 def override_copy(orig, ui, repo, pats, opts, rename=False):
296 # doesn't remove lfile on rename 297 # doesn't remove largefile on rename
297 if len(pats) < 2: 298 if len(pats) < 2:
298 # this isn't legal, let the original function deal with it 299 # this isn't legal, let the original function deal with it
299 return orig(ui, repo, pats, opts, rename) 300 return orig(ui, repo, pats, opts, rename)
300 301
301 def makestandin(relpath): 302 def makestandin(relpath):
307 dest = fullpats[-1] 308 dest = fullpats[-1]
308 309
309 if os.path.isdir(dest): 310 if os.path.isdir(dest):
310 if not os.path.isdir(makestandin(dest)): 311 if not os.path.isdir(makestandin(dest)):
311 os.makedirs(makestandin(dest)) 312 os.makedirs(makestandin(dest))
312 # This could copy both lfiles and normal files in one command, but we don't 313 # This could copy both largefiles and normal files in one command,
313 # want to do that first replace their matcher to only match normal files 314 # but we don't want to do that first replace their matcher to only
314 # and run it then replace it to just match lfiles and run it again 315 # match normal files and run it then replace it to just match
316 # lfiles and run it again
315 nonormalfiles = False 317 nonormalfiles = False
316 nolfiles = False 318 nolfiles = False
317 try: 319 try:
318 installnormalfilesmatchfn(repo[None].manifest()) 320 installnormalfilesmatchfn(repo[None].manifest())
319 result = orig(ui, repo, pats, opts, rename) 321 result = orig(ui, repo, pats, opts, rename)