##// END OF EJS Templates
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard -
r15224:7c604d8c default
parent child Browse files
Show More
@@ -466,12 +466,7 b' def _updatelfile(repo, lfdirstate, lfile'
466 466 elif state == 'a':
467 467 lfdirstate.add(lfile)
468 468 elif state == '?':
469 try:
470 # Mercurial >= 1.9
471 lfdirstate.drop(lfile)
472 except AttributeError:
473 # Mercurial <= 1.8
474 lfdirstate.forget(lfile)
469 lfdirstate.drop(lfile)
475 470 return ret
476 471
477 472 # -- hg commands declarations ------------------------------------------------
@@ -10,13 +10,11 b''
10 10
11 11 import os
12 12 import errno
13 import inspect
14 13 import shutil
15 14 import stat
16 15 import hashlib
17 16
18 from mercurial import cmdutil, dirstate, httpconnection, match as match_, \
19 url as url_, util
17 from mercurial import dirstate, httpconnection, match as match_, util
20 18 from mercurial.i18n import _
21 19
22 20 try:
@@ -30,74 +28,38 b" longname = 'largefiles'"
30 28
31 29 # -- Portability wrappers ----------------------------------------------
32 30
33 if 'subrepos' in inspect.getargspec(dirstate.dirstate.status)[0]:
34 # for Mercurial >= 1.5
35 def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
36 return dirstate.walk(matcher, [], unknown, ignored)
37 else:
38 # for Mercurial <= 1.4
39 def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
40 return dirstate.walk(matcher, unknown, ignored)
31 def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
32 return dirstate.walk(matcher, [], unknown, ignored)
41 33
42 34 def repo_add(repo, list):
43 try:
44 # Mercurial <= 1.5
45 add = repo.add
46 except AttributeError:
47 # Mercurial >= 1.6
48 add = repo[None].add
35 add = repo[None].add
49 36 return add(list)
50 37
51 38 def repo_remove(repo, list, unlink=False):
52 try:
53 # Mercurial <= 1.5
54 remove = repo.remove
55 except AttributeError:
56 # Mercurial >= 1.6
39 def remove(list, unlink):
40 wlock = repo.wlock()
57 41 try:
58 # Mercurial <= 1.8
59 remove = repo[None].remove
60 except AttributeError:
61 # Mercurial >= 1.9
62 def remove(list, unlink):
63 wlock = repo.wlock()
64 try:
65 if unlink:
66 for f in list:
67 try:
68 util.unlinkpath(repo.wjoin(f))
69 except OSError, inst:
70 if inst.errno != errno.ENOENT:
71 raise
72 repo[None].forget(list)
73 finally:
74 wlock.release()
75
42 if unlink:
43 for f in list:
44 try:
45 util.unlinkpath(repo.wjoin(f))
46 except OSError, inst:
47 if inst.errno != errno.ENOENT:
48 raise
49 repo[None].forget(list)
50 finally:
51 wlock.release()
76 52 return remove(list, unlink=unlink)
77 53
78 54 def repo_forget(repo, list):
79 try:
80 # Mercurial <= 1.5
81 forget = repo.forget
82 except AttributeError:
83 # Mercurial >= 1.6
84 forget = repo[None].forget
55 forget = repo[None].forget
85 56 return forget(list)
86 57
87 58 def findoutgoing(repo, remote, force):
88 # First attempt is for Mercurial <= 1.5 second is for >= 1.6
89 try:
90 return repo.findoutgoing(remote)
91 except AttributeError:
92 from mercurial import discovery
93 try:
94 # Mercurial <= 1.8
95 return discovery.findoutgoing(repo, remote, force=force)
96 except AttributeError:
97 # Mercurial >= 1.9
98 common, _anyinc, _heads = discovery.findcommonincoming(repo,
99 remote, force=force)
100 return repo.changelog.findmissing(common)
59 from mercurial import discovery
60 common, _anyinc, _heads = discovery.findcommonincoming(repo,
61 remote, force=force)
62 return repo.changelog.findmissing(common)
101 63
102 64 # -- Private worker functions ------------------------------------------
103 65
@@ -155,12 +117,7 b' def openlfdirstate(ui, repo):'
155 117 repo root, but it is saved in .hg/largefiles/dirstate.
156 118 '''
157 119 admin = repo.join(longname)
158 try:
159 # Mercurial >= 1.9
160 opener = scmutil.opener(admin)
161 except ImportError:
162 # Mercurial <= 1.8
163 opener = util.opener(admin)
120 opener = scmutil.opener(admin)
164 121 if util.safehasattr(repo.dirstate, '_validate'):
165 122 lfdirstate = largefiles_dirstate(opener, ui, repo.root,
166 123 repo.dirstate._validate)
@@ -286,12 +243,7 b' def getmatcher(repo, pats=[], opts={}, s'
286 243 '''Wrapper around scmutil.match() that adds showbad: if false, neuter
287 244 the match object\'s bad() method so it does not print any warnings
288 245 about missing files or directories.'''
289 try:
290 # Mercurial >= 1.9
291 match = scmutil.match(repo[None], pats, opts)
292 except ImportError:
293 # Mercurial <= 1.8
294 match = cmdutil.match(repo, pats, opts)
246 match = scmutil.match(repo[None], pats, opts)
295 247
296 248 if not showbad:
297 249 match.bad = lambda f, msg: None
@@ -462,16 +414,7 b' def hexsha1(data):'
462 414 return h.hexdigest()
463 415
464 416 def httpsendfile(ui, filename):
465 try:
466 # Mercurial >= 1.9
467 return httpconnection.httpsendfile(ui, filename, 'rb')
468 except ImportError:
469 if 'ui' in inspect.getargspec(url_.httpsendfile.__init__)[0]:
470 # Mercurial == 1.8
471 return url_.httpsendfile(ui, filename, 'rb')
472 else:
473 # Mercurial <= 1.7
474 return url_.httpsendfile(filename, 'rb')
417 return httpconnection.httpsendfile(ui, filename, 'rb')
475 418
476 419 # Convert a path to a unix style path. This is used to give a
477 420 # canonical path to the lfdirstate.
@@ -43,19 +43,9 b' def installnormalfilesmatchfn(manifest):'
43 43 oldmatch = installmatchfn(override_match)
44 44
45 45 def installmatchfn(f):
46 try:
47 # Mercurial >= 1.9
48 oldmatch = scmutil.match
49 except ImportError:
50 # Mercurial <= 1.8
51 oldmatch = cmdutil.match
46 oldmatch = scmutil.match
52 47 setattr(f, 'oldmatch', oldmatch)
53 try:
54 # Mercurial >= 1.9
55 scmutil.match = f
56 except ImportError:
57 # Mercurial <= 1.8
58 cmdutil.match = f
48 scmutil.match = f
59 49 return oldmatch
60 50
61 51 def restorematchfn():
@@ -64,12 +54,7 b' def restorematchfn():'
64 54
65 55 Note that n calls to installnormalfilesmatchfn will require n calls to
66 56 restore matchfn to reverse'''
67 try:
68 # Mercurial >= 1.9
69 scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
70 except ImportError:
71 # Mercurial <= 1.8
72 cmdutil.match = getattr(cmdutil.match, 'oldmatch', cmdutil.match)
57 scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
73 58
74 59 # -- Wrappers: modify existing commands --------------------------------
75 60
@@ -98,12 +83,7 b' def override_add(orig, ui, repo, *pats, '
98 83 lfmatcher = match_.match(repo.root, '', list(lfpats))
99 84
100 85 lfnames = []
101 try:
102 # Mercurial >= 1.9
103 m = scmutil.match(repo[None], pats, opts)
104 except ImportError:
105 # Mercurial <= 1.8
106 m = cmdutil.match(repo, pats, opts)
86 m = scmutil.match(repo[None], pats, opts)
107 87 m.bad = lambda x, y: None
108 88 wctx = repo[None]
109 89 for f in repo.walk(m):
@@ -165,12 +145,7 b' def override_remove(orig, ui, repo, *pat'
165 145 after, force = opts.get('after'), opts.get('force')
166 146 if not pats and not after:
167 147 raise util.Abort(_('no files specified'))
168 try:
169 # Mercurial >= 1.9
170 m = scmutil.match(repo[None], pats, opts)
171 except ImportError:
172 # Mercurial <= 1.8
173 m = cmdutil.match(repo, pats, opts)
148 m = scmutil.match(repo[None], pats, opts)
174 149 try:
175 150 repo.lfstatus = True
176 151 s = repo.status(match=m, clean=True)
@@ -332,21 +307,11 b' def override_copy(orig, ui, repo, pats, '
332 307 return orig(ui, repo, pats, opts, rename)
333 308
334 309 def makestandin(relpath):
335 try:
336 # Mercurial >= 1.9
337 path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
338 except ImportError:
339 # Mercurial <= 1.8
340 path = util.canonpath(repo.root, repo.getcwd(), relpath)
310 path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
341 311 return os.path.join(os.path.relpath('.', repo.getcwd()),
342 312 lfutil.standin(path))
343 313
344 try:
345 # Mercurial >= 1.9
346 fullpats = scmutil.expandpats(pats)
347 except ImportError:
348 # Mercurial <= 1.8
349 fullpats = cmdutil.expandpats(pats)
314 fullpats = scmutil.expandpats(pats)
350 315 dest = fullpats[-1]
351 316
352 317 if os.path.isdir(dest):
@@ -520,13 +485,8 b' def override_revert(orig, ui, repo, *pat'
520 485 m.matchfn = matchfn
521 486 return m
522 487 oldmatch = installmatchfn(override_match)
523 try:
524 # Mercurial >= 1.9
525 scmutil.match
526 matches = override_match(repo[None], pats, opts)
527 except ImportError:
528 # Mercurial <= 1.8
529 matches = override_match(repo, pats, opts)
488 scmutil.match
489 matches = override_match(repo[None], pats, opts)
530 490 orig(ui, repo, *pats, **opts)
531 491 finally:
532 492 restorematchfn()
@@ -547,12 +507,7 b' def override_revert(orig, ui, repo, *pat'
547 507 standin = lfutil.standin(lfile)
548 508 if standin not in ctx and (standin in matches or opts.get('all')):
549 509 if lfile in lfdirstate:
550 try:
551 # Mercurial >= 1.9
552 lfdirstate.drop(lfile)
553 except AttributeError:
554 # Mercurial <= 1.8
555 lfdirstate.forget(lfile)
510 lfdirstate.drop(lfile)
556 511 util.unlinkpath(repo.wjoin(standin))
557 512 lfdirstate.write()
558 513 finally:
@@ -586,12 +541,7 b' def override_pull(orig, ui, repo, source'
586 541 ui.debug('--update and --rebase are not compatible, ignoring '
587 542 'the update flag\n')
588 543 del opts['rebase']
589 try:
590 # Mercurial >= 1.9
591 cmdutil.bailifchanged(repo)
592 except AttributeError:
593 # Mercurial <= 1.8
594 cmdutil.bail_if_changed(repo)
544 cmdutil.bailifchanged(repo)
595 545 revsprepull = len(repo)
596 546 origpostincoming = commands.postincoming
597 547 def _dummy(*args, **kwargs):
@@ -635,37 +585,22 b' def override_archive(orig, repo, dest, n'
635 585
636 586 ctx = repo[node]
637 587
638 # In Mercurial <= 1.5 the prefix is passed to the archiver so try that
639 # if that doesn't work we are probably in Mercurial >= 1.6 where the
640 # prefix is not handled by the archiver
641 try:
642 archiver = archival.archivers[kind](dest, prefix, mtime or \
643 ctx.date()[0])
588 if kind == 'files':
589 if prefix:
590 raise util.Abort(
591 _('cannot give prefix when archiving to files'))
592 else:
593 prefix = archival.tidyprefix(dest, kind, prefix)
644 594
645 def write(name, mode, islink, getdata):
646 if matchfn and not matchfn(name):
647 return
648 data = getdata()
649 if decode:
650 data = repo.wwritedata(name, data)
651 archiver.addfile(name, mode, islink, data)
652 except TypeError:
653 if kind == 'files':
654 if prefix:
655 raise util.Abort(
656 _('cannot give prefix when archiving to files'))
657 else:
658 prefix = archival.tidyprefix(dest, kind, prefix)
595 def write(name, mode, islink, getdata):
596 if matchfn and not matchfn(name):
597 return
598 data = getdata()
599 if decode:
600 data = repo.wwritedata(name, data)
601 archiver.addfile(prefix + name, mode, islink, data)
659 602
660 def write(name, mode, islink, getdata):
661 if matchfn and not matchfn(name):
662 return
663 data = getdata()
664 if decode:
665 data = repo.wwritedata(name, data)
666 archiver.addfile(prefix + name, mode, islink, data)
667
668 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
603 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
669 604
670 605 if repo.ui.configbool("ui", "archivemeta", True):
671 606 def metadata():
@@ -739,12 +674,7 b' def override_forget(orig, ui, repo, *pat'
739 674 installnormalfilesmatchfn(repo[None].manifest())
740 675 orig(ui, repo, *pats, **opts)
741 676 restorematchfn()
742 try:
743 # Mercurial >= 1.9
744 m = scmutil.match(repo[None], pats, opts)
745 except ImportError:
746 # Mercurial <= 1.8
747 m = cmdutil.match(repo, pats, opts)
677 m = scmutil.match(repo[None], pats, opts)
748 678
749 679 try:
750 680 repo.lfstatus = True
@@ -787,11 +717,7 b' def getoutgoinglfiles(ui, repo, dest=Non'
787 717 if revs:
788 718 revs = [repo.lookup(rev) for rev in revs]
789 719
790 # Mercurial <= 1.5 had remoteui in cmdutil, then it moved to hg
791 try:
792 remoteui = cmdutil.remoteui
793 except AttributeError:
794 remoteui = hg.remoteui
720 remoteui = hg.remoteui
795 721
796 722 try:
797 723 remote = hg.repository(remoteui(repo, opts), dest)
@@ -140,11 +140,7 b' def sshproto_refuseclient(self, message)'
140 140
141 141 def heads(repo, proto):
142 142 if lfutil.islfilesrepo(repo):
143 try:
144 # Mercurial >= f4522df38c65
145 return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
146 except AttributeError:
147 return proto.refuseclient(LARGEFILES_REQUIRED_MSG)
143 return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
148 144 return wireproto.heads(repo, proto)
149 145
150 146 def sshrepo_callstream(self, cmd, **args):
@@ -267,12 +267,7 b' def reposetup(ui, repo):'
267 267 for lfile in lfdirstate:
268 268 if not os.path.exists(
269 269 repo.wjoin(lfutil.standin(lfile))):
270 try:
271 # Mercurial >= 1.9
272 lfdirstate.drop(lfile)
273 except AttributeError:
274 # Mercurial <= 1.8
275 lfdirstate.forget(lfile)
270 lfdirstate.drop(lfile)
276 271 lfdirstate.write()
277 272
278 273 return orig(text=text, user=user, date=date, match=match,
@@ -306,12 +301,7 b' def reposetup(ui, repo):'
306 301 lfutil.updatestandin(self, standin)
307 302 lfdirstate.normal(lfile)
308 303 else:
309 try:
310 # Mercurial >= 1.9
311 lfdirstate.drop(lfile)
312 except AttributeError:
313 # Mercurial <= 1.8
314 lfdirstate.forget(lfile)
304 lfdirstate.drop(lfile)
315 305 lfdirstate.write()
316 306
317 307 # Cook up a new matcher that only matches regular files or
@@ -386,12 +376,8 b' def reposetup(ui, repo):'
386 376 toupload = toupload.union(set([ctx[f].data().strip() for f\
387 377 in files if lfutil.isstandin(f) and f in ctx]))
388 378 lfcommands.uploadlfiles(ui, self, remote, toupload)
389 # Mercurial >= 1.6 takes the newbranch argument, try that first.
390 try:
391 return super(lfiles_repo, self).push(remote, force, revs,
392 newbranch)
393 except TypeError:
394 return super(lfiles_repo, self).push(remote, force, revs)
379 return super(lfiles_repo, self).push(remote, force, revs,
380 newbranch)
395 381
396 382 repo.__class__ = lfiles_repo
397 383
General Comments 0
You need to be logged in to leave comments. Login now