annotate hgext/largefiles/overrides.py @ 15305:683f417fa538 stable

largefiles: tidy imports - no need to defensively import scmutil - remove duplicate - unwrap non-long line
author Greg Ward <greg@gerg.ca>
date Sun, 16 Oct 2011 10:29:51 -0400
parents db7b09e689f1
children 94527d67f3da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
1 # Copyright 2009-2010 Gregory P. Ward
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
3 # Copyright 2010-2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
4 # Copyright 2010-2011 Unity Technologies
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
5 #
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
8
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
9 '''Overridden Mercurial commands and functions for the largefiles extension'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
10
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
11 import os
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
12 import copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
13
15305
683f417fa538 largefiles: tidy imports
Greg Ward <greg@gerg.ca>
parents: 15294
diff changeset
14 from mercurial import hg, commands, util, cmdutil, scmutil, match as match_, \
683f417fa538 largefiles: tidy imports
Greg Ward <greg@gerg.ca>
parents: 15294
diff changeset
15 node, archival, error, merge
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
16 from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
17 from mercurial.node import hex
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
18 from hgext import rebase
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
19
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
20 import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
21 import lfcommands
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
22
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
23 def installnormalfilesmatchfn(manifest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
24 '''overrides scmutil.match so that the matcher it returns will ignore all
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
25 largefiles'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
26 oldmatch = None # for the closure
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
27 def override_match(repo, pats=[], opts={}, globbed=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
28 default='relpath'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
29 match = oldmatch(repo, pats, opts, globbed, default)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
30 m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
31 notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
32 manifest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
33 m._files = filter(notlfile, m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
34 m._fmap = set(m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
35 orig_matchfn = m.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
36 m.matchfn = lambda f: notlfile(f) and orig_matchfn(f) or None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
37 return m
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
38 oldmatch = installmatchfn(override_match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
39
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
40 def installmatchfn(f):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
41 oldmatch = scmutil.match
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
42 setattr(f, 'oldmatch', oldmatch)
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
43 scmutil.match = f
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
44 return oldmatch
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
45
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
46 def restorematchfn():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
47 '''restores scmutil.match to what it was before installnormalfilesmatchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
48 was called. no-op if scmutil.match is its original function.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
49
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
50 Note that n calls to installnormalfilesmatchfn will require n calls to
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
51 restore matchfn to reverse'''
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
52 scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
53
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
54 # -- Wrappers: modify existing commands --------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
55
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
56 # Add works by going through the files that the user wanted to add and
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
57 # checking if they should be added as largefiles. Then it makes a new
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
58 # matcher which matches only the normal files and runs the original
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
59 # version of add.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
60 def override_add(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
61 large = opts.pop('large', None)
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
62 lfsize = lfutil.getminsize(
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
63 ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
64
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
65 lfmatcher = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
66 if os.path.exists(repo.wjoin(lfutil.shortname)):
15229
89e19ca2a90e largefiles: use ui.configlist() to split largefiles.patterns
Greg Ward <greg@gerg.ca>
parents: 15227
diff changeset
67 lfpats = ui.configlist(lfutil.longname, 'patterns', default=[])
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
68 if lfpats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
69 lfmatcher = match_.match(repo.root, '', list(lfpats))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
70
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
71 lfnames = []
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
72 m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
73 m.bad = lambda x, y: None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
74 wctx = repo[None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
75 for f in repo.walk(m):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
76 exact = m.exact(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
77 lfile = lfutil.standin(f) in wctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
78 nfile = f in wctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
79 exists = lfile or nfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
80
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
81 # Don't warn the user when they attempt to add a normal tracked file.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
82 # The normal add code will do that for us.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
83 if exact and exists:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
84 if lfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
85 ui.warn(_('%s already a largefile\n') % f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
86 continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
87
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
88 if exact or not exists:
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
89 abovemin = (lfsize and
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
90 os.path.getsize(repo.wjoin(f)) >= lfsize * 1024 * 1024)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
91 if large or abovemin or (lfmatcher and lfmatcher(f)):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
92 lfnames.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
93 if ui.verbose or not exact:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
94 ui.status(_('adding %s as a largefile\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
95
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
96 bad = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
97 standins = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
98
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
99 # Need to lock, otherwise there could be a race condition between
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
100 # when standins are created and added to the repo.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
101 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
102 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
103 if not opts.get('dry_run'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
104 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
105 for f in lfnames:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
106 standinname = lfutil.standin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
107 lfutil.writestandin(repo, standinname, hash='',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
108 executable=lfutil.getexecutable(repo.wjoin(f)))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
109 standins.append(standinname)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
110 if lfdirstate[f] == 'r':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
111 lfdirstate.normallookup(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
112 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
113 lfdirstate.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
114 lfdirstate.write()
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
115 bad += [lfutil.splitstandin(f)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
116 for f in lfutil.repo_add(repo, standins)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
117 if f in m.files()]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
118 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
119 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
120
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
121 installnormalfilesmatchfn(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
122 result = orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
123 restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
124
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
125 return (result == 1 or bad) and 1 or 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
126
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
127 def override_remove(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
128 manifest = repo[None].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
129 installnormalfilesmatchfn(manifest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
130 orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
131 restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
132
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
133 after, force = opts.get('after'), opts.get('force')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
134 if not pats and not after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
135 raise util.Abort(_('no files specified'))
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
136 m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
137 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
138 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
139 s = repo.status(match=m, clean=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
140 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
141 repo.lfstatus = False
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
142 modified, added, deleted, clean = [[f for f in list
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
143 if lfutil.standin(f) in manifest]
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
144 for list in [s[0], s[1], s[3], s[6]]]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
145
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
146 def warn(files, reason):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
147 for f in files:
15294
db7b09e689f1 largefiles: make parameter more i18n-friendly
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15279
diff changeset
148 ui.warn(_('not removing %s: %s (use -f to force removal)\n')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
149 % (m.rel(f), reason))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
150
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
151 if force:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
152 remove, forget = modified + deleted + clean, added
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
153 elif after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
154 remove, forget = deleted, []
15294
db7b09e689f1 largefiles: make parameter more i18n-friendly
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15279
diff changeset
155 warn(modified + added + clean, _('file still exists'))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
156 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
157 remove, forget = deleted + clean, []
15294
db7b09e689f1 largefiles: make parameter more i18n-friendly
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15279
diff changeset
158 warn(modified, _('file is modified'))
db7b09e689f1 largefiles: make parameter more i18n-friendly
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15279
diff changeset
159 warn(added, _('file has been marked for add'))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
160
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
161 for f in sorted(remove + forget):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
162 if ui.verbose or not m.exact(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
163 ui.status(_('removing %s\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
164
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
165 # Need to lock because standin files are deleted then removed from the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
166 # repository and we could race inbetween.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
167 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
168 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
169 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
170 for f in remove:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
171 if not after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
172 os.unlink(repo.wjoin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
173 currentdir = os.path.split(f)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
174 while currentdir and not os.listdir(repo.wjoin(currentdir)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
175 os.rmdir(repo.wjoin(currentdir))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
176 currentdir = os.path.split(currentdir)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
177 lfdirstate.remove(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
178 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
179
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
180 forget = [lfutil.standin(f) for f in forget]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
181 remove = [lfutil.standin(f) for f in remove]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
182 lfutil.repo_forget(repo, forget)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
183 lfutil.repo_remove(repo, remove, unlink=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
184 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
185 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
186
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
187 def override_status(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
188 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
189 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
190 return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
191 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
192 repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
193
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
194 def override_log(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
195 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
196 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
197 orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
198 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
199 repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
200
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
201 def override_verify(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
202 large = opts.pop('large', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
203 all = opts.pop('lfa', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
204 contents = opts.pop('lfc', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
205
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
206 result = orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
207 if large:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
208 result = result or lfcommands.verifylfiles(ui, repo, all, contents)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
209 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
210
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
211 # Override needs to refresh standins so that update's normal merge
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
212 # will go through properly. Then the other update hook (overriding repo.update)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
213 # will get the new files. Filemerge is also overriden so that the merge
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
214 # will merge standins correctly.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
215 def override_update(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
216 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
217 s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
218 False, False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
219 (unsure, modified, added, removed, missing, unknown, ignored, clean) = s
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
220
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
221 # Need to lock between the standins getting updated and their
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
222 # largefiles getting updated
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
223 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
224 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
225 if opts['check']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
226 mod = len(modified) > 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
227 for lfile in unsure:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
228 standin = lfutil.standin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
229 if repo['.'][standin].data().strip() != \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
230 lfutil.hashfile(repo.wjoin(lfile)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
231 mod = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
232 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
233 lfdirstate.normal(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
234 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
235 if mod:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
236 raise util.Abort(_('uncommitted local changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
237 # XXX handle removed differently
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
238 if not opts['clean']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
239 for lfile in unsure + modified + added:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
240 lfutil.updatestandin(repo, lfutil.standin(lfile))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
241 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
242 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
243 return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
244
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
245 # Override filemerge to prompt the user about how they wish to merge
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
246 # largefiles. This will handle identical edits, and copy/rename +
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
247 # edit without prompting the user.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
248 def override_filemerge(origfn, repo, mynode, orig, fcd, fco, fca):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
249 # Use better variable names here. Because this is a wrapper we cannot
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
250 # change the variable names in the function declaration.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
251 fcdest, fcother, fcancestor = fcd, fco, fca
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
252 if not lfutil.isstandin(orig):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
253 return origfn(repo, mynode, orig, fcdest, fcother, fcancestor)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
254 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
255 if not fcother.cmp(fcdest): # files identical?
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
256 return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
257
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
258 # backwards, use working dir parent as ancestor
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
259 if fcancestor == fcother:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
260 fcancestor = fcdest.parents()[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
261
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
262 if orig != fcother.path():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
263 repo.ui.status(_('merging %s and %s to %s\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
264 % (lfutil.splitstandin(orig),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
265 lfutil.splitstandin(fcother.path()),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
266 lfutil.splitstandin(fcdest.path())))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
267 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
268 repo.ui.status(_('merging %s\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
269 % lfutil.splitstandin(fcdest.path()))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
270
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
271 if fcancestor.path() != fcother.path() and fcother.data() == \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
272 fcancestor.data():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
273 return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
274 if fcancestor.path() != fcdest.path() and fcdest.data() == \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
275 fcancestor.data():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
276 repo.wwrite(fcdest.path(), fcother.data(), fcother.flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
277 return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
278
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
279 if repo.ui.promptchoice(_('largefile %s has a merge conflict\n'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
280 'keep (l)ocal or take (o)ther?') %
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
281 lfutil.splitstandin(orig),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
282 (_('&Local'), _('&Other')), 0) == 0:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
283 return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
284 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
285 repo.wwrite(fcdest.path(), fcother.data(), fcother.flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
286 return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
287
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
288 # Copy first changes the matchers to match standins instead of
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
289 # largefiles. Then it overrides util.copyfile in that function it
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
290 # checks if the destination largefile already exists. It also keeps a
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
291 # list of copied files so that the largefiles can be copied and the
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
292 # dirstate updated.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
293 def override_copy(orig, ui, repo, pats, opts, rename=False):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15229
diff changeset
294 # doesn't remove largefile on rename
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
295 if len(pats) < 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
296 # this isn't legal, let the original function deal with it
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
297 return orig(ui, repo, pats, opts, rename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
298
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
299 def makestandin(relpath):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
300 path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
301 return os.path.join(os.path.relpath('.', repo.getcwd()),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
302 lfutil.standin(path))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
303
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
304 fullpats = scmutil.expandpats(pats)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
305 dest = fullpats[-1]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
306
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
307 if os.path.isdir(dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
308 if not os.path.isdir(makestandin(dest)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
309 os.makedirs(makestandin(dest))
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
310 # This could copy both lfiles and normal files in one command,
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
311 # but we don't want to do that. First replace their matcher to
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
312 # only match normal files and run it, then replace it to just
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
313 # match largefiles and run it again.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
314 nonormalfiles = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
315 nolfiles = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
316 try:
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
317 try:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
318 installnormalfilesmatchfn(repo[None].manifest())
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
319 result = orig(ui, repo, pats, opts, rename)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
320 except util.Abort, e:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
321 if str(e) != 'no files to copy':
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
322 raise e
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
323 else:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
324 nonormalfiles = True
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
325 result = 0
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
326 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
327 restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
328
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
329 # The first rename can cause our current working directory to be removed.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
330 # In that case there is nothing left to copy/rename so just quit.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
331 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
332 repo.getcwd()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
333 except OSError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
334 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
335
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
336 try:
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
337 try:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
338 # When we call orig below it creates the standins but we don't add them
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
339 # to the dir state until later so lock during that time.
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
340 wlock = repo.wlock()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
341
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
342 manifest = repo[None].manifest()
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
343 oldmatch = None # for the closure
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
344 def override_match(repo, pats=[], opts={}, globbed=False,
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
345 default='relpath'):
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
346 newpats = []
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
347 # The patterns were previously mangled to add the standin
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
348 # directory; we need to remove that now
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
349 for pat in pats:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
350 if match_.patkind(pat) is None and lfutil.shortname in pat:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
351 newpats.append(pat.replace(lfutil.shortname, ''))
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
352 else:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
353 newpats.append(pat)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
354 match = oldmatch(repo, newpats, opts, globbed, default)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
355 m = copy.copy(match)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
356 lfile = lambda f: lfutil.standin(f) in manifest
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
357 m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
358 m._fmap = set(m._files)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
359 orig_matchfn = m.matchfn
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
360 m.matchfn = lambda f: (lfutil.isstandin(f) and
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
361 lfile(lfutil.splitstandin(f)) and
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
362 orig_matchfn(lfutil.splitstandin(f)) or
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
363 None)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
364 return m
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
365 oldmatch = installmatchfn(override_match)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
366 listpats = []
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
367 for pat in pats:
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
368 if match_.patkind(pat) is not None:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
369 listpats.append(pat)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
370 else:
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
371 listpats.append(makestandin(pat))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
372
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
373 try:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
374 origcopyfile = util.copyfile
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
375 copiedfiles = []
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
376 def override_copyfile(src, dest):
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
377 if lfutil.shortname in src and lfutil.shortname in dest:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
378 destlfile = dest.replace(lfutil.shortname, '')
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
379 if not opts['force'] and os.path.exists(destlfile):
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
380 raise IOError('',
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
381 _('destination largefile already exists'))
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
382 copiedfiles.append((src, dest))
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
383 origcopyfile(src, dest)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
384
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
385 util.copyfile = override_copyfile
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
386 result += orig(ui, repo, listpats, opts, rename)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
387 finally:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
388 util.copyfile = origcopyfile
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
389
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
390 lfdirstate = lfutil.openlfdirstate(ui, repo)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
391 for (src, dest) in copiedfiles:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
392 if lfutil.shortname in src and lfutil.shortname in dest:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
393 srclfile = src.replace(lfutil.shortname, '')
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
394 destlfile = dest.replace(lfutil.shortname, '')
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
395 destlfiledir = os.path.dirname(destlfile) or '.'
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
396 if not os.path.isdir(destlfiledir):
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
397 os.makedirs(destlfiledir)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
398 if rename:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
399 os.rename(srclfile, destlfile)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
400 lfdirstate.remove(os.path.relpath(srclfile,
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
401 repo.root))
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
402 else:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
403 util.copyfile(srclfile, destlfile)
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
404 lfdirstate.add(os.path.relpath(destlfile,
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
405 repo.root))
15279
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
406 lfdirstate.write()
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
407 except util.Abort, e:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
408 if str(e) != 'no files to copy':
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
409 raise e
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
410 else:
018608160299 largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15255
diff changeset
411 nolfiles = True
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
412 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
413 restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
414 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
415
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
416 if nolfiles and nonormalfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
417 raise util.Abort(_('no files to copy'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
418
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
419 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
420
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
421 # When the user calls revert, we have to be careful to not revert any
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
422 # changes to other largefiles accidentally. This means we have to keep
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
423 # track of the largefiles that are being reverted so we only pull down
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
424 # the necessary largefiles.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
425 #
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
426 # Standins are only updated (to match the hash of largefiles) before
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
427 # commits. Update the standins then run the original revert, changing
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
428 # the matcher to hit standins instead of largefiles. Based on the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
429 # resulting standins update the largefiles. Then return the standins
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
430 # to their proper state
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
431 def override_revert(orig, ui, repo, *pats, **opts):
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
432 # Because we put the standins in a bad state (by updating them)
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
433 # and then return them to a correct state we need to lock to
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
434 # prevent others from changing them in their incorrect state.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
435 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
436 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
437 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
438 (modified, added, removed, missing, unknown, ignored, clean) = \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
439 lfutil.lfdirstate_status(lfdirstate, repo, repo['.'].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
440 for lfile in modified:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
441 lfutil.updatestandin(repo, lfutil.standin(lfile))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
442
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
443 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
444 ctx = repo[opts.get('rev')]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
445 oldmatch = None # for the closure
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
446 def override_match(ctxorrepo, pats=[], opts={}, globbed=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
447 default='relpath'):
15169
aa262fff87ac largefile: fix up hasattr usage
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
448 if util.safehasattr(ctxorrepo, 'match'):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
449 ctx0 = ctxorrepo
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
450 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
451 ctx0 = ctxorrepo[None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
452 match = oldmatch(ctxorrepo, pats, opts, globbed, default)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
453 m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
454 def tostandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
455 if lfutil.standin(f) in ctx0 or lfutil.standin(f) in ctx:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
456 return lfutil.standin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
457 elif lfutil.standin(f) in repo[None]:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
458 return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
459 return f
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
460 m._files = [tostandin(f) for f in m._files]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
461 m._files = [f for f in m._files if f is not None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
462 m._fmap = set(m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
463 orig_matchfn = m.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
464 def matchfn(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
465 if lfutil.isstandin(f):
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
466 # We need to keep track of what largefiles are being
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
467 # matched so we know which ones to update later --
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
468 # otherwise we accidentally revert changes to other
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
469 # largefiles. This is repo-specific, so duckpunch the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
470 # repo object to keep the list of largefiles for us
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
471 # later.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
472 if orig_matchfn(lfutil.splitstandin(f)) and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
473 (f in repo[None] or f in ctx):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
474 lfileslist = getattr(repo, '_lfilestoupdate', [])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
475 lfileslist.append(lfutil.splitstandin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
476 repo._lfilestoupdate = lfileslist
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
477 return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
478 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
479 return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
480 return orig_matchfn(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
481 m.matchfn = matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
482 return m
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
483 oldmatch = installmatchfn(override_match)
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
484 scmutil.match
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
485 matches = override_match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
486 orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
487 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
488 restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
489 lfileslist = getattr(repo, '_lfilestoupdate', [])
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
490 lfcommands.updatelfiles(ui, repo, filelist=lfileslist,
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
491 printmessage=False)
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
492
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
493 # empty out the largefiles list so we start fresh next time
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
494 repo._lfilestoupdate = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
495 for lfile in modified:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
496 if lfile in lfileslist:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
497 if os.path.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
498 in repo['.']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
499 lfutil.writestandin(repo, lfutil.standin(lfile),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
500 repo['.'][lfile].data().strip(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
501 'x' in repo['.'][lfile].flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
502 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
503 for lfile in added:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
504 standin = lfutil.standin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
505 if standin not in ctx and (standin in matches or opts.get('all')):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
506 if lfile in lfdirstate:
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
507 lfdirstate.drop(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
508 util.unlinkpath(repo.wjoin(standin))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
509 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
510 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
511 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
512
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
513 def hg_update(orig, repo, node):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
514 result = orig(repo, node)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
515 # XXX check if it worked first
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
516 lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
517 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
518
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
519 def hg_clean(orig, repo, node, show_stats=True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
520 result = orig(repo, node, show_stats)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
521 lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
522 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
523
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
524 def hg_merge(orig, repo, node, force=None, remind=True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
525 result = orig(repo, node, force, remind)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
526 lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
527 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
528
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
529 # When we rebase a repository with remotely changed largefiles, we need to
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
530 # take some extra care so that the largefiles are correctly updated in the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
531 # working copy
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
532 def override_pull(orig, ui, repo, source=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
533 if opts.get('rebase', False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
534 repo._isrebasing = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
535 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
536 if opts.get('update'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
537 del opts['update']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
538 ui.debug('--update and --rebase are not compatible, ignoring '
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
539 'the update flag\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
540 del opts['rebase']
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
541 cmdutil.bailifchanged(repo)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
542 revsprepull = len(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
543 origpostincoming = commands.postincoming
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
544 def _dummy(*args, **kwargs):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
545 pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
546 commands.postincoming = _dummy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
547 repo.lfpullsource = source
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
548 if not source:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
549 source = 'default'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
550 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
551 result = commands.pull(ui, repo, source, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
552 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
553 commands.postincoming = origpostincoming
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
554 revspostpull = len(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
555 if revspostpull > revsprepull:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
556 result = result or rebase.rebase(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
557 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
558 repo._isrebasing = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
559 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
560 repo.lfpullsource = source
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
561 if not source:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
562 source = 'default'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
563 result = orig(ui, repo, source, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
564 return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
565
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
566 def override_rebase(orig, ui, repo, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
567 repo._isrebasing = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
568 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
569 orig(ui, repo, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
570 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
571 repo._isrebasing = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
572
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
573 def override_archive(orig, repo, dest, node, kind, decode=True, matchfn=None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
574 prefix=None, mtime=None, subrepos=None):
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
575 # No need to lock because we are only reading history and
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
576 # largefile caches, neither of which are modified.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
577 lfcommands.cachelfiles(repo.ui, repo, node)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
578
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
579 if kind not in archival.archivers:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
580 raise util.Abort(_("unknown archive type '%s'") % kind)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
581
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
582 ctx = repo[node]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
583
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
584 if kind == 'files':
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
585 if prefix:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
586 raise util.Abort(
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
587 _('cannot give prefix when archiving to files'))
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
588 else:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
589 prefix = archival.tidyprefix(dest, kind, prefix)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
590
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
591 def write(name, mode, islink, getdata):
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
592 if matchfn and not matchfn(name):
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
593 return
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
594 data = getdata()
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
595 if decode:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
596 data = repo.wwritedata(name, data)
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
597 archiver.addfile(prefix + name, mode, islink, data)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
598
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
599 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
600
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
601 if repo.ui.configbool("ui", "archivemeta", True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
602 def metadata():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
603 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
604 hex(repo.changelog.node(0)), hex(node), ctx.branch())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
605
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
606 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
607 if repo.tagtype(t) == 'global')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
608 if not tags:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
609 repo.ui.pushbuffer()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
610 opts = {'template': '{latesttag}\n{latesttagdistance}',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
611 'style': '', 'patch': None, 'git': None}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
612 cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
613 ltags, dist = repo.ui.popbuffer().split('\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
614 tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
615 tags += 'latesttagdistance: %s\n' % dist
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
616
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
617 return base + tags
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
618
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
619 write('.hg_archival.txt', 0644, False, metadata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
620
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
621 for f in ctx:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
622 ff = ctx.flags(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
623 getdata = ctx[f].data
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
624 if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
625 path = lfutil.findfile(repo, getdata().strip())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
626 f = lfutil.splitstandin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
627
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
628 def getdatafn():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
629 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
630 fd = open(path, 'rb')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
631 return fd.read()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
632 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
633 fd.close()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
634
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
635 getdata = getdatafn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
636 write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
637
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
638 if subrepos:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
639 for subpath in ctx.substate:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
640 sub = ctx.sub(subpath)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
641 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
642 sub.archive(repo.ui, archiver, prefix)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
643 except TypeError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
644 sub.archive(archiver, prefix)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
645
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
646 archiver.done()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
647
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
648 # If a largefile is modified, the change is not reflected in its
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
649 # standin until a commit. cmdutil.bailifchanged() raises an exception
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
650 # if the repo has uncommitted changes. Wrap it to also check if
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
651 # largefiles were changed. This is used by bisect and backout.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
652 def override_bailifchanged(orig, repo):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
653 orig(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
654 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
655 modified, added, removed, deleted = repo.status()[:4]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
656 repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
657 if modified or added or removed or deleted:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
658 raise util.Abort(_('outstanding uncommitted changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
659
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
660 # Fetch doesn't use cmdutil.bail_if_changed so override it to add the check
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
661 def override_fetch(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
662 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
663 modified, added, removed, deleted = repo.status()[:4]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
664 repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
665 if modified or added or removed or deleted:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
666 raise util.Abort(_('outstanding uncommitted changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
667 return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
668
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
669 def override_forget(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
670 installnormalfilesmatchfn(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
671 orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
672 restorematchfn()
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
673 m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
674
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
675 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
676 repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
677 s = repo.status(match=m, clean=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
678 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
679 repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
680 forget = sorted(s[0] + s[1] + s[3] + s[6])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
681 forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
682
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
683 for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
684 if lfutil.standin(f) not in repo.dirstate and not \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
685 os.path.isdir(m.rel(lfutil.standin(f))):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
686 ui.warn(_('not removing %s: file is already untracked\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
687 % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
688
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
689 for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
690 if ui.verbose or not m.exact(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
691 ui.status(_('removing %s\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
692
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
693 # Need to lock because standin files are deleted then removed from the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
694 # repository and we could race inbetween.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
695 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
696 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
697 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
698 for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
699 if lfdirstate[f] == 'a':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
700 lfdirstate.drop(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
701 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
702 lfdirstate.remove(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
703 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
704 lfutil.repo_remove(repo, [lfutil.standin(f) for f in forget],
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
705 unlink=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
706 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
707 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
708
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
709 def getoutgoinglfiles(ui, repo, dest=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
710 dest = ui.expandpath(dest or 'default-push', dest or 'default')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
711 dest, branches = hg.parseurl(dest, opts.get('branch'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
712 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
713 if revs:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
714 revs = [repo.lookup(rev) for rev in revs]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
715
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
716 remoteui = hg.remoteui
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
717
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
718 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
719 remote = hg.repository(remoteui(repo, opts), dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
720 except error.RepoError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
721 return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
722 o = lfutil.findoutgoing(repo, remote, False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
723 if not o:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
724 return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
725 o = repo.changelog.nodesbetween(o, revs)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
726 if opts.get('newest_first'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
727 o.reverse()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
728
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
729 toupload = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
730 for n in o:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
731 parents = [p for p in repo.changelog.parents(n) if p != node.nullid]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
732 ctx = repo[n]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
733 files = set(ctx.files())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
734 if len(parents) == 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
735 mc = ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
736 mp1 = ctx.parents()[0].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
737 mp2 = ctx.parents()[1].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
738 for f in mp1:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
739 if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
740 files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
741 for f in mp2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
742 if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
743 files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
744 for f in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
745 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
746 files.add(f)
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
747 toupload = toupload.union(
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
748 set([f for f in files if lfutil.isstandin(f) and f in ctx]))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
749 return toupload
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
750
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
751 def override_outgoing(orig, ui, repo, dest=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
752 orig(ui, repo, dest, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
753
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
754 if opts.pop('large', None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
755 toupload = getoutgoinglfiles(ui, repo, dest, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
756 if toupload is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
757 ui.status(_('largefiles: No remote repo\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
758 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
759 ui.status(_('largefiles to upload:\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
760 for file in toupload:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
761 ui.status(lfutil.splitstandin(file) + '\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
762 ui.status('\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
763
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
764 def override_summary(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
765 orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
766
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
767 if opts.pop('large', None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
768 toupload = getoutgoinglfiles(ui, repo, None, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
769 if toupload is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
770 ui.status(_('largefiles: No remote repo\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
771 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
772 ui.status(_('largefiles: %d to upload\n') % len(toupload))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
773
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
774 def override_addremove(orig, ui, repo, *pats, **opts):
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
775 # Check if the parent or child has largefiles; if so, disallow
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
776 # addremove. If there is a symlink in the manifest then getting
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
777 # the manifest throws an exception: catch it and let addremove
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
778 # deal with it.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
779 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
780 manifesttip = set(repo['tip'].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
781 except util.Abort:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
782 manifesttip = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
783 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
784 manifestworking = set(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
785 except util.Abort:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
786 manifestworking = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
787
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
788 # Manifests are only iterable so turn them into sets then union
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
789 for file in manifesttip.union(manifestworking):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
790 if file.startswith(lfutil.shortname):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
791 raise util.Abort(
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
792 _('addremove cannot be run on a repo with largefiles'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
793
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
794 return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
795
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
796 # Calling purge with --all will cause the largefiles to be deleted.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
797 # Override repo.status to prevent this from happening.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
798 def override_purge(orig, ui, repo, *dirs, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
799 oldstatus = repo.status
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
800 def override_status(node1='.', node2=None, match=None, ignored=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
801 clean=False, unknown=False, listsubrepos=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
802 r = oldstatus(node1, node2, match, ignored, clean, unknown,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
803 listsubrepos)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
804 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
805 modified, added, removed, deleted, unknown, ignored, clean = r
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
806 unknown = [f for f in unknown if lfdirstate[f] == '?']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
807 ignored = [f for f in ignored if lfdirstate[f] == '?']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
808 return modified, added, removed, deleted, unknown, ignored, clean
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
809 repo.status = override_status
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
810 orig(ui, repo, *dirs, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
811 repo.status = oldstatus
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
812
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
813 def override_rollback(orig, ui, repo, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
814 result = orig(ui, repo, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
815 merge.update(repo, node=None, branchmerge=False, force=True,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
816 partial=lfutil.isstandin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
817 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
818 lfiles = lfutil.listlfiles(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
819 oldlfiles = lfutil.listlfiles(repo, repo[None].parents()[0].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
820 for file in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
821 if file in oldlfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
822 lfdirstate.normallookup(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
823 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
824 lfdirstate.add(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
825 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
826 return result