comparison hgext/largefiles/overrides.py @ 41654:f164076427b2

largefiles: use uipathfn instead of match.{rel,uipath}() (API) All callers now pass in a uipathfn, so we can just use that instead of choosing the right match function. This also means that when we make add/remove respect ui.relative-paths, it will work for largefiles too. Differential Revision: https://phab.mercurial-scm.org/D5904
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Feb 2019 23:29:14 -0800
parents 16a49c778bde
children 8fa1a5fb8a28
comparison
equal deleted inserted replaced
41653:16a49c778bde 41654:f164076427b2
76 m.always = lambda: False 76 m.always = lambda: False
77 origmatchfn = m.matchfn 77 origmatchfn = m.matchfn
78 m.matchfn = lambda f: notlfile(f) and origmatchfn(f) 78 m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
79 return m 79 return m
80 80
81 def addlargefiles(ui, repo, isaddremove, matcher, **opts): 81 def addlargefiles(ui, repo, isaddremove, matcher, uipathfn, **opts):
82 large = opts.get(r'large') 82 large = opts.get(r'large')
83 lfsize = lfutil.getminsize( 83 lfsize = lfutil.getminsize(
84 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize')) 84 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize'))
85 85
86 lfmatcher = None 86 lfmatcher = None
97 exact = m.exact(f) 97 exact = m.exact(f)
98 lfile = lfutil.standin(f) in wctx 98 lfile = lfutil.standin(f) in wctx
99 nfile = f in wctx 99 nfile = f in wctx
100 exists = lfile or nfile 100 exists = lfile or nfile
101 101
102 # addremove in core gets fancy with the name, add doesn't
103 if isaddremove:
104 name = m.uipath(f)
105 else:
106 name = m.rel(f)
107
108 # Don't warn the user when they attempt to add a normal tracked file. 102 # Don't warn the user when they attempt to add a normal tracked file.
109 # The normal add code will do that for us. 103 # The normal add code will do that for us.
110 if exact and exists: 104 if exact and exists:
111 if lfile: 105 if lfile:
112 ui.warn(_('%s already a largefile\n') % name) 106 ui.warn(_('%s already a largefile\n') % uipathfn(f))
113 continue 107 continue
114 108
115 if (exact or not exists) and not lfutil.isstandin(f): 109 if (exact or not exists) and not lfutil.isstandin(f):
116 # In case the file was removed previously, but not committed 110 # In case the file was removed previously, but not committed
117 # (issue3507) 111 # (issue3507)
121 abovemin = (lfsize and 115 abovemin = (lfsize and
122 repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024) 116 repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024)
123 if large or abovemin or (lfmatcher and lfmatcher(f)): 117 if large or abovemin or (lfmatcher and lfmatcher(f)):
124 lfnames.append(f) 118 lfnames.append(f)
125 if ui.verbose or not exact: 119 if ui.verbose or not exact:
126 ui.status(_('adding %s as a largefile\n') % name) 120 ui.status(_('adding %s as a largefile\n') % uipathfn(f))
127 121
128 bad = [] 122 bad = []
129 123
130 # Need to lock, otherwise there could be a race condition between 124 # Need to lock, otherwise there could be a race condition between
131 # when standins are created and added to the repo. 125 # when standins are created and added to the repo.
148 if f in m.files()] 142 if f in m.files()]
149 143
150 added = [f for f in lfnames if f not in bad] 144 added = [f for f in lfnames if f not in bad]
151 return added, bad 145 return added, bad
152 146
153 def removelargefiles(ui, repo, isaddremove, matcher, dryrun, **opts): 147 def removelargefiles(ui, repo, isaddremove, matcher, uipathfn, dryrun, **opts):
154 after = opts.get(r'after') 148 after = opts.get(r'after')
155 m = composelargefilematcher(matcher, repo[None].manifest()) 149 m = composelargefilematcher(matcher, repo[None].manifest())
156 try: 150 try:
157 repo.lfstatus = True 151 repo.lfstatus = True
158 s = repo.status(match=m, clean=not isaddremove) 152 s = repo.status(match=m, clean=not isaddremove)
164 for list in (s.modified, s.added, 158 for list in (s.modified, s.added,
165 s.deleted, s.clean)] 159 s.deleted, s.clean)]
166 160
167 def warn(files, msg): 161 def warn(files, msg):
168 for f in files: 162 for f in files:
169 ui.warn(msg % m.rel(f)) 163 ui.warn(msg % uipathfn(f))
170 return int(len(files) > 0) 164 return int(len(files) > 0)
171 165
172 if after: 166 if after:
173 remove = deleted 167 remove = deleted
174 result = warn(modified + added + clean, 168 result = warn(modified + added + clean,
184 # repository and we could race in-between. 178 # repository and we could race in-between.
185 with repo.wlock(): 179 with repo.wlock():
186 lfdirstate = lfutil.openlfdirstate(ui, repo) 180 lfdirstate = lfutil.openlfdirstate(ui, repo)
187 for f in sorted(remove): 181 for f in sorted(remove):
188 if ui.verbose or not m.exact(f): 182 if ui.verbose or not m.exact(f):
189 # addremove in core gets fancy with the name, remove doesn't 183 ui.status(_('removing %s\n') % uipathfn(f))
190 if isaddremove:
191 name = m.uipath(f)
192 else:
193 name = m.rel(f)
194 ui.status(_('removing %s\n') % name)
195 184
196 if not dryrun: 185 if not dryrun:
197 if not after: 186 if not after:
198 repo.wvfs.unlinkpath(f, ignoremissing=True) 187 repo.wvfs.unlinkpath(f, ignoremissing=True)
199 188
238 def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts): 227 def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts):
239 # The --normal flag short circuits this override 228 # The --normal flag short circuits this override
240 if opts.get(r'normal'): 229 if opts.get(r'normal'):
241 return orig(ui, repo, matcher, prefix, uipathfn, explicitonly, **opts) 230 return orig(ui, repo, matcher, prefix, uipathfn, explicitonly, **opts)
242 231
243 ladded, lbad = addlargefiles(ui, repo, False, matcher, **opts) 232 ladded, lbad = addlargefiles(ui, repo, False, matcher, uipathfn, **opts)
244 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(), 233 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(),
245 ladded) 234 ladded)
246 bad = orig(ui, repo, normalmatcher, prefix, uipathfn, explicitonly, **opts) 235 bad = orig(ui, repo, normalmatcher, prefix, uipathfn, explicitonly, **opts)
247 236
248 bad.extend(f for f in lbad) 237 bad.extend(f for f in lbad)
252 def cmdutilremove(orig, ui, repo, matcher, prefix, uipathfn, after, force, 241 def cmdutilremove(orig, ui, repo, matcher, prefix, uipathfn, after, force,
253 subrepos, dryrun): 242 subrepos, dryrun):
254 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest()) 243 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
255 result = orig(ui, repo, normalmatcher, prefix, uipathfn, after, force, 244 result = orig(ui, repo, normalmatcher, prefix, uipathfn, after, force,
256 subrepos, dryrun) 245 subrepos, dryrun)
257 return removelargefiles(ui, repo, False, matcher, dryrun, after=after, 246 return removelargefiles(ui, repo, False, matcher, uipathfn, dryrun,
258 force=force) or result 247 after=after, force=force) or result
259 248
260 @eh.wrapfunction(subrepo.hgsubrepo, 'status') 249 @eh.wrapfunction(subrepo.hgsubrepo, 'status')
261 def overridestatusfn(orig, repo, rev2, **opts): 250 def overridestatusfn(orig, repo, rev2, **opts):
262 try: 251 try:
263 repo._repo.lfstatus = True 252 repo._repo.lfstatus = True
1248 # or not the file name is printed, and how. Simply limit the original 1237 # or not the file name is printed, and how. Simply limit the original
1249 # matches to those in the deleted status list. 1238 # matches to those in the deleted status list.
1250 matchfn = m.matchfn 1239 matchfn = m.matchfn
1251 m.matchfn = lambda f: f in s.deleted and matchfn(f) 1240 m.matchfn = lambda f: f in s.deleted and matchfn(f)
1252 1241
1253 removelargefiles(repo.ui, repo, True, m, opts.get('dry_run'), 1242 removelargefiles(repo.ui, repo, True, m, uipathfn, opts.get('dry_run'),
1254 **pycompat.strkwargs(opts)) 1243 **pycompat.strkwargs(opts))
1255 # Call into the normal add code, and any files that *should* be added as 1244 # Call into the normal add code, and any files that *should* be added as
1256 # largefiles will be 1245 # largefiles will be
1257 added, bad = addlargefiles(repo.ui, repo, True, matcher, 1246 added, bad = addlargefiles(repo.ui, repo, True, matcher, uipathfn,
1258 **pycompat.strkwargs(opts)) 1247 **pycompat.strkwargs(opts))
1259 # Now that we've handled largefiles, hand off to the original addremove 1248 # Now that we've handled largefiles, hand off to the original addremove
1260 # function to take care of the rest. Make sure it doesn't do anything with 1249 # function to take care of the rest. Make sure it doesn't do anything with
1261 # largefiles by passing a matcher that will ignore them. 1250 # largefiles by passing a matcher that will ignore them.
1262 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added) 1251 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added)