comparison hgext/largefiles/lfutil.py @ 15224:7c604d8c7e83

largefiles: remove pre-1.9 code from extension first bundled with 1.9
author Na'Tosha Bard <natosha@unity3d.com>
date Tue, 11 Oct 2011 10:42:56 +0200
parents f85c76b16f27
children 2223ea21c98f
comparison
equal deleted inserted replaced
15223:fc035e5370ca 15224:7c604d8c7e83
8 8
9 '''largefiles utility code: must not import other modules in this package.''' 9 '''largefiles utility code: must not import other modules in this package.'''
10 10
11 import os 11 import os
12 import errno 12 import errno
13 import inspect
14 import shutil 13 import shutil
15 import stat 14 import stat
16 import hashlib 15 import hashlib
17 16
18 from mercurial import cmdutil, dirstate, httpconnection, match as match_, \ 17 from mercurial import dirstate, httpconnection, match as match_, util
19 url as url_, util
20 from mercurial.i18n import _ 18 from mercurial.i18n import _
21 19
22 try: 20 try:
23 from mercurial import scmutil 21 from mercurial import scmutil
24 except ImportError: 22 except ImportError:
28 longname = 'largefiles' 26 longname = 'largefiles'
29 27
30 28
31 # -- Portability wrappers ---------------------------------------------- 29 # -- Portability wrappers ----------------------------------------------
32 30
33 if 'subrepos' in inspect.getargspec(dirstate.dirstate.status)[0]: 31 def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
34 # for Mercurial >= 1.5 32 return dirstate.walk(matcher, [], unknown, ignored)
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)
41 33
42 def repo_add(repo, list): 34 def repo_add(repo, list):
43 try: 35 add = repo[None].add
44 # Mercurial <= 1.5
45 add = repo.add
46 except AttributeError:
47 # Mercurial >= 1.6
48 add = repo[None].add
49 return add(list) 36 return add(list)
50 37
51 def repo_remove(repo, list, unlink=False): 38 def repo_remove(repo, list, unlink=False):
52 try: 39 def remove(list, unlink):
53 # Mercurial <= 1.5 40 wlock = repo.wlock()
54 remove = repo.remove
55 except AttributeError:
56 # Mercurial >= 1.6
57 try: 41 try:
58 # Mercurial <= 1.8 42 if unlink:
59 remove = repo[None].remove 43 for f in list:
60 except AttributeError: 44 try:
61 # Mercurial >= 1.9 45 util.unlinkpath(repo.wjoin(f))
62 def remove(list, unlink): 46 except OSError, inst:
63 wlock = repo.wlock() 47 if inst.errno != errno.ENOENT:
64 try: 48 raise
65 if unlink: 49 repo[None].forget(list)
66 for f in list: 50 finally:
67 try: 51 wlock.release()
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
76 return remove(list, unlink=unlink) 52 return remove(list, unlink=unlink)
77 53
78 def repo_forget(repo, list): 54 def repo_forget(repo, list):
79 try: 55 forget = repo[None].forget
80 # Mercurial <= 1.5
81 forget = repo.forget
82 except AttributeError:
83 # Mercurial >= 1.6
84 forget = repo[None].forget
85 return forget(list) 56 return forget(list)
86 57
87 def findoutgoing(repo, remote, force): 58 def findoutgoing(repo, remote, force):
88 # First attempt is for Mercurial <= 1.5 second is for >= 1.6 59 from mercurial import discovery
89 try: 60 common, _anyinc, _heads = discovery.findcommonincoming(repo,
90 return repo.findoutgoing(remote) 61 remote, force=force)
91 except AttributeError: 62 return repo.changelog.findmissing(common)
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)
101 63
102 # -- Private worker functions ------------------------------------------ 64 # -- Private worker functions ------------------------------------------
103 65
104 def link(src, dest): 66 def link(src, dest):
105 try: 67 try:
153 ''' 115 '''
154 Return a dirstate object that tracks big files: i.e. its root is the 116 Return a dirstate object that tracks big files: i.e. its root is the
155 repo root, but it is saved in .hg/largefiles/dirstate. 117 repo root, but it is saved in .hg/largefiles/dirstate.
156 ''' 118 '''
157 admin = repo.join(longname) 119 admin = repo.join(longname)
158 try: 120 opener = scmutil.opener(admin)
159 # Mercurial >= 1.9
160 opener = scmutil.opener(admin)
161 except ImportError:
162 # Mercurial <= 1.8
163 opener = util.opener(admin)
164 if util.safehasattr(repo.dirstate, '_validate'): 121 if util.safehasattr(repo.dirstate, '_validate'):
165 lfdirstate = largefiles_dirstate(opener, ui, repo.root, 122 lfdirstate = largefiles_dirstate(opener, ui, repo.root,
166 repo.dirstate._validate) 123 repo.dirstate._validate)
167 else: 124 else:
168 lfdirstate = largefiles_dirstate(opener, ui, repo.root) 125 lfdirstate = largefiles_dirstate(opener, ui, repo.root)
284 241
285 def getmatcher(repo, pats=[], opts={}, showbad=True): 242 def getmatcher(repo, pats=[], opts={}, showbad=True):
286 '''Wrapper around scmutil.match() that adds showbad: if false, neuter 243 '''Wrapper around scmutil.match() that adds showbad: if false, neuter
287 the match object\'s bad() method so it does not print any warnings 244 the match object\'s bad() method so it does not print any warnings
288 about missing files or directories.''' 245 about missing files or directories.'''
289 try: 246 match = scmutil.match(repo[None], pats, opts)
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)
295 247
296 if not showbad: 248 if not showbad:
297 match.bad = lambda f, msg: None 249 match.bad = lambda f, msg: None
298 return match 250 return match
299 251
460 for chunk in util.filechunkiter(data): 412 for chunk in util.filechunkiter(data):
461 h.update(chunk) 413 h.update(chunk)
462 return h.hexdigest() 414 return h.hexdigest()
463 415
464 def httpsendfile(ui, filename): 416 def httpsendfile(ui, filename):
465 try: 417 return httpconnection.httpsendfile(ui, filename, 'rb')
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')
475 418
476 # Convert a path to a unix style path. This is used to give a 419 # Convert a path to a unix style path. This is used to give a
477 # canonical path to the lfdirstate. 420 # canonical path to the lfdirstate.
478 def unixpath(path): 421 def unixpath(path):
479 return os.path.normpath(path).replace(os.sep, '/') 422 return os.path.normpath(path).replace(os.sep, '/')