Kiln » largefiles » largefiles-mercurial-truncated changes working towards inclusion in Mercurial
Clone URL:  

overrides: use installmatchfn() and restorematchfn() rather than doing it manually each time

Changeset b1f93cee7a1a

Parent c0e0b63fc148

by Profile picture of User 521Andrew Pritchard <andrewp@fogcreek.com>

Changes to one file · Browse files at b1f93cee7a1a Showing diff from parent c0e0b63fc148 Diff from another changeset...

Change 1 of 7 Show Entire File overrides.py Stacked
 
29
30
31
32
33
34
35
36
37
 
38
39
40
 
46
47
48
49
 
 
 
50
51
52
 
53
54
55
 
 
 
 
 
 
 
 
 
56
57
58
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
 
385
386
387
 
402
403
404
405
406
407
408
409
410
 
411
412
413
 
455
456
457
458
459
460
461
462
463
 
464
465
466
 
489
490
491
492
493
494
495
496
497
498
 
499
500
501
 
533
534
535
 
536
537
538
 
539
540
541
542
543
544
545
546
547
548
549
550
551
 
552
553
554
 
29
30
31
 
 
 
 
 
 
32
33
34
35
 
41
42
43
 
44
45
46
47
48
 
49
50
51
 
52
53
54
55
56
57
58
59
60
61
62
63
 
376
377
378
 
 
 
 
 
 
379
380
381
382
383
384
385
386
387
 
402
403
404
 
 
 
 
 
 
405
406
407
408
 
450
451
452
 
 
 
 
 
 
453
454
455
456
 
479
480
481
 
 
 
 
 
 
482
483
484
485
486
 
518
519
520
521
522
523
 
524
525
526
527
 
528
529
530
 
 
 
 
 
 
531
532
533
534
@@ -29,12 +29,7 @@
 def installnormalfilesmatchfn(manifest):   '''overrides scmutil.match so that the matcher it returns will ignore all   largefiles''' - try: - # Mercurial >= 1.9 - oldmatch = scmutil.match - except ImportError: - # Mercurial <= 1.8 - oldmatch = cmdutil.match + oldmatch = None # for the closure   def override_match(repo, pats=[], opts={}, globbed=False,   default='relpath'):   match = oldmatch(repo, pats, opts, globbed, default) @@ -46,13 +41,23 @@
  orig_matchfn = m.matchfn   m.matchfn = lambda f: notlfile(f) and orig_matchfn(f) or None   return m - setattr(override_match, 'oldmatch', oldmatch) + oldmatch = installmatchfn(override_match) + +def installmatchfn(f):   try:   # Mercurial >= 1.9 - scmutil.match = override_match + oldmatch = scmutil.match   except ImportError:   # Mercurial <= 1.8 - cmdutil.match = override_match + oldmatch = cmdutil.match + setattr(f, 'oldmatch', oldmatch) + try: + # Mercurial >= 1.9 + scmutil.match = f + except ImportError: + # Mercurial <= 1.8 + cmdutil.match = f + return oldmatch    def restorematchfn():   '''restores scmutil.match to what it was before installnormalfilesmatchfn @@ -371,17 +376,12 @@
  return result     try: - # Mercurial >= 1.9 - oldmatch = scmutil.match - except ImportError: - # Mercurial <= 1.8 - oldmatch = cmdutil.match - try:   # When we call orig below it creates the standins but we don't add them   # to the dir state until later so lock during that time.   wlock = repo.wlock()     manifest = repo[None].manifest() + oldmatch = None # for the closure   def override_match(repo, pats=[], opts={}, globbed=False,   default='relpath'):   newpats = [] @@ -402,12 +402,7 @@
  lfile(lfutil.splitstandin(f)) and \   orig_matchfn(lfutil.splitstandin(f)) or None   return m - try: - # Mercurial >= 1.9 - scmutil.match = override_match - except ImportError: - # Mercurial <= 1.9 - cmdutil.match = override_match + oldmatch = installmatchfn(override_match)   listpats = []   for pat in pats:   if match_.patkind(pat) is not None: @@ -455,12 +450,7 @@
  else:   nolfiles = True   finally: - try: - # Mercurial >= 1.9 - scmutil.match = oldmatch - except ImportError: - # Mercurial <= 1.8 - cmdutil.match = oldmatch + restorematchfn()   wlock.release()     if nolfiles and nonormalfiles: @@ -489,13 +479,8 @@
  lfutil.updatestandin(repo, lfutil.standin(lfile))     try: - # Mercurial >= 1.9 - oldmatch = scmutil.match - except ImportError: - # Mercurial <= 1.8 - oldmatch = cmdutil.match - try:   ctx = repo[opts.get('rev')] + oldmatch = None # for the closure   def override_match(ctxorrepo, pats=[], opts={}, globbed=False,   default='relpath'):   if hasattr(ctxorrepo, 'match'): @@ -533,22 +518,17 @@
  return orig_matchfn(f)   m.matchfn = matchfn   return m + oldmatch = installmatchfn(override_match)   try:   # Mercurial >= 1.9 - scmutil.match = override_match + scmutil.match   matches = override_match(repo[None], pats, opts)   except ImportError:   # Mercurial <= 1.8 - cmdutil.match = override_match   matches = override_match(repo, pats, opts)   orig(ui, repo, *pats, **opts)   finally: - try: - # Mercurial >= 1.9 - scmutil.match = oldmatch - except ImportError: - # Mercurial <= 1.8 - cmdutil.match = oldmatch + restorematchfn()   lfileslist = getattr(repo, '_lfilestoupdate', [])   lfcommands.updatelfiles(ui, repo, filelist=lfileslist, printmessage=False)   # Empty out the lfiles list so we start fresh next time