annotate hgext/largefiles/overrides.py @ 15169:aa262fff87ac

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