Mercurial > hg
comparison hgext/largefiles/overrides.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | eef9a2d67051 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
86 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize') | 86 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize') |
87 ) | 87 ) |
88 | 88 |
89 lfmatcher = None | 89 lfmatcher = None |
90 if lfutil.islfilesrepo(repo): | 90 if lfutil.islfilesrepo(repo): |
91 lfpats = ui.configlist(lfutil.longname, 'patterns') | 91 lfpats = ui.configlist(lfutil.longname, b'patterns') |
92 if lfpats: | 92 if lfpats: |
93 lfmatcher = matchmod.match(repo.root, '', list(lfpats)) | 93 lfmatcher = matchmod.match(repo.root, b'', list(lfpats)) |
94 | 94 |
95 lfnames = [] | 95 lfnames = [] |
96 m = matcher | 96 m = matcher |
97 | 97 |
98 wctx = repo[None] | 98 wctx = repo[None] |
104 | 104 |
105 # Don't warn the user when they attempt to add a normal tracked file. | 105 # Don't warn the user when they attempt to add a normal tracked file. |
106 # The normal add code will do that for us. | 106 # The normal add code will do that for us. |
107 if exact and exists: | 107 if exact and exists: |
108 if lfile: | 108 if lfile: |
109 ui.warn(_('%s already a largefile\n') % uipathfn(f)) | 109 ui.warn(_(b'%s already a largefile\n') % uipathfn(f)) |
110 continue | 110 continue |
111 | 111 |
112 if (exact or not exists) and not lfutil.isstandin(f): | 112 if (exact or not exists) and not lfutil.isstandin(f): |
113 # In case the file was removed previously, but not committed | 113 # In case the file was removed previously, but not committed |
114 # (issue3507) | 114 # (issue3507) |
119 lfsize and repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024 | 119 lfsize and repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024 |
120 ) | 120 ) |
121 if large or abovemin or (lfmatcher and lfmatcher(f)): | 121 if large or abovemin or (lfmatcher and lfmatcher(f)): |
122 lfnames.append(f) | 122 lfnames.append(f) |
123 if ui.verbose or not exact: | 123 if ui.verbose or not exact: |
124 ui.status(_('adding %s as a largefile\n') % uipathfn(f)) | 124 ui.status(_(b'adding %s as a largefile\n') % uipathfn(f)) |
125 | 125 |
126 bad = [] | 126 bad = [] |
127 | 127 |
128 # Need to lock, otherwise there could be a race condition between | 128 # Need to lock, otherwise there could be a race condition between |
129 # when standins are created and added to the repo. | 129 # when standins are created and added to the repo. |
134 for f in lfnames: | 134 for f in lfnames: |
135 standinname = lfutil.standin(f) | 135 standinname = lfutil.standin(f) |
136 lfutil.writestandin( | 136 lfutil.writestandin( |
137 repo, | 137 repo, |
138 standinname, | 138 standinname, |
139 hash='', | 139 hash=b'', |
140 executable=lfutil.getexecutable(repo.wjoin(f)), | 140 executable=lfutil.getexecutable(repo.wjoin(f)), |
141 ) | 141 ) |
142 standins.append(standinname) | 142 standins.append(standinname) |
143 if lfdirstate[f] == 'r': | 143 if lfdirstate[f] == b'r': |
144 lfdirstate.normallookup(f) | 144 lfdirstate.normallookup(f) |
145 else: | 145 else: |
146 lfdirstate.add(f) | 146 lfdirstate.add(f) |
147 lfdirstate.write() | 147 lfdirstate.write() |
148 bad += [ | 148 bad += [ |
175 return int(len(files) > 0) | 175 return int(len(files) > 0) |
176 | 176 |
177 if after: | 177 if after: |
178 remove = deleted | 178 remove = deleted |
179 result = warn( | 179 result = warn( |
180 modified + added + clean, _('not removing %s: file still exists\n') | 180 modified + added + clean, _(b'not removing %s: file still exists\n') |
181 ) | 181 ) |
182 else: | 182 else: |
183 remove = deleted + clean | 183 remove = deleted + clean |
184 result = warn( | 184 result = warn( |
185 modified, | 185 modified, |
186 _( | 186 _( |
187 'not removing %s: file is modified (use -f' | 187 b'not removing %s: file is modified (use -f' |
188 ' to force removal)\n' | 188 b' to force removal)\n' |
189 ), | 189 ), |
190 ) | 190 ) |
191 result = ( | 191 result = ( |
192 warn( | 192 warn( |
193 added, | 193 added, |
194 _( | 194 _( |
195 'not removing %s: file has been marked for add' | 195 b'not removing %s: file has been marked for add' |
196 ' (use forget to undo)\n' | 196 b' (use forget to undo)\n' |
197 ), | 197 ), |
198 ) | 198 ) |
199 or result | 199 or result |
200 ) | 200 ) |
201 | 201 |
203 # repository and we could race in-between. | 203 # repository and we could race in-between. |
204 with repo.wlock(): | 204 with repo.wlock(): |
205 lfdirstate = lfutil.openlfdirstate(ui, repo) | 205 lfdirstate = lfutil.openlfdirstate(ui, repo) |
206 for f in sorted(remove): | 206 for f in sorted(remove): |
207 if ui.verbose or not m.exact(f): | 207 if ui.verbose or not m.exact(f): |
208 ui.status(_('removing %s\n') % uipathfn(f)) | 208 ui.status(_(b'removing %s\n') % uipathfn(f)) |
209 | 209 |
210 if not dryrun: | 210 if not dryrun: |
211 if not after: | 211 if not after: |
212 repo.wvfs.unlinkpath(f, ignoremissing=True) | 212 repo.wvfs.unlinkpath(f, ignoremissing=True) |
213 | 213 |
232 return result | 232 return result |
233 | 233 |
234 | 234 |
235 # For overriding mercurial.hgweb.webcommands so that largefiles will | 235 # For overriding mercurial.hgweb.webcommands so that largefiles will |
236 # appear at their right place in the manifests. | 236 # appear at their right place in the manifests. |
237 @eh.wrapfunction(webcommands, 'decodepath') | 237 @eh.wrapfunction(webcommands, b'decodepath') |
238 def decodepath(orig, path): | 238 def decodepath(orig, path): |
239 return lfutil.splitstandin(path) or path | 239 return lfutil.splitstandin(path) or path |
240 | 240 |
241 | 241 |
242 # -- Wrappers: modify existing commands -------------------------------- | 242 # -- Wrappers: modify existing commands -------------------------------- |
243 | 243 |
244 | 244 |
245 @eh.wrapcommand( | 245 @eh.wrapcommand( |
246 'add', | 246 b'add', |
247 opts=[ | 247 opts=[ |
248 ('', 'large', None, _('add as largefile')), | 248 (b'', b'large', None, _(b'add as largefile')), |
249 ('', 'normal', None, _('add as normal file')), | 249 (b'', b'normal', None, _(b'add as normal file')), |
250 ( | 250 ( |
251 '', | 251 b'', |
252 'lfsize', | 252 b'lfsize', |
253 '', | 253 b'', |
254 _( | 254 _( |
255 'add all files above this size (in megabytes) ' | 255 b'add all files above this size (in megabytes) ' |
256 'as largefiles (default: 10)' | 256 b'as largefiles (default: 10)' |
257 ), | 257 ), |
258 ), | 258 ), |
259 ], | 259 ], |
260 ) | 260 ) |
261 def overrideadd(orig, ui, repo, *pats, **opts): | 261 def overrideadd(orig, ui, repo, *pats, **opts): |
262 if opts.get(r'normal') and opts.get(r'large'): | 262 if opts.get(r'normal') and opts.get(r'large'): |
263 raise error.Abort(_('--normal cannot be used with --large')) | 263 raise error.Abort(_(b'--normal cannot be used with --large')) |
264 return orig(ui, repo, *pats, **opts) | 264 return orig(ui, repo, *pats, **opts) |
265 | 265 |
266 | 266 |
267 @eh.wrapfunction(cmdutil, 'add') | 267 @eh.wrapfunction(cmdutil, b'add') |
268 def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts): | 268 def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts): |
269 # The --normal flag short circuits this override | 269 # The --normal flag short circuits this override |
270 if opts.get(r'normal'): | 270 if opts.get(r'normal'): |
271 return orig(ui, repo, matcher, prefix, uipathfn, explicitonly, **opts) | 271 return orig(ui, repo, matcher, prefix, uipathfn, explicitonly, **opts) |
272 | 272 |
278 | 278 |
279 bad.extend(f for f in lbad) | 279 bad.extend(f for f in lbad) |
280 return bad | 280 return bad |
281 | 281 |
282 | 282 |
283 @eh.wrapfunction(cmdutil, 'remove') | 283 @eh.wrapfunction(cmdutil, b'remove') |
284 def cmdutilremove( | 284 def cmdutilremove( |
285 orig, ui, repo, matcher, prefix, uipathfn, after, force, subrepos, dryrun | 285 orig, ui, repo, matcher, prefix, uipathfn, after, force, subrepos, dryrun |
286 ): | 286 ): |
287 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest()) | 287 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest()) |
288 result = orig( | 288 result = orig( |
302 ) | 302 ) |
303 or result | 303 or result |
304 ) | 304 ) |
305 | 305 |
306 | 306 |
307 @eh.wrapfunction(subrepo.hgsubrepo, 'status') | 307 @eh.wrapfunction(subrepo.hgsubrepo, b'status') |
308 def overridestatusfn(orig, repo, rev2, **opts): | 308 def overridestatusfn(orig, repo, rev2, **opts): |
309 try: | 309 try: |
310 repo._repo.lfstatus = True | 310 repo._repo.lfstatus = True |
311 return orig(repo, rev2, **opts) | 311 return orig(repo, rev2, **opts) |
312 finally: | 312 finally: |
313 repo._repo.lfstatus = False | 313 repo._repo.lfstatus = False |
314 | 314 |
315 | 315 |
316 @eh.wrapcommand('status') | 316 @eh.wrapcommand(b'status') |
317 def overridestatus(orig, ui, repo, *pats, **opts): | 317 def overridestatus(orig, ui, repo, *pats, **opts): |
318 try: | 318 try: |
319 repo.lfstatus = True | 319 repo.lfstatus = True |
320 return orig(ui, repo, *pats, **opts) | 320 return orig(ui, repo, *pats, **opts) |
321 finally: | 321 finally: |
322 repo.lfstatus = False | 322 repo.lfstatus = False |
323 | 323 |
324 | 324 |
325 @eh.wrapfunction(subrepo.hgsubrepo, 'dirty') | 325 @eh.wrapfunction(subrepo.hgsubrepo, b'dirty') |
326 def overridedirty(orig, repo, ignoreupdate=False, missing=False): | 326 def overridedirty(orig, repo, ignoreupdate=False, missing=False): |
327 try: | 327 try: |
328 repo._repo.lfstatus = True | 328 repo._repo.lfstatus = True |
329 return orig(repo, ignoreupdate=ignoreupdate, missing=missing) | 329 return orig(repo, ignoreupdate=ignoreupdate, missing=missing) |
330 finally: | 330 finally: |
331 repo._repo.lfstatus = False | 331 repo._repo.lfstatus = False |
332 | 332 |
333 | 333 |
334 @eh.wrapcommand('log') | 334 @eh.wrapcommand(b'log') |
335 def overridelog(orig, ui, repo, *pats, **opts): | 335 def overridelog(orig, ui, repo, *pats, **opts): |
336 def overridematchandpats( | 336 def overridematchandpats( |
337 orig, | 337 orig, |
338 ctx, | 338 ctx, |
339 pats=(), | 339 pats=(), |
340 opts=None, | 340 opts=None, |
341 globbed=False, | 341 globbed=False, |
342 default='relpath', | 342 default=b'relpath', |
343 badfn=None, | 343 badfn=None, |
344 ): | 344 ): |
345 """Matcher that merges root directory with .hglf, suitable for log. | 345 """Matcher that merges root directory with .hglf, suitable for log. |
346 It is still possible to match .hglf directly. | 346 It is still possible to match .hglf directly. |
347 For any listed files run log on the standin too. | 347 For any listed files run log on the standin too. |
358 return matchandpats | 358 return matchandpats |
359 | 359 |
360 pats = set(p) | 360 pats = set(p) |
361 | 361 |
362 def fixpats(pat, tostandin=lfutil.standin): | 362 def fixpats(pat, tostandin=lfutil.standin): |
363 if pat.startswith('set:'): | 363 if pat.startswith(b'set:'): |
364 return pat | 364 return pat |
365 | 365 |
366 kindpat = matchmod._patsplit(pat, None) | 366 kindpat = matchmod._patsplit(pat, None) |
367 | 367 |
368 if kindpat[0] is not None: | 368 if kindpat[0] is not None: |
369 return kindpat[0] + ':' + tostandin(kindpat[1]) | 369 return kindpat[0] + b':' + tostandin(kindpat[1]) |
370 return tostandin(kindpat[1]) | 370 return tostandin(kindpat[1]) |
371 | 371 |
372 cwd = repo.getcwd() | 372 cwd = repo.getcwd() |
373 if cwd: | 373 if cwd: |
374 hglf = lfutil.shortname | 374 hglf = lfutil.shortname |
386 # is somewhere in the repo, relative to root, and needs to be | 386 # is somewhere in the repo, relative to root, and needs to be |
387 # prepended before building the standin. | 387 # prepended before building the standin. |
388 if os.path.isabs(cwd): | 388 if os.path.isabs(cwd): |
389 f = f[len(back) :] | 389 f = f[len(back) :] |
390 else: | 390 else: |
391 f = cwd + '/' + f | 391 f = cwd + b'/' + f |
392 return back + lfutil.standin(f) | 392 return back + lfutil.standin(f) |
393 | 393 |
394 else: | 394 else: |
395 | 395 |
396 def tostandin(f): | 396 def tostandin(f): |
400 | 400 |
401 pats.update(fixpats(f, tostandin) for f in p) | 401 pats.update(fixpats(f, tostandin) for f in p) |
402 | 402 |
403 for i in range(0, len(m._files)): | 403 for i in range(0, len(m._files)): |
404 # Don't add '.hglf' to m.files, since that is already covered by '.' | 404 # Don't add '.hglf' to m.files, since that is already covered by '.' |
405 if m._files[i] == '.': | 405 if m._files[i] == b'.': |
406 continue | 406 continue |
407 standin = lfutil.standin(m._files[i]) | 407 standin = lfutil.standin(m._files[i]) |
408 # If the "standin" is a directory, append instead of replace to | 408 # If the "standin" is a directory, append instead of replace to |
409 # support naming a directory on the command line with only | 409 # support naming a directory on the command line with only |
410 # largefiles. The original directory is kept to support normal | 410 # largefiles. The original directory is kept to support normal |
425 r = origmatchfn(f) | 425 r = origmatchfn(f) |
426 return r | 426 return r |
427 | 427 |
428 m.matchfn = lfmatchfn | 428 m.matchfn = lfmatchfn |
429 | 429 |
430 ui.debug('updated patterns: %s\n' % ', '.join(sorted(pats))) | 430 ui.debug(b'updated patterns: %s\n' % b', '.join(sorted(pats))) |
431 return m, pats | 431 return m, pats |
432 | 432 |
433 # For hg log --patch, the match object is used in two different senses: | 433 # For hg log --patch, the match object is used in two different senses: |
434 # (1) to determine what revisions should be printed out, and | 434 # (1) to determine what revisions should be printed out, and |
435 # (2) to determine what files to print out diffs for. | 435 # (2) to determine what files to print out diffs for. |
441 wctx = repo[None] | 441 wctx = repo[None] |
442 match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn) | 442 match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn) |
443 return lambda ctx: match | 443 return lambda ctx: match |
444 | 444 |
445 wrappedmatchandpats = extensions.wrappedfunction( | 445 wrappedmatchandpats = extensions.wrappedfunction( |
446 scmutil, 'matchandpats', overridematchandpats | 446 scmutil, b'matchandpats', overridematchandpats |
447 ) | 447 ) |
448 wrappedmakefilematcher = extensions.wrappedfunction( | 448 wrappedmakefilematcher = extensions.wrappedfunction( |
449 logcmdutil, '_makenofollowfilematcher', overridemakefilematcher | 449 logcmdutil, b'_makenofollowfilematcher', overridemakefilematcher |
450 ) | 450 ) |
451 with wrappedmatchandpats, wrappedmakefilematcher: | 451 with wrappedmatchandpats, wrappedmakefilematcher: |
452 return orig(ui, repo, *pats, **opts) | 452 return orig(ui, repo, *pats, **opts) |
453 | 453 |
454 | 454 |
455 @eh.wrapcommand( | 455 @eh.wrapcommand( |
456 'verify', | 456 b'verify', |
457 opts=[ | 457 opts=[ |
458 ( | 458 ( |
459 '', | 459 b'', |
460 'large', | 460 b'large', |
461 None, | 461 None, |
462 _('verify that all largefiles in current revision exists'), | 462 _(b'verify that all largefiles in current revision exists'), |
463 ), | 463 ), |
464 ( | 464 ( |
465 '', | 465 b'', |
466 'lfa', | 466 b'lfa', |
467 None, | 467 None, |
468 _('verify largefiles in all revisions, not just current'), | 468 _(b'verify largefiles in all revisions, not just current'), |
469 ), | 469 ), |
470 ( | 470 ( |
471 '', | 471 b'', |
472 'lfc', | 472 b'lfc', |
473 None, | 473 None, |
474 _('verify local largefile contents, not just existence'), | 474 _(b'verify local largefile contents, not just existence'), |
475 ), | 475 ), |
476 ], | 476 ], |
477 ) | 477 ) |
478 def overrideverify(orig, ui, repo, *pats, **opts): | 478 def overrideverify(orig, ui, repo, *pats, **opts): |
479 large = opts.pop(r'large', False) | 479 large = opts.pop(r'large', False) |
485 result = result or lfcommands.verifylfiles(ui, repo, all, contents) | 485 result = result or lfcommands.verifylfiles(ui, repo, all, contents) |
486 return result | 486 return result |
487 | 487 |
488 | 488 |
489 @eh.wrapcommand( | 489 @eh.wrapcommand( |
490 'debugstate', opts=[('', 'large', None, _('display largefiles dirstate'))] | 490 b'debugstate', |
491 opts=[(b'', b'large', None, _(b'display largefiles dirstate'))], | |
491 ) | 492 ) |
492 def overridedebugstate(orig, ui, repo, *pats, **opts): | 493 def overridedebugstate(orig, ui, repo, *pats, **opts): |
493 large = opts.pop(r'large', False) | 494 large = opts.pop(r'large', False) |
494 if large: | 495 if large: |
495 | 496 |
509 # in a file 'foo' if we already have a largefile with the same name. | 510 # in a file 'foo' if we already have a largefile with the same name. |
510 # | 511 # |
511 # The overridden function filters the unknown files by removing any | 512 # The overridden function filters the unknown files by removing any |
512 # largefiles. This makes the merge proceed and we can then handle this | 513 # largefiles. This makes the merge proceed and we can then handle this |
513 # case further in the overridden calculateupdates function below. | 514 # case further in the overridden calculateupdates function below. |
514 @eh.wrapfunction(merge, '_checkunknownfile') | 515 @eh.wrapfunction(merge, b'_checkunknownfile') |
515 def overridecheckunknownfile(origfn, repo, wctx, mctx, f, f2=None): | 516 def overridecheckunknownfile(origfn, repo, wctx, mctx, f, f2=None): |
516 if lfutil.standin(repo.dirstate.normalize(f)) in wctx: | 517 if lfutil.standin(repo.dirstate.normalize(f)) in wctx: |
517 return False | 518 return False |
518 return origfn(repo, wctx, mctx, f, f2) | 519 return origfn(repo, wctx, mctx, f, f2) |
519 | 520 |
542 # presumably changed on purpose. | 543 # presumably changed on purpose. |
543 # | 544 # |
544 # Finally, the merge.applyupdates function will then take care of | 545 # Finally, the merge.applyupdates function will then take care of |
545 # writing the files into the working copy and lfcommands.updatelfiles | 546 # writing the files into the working copy and lfcommands.updatelfiles |
546 # will update the largefiles. | 547 # will update the largefiles. |
547 @eh.wrapfunction(merge, 'calculateupdates') | 548 @eh.wrapfunction(merge, b'calculateupdates') |
548 def overridecalculateupdates( | 549 def overridecalculateupdates( |
549 origfn, repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs | 550 origfn, repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs |
550 ): | 551 ): |
551 overwrite = force and not branchmerge | 552 overwrite = force and not branchmerge |
552 actions, diverge, renamedelete = origfn( | 553 actions, diverge, renamedelete = origfn( |
567 | 568 |
568 for lfile in sorted(lfiles): | 569 for lfile in sorted(lfiles): |
569 standin = lfutil.standin(lfile) | 570 standin = lfutil.standin(lfile) |
570 (lm, largs, lmsg) = actions.get(lfile, (None, None, None)) | 571 (lm, largs, lmsg) = actions.get(lfile, (None, None, None)) |
571 (sm, sargs, smsg) = actions.get(standin, (None, None, None)) | 572 (sm, sargs, smsg) = actions.get(standin, (None, None, None)) |
572 if sm in ('g', 'dc') and lm != 'r': | 573 if sm in (b'g', b'dc') and lm != b'r': |
573 if sm == 'dc': | 574 if sm == b'dc': |
574 f1, f2, fa, move, anc = sargs | 575 f1, f2, fa, move, anc = sargs |
575 sargs = (p2[f2].flags(), False) | 576 sargs = (p2[f2].flags(), False) |
576 # Case 1: normal file in the working copy, largefile in | 577 # Case 1: normal file in the working copy, largefile in |
577 # the second parent | 578 # the second parent |
578 usermsg = ( | 579 usermsg = ( |
579 _( | 580 _( |
580 'remote turned local normal file %s into a largefile\n' | 581 b'remote turned local normal file %s into a largefile\n' |
581 'use (l)argefile or keep (n)ormal file?' | 582 b'use (l)argefile or keep (n)ormal file?' |
582 '$$ &Largefile $$ &Normal file' | 583 b'$$ &Largefile $$ &Normal file' |
583 ) | 584 ) |
584 % lfile | 585 % lfile |
585 ) | 586 ) |
586 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile | 587 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile |
587 actions[lfile] = ('r', None, 'replaced by standin') | 588 actions[lfile] = (b'r', None, b'replaced by standin') |
588 actions[standin] = ('g', sargs, 'replaces standin') | 589 actions[standin] = (b'g', sargs, b'replaces standin') |
589 else: # keep local normal file | 590 else: # keep local normal file |
590 actions[lfile] = ('k', None, 'replaces standin') | 591 actions[lfile] = (b'k', None, b'replaces standin') |
591 if branchmerge: | 592 if branchmerge: |
592 actions[standin] = ('k', None, 'replaced by non-standin') | 593 actions[standin] = (b'k', None, b'replaced by non-standin') |
593 else: | 594 else: |
594 actions[standin] = ('r', None, 'replaced by non-standin') | 595 actions[standin] = (b'r', None, b'replaced by non-standin') |
595 elif lm in ('g', 'dc') and sm != 'r': | 596 elif lm in (b'g', b'dc') and sm != b'r': |
596 if lm == 'dc': | 597 if lm == b'dc': |
597 f1, f2, fa, move, anc = largs | 598 f1, f2, fa, move, anc = largs |
598 largs = (p2[f2].flags(), False) | 599 largs = (p2[f2].flags(), False) |
599 # Case 2: largefile in the working copy, normal file in | 600 # Case 2: largefile in the working copy, normal file in |
600 # the second parent | 601 # the second parent |
601 usermsg = ( | 602 usermsg = ( |
602 _( | 603 _( |
603 'remote turned local largefile %s into a normal file\n' | 604 b'remote turned local largefile %s into a normal file\n' |
604 'keep (l)argefile or use (n)ormal file?' | 605 b'keep (l)argefile or use (n)ormal file?' |
605 '$$ &Largefile $$ &Normal file' | 606 b'$$ &Largefile $$ &Normal file' |
606 ) | 607 ) |
607 % lfile | 608 % lfile |
608 ) | 609 ) |
609 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile | 610 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile |
610 if branchmerge: | 611 if branchmerge: |
611 # largefile can be restored from standin safely | 612 # largefile can be restored from standin safely |
612 actions[lfile] = ('k', None, 'replaced by standin') | 613 actions[lfile] = (b'k', None, b'replaced by standin') |
613 actions[standin] = ('k', None, 'replaces standin') | 614 actions[standin] = (b'k', None, b'replaces standin') |
614 else: | 615 else: |
615 # "lfile" should be marked as "removed" without | 616 # "lfile" should be marked as "removed" without |
616 # removal of itself | 617 # removal of itself |
617 actions[lfile] = ( | 618 actions[lfile] = ( |
618 'lfmr', | 619 b'lfmr', |
619 None, | 620 None, |
620 'forget non-standin largefile', | 621 b'forget non-standin largefile', |
621 ) | 622 ) |
622 | 623 |
623 # linear-merge should treat this largefile as 're-added' | 624 # linear-merge should treat this largefile as 're-added' |
624 actions[standin] = ('a', None, 'keep standin') | 625 actions[standin] = (b'a', None, b'keep standin') |
625 else: # pick remote normal file | 626 else: # pick remote normal file |
626 actions[lfile] = ('g', largs, 'replaces standin') | 627 actions[lfile] = (b'g', largs, b'replaces standin') |
627 actions[standin] = ('r', None, 'replaced by non-standin') | 628 actions[standin] = (b'r', None, b'replaced by non-standin') |
628 | 629 |
629 return actions, diverge, renamedelete | 630 return actions, diverge, renamedelete |
630 | 631 |
631 | 632 |
632 @eh.wrapfunction(merge, 'recordupdates') | 633 @eh.wrapfunction(merge, b'recordupdates') |
633 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata): | 634 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata): |
634 if 'lfmr' in actions: | 635 if b'lfmr' in actions: |
635 lfdirstate = lfutil.openlfdirstate(repo.ui, repo) | 636 lfdirstate = lfutil.openlfdirstate(repo.ui, repo) |
636 for lfile, args, msg in actions['lfmr']: | 637 for lfile, args, msg in actions[b'lfmr']: |
637 # this should be executed before 'orig', to execute 'remove' | 638 # this should be executed before 'orig', to execute 'remove' |
638 # before all other actions | 639 # before all other actions |
639 repo.dirstate.remove(lfile) | 640 repo.dirstate.remove(lfile) |
640 # make sure lfile doesn't get synclfdirstate'd as normal | 641 # make sure lfile doesn't get synclfdirstate'd as normal |
641 lfdirstate.add(lfile) | 642 lfdirstate.add(lfile) |
644 return orig(repo, actions, branchmerge, getfiledata) | 645 return orig(repo, actions, branchmerge, getfiledata) |
645 | 646 |
646 | 647 |
647 # Override filemerge to prompt the user about how they wish to merge | 648 # Override filemerge to prompt the user about how they wish to merge |
648 # largefiles. This will handle identical edits without prompting the user. | 649 # largefiles. This will handle identical edits without prompting the user. |
649 @eh.wrapfunction(filemerge, '_filemerge') | 650 @eh.wrapfunction(filemerge, b'_filemerge') |
650 def overridefilemerge( | 651 def overridefilemerge( |
651 origfn, premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None | 652 origfn, premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None |
652 ): | 653 ): |
653 if not lfutil.isstandin(orig) or fcd.isabsent() or fco.isabsent(): | 654 if not lfutil.isstandin(orig) or fcd.isabsent() or fco.isabsent(): |
654 return origfn( | 655 return origfn( |
663 and ohash != dhash | 664 and ohash != dhash |
664 and ( | 665 and ( |
665 dhash == ahash | 666 dhash == ahash |
666 or repo.ui.promptchoice( | 667 or repo.ui.promptchoice( |
667 _( | 668 _( |
668 'largefile %s has a merge conflict\nancestor was %s\n' | 669 b'largefile %s has a merge conflict\nancestor was %s\n' |
669 'you can keep (l)ocal %s or take (o)ther %s.\n' | 670 b'you can keep (l)ocal %s or take (o)ther %s.\n' |
670 'what do you want to do?' | 671 b'what do you want to do?' |
671 '$$ &Local $$ &Other' | 672 b'$$ &Local $$ &Other' |
672 ) | 673 ) |
673 % (lfutil.splitstandin(orig), ahash, dhash, ohash), | 674 % (lfutil.splitstandin(orig), ahash, dhash, ohash), |
674 0, | 675 0, |
675 ) | 676 ) |
676 == 1 | 677 == 1 |
678 ): | 679 ): |
679 repo.wwrite(fcd.path(), fco.data(), fco.flags()) | 680 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
680 return True, 0, False | 681 return True, 0, False |
681 | 682 |
682 | 683 |
683 @eh.wrapfunction(copiesmod, 'pathcopies') | 684 @eh.wrapfunction(copiesmod, b'pathcopies') |
684 def copiespathcopies(orig, ctx1, ctx2, match=None): | 685 def copiespathcopies(orig, ctx1, ctx2, match=None): |
685 copies = orig(ctx1, ctx2, match=match) | 686 copies = orig(ctx1, ctx2, match=match) |
686 updated = {} | 687 updated = {} |
687 | 688 |
688 for k, v in copies.iteritems(): | 689 for k, v in copies.iteritems(): |
694 # Copy first changes the matchers to match standins instead of | 695 # Copy first changes the matchers to match standins instead of |
695 # largefiles. Then it overrides util.copyfile in that function it | 696 # largefiles. Then it overrides util.copyfile in that function it |
696 # checks if the destination largefile already exists. It also keeps a | 697 # checks if the destination largefile already exists. It also keeps a |
697 # list of copied files so that the largefiles can be copied and the | 698 # list of copied files so that the largefiles can be copied and the |
698 # dirstate updated. | 699 # dirstate updated. |
699 @eh.wrapfunction(cmdutil, 'copy') | 700 @eh.wrapfunction(cmdutil, b'copy') |
700 def overridecopy(orig, ui, repo, pats, opts, rename=False): | 701 def overridecopy(orig, ui, repo, pats, opts, rename=False): |
701 # doesn't remove largefile on rename | 702 # doesn't remove largefile on rename |
702 if len(pats) < 2: | 703 if len(pats) < 2: |
703 # this isn't legal, let the original function deal with it | 704 # this isn't legal, let the original function deal with it |
704 return orig(ui, repo, pats, opts, rename) | 705 return orig(ui, repo, pats, opts, rename) |
715 orig, | 716 orig, |
716 ctx, | 717 ctx, |
717 pats=(), | 718 pats=(), |
718 opts=None, | 719 opts=None, |
719 globbed=False, | 720 globbed=False, |
720 default='relpath', | 721 default=b'relpath', |
721 badfn=None, | 722 badfn=None, |
722 ): | 723 ): |
723 if opts is None: | 724 if opts is None: |
724 opts = {} | 725 opts = {} |
725 match = orig(ctx, pats, opts, globbed, default, badfn=badfn) | 726 match = orig(ctx, pats, opts, globbed, default, badfn=badfn) |
726 return composenormalfilematcher(match, manifest) | 727 return composenormalfilematcher(match, manifest) |
727 | 728 |
728 with extensions.wrappedfunction(scmutil, 'match', normalfilesmatchfn): | 729 with extensions.wrappedfunction(scmutil, b'match', normalfilesmatchfn): |
729 try: | 730 try: |
730 result = orig(ui, repo, pats, opts, rename) | 731 result = orig(ui, repo, pats, opts, rename) |
731 except error.Abort as e: | 732 except error.Abort as e: |
732 if pycompat.bytestr(e) != _('no files to copy'): | 733 if pycompat.bytestr(e) != _(b'no files to copy'): |
733 raise e | 734 raise e |
734 else: | 735 else: |
735 nonormalfiles = True | 736 nonormalfiles = True |
736 result = 0 | 737 result = 0 |
737 | 738 |
764 orig, | 765 orig, |
765 ctx, | 766 ctx, |
766 pats=(), | 767 pats=(), |
767 opts=None, | 768 opts=None, |
768 globbed=False, | 769 globbed=False, |
769 default='relpath', | 770 default=b'relpath', |
770 badfn=None, | 771 badfn=None, |
771 ): | 772 ): |
772 if opts is None: | 773 if opts is None: |
773 opts = {} | 774 opts = {} |
774 newpats = [] | 775 newpats = [] |
775 # The patterns were previously mangled to add the standin | 776 # The patterns were previously mangled to add the standin |
776 # directory; we need to remove that now | 777 # directory; we need to remove that now |
777 for pat in pats: | 778 for pat in pats: |
778 if matchmod.patkind(pat) is None and lfutil.shortname in pat: | 779 if matchmod.patkind(pat) is None and lfutil.shortname in pat: |
779 newpats.append(pat.replace(lfutil.shortname, '')) | 780 newpats.append(pat.replace(lfutil.shortname, b'')) |
780 else: | 781 else: |
781 newpats.append(pat) | 782 newpats.append(pat) |
782 match = orig(ctx, newpats, opts, globbed, default, badfn=badfn) | 783 match = orig(ctx, newpats, opts, globbed, default, badfn=badfn) |
783 m = copy.copy(match) | 784 m = copy.copy(match) |
784 lfile = lambda f: lfutil.standin(f) in manifest | 785 lfile = lambda f: lfutil.standin(f) in manifest |
809 | 810 |
810 def overridecopyfile(orig, src, dest, *args, **kwargs): | 811 def overridecopyfile(orig, src, dest, *args, **kwargs): |
811 if lfutil.shortname in src and dest.startswith( | 812 if lfutil.shortname in src and dest.startswith( |
812 repo.wjoin(lfutil.shortname) | 813 repo.wjoin(lfutil.shortname) |
813 ): | 814 ): |
814 destlfile = dest.replace(lfutil.shortname, '') | 815 destlfile = dest.replace(lfutil.shortname, b'') |
815 if not opts['force'] and os.path.exists(destlfile): | 816 if not opts[b'force'] and os.path.exists(destlfile): |
816 raise IOError('', _('destination largefile already exists')) | 817 raise IOError( |
818 b'', _(b'destination largefile already exists') | |
819 ) | |
817 copiedfiles.append((src, dest)) | 820 copiedfiles.append((src, dest)) |
818 orig(src, dest, *args, **kwargs) | 821 orig(src, dest, *args, **kwargs) |
819 | 822 |
820 with extensions.wrappedfunction(util, 'copyfile', overridecopyfile): | 823 with extensions.wrappedfunction(util, b'copyfile', overridecopyfile): |
821 with extensions.wrappedfunction(scmutil, 'match', overridematch): | 824 with extensions.wrappedfunction(scmutil, b'match', overridematch): |
822 result += orig(ui, repo, listpats, opts, rename) | 825 result += orig(ui, repo, listpats, opts, rename) |
823 | 826 |
824 lfdirstate = lfutil.openlfdirstate(ui, repo) | 827 lfdirstate = lfutil.openlfdirstate(ui, repo) |
825 for (src, dest) in copiedfiles: | 828 for (src, dest) in copiedfiles: |
826 if lfutil.shortname in src and dest.startswith( | 829 if lfutil.shortname in src and dest.startswith( |
827 repo.wjoin(lfutil.shortname) | 830 repo.wjoin(lfutil.shortname) |
828 ): | 831 ): |
829 srclfile = src.replace(repo.wjoin(lfutil.standin('')), '') | 832 srclfile = src.replace(repo.wjoin(lfutil.standin(b'')), b'') |
830 destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '') | 833 destlfile = dest.replace(repo.wjoin(lfutil.standin(b'')), b'') |
831 destlfiledir = repo.wvfs.dirname(repo.wjoin(destlfile)) or '.' | 834 destlfiledir = repo.wvfs.dirname(repo.wjoin(destlfile)) or b'.' |
832 if not os.path.isdir(destlfiledir): | 835 if not os.path.isdir(destlfiledir): |
833 os.makedirs(destlfiledir) | 836 os.makedirs(destlfiledir) |
834 if rename: | 837 if rename: |
835 os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile)) | 838 os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile)) |
836 | 839 |
842 util.copyfile(repo.wjoin(srclfile), repo.wjoin(destlfile)) | 845 util.copyfile(repo.wjoin(srclfile), repo.wjoin(destlfile)) |
843 | 846 |
844 lfdirstate.add(destlfile) | 847 lfdirstate.add(destlfile) |
845 lfdirstate.write() | 848 lfdirstate.write() |
846 except error.Abort as e: | 849 except error.Abort as e: |
847 if pycompat.bytestr(e) != _('no files to copy'): | 850 if pycompat.bytestr(e) != _(b'no files to copy'): |
848 raise e | 851 raise e |
849 else: | 852 else: |
850 nolfiles = True | 853 nolfiles = True |
851 finally: | 854 finally: |
852 wlock.release() | 855 wlock.release() |
853 | 856 |
854 if nolfiles and nonormalfiles: | 857 if nolfiles and nonormalfiles: |
855 raise error.Abort(_('no files to copy')) | 858 raise error.Abort(_(b'no files to copy')) |
856 | 859 |
857 return result | 860 return result |
858 | 861 |
859 | 862 |
860 # When the user calls revert, we have to be careful to not revert any | 863 # When the user calls revert, we have to be careful to not revert any |
864 # | 867 # |
865 # Standins are only updated (to match the hash of largefiles) before | 868 # Standins are only updated (to match the hash of largefiles) before |
866 # commits. Update the standins then run the original revert, changing | 869 # commits. Update the standins then run the original revert, changing |
867 # the matcher to hit standins instead of largefiles. Based on the | 870 # the matcher to hit standins instead of largefiles. Based on the |
868 # resulting standins update the largefiles. | 871 # resulting standins update the largefiles. |
869 @eh.wrapfunction(cmdutil, 'revert') | 872 @eh.wrapfunction(cmdutil, b'revert') |
870 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts): | 873 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts): |
871 # Because we put the standins in a bad state (by updating them) | 874 # Because we put the standins in a bad state (by updating them) |
872 # and then return them to a correct state we need to lock to | 875 # and then return them to a correct state we need to lock to |
873 # prevent others from changing them in their incorrect state. | 876 # prevent others from changing them in their incorrect state. |
874 with repo.wlock(): | 877 with repo.wlock(): |
888 orig, | 891 orig, |
889 mctx, | 892 mctx, |
890 pats=(), | 893 pats=(), |
891 opts=None, | 894 opts=None, |
892 globbed=False, | 895 globbed=False, |
893 default='relpath', | 896 default=b'relpath', |
894 badfn=None, | 897 badfn=None, |
895 ): | 898 ): |
896 if opts is None: | 899 if opts is None: |
897 opts = {} | 900 opts = {} |
898 match = orig(mctx, pats, opts, globbed, default, badfn=badfn) | 901 match = orig(mctx, pats, opts, globbed, default, badfn=badfn) |
910 matchfiles = [] | 913 matchfiles = [] |
911 for f in m._files: | 914 for f in m._files: |
912 standin = lfutil.standin(f) | 915 standin = lfutil.standin(f) |
913 if standin in ctx or standin in mctx: | 916 if standin in ctx or standin in mctx: |
914 matchfiles.append(standin) | 917 matchfiles.append(standin) |
915 elif standin in wctx or lfdirstate[f] == 'r': | 918 elif standin in wctx or lfdirstate[f] == b'r': |
916 continue | 919 continue |
917 else: | 920 else: |
918 matchfiles.append(f) | 921 matchfiles.append(f) |
919 m._files = matchfiles | 922 m._files = matchfiles |
920 m._fileset = set(m._files) | 923 m._fileset = set(m._files) |
927 return origmatchfn(f) | 930 return origmatchfn(f) |
928 | 931 |
929 m.matchfn = matchfn | 932 m.matchfn = matchfn |
930 return m | 933 return m |
931 | 934 |
932 with extensions.wrappedfunction(scmutil, 'match', overridematch): | 935 with extensions.wrappedfunction(scmutil, b'match', overridematch): |
933 orig(ui, repo, ctx, parents, *pats, **opts) | 936 orig(ui, repo, ctx, parents, *pats, **opts) |
934 | 937 |
935 newstandins = lfutil.getstandinsstate(repo) | 938 newstandins = lfutil.getstandinsstate(repo) |
936 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) | 939 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) |
937 # lfdirstate should be 'normallookup'-ed for updated files, | 940 # lfdirstate should be 'normallookup'-ed for updated files, |
945 | 948 |
946 | 949 |
947 # after pulling changesets, we need to take some extra care to get | 950 # after pulling changesets, we need to take some extra care to get |
948 # largefiles updated remotely | 951 # largefiles updated remotely |
949 @eh.wrapcommand( | 952 @eh.wrapcommand( |
950 'pull', | 953 b'pull', |
951 opts=[ | 954 opts=[ |
952 ( | 955 ( |
953 '', | 956 b'', |
954 'all-largefiles', | 957 b'all-largefiles', |
955 None, | 958 None, |
956 _('download all pulled versions of largefiles (DEPRECATED)'), | 959 _(b'download all pulled versions of largefiles (DEPRECATED)'), |
957 ), | 960 ), |
958 ( | 961 ( |
959 '', | 962 b'', |
960 'lfrev', | 963 b'lfrev', |
961 [], | 964 [], |
962 _('download largefiles for these revisions'), | 965 _(b'download largefiles for these revisions'), |
963 _('REV'), | 966 _(b'REV'), |
964 ), | 967 ), |
965 ], | 968 ], |
966 ) | 969 ) |
967 def overridepull(orig, ui, repo, source=None, **opts): | 970 def overridepull(orig, ui, repo, source=None, **opts): |
968 revsprepull = len(repo) | 971 revsprepull = len(repo) |
969 if not source: | 972 if not source: |
970 source = 'default' | 973 source = b'default' |
971 repo.lfpullsource = source | 974 repo.lfpullsource = source |
972 result = orig(ui, repo, source, **opts) | 975 result = orig(ui, repo, source, **opts) |
973 revspostpull = len(repo) | 976 revspostpull = len(repo) |
974 lfrevs = opts.get(r'lfrev', []) | 977 lfrevs = opts.get(r'lfrev', []) |
975 if opts.get(r'all_largefiles'): | 978 if opts.get(r'all_largefiles'): |
976 lfrevs.append('pulled()') | 979 lfrevs.append(b'pulled()') |
977 if lfrevs and revspostpull > revsprepull: | 980 if lfrevs and revspostpull > revsprepull: |
978 numcached = 0 | 981 numcached = 0 |
979 repo.firstpulled = revsprepull # for pulled() revset expression | 982 repo.firstpulled = revsprepull # for pulled() revset expression |
980 try: | 983 try: |
981 for rev in scmutil.revrange(repo, lfrevs): | 984 for rev in scmutil.revrange(repo, lfrevs): |
982 ui.note(_('pulling largefiles for revision %d\n') % rev) | 985 ui.note(_(b'pulling largefiles for revision %d\n') % rev) |
983 (cached, missing) = lfcommands.cachelfiles(ui, repo, rev) | 986 (cached, missing) = lfcommands.cachelfiles(ui, repo, rev) |
984 numcached += len(cached) | 987 numcached += len(cached) |
985 finally: | 988 finally: |
986 del repo.firstpulled | 989 del repo.firstpulled |
987 ui.status(_("%d largefiles cached\n") % numcached) | 990 ui.status(_(b"%d largefiles cached\n") % numcached) |
988 return result | 991 return result |
989 | 992 |
990 | 993 |
991 @eh.wrapcommand( | 994 @eh.wrapcommand( |
992 'push', | 995 b'push', |
993 opts=[ | 996 opts=[ |
994 ('', 'lfrev', [], _('upload largefiles for these revisions'), _('REV')) | 997 ( |
998 b'', | |
999 b'lfrev', | |
1000 [], | |
1001 _(b'upload largefiles for these revisions'), | |
1002 _(b'REV'), | |
1003 ) | |
995 ], | 1004 ], |
996 ) | 1005 ) |
997 def overridepush(orig, ui, repo, *args, **kwargs): | 1006 def overridepush(orig, ui, repo, *args, **kwargs): |
998 """Override push command and store --lfrev parameters in opargs""" | 1007 """Override push command and store --lfrev parameters in opargs""" |
999 lfrevs = kwargs.pop(r'lfrev', None) | 1008 lfrevs = kwargs.pop(r'lfrev', None) |
1000 if lfrevs: | 1009 if lfrevs: |
1001 opargs = kwargs.setdefault(r'opargs', {}) | 1010 opargs = kwargs.setdefault(r'opargs', {}) |
1002 opargs['lfrevs'] = scmutil.revrange(repo, lfrevs) | 1011 opargs[b'lfrevs'] = scmutil.revrange(repo, lfrevs) |
1003 return orig(ui, repo, *args, **kwargs) | 1012 return orig(ui, repo, *args, **kwargs) |
1004 | 1013 |
1005 | 1014 |
1006 @eh.wrapfunction(exchange, 'pushoperation') | 1015 @eh.wrapfunction(exchange, b'pushoperation') |
1007 def exchangepushoperation(orig, *args, **kwargs): | 1016 def exchangepushoperation(orig, *args, **kwargs): |
1008 """Override pushoperation constructor and store lfrevs parameter""" | 1017 """Override pushoperation constructor and store lfrevs parameter""" |
1009 lfrevs = kwargs.pop(r'lfrevs', None) | 1018 lfrevs = kwargs.pop(r'lfrevs', None) |
1010 pushop = orig(*args, **kwargs) | 1019 pushop = orig(*args, **kwargs) |
1011 pushop.lfrevs = lfrevs | 1020 pushop.lfrevs = lfrevs |
1012 return pushop | 1021 return pushop |
1013 | 1022 |
1014 | 1023 |
1015 @eh.revsetpredicate('pulled()') | 1024 @eh.revsetpredicate(b'pulled()') |
1016 def pulledrevsetsymbol(repo, subset, x): | 1025 def pulledrevsetsymbol(repo, subset, x): |
1017 """Changesets that just has been pulled. | 1026 """Changesets that just has been pulled. |
1018 | 1027 |
1019 Only available with largefiles from pull --lfrev expressions. | 1028 Only available with largefiles from pull --lfrev expressions. |
1020 | 1029 |
1033 """ | 1042 """ |
1034 | 1043 |
1035 try: | 1044 try: |
1036 firstpulled = repo.firstpulled | 1045 firstpulled = repo.firstpulled |
1037 except AttributeError: | 1046 except AttributeError: |
1038 raise error.Abort(_("pulled() only available in --lfrev")) | 1047 raise error.Abort(_(b"pulled() only available in --lfrev")) |
1039 return smartset.baseset([r for r in subset if r >= firstpulled]) | 1048 return smartset.baseset([r for r in subset if r >= firstpulled]) |
1040 | 1049 |
1041 | 1050 |
1042 @eh.wrapcommand( | 1051 @eh.wrapcommand( |
1043 'clone', | 1052 b'clone', |
1044 opts=[ | 1053 opts=[ |
1045 ( | 1054 ( |
1046 '', | 1055 b'', |
1047 'all-largefiles', | 1056 b'all-largefiles', |
1048 None, | 1057 None, |
1049 _('download all versions of all largefiles'), | 1058 _(b'download all versions of all largefiles'), |
1050 ) | 1059 ) |
1051 ], | 1060 ], |
1052 ) | 1061 ) |
1053 def overrideclone(orig, ui, source, dest=None, **opts): | 1062 def overrideclone(orig, ui, source, dest=None, **opts): |
1054 d = dest | 1063 d = dest |
1055 if d is None: | 1064 if d is None: |
1056 d = hg.defaultdest(source) | 1065 d = hg.defaultdest(source) |
1057 if opts.get(r'all_largefiles') and not hg.islocal(d): | 1066 if opts.get(r'all_largefiles') and not hg.islocal(d): |
1058 raise error.Abort( | 1067 raise error.Abort( |
1059 _('--all-largefiles is incompatible with non-local destination %s') | 1068 _(b'--all-largefiles is incompatible with non-local destination %s') |
1060 % d | 1069 % d |
1061 ) | 1070 ) |
1062 | 1071 |
1063 return orig(ui, source, dest, **opts) | 1072 return orig(ui, source, dest, **opts) |
1064 | 1073 |
1065 | 1074 |
1066 @eh.wrapfunction(hg, 'clone') | 1075 @eh.wrapfunction(hg, b'clone') |
1067 def hgclone(orig, ui, opts, *args, **kwargs): | 1076 def hgclone(orig, ui, opts, *args, **kwargs): |
1068 result = orig(ui, opts, *args, **kwargs) | 1077 result = orig(ui, opts, *args, **kwargs) |
1069 | 1078 |
1070 if result is not None: | 1079 if result is not None: |
1071 sourcerepo, destrepo = result | 1080 sourcerepo, destrepo = result |
1078 return result | 1087 return result |
1079 | 1088 |
1080 # Caching is implicitly limited to 'rev' option, since the dest repo was | 1089 # Caching is implicitly limited to 'rev' option, since the dest repo was |
1081 # truncated at that point. The user may expect a download count with | 1090 # truncated at that point. The user may expect a download count with |
1082 # this option, so attempt whether or not this is a largefile repo. | 1091 # this option, so attempt whether or not this is a largefile repo. |
1083 if opts.get('all_largefiles'): | 1092 if opts.get(b'all_largefiles'): |
1084 success, missing = lfcommands.downloadlfiles(ui, repo, None) | 1093 success, missing = lfcommands.downloadlfiles(ui, repo, None) |
1085 | 1094 |
1086 if missing != 0: | 1095 if missing != 0: |
1087 return None | 1096 return None |
1088 | 1097 |
1089 return result | 1098 return result |
1090 | 1099 |
1091 | 1100 |
1092 @eh.wrapcommand('rebase', extension='rebase') | 1101 @eh.wrapcommand(b'rebase', extension=b'rebase') |
1093 def overriderebase(orig, ui, repo, **opts): | 1102 def overriderebase(orig, ui, repo, **opts): |
1094 if not util.safehasattr(repo, '_largefilesenabled'): | 1103 if not util.safehasattr(repo, b'_largefilesenabled'): |
1095 return orig(ui, repo, **opts) | 1104 return orig(ui, repo, **opts) |
1096 | 1105 |
1097 resuming = opts.get(r'continue') | 1106 resuming = opts.get(r'continue') |
1098 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) | 1107 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) |
1099 repo._lfstatuswriters.append(lambda *msg, **opts: None) | 1108 repo._lfstatuswriters.append(lambda *msg, **opts: None) |
1102 finally: | 1111 finally: |
1103 repo._lfstatuswriters.pop() | 1112 repo._lfstatuswriters.pop() |
1104 repo._lfcommithooks.pop() | 1113 repo._lfcommithooks.pop() |
1105 | 1114 |
1106 | 1115 |
1107 @eh.wrapcommand('archive') | 1116 @eh.wrapcommand(b'archive') |
1108 def overridearchivecmd(orig, ui, repo, dest, **opts): | 1117 def overridearchivecmd(orig, ui, repo, dest, **opts): |
1109 repo.unfiltered().lfstatus = True | 1118 repo.unfiltered().lfstatus = True |
1110 | 1119 |
1111 try: | 1120 try: |
1112 return orig(ui, repo.unfiltered(), dest, **opts) | 1121 return orig(ui, repo.unfiltered(), dest, **opts) |
1113 finally: | 1122 finally: |
1114 repo.unfiltered().lfstatus = False | 1123 repo.unfiltered().lfstatus = False |
1115 | 1124 |
1116 | 1125 |
1117 @eh.wrapfunction(webcommands, 'archive') | 1126 @eh.wrapfunction(webcommands, b'archive') |
1118 def hgwebarchive(orig, web): | 1127 def hgwebarchive(orig, web): |
1119 web.repo.lfstatus = True | 1128 web.repo.lfstatus = True |
1120 | 1129 |
1121 try: | 1130 try: |
1122 return orig(web) | 1131 return orig(web) |
1123 finally: | 1132 finally: |
1124 web.repo.lfstatus = False | 1133 web.repo.lfstatus = False |
1125 | 1134 |
1126 | 1135 |
1127 @eh.wrapfunction(archival, 'archive') | 1136 @eh.wrapfunction(archival, b'archive') |
1128 def overridearchive( | 1137 def overridearchive( |
1129 orig, | 1138 orig, |
1130 repo, | 1139 repo, |
1131 dest, | 1140 dest, |
1132 node, | 1141 node, |
1133 kind, | 1142 kind, |
1134 decode=True, | 1143 decode=True, |
1135 match=None, | 1144 match=None, |
1136 prefix='', | 1145 prefix=b'', |
1137 mtime=None, | 1146 mtime=None, |
1138 subrepos=None, | 1147 subrepos=None, |
1139 ): | 1148 ): |
1140 # For some reason setting repo.lfstatus in hgwebarchive only changes the | 1149 # For some reason setting repo.lfstatus in hgwebarchive only changes the |
1141 # unfiltered repo's attr, so check that as well. | 1150 # unfiltered repo's attr, so check that as well. |
1148 # largefile caches, neither of which are modified. | 1157 # largefile caches, neither of which are modified. |
1149 if node is not None: | 1158 if node is not None: |
1150 lfcommands.cachelfiles(repo.ui, repo, node) | 1159 lfcommands.cachelfiles(repo.ui, repo, node) |
1151 | 1160 |
1152 if kind not in archival.archivers: | 1161 if kind not in archival.archivers: |
1153 raise error.Abort(_("unknown archive type '%s'") % kind) | 1162 raise error.Abort(_(b"unknown archive type '%s'") % kind) |
1154 | 1163 |
1155 ctx = repo[node] | 1164 ctx = repo[node] |
1156 | 1165 |
1157 if kind == 'files': | 1166 if kind == b'files': |
1158 if prefix: | 1167 if prefix: |
1159 raise error.Abort(_('cannot give prefix when archiving to files')) | 1168 raise error.Abort(_(b'cannot give prefix when archiving to files')) |
1160 else: | 1169 else: |
1161 prefix = archival.tidyprefix(dest, kind, prefix) | 1170 prefix = archival.tidyprefix(dest, kind, prefix) |
1162 | 1171 |
1163 def write(name, mode, islink, getdata): | 1172 def write(name, mode, islink, getdata): |
1164 if match and not match(name): | 1173 if match and not match(name): |
1168 data = repo.wwritedata(name, data) | 1177 data = repo.wwritedata(name, data) |
1169 archiver.addfile(prefix + name, mode, islink, data) | 1178 archiver.addfile(prefix + name, mode, islink, data) |
1170 | 1179 |
1171 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0]) | 1180 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0]) |
1172 | 1181 |
1173 if repo.ui.configbool("ui", "archivemeta"): | 1182 if repo.ui.configbool(b"ui", b"archivemeta"): |
1174 write( | 1183 write( |
1175 '.hg_archival.txt', | 1184 b'.hg_archival.txt', |
1176 0o644, | 1185 0o644, |
1177 False, | 1186 False, |
1178 lambda: archival.buildmetadata(ctx), | 1187 lambda: archival.buildmetadata(ctx), |
1179 ) | 1188 ) |
1180 | 1189 |
1187 path = lfutil.findfile(repo, getdata().strip()) | 1196 path = lfutil.findfile(repo, getdata().strip()) |
1188 | 1197 |
1189 if path is None: | 1198 if path is None: |
1190 raise error.Abort( | 1199 raise error.Abort( |
1191 _( | 1200 _( |
1192 'largefile %s not found in repo store or system cache' | 1201 b'largefile %s not found in repo store or system cache' |
1193 ) | 1202 ) |
1194 % lfile | 1203 % lfile |
1195 ) | 1204 ) |
1196 else: | 1205 else: |
1197 path = lfile | 1206 path = lfile |
1198 | 1207 |
1199 f = lfile | 1208 f = lfile |
1200 | 1209 |
1201 getdata = lambda: util.readfile(path) | 1210 getdata = lambda: util.readfile(path) |
1202 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata) | 1211 write(f, b'x' in ff and 0o755 or 0o644, b'l' in ff, getdata) |
1203 | 1212 |
1204 if subrepos: | 1213 if subrepos: |
1205 for subpath in sorted(ctx.substate): | 1214 for subpath in sorted(ctx.substate): |
1206 sub = ctx.workingsub(subpath) | 1215 sub = ctx.workingsub(subpath) |
1207 submatch = matchmod.subdirmatcher(subpath, match) | 1216 submatch = matchmod.subdirmatcher(subpath, match) |
1208 subprefix = prefix + subpath + '/' | 1217 subprefix = prefix + subpath + b'/' |
1209 sub._repo.lfstatus = True | 1218 sub._repo.lfstatus = True |
1210 sub.archive(archiver, subprefix, submatch) | 1219 sub.archive(archiver, subprefix, submatch) |
1211 | 1220 |
1212 archiver.done() | 1221 archiver.done() |
1213 | 1222 |
1214 | 1223 |
1215 @eh.wrapfunction(subrepo.hgsubrepo, 'archive') | 1224 @eh.wrapfunction(subrepo.hgsubrepo, b'archive') |
1216 def hgsubrepoarchive(orig, repo, archiver, prefix, match=None, decode=True): | 1225 def hgsubrepoarchive(orig, repo, archiver, prefix, match=None, decode=True): |
1217 lfenabled = util.safehasattr(repo._repo, '_largefilesenabled') | 1226 lfenabled = util.safehasattr(repo._repo, b'_largefilesenabled') |
1218 if not lfenabled or not repo._repo.lfstatus: | 1227 if not lfenabled or not repo._repo.lfstatus: |
1219 return orig(repo, archiver, prefix, match, decode) | 1228 return orig(repo, archiver, prefix, match, decode) |
1220 | 1229 |
1221 repo._get(repo._state + ('hg',)) | 1230 repo._get(repo._state + (b'hg',)) |
1222 rev = repo._state[1] | 1231 rev = repo._state[1] |
1223 ctx = repo._repo[rev] | 1232 ctx = repo._repo[rev] |
1224 | 1233 |
1225 if ctx.node() is not None: | 1234 if ctx.node() is not None: |
1226 lfcommands.cachelfiles(repo.ui, repo._repo, ctx.node()) | 1235 lfcommands.cachelfiles(repo.ui, repo._repo, ctx.node()) |
1245 path = lfutil.findfile(repo._repo, getdata().strip()) | 1254 path = lfutil.findfile(repo._repo, getdata().strip()) |
1246 | 1255 |
1247 if path is None: | 1256 if path is None: |
1248 raise error.Abort( | 1257 raise error.Abort( |
1249 _( | 1258 _( |
1250 'largefile %s not found in repo store or system cache' | 1259 b'largefile %s not found in repo store or system cache' |
1251 ) | 1260 ) |
1252 % lfile | 1261 % lfile |
1253 ) | 1262 ) |
1254 else: | 1263 else: |
1255 path = lfile | 1264 path = lfile |
1256 | 1265 |
1257 f = lfile | 1266 f = lfile |
1258 | 1267 |
1259 getdata = lambda: util.readfile(os.path.join(prefix, path)) | 1268 getdata = lambda: util.readfile(os.path.join(prefix, path)) |
1260 | 1269 |
1261 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata) | 1270 write(f, b'x' in ff and 0o755 or 0o644, b'l' in ff, getdata) |
1262 | 1271 |
1263 for subpath in sorted(ctx.substate): | 1272 for subpath in sorted(ctx.substate): |
1264 sub = ctx.workingsub(subpath) | 1273 sub = ctx.workingsub(subpath) |
1265 submatch = matchmod.subdirmatcher(subpath, match) | 1274 submatch = matchmod.subdirmatcher(subpath, match) |
1266 subprefix = prefix + subpath + '/' | 1275 subprefix = prefix + subpath + b'/' |
1267 sub._repo.lfstatus = True | 1276 sub._repo.lfstatus = True |
1268 sub.archive(archiver, subprefix, submatch, decode) | 1277 sub.archive(archiver, subprefix, submatch, decode) |
1269 | 1278 |
1270 | 1279 |
1271 # If a largefile is modified, the change is not reflected in its | 1280 # If a largefile is modified, the change is not reflected in its |
1272 # standin until a commit. cmdutil.bailifchanged() raises an exception | 1281 # standin until a commit. cmdutil.bailifchanged() raises an exception |
1273 # if the repo has uncommitted changes. Wrap it to also check if | 1282 # if the repo has uncommitted changes. Wrap it to also check if |
1274 # largefiles were changed. This is used by bisect, backout and fetch. | 1283 # largefiles were changed. This is used by bisect, backout and fetch. |
1275 @eh.wrapfunction(cmdutil, 'bailifchanged') | 1284 @eh.wrapfunction(cmdutil, b'bailifchanged') |
1276 def overridebailifchanged(orig, repo, *args, **kwargs): | 1285 def overridebailifchanged(orig, repo, *args, **kwargs): |
1277 orig(repo, *args, **kwargs) | 1286 orig(repo, *args, **kwargs) |
1278 repo.lfstatus = True | 1287 repo.lfstatus = True |
1279 s = repo.status() | 1288 s = repo.status() |
1280 repo.lfstatus = False | 1289 repo.lfstatus = False |
1281 if s.modified or s.added or s.removed or s.deleted: | 1290 if s.modified or s.added or s.removed or s.deleted: |
1282 raise error.Abort(_('uncommitted changes')) | 1291 raise error.Abort(_(b'uncommitted changes')) |
1283 | 1292 |
1284 | 1293 |
1285 @eh.wrapfunction(cmdutil, 'postcommitstatus') | 1294 @eh.wrapfunction(cmdutil, b'postcommitstatus') |
1286 def postcommitstatus(orig, repo, *args, **kwargs): | 1295 def postcommitstatus(orig, repo, *args, **kwargs): |
1287 repo.lfstatus = True | 1296 repo.lfstatus = True |
1288 try: | 1297 try: |
1289 return orig(repo, *args, **kwargs) | 1298 return orig(repo, *args, **kwargs) |
1290 finally: | 1299 finally: |
1291 repo.lfstatus = False | 1300 repo.lfstatus = False |
1292 | 1301 |
1293 | 1302 |
1294 @eh.wrapfunction(cmdutil, 'forget') | 1303 @eh.wrapfunction(cmdutil, b'forget') |
1295 def cmdutilforget( | 1304 def cmdutilforget( |
1296 orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive | 1305 orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive |
1297 ): | 1306 ): |
1298 normalmatcher = composenormalfilematcher(match, repo[None].manifest()) | 1307 normalmatcher = composenormalfilematcher(match, repo[None].manifest()) |
1299 bad, forgot = orig( | 1308 bad, forgot = orig( |
1319 | 1328 |
1320 for f in forget: | 1329 for f in forget: |
1321 fstandin = lfutil.standin(f) | 1330 fstandin = lfutil.standin(f) |
1322 if fstandin not in repo.dirstate and not repo.wvfs.isdir(fstandin): | 1331 if fstandin not in repo.dirstate and not repo.wvfs.isdir(fstandin): |
1323 ui.warn( | 1332 ui.warn( |
1324 _('not removing %s: file is already untracked\n') % uipathfn(f) | 1333 _(b'not removing %s: file is already untracked\n') % uipathfn(f) |
1325 ) | 1334 ) |
1326 bad.append(f) | 1335 bad.append(f) |
1327 | 1336 |
1328 for f in forget: | 1337 for f in forget: |
1329 if ui.verbose or not m.exact(f): | 1338 if ui.verbose or not m.exact(f): |
1330 ui.status(_('removing %s\n') % uipathfn(f)) | 1339 ui.status(_(b'removing %s\n') % uipathfn(f)) |
1331 | 1340 |
1332 # Need to lock because standin files are deleted then removed from the | 1341 # Need to lock because standin files are deleted then removed from the |
1333 # repository and we could race in-between. | 1342 # repository and we could race in-between. |
1334 with repo.wlock(): | 1343 with repo.wlock(): |
1335 lfdirstate = lfutil.openlfdirstate(ui, repo) | 1344 lfdirstate = lfutil.openlfdirstate(ui, repo) |
1336 for f in forget: | 1345 for f in forget: |
1337 if lfdirstate[f] == 'a': | 1346 if lfdirstate[f] == b'a': |
1338 lfdirstate.drop(f) | 1347 lfdirstate.drop(f) |
1339 else: | 1348 else: |
1340 lfdirstate.remove(f) | 1349 lfdirstate.remove(f) |
1341 lfdirstate.write() | 1350 lfdirstate.write() |
1342 standins = [lfutil.standin(f) for f in forget] | 1351 standins = [lfutil.standin(f) for f in forget] |
1374 if not lfexists[lfhash]: # lfhash doesn't exist on "other" | 1383 if not lfexists[lfhash]: # lfhash doesn't exist on "other" |
1375 addfunc(fn, lfhash) | 1384 addfunc(fn, lfhash) |
1376 | 1385 |
1377 | 1386 |
1378 def outgoinghook(ui, repo, other, opts, missing): | 1387 def outgoinghook(ui, repo, other, opts, missing): |
1379 if opts.pop('large', None): | 1388 if opts.pop(b'large', None): |
1380 lfhashes = set() | 1389 lfhashes = set() |
1381 if ui.debugflag: | 1390 if ui.debugflag: |
1382 toupload = {} | 1391 toupload = {} |
1383 | 1392 |
1384 def addfunc(fn, lfhash): | 1393 def addfunc(fn, lfhash): |
1387 toupload[fn].append(lfhash) | 1396 toupload[fn].append(lfhash) |
1388 lfhashes.add(lfhash) | 1397 lfhashes.add(lfhash) |
1389 | 1398 |
1390 def showhashes(fn): | 1399 def showhashes(fn): |
1391 for lfhash in sorted(toupload[fn]): | 1400 for lfhash in sorted(toupload[fn]): |
1392 ui.debug(' %s\n' % lfhash) | 1401 ui.debug(b' %s\n' % lfhash) |
1393 | 1402 |
1394 else: | 1403 else: |
1395 toupload = set() | 1404 toupload = set() |
1396 | 1405 |
1397 def addfunc(fn, lfhash): | 1406 def addfunc(fn, lfhash): |
1402 pass | 1411 pass |
1403 | 1412 |
1404 _getoutgoings(repo, other, missing, addfunc) | 1413 _getoutgoings(repo, other, missing, addfunc) |
1405 | 1414 |
1406 if not toupload: | 1415 if not toupload: |
1407 ui.status(_('largefiles: no files to upload\n')) | 1416 ui.status(_(b'largefiles: no files to upload\n')) |
1408 else: | 1417 else: |
1409 ui.status( | 1418 ui.status( |
1410 _('largefiles to upload (%d entities):\n') % (len(lfhashes)) | 1419 _(b'largefiles to upload (%d entities):\n') % (len(lfhashes)) |
1411 ) | 1420 ) |
1412 for file in sorted(toupload): | 1421 for file in sorted(toupload): |
1413 ui.status(lfutil.splitstandin(file) + '\n') | 1422 ui.status(lfutil.splitstandin(file) + b'\n') |
1414 showhashes(file) | 1423 showhashes(file) |
1415 ui.status('\n') | 1424 ui.status(b'\n') |
1416 | 1425 |
1417 | 1426 |
1418 @eh.wrapcommand( | 1427 @eh.wrapcommand( |
1419 'outgoing', opts=[('', 'large', None, _('display outgoing largefiles'))] | 1428 b'outgoing', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))] |
1420 ) | 1429 ) |
1421 def _outgoingcmd(orig, *args, **kwargs): | 1430 def _outgoingcmd(orig, *args, **kwargs): |
1422 # Nothing to do here other than add the extra help option- the hook above | 1431 # Nothing to do here other than add the extra help option- the hook above |
1423 # processes it. | 1432 # processes it. |
1424 return orig(*args, **kwargs) | 1433 return orig(*args, **kwargs) |
1425 | 1434 |
1426 | 1435 |
1427 def summaryremotehook(ui, repo, opts, changes): | 1436 def summaryremotehook(ui, repo, opts, changes): |
1428 largeopt = opts.get('large', False) | 1437 largeopt = opts.get(b'large', False) |
1429 if changes is None: | 1438 if changes is None: |
1430 if largeopt: | 1439 if largeopt: |
1431 return (False, True) # only outgoing check is needed | 1440 return (False, True) # only outgoing check is needed |
1432 else: | 1441 else: |
1433 return (False, False) | 1442 return (False, False) |
1434 elif largeopt: | 1443 elif largeopt: |
1435 url, branch, peer, outgoing = changes[1] | 1444 url, branch, peer, outgoing = changes[1] |
1436 if peer is None: | 1445 if peer is None: |
1437 # i18n: column positioning for "hg summary" | 1446 # i18n: column positioning for "hg summary" |
1438 ui.status(_('largefiles: (no remote repo)\n')) | 1447 ui.status(_(b'largefiles: (no remote repo)\n')) |
1439 return | 1448 return |
1440 | 1449 |
1441 toupload = set() | 1450 toupload = set() |
1442 lfhashes = set() | 1451 lfhashes = set() |
1443 | 1452 |
1447 | 1456 |
1448 _getoutgoings(repo, peer, outgoing.missing, addfunc) | 1457 _getoutgoings(repo, peer, outgoing.missing, addfunc) |
1449 | 1458 |
1450 if not toupload: | 1459 if not toupload: |
1451 # i18n: column positioning for "hg summary" | 1460 # i18n: column positioning for "hg summary" |
1452 ui.status(_('largefiles: (no files to upload)\n')) | 1461 ui.status(_(b'largefiles: (no files to upload)\n')) |
1453 else: | 1462 else: |
1454 # i18n: column positioning for "hg summary" | 1463 # i18n: column positioning for "hg summary" |
1455 ui.status( | 1464 ui.status( |
1456 _('largefiles: %d entities for %d files to upload\n') | 1465 _(b'largefiles: %d entities for %d files to upload\n') |
1457 % (len(lfhashes), len(toupload)) | 1466 % (len(lfhashes), len(toupload)) |
1458 ) | 1467 ) |
1459 | 1468 |
1460 | 1469 |
1461 @eh.wrapcommand( | 1470 @eh.wrapcommand( |
1462 'summary', opts=[('', 'large', None, _('display outgoing largefiles'))] | 1471 b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))] |
1463 ) | 1472 ) |
1464 def overridesummary(orig, ui, repo, *pats, **opts): | 1473 def overridesummary(orig, ui, repo, *pats, **opts): |
1465 try: | 1474 try: |
1466 repo.lfstatus = True | 1475 repo.lfstatus = True |
1467 orig(ui, repo, *pats, **opts) | 1476 orig(ui, repo, *pats, **opts) |
1468 finally: | 1477 finally: |
1469 repo.lfstatus = False | 1478 repo.lfstatus = False |
1470 | 1479 |
1471 | 1480 |
1472 @eh.wrapfunction(scmutil, 'addremove') | 1481 @eh.wrapfunction(scmutil, b'addremove') |
1473 def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None): | 1482 def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None): |
1474 if opts is None: | 1483 if opts is None: |
1475 opts = {} | 1484 opts = {} |
1476 if not lfutil.islfilesrepo(repo): | 1485 if not lfutil.islfilesrepo(repo): |
1477 return orig(repo, matcher, prefix, uipathfn, opts) | 1486 return orig(repo, matcher, prefix, uipathfn, opts) |
1503 repo.ui, | 1512 repo.ui, |
1504 repo, | 1513 repo, |
1505 True, | 1514 True, |
1506 m, | 1515 m, |
1507 uipathfn, | 1516 uipathfn, |
1508 opts.get('dry_run'), | 1517 opts.get(b'dry_run'), |
1509 **pycompat.strkwargs(opts) | 1518 **pycompat.strkwargs(opts) |
1510 ) | 1519 ) |
1511 # Call into the normal add code, and any files that *should* be added as | 1520 # Call into the normal add code, and any files that *should* be added as |
1512 # largefiles will be | 1521 # largefiles will be |
1513 added, bad = addlargefiles( | 1522 added, bad = addlargefiles( |
1520 return orig(repo, matcher, prefix, uipathfn, opts) | 1529 return orig(repo, matcher, prefix, uipathfn, opts) |
1521 | 1530 |
1522 | 1531 |
1523 # Calling purge with --all will cause the largefiles to be deleted. | 1532 # Calling purge with --all will cause the largefiles to be deleted. |
1524 # Override repo.status to prevent this from happening. | 1533 # Override repo.status to prevent this from happening. |
1525 @eh.wrapcommand('purge', extension='purge') | 1534 @eh.wrapcommand(b'purge', extension=b'purge') |
1526 def overridepurge(orig, ui, repo, *dirs, **opts): | 1535 def overridepurge(orig, ui, repo, *dirs, **opts): |
1527 # XXX Monkey patching a repoview will not work. The assigned attribute will | 1536 # XXX Monkey patching a repoview will not work. The assigned attribute will |
1528 # be set on the unfiltered repo, but we will only lookup attributes in the | 1537 # be set on the unfiltered repo, but we will only lookup attributes in the |
1529 # unfiltered repo if the lookup in the repoview object itself fails. As the | 1538 # unfiltered repo if the lookup in the repoview object itself fails. As the |
1530 # monkey patched method exists on the repoview class the lookup will not | 1539 # monkey patched method exists on the repoview class the lookup will not |
1535 # cleaner instead. | 1544 # cleaner instead. |
1536 repo = repo.unfiltered() | 1545 repo = repo.unfiltered() |
1537 oldstatus = repo.status | 1546 oldstatus = repo.status |
1538 | 1547 |
1539 def overridestatus( | 1548 def overridestatus( |
1540 node1='.', | 1549 node1=b'.', |
1541 node2=None, | 1550 node2=None, |
1542 match=None, | 1551 match=None, |
1543 ignored=False, | 1552 ignored=False, |
1544 clean=False, | 1553 clean=False, |
1545 unknown=False, | 1554 unknown=False, |
1547 ): | 1556 ): |
1548 r = oldstatus( | 1557 r = oldstatus( |
1549 node1, node2, match, ignored, clean, unknown, listsubrepos | 1558 node1, node2, match, ignored, clean, unknown, listsubrepos |
1550 ) | 1559 ) |
1551 lfdirstate = lfutil.openlfdirstate(ui, repo) | 1560 lfdirstate = lfutil.openlfdirstate(ui, repo) |
1552 unknown = [f for f in r.unknown if lfdirstate[f] == '?'] | 1561 unknown = [f for f in r.unknown if lfdirstate[f] == b'?'] |
1553 ignored = [f for f in r.ignored if lfdirstate[f] == '?'] | 1562 ignored = [f for f in r.ignored if lfdirstate[f] == b'?'] |
1554 return scmutil.status( | 1563 return scmutil.status( |
1555 r.modified, r.added, r.removed, r.deleted, unknown, ignored, r.clean | 1564 r.modified, r.added, r.removed, r.deleted, unknown, ignored, r.clean |
1556 ) | 1565 ) |
1557 | 1566 |
1558 repo.status = overridestatus | 1567 repo.status = overridestatus |
1559 orig(ui, repo, *dirs, **opts) | 1568 orig(ui, repo, *dirs, **opts) |
1560 repo.status = oldstatus | 1569 repo.status = oldstatus |
1561 | 1570 |
1562 | 1571 |
1563 @eh.wrapcommand('rollback') | 1572 @eh.wrapcommand(b'rollback') |
1564 def overriderollback(orig, ui, repo, **opts): | 1573 def overriderollback(orig, ui, repo, **opts): |
1565 with repo.wlock(): | 1574 with repo.wlock(): |
1566 before = repo.dirstate.parents() | 1575 before = repo.dirstate.parents() |
1567 orphans = set( | 1576 orphans = set( |
1568 f | 1577 f |
1569 for f in repo.dirstate | 1578 for f in repo.dirstate |
1570 if lfutil.isstandin(f) and repo.dirstate[f] != 'r' | 1579 if lfutil.isstandin(f) and repo.dirstate[f] != b'r' |
1571 ) | 1580 ) |
1572 result = orig(ui, repo, **opts) | 1581 result = orig(ui, repo, **opts) |
1573 after = repo.dirstate.parents() | 1582 after = repo.dirstate.parents() |
1574 if before == after: | 1583 if before == after: |
1575 return result # no need to restore standins | 1584 return result # no need to restore standins |
1576 | 1585 |
1577 pctx = repo['.'] | 1586 pctx = repo[b'.'] |
1578 for f in repo.dirstate: | 1587 for f in repo.dirstate: |
1579 if lfutil.isstandin(f): | 1588 if lfutil.isstandin(f): |
1580 orphans.discard(f) | 1589 orphans.discard(f) |
1581 if repo.dirstate[f] == 'r': | 1590 if repo.dirstate[f] == b'r': |
1582 repo.wvfs.unlinkpath(f, ignoremissing=True) | 1591 repo.wvfs.unlinkpath(f, ignoremissing=True) |
1583 elif f in pctx: | 1592 elif f in pctx: |
1584 fctx = pctx[f] | 1593 fctx = pctx[f] |
1585 repo.wwrite(f, fctx.data(), fctx.flags()) | 1594 repo.wwrite(f, fctx.data(), fctx.flags()) |
1586 else: | 1595 else: |
1587 # content of standin is not so important in 'a', | 1596 # content of standin is not so important in 'a', |
1588 # 'm' or 'n' (coming from the 2nd parent) cases | 1597 # 'm' or 'n' (coming from the 2nd parent) cases |
1589 lfutil.writestandin(repo, f, '', False) | 1598 lfutil.writestandin(repo, f, b'', False) |
1590 for standin in orphans: | 1599 for standin in orphans: |
1591 repo.wvfs.unlinkpath(standin, ignoremissing=True) | 1600 repo.wvfs.unlinkpath(standin, ignoremissing=True) |
1592 | 1601 |
1593 lfdirstate = lfutil.openlfdirstate(ui, repo) | 1602 lfdirstate = lfutil.openlfdirstate(ui, repo) |
1594 orphans = set(lfdirstate) | 1603 orphans = set(lfdirstate) |
1600 lfdirstate.drop(lfile) | 1609 lfdirstate.drop(lfile) |
1601 lfdirstate.write() | 1610 lfdirstate.write() |
1602 return result | 1611 return result |
1603 | 1612 |
1604 | 1613 |
1605 @eh.wrapcommand('transplant', extension='transplant') | 1614 @eh.wrapcommand(b'transplant', extension=b'transplant') |
1606 def overridetransplant(orig, ui, repo, *revs, **opts): | 1615 def overridetransplant(orig, ui, repo, *revs, **opts): |
1607 resuming = opts.get(r'continue') | 1616 resuming = opts.get(r'continue') |
1608 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) | 1617 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) |
1609 repo._lfstatuswriters.append(lambda *msg, **opts: None) | 1618 repo._lfstatuswriters.append(lambda *msg, **opts: None) |
1610 try: | 1619 try: |
1613 repo._lfstatuswriters.pop() | 1622 repo._lfstatuswriters.pop() |
1614 repo._lfcommithooks.pop() | 1623 repo._lfcommithooks.pop() |
1615 return result | 1624 return result |
1616 | 1625 |
1617 | 1626 |
1618 @eh.wrapcommand('cat') | 1627 @eh.wrapcommand(b'cat') |
1619 def overridecat(orig, ui, repo, file1, *pats, **opts): | 1628 def overridecat(orig, ui, repo, file1, *pats, **opts): |
1620 opts = pycompat.byteskwargs(opts) | 1629 opts = pycompat.byteskwargs(opts) |
1621 ctx = scmutil.revsingle(repo, opts.get('rev')) | 1630 ctx = scmutil.revsingle(repo, opts.get(b'rev')) |
1622 err = 1 | 1631 err = 1 |
1623 notbad = set() | 1632 notbad = set() |
1624 m = scmutil.match(ctx, (file1,) + pats, opts) | 1633 m = scmutil.match(ctx, (file1,) + pats, opts) |
1625 origmatchfn = m.matchfn | 1634 origmatchfn = m.matchfn |
1626 | 1635 |
1656 return origvisitdirfn(lf) | 1665 return origvisitdirfn(lf) |
1657 | 1666 |
1658 m.visitdir = lfvisitdirfn | 1667 m.visitdir = lfvisitdirfn |
1659 | 1668 |
1660 for f in ctx.walk(m): | 1669 for f in ctx.walk(m): |
1661 with cmdutil.makefileobj(ctx, opts.get('output'), pathname=f) as fp: | 1670 with cmdutil.makefileobj(ctx, opts.get(b'output'), pathname=f) as fp: |
1662 lf = lfutil.splitstandin(f) | 1671 lf = lfutil.splitstandin(f) |
1663 if lf is None or origmatchfn(f): | 1672 if lf is None or origmatchfn(f): |
1664 # duplicating unreachable code from commands.cat | 1673 # duplicating unreachable code from commands.cat |
1665 data = ctx[f].data() | 1674 data = ctx[f].data() |
1666 if opts.get('decode'): | 1675 if opts.get(b'decode'): |
1667 data = repo.wwritedata(f, data) | 1676 data = repo.wwritedata(f, data) |
1668 fp.write(data) | 1677 fp.write(data) |
1669 else: | 1678 else: |
1670 hash = lfutil.readasstandin(ctx[f]) | 1679 hash = lfutil.readasstandin(ctx[f]) |
1671 if not lfutil.inusercache(repo.ui, hash): | 1680 if not lfutil.inusercache(repo.ui, hash): |
1672 store = storefactory.openstore(repo) | 1681 store = storefactory.openstore(repo) |
1673 success, missing = store.get([(lf, hash)]) | 1682 success, missing = store.get([(lf, hash)]) |
1674 if len(success) != 1: | 1683 if len(success) != 1: |
1675 raise error.Abort( | 1684 raise error.Abort( |
1676 _( | 1685 _( |
1677 'largefile %s is not in cache and could not be ' | 1686 b'largefile %s is not in cache and could not be ' |
1678 'downloaded' | 1687 b'downloaded' |
1679 ) | 1688 ) |
1680 % lf | 1689 % lf |
1681 ) | 1690 ) |
1682 path = lfutil.usercachepath(repo.ui, hash) | 1691 path = lfutil.usercachepath(repo.ui, hash) |
1683 with open(path, "rb") as fpin: | 1692 with open(path, b"rb") as fpin: |
1684 for chunk in util.filechunkiter(fpin): | 1693 for chunk in util.filechunkiter(fpin): |
1685 fp.write(chunk) | 1694 fp.write(chunk) |
1686 err = 0 | 1695 err = 0 |
1687 return err | 1696 return err |
1688 | 1697 |
1689 | 1698 |
1690 @eh.wrapfunction(merge, 'update') | 1699 @eh.wrapfunction(merge, b'update') |
1691 def mergeupdate(orig, repo, node, branchmerge, force, *args, **kwargs): | 1700 def mergeupdate(orig, repo, node, branchmerge, force, *args, **kwargs): |
1692 matcher = kwargs.get(r'matcher', None) | 1701 matcher = kwargs.get(r'matcher', None) |
1693 # note if this is a partial update | 1702 # note if this is a partial update |
1694 partial = matcher and not matcher.always() | 1703 partial = matcher and not matcher.always() |
1695 with repo.wlock(): | 1704 with repo.wlock(): |
1715 ignored=False, | 1724 ignored=False, |
1716 clean=True, | 1725 clean=True, |
1717 unknown=False, | 1726 unknown=False, |
1718 ) | 1727 ) |
1719 oldclean = set(s.clean) | 1728 oldclean = set(s.clean) |
1720 pctx = repo['.'] | 1729 pctx = repo[b'.'] |
1721 dctx = repo[node] | 1730 dctx = repo[node] |
1722 for lfile in unsure + s.modified: | 1731 for lfile in unsure + s.modified: |
1723 lfileabs = repo.wvfs.join(lfile) | 1732 lfileabs = repo.wvfs.join(lfile) |
1724 if not repo.wvfs.exists(lfileabs): | 1733 if not repo.wvfs.exists(lfileabs): |
1725 continue | 1734 continue |
1769 ) | 1778 ) |
1770 | 1779 |
1771 return result | 1780 return result |
1772 | 1781 |
1773 | 1782 |
1774 @eh.wrapfunction(scmutil, 'marktouched') | 1783 @eh.wrapfunction(scmutil, b'marktouched') |
1775 def scmutilmarktouched(orig, repo, files, *args, **kwargs): | 1784 def scmutilmarktouched(orig, repo, files, *args, **kwargs): |
1776 result = orig(repo, files, *args, **kwargs) | 1785 result = orig(repo, files, *args, **kwargs) |
1777 | 1786 |
1778 filelist = [] | 1787 filelist = [] |
1779 for f in files: | 1788 for f in files: |
1790 ) | 1799 ) |
1791 | 1800 |
1792 return result | 1801 return result |
1793 | 1802 |
1794 | 1803 |
1795 @eh.wrapfunction(upgrade, 'preservedrequirements') | 1804 @eh.wrapfunction(upgrade, b'preservedrequirements') |
1796 @eh.wrapfunction(upgrade, 'supporteddestrequirements') | 1805 @eh.wrapfunction(upgrade, b'supporteddestrequirements') |
1797 def upgraderequirements(orig, repo): | 1806 def upgraderequirements(orig, repo): |
1798 reqs = orig(repo) | 1807 reqs = orig(repo) |
1799 if 'largefiles' in repo.requirements: | 1808 if b'largefiles' in repo.requirements: |
1800 reqs.add('largefiles') | 1809 reqs.add(b'largefiles') |
1801 return reqs | 1810 return reqs |
1802 | 1811 |
1803 | 1812 |
1804 _lfscheme = 'largefile://' | 1813 _lfscheme = b'largefile://' |
1805 | 1814 |
1806 | 1815 |
1807 @eh.wrapfunction(urlmod, 'open') | 1816 @eh.wrapfunction(urlmod, b'open') |
1808 def openlargefile(orig, ui, url_, data=None): | 1817 def openlargefile(orig, ui, url_, data=None): |
1809 if url_.startswith(_lfscheme): | 1818 if url_.startswith(_lfscheme): |
1810 if data: | 1819 if data: |
1811 msg = "cannot use data on a 'largefile://' url" | 1820 msg = b"cannot use data on a 'largefile://' url" |
1812 raise error.ProgrammingError(msg) | 1821 raise error.ProgrammingError(msg) |
1813 lfid = url_[len(_lfscheme) :] | 1822 lfid = url_[len(_lfscheme) :] |
1814 return storefactory.getlfile(ui, lfid) | 1823 return storefactory.getlfile(ui, lfid) |
1815 else: | 1824 else: |
1816 return orig(ui, url_, data=data) | 1825 return orig(ui, url_, data=data) |