Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG03dae1044edd: largefiles: add context manager for setting/clearing "lfstatus" attribute
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | hgext/largefiles/overrides.py (62 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| c7a4f23dc7cd | d0f89e8c615a | Martin von Zweigbergk | Oct 18 2019, 5:40 PM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| # Copyright 2009-2010 Gregory P. Ward | # Copyright 2009-2010 Gregory P. Ward | ||||
| # Copyright 2009-2010 Intelerad Medical Systems Incorporated | # Copyright 2009-2010 Intelerad Medical Systems Incorporated | ||||
| # Copyright 2010-2011 Fog Creek Software | # Copyright 2010-2011 Fog Creek Software | ||||
| # Copyright 2010-2011 Unity Technologies | # Copyright 2010-2011 Unity Technologies | ||||
| # | # | ||||
| # This software may be used and distributed according to the terms of the | # This software may be used and distributed according to the terms of the | ||||
| # GNU General Public License version 2 or any later version. | # GNU General Public License version 2 or any later version. | ||||
| '''Overridden Mercurial commands and functions for the largefiles extension''' | '''Overridden Mercurial commands and functions for the largefiles extension''' | ||||
| from __future__ import absolute_import | from __future__ import absolute_import | ||||
| import contextlib | |||||
| import copy | import copy | ||||
| import os | import os | ||||
| from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
| from mercurial.pycompat import open | from mercurial.pycompat import open | ||||
| from mercurial.hgweb import webcommands | from mercurial.hgweb import webcommands | ||||
| for f in repo[None].add(standins) | for f in repo[None].add(standins) | ||||
| if f in m.files() | if f in m.files() | ||||
| ] | ] | ||||
| added = [f for f in lfnames if f not in bad] | added = [f for f in lfnames if f not in bad] | ||||
| return added, bad | return added, bad | ||||
| @contextlib.contextmanager | |||||
| def lfstatus(repo): | |||||
| repo.lfstatus = True | |||||
| try: | |||||
| yield | |||||
| finally: | |||||
| repo.lfstatus = False | |||||
| def removelargefiles(ui, repo, isaddremove, matcher, uipathfn, dryrun, **opts): | def removelargefiles(ui, repo, isaddremove, matcher, uipathfn, dryrun, **opts): | ||||
| after = opts.get(r'after') | after = opts.get(r'after') | ||||
| m = composelargefilematcher(matcher, repo[None].manifest()) | m = composelargefilematcher(matcher, repo[None].manifest()) | ||||
| try: | with lfstatus(repo): | ||||
| repo.lfstatus = True | |||||
| s = repo.status(match=m, clean=not isaddremove) | s = repo.status(match=m, clean=not isaddremove) | ||||
| finally: | |||||
| repo.lfstatus = False | |||||
| manifest = repo[None].manifest() | manifest = repo[None].manifest() | ||||
| modified, added, deleted, clean = [ | modified, added, deleted, clean = [ | ||||
| [f for f in list if lfutil.standin(f) in manifest] | [f for f in list if lfutil.standin(f) in manifest] | ||||
| for list in (s.modified, s.added, s.deleted, s.clean) | for list in (s.modified, s.added, s.deleted, s.clean) | ||||
| ] | ] | ||||
| def warn(files, msg): | def warn(files, msg): | ||||
| for f in files: | for f in files: | ||||
| ui, repo, False, matcher, uipathfn, dryrun, after=after, force=force | ui, repo, False, matcher, uipathfn, dryrun, after=after, force=force | ||||
| ) | ) | ||||
| or result | or result | ||||
| ) | ) | ||||
| @eh.wrapfunction(subrepo.hgsubrepo, b'status') | @eh.wrapfunction(subrepo.hgsubrepo, b'status') | ||||
| def overridestatusfn(orig, repo, rev2, **opts): | def overridestatusfn(orig, repo, rev2, **opts): | ||||
| try: | with lfstatus(repo._repo): | ||||
| repo._repo.lfstatus = True | |||||
| return orig(repo, rev2, **opts) | return orig(repo, rev2, **opts) | ||||
| finally: | |||||
| repo._repo.lfstatus = False | |||||
| @eh.wrapcommand(b'status') | @eh.wrapcommand(b'status') | ||||
| def overridestatus(orig, ui, repo, *pats, **opts): | def overridestatus(orig, ui, repo, *pats, **opts): | ||||
| try: | with lfstatus(repo): | ||||
| repo.lfstatus = True | |||||
| return orig(ui, repo, *pats, **opts) | return orig(ui, repo, *pats, **opts) | ||||
| finally: | |||||
| repo.lfstatus = False | |||||
| @eh.wrapfunction(subrepo.hgsubrepo, b'dirty') | @eh.wrapfunction(subrepo.hgsubrepo, b'dirty') | ||||
| def overridedirty(orig, repo, ignoreupdate=False, missing=False): | def overridedirty(orig, repo, ignoreupdate=False, missing=False): | ||||
| try: | with lfstatus(repo._repo): | ||||
| repo._repo.lfstatus = True | |||||
| return orig(repo, ignoreupdate=ignoreupdate, missing=missing) | return orig(repo, ignoreupdate=ignoreupdate, missing=missing) | ||||
| finally: | |||||
| repo._repo.lfstatus = False | |||||
| @eh.wrapcommand(b'log') | @eh.wrapcommand(b'log') | ||||
| def overridelog(orig, ui, repo, *pats, **opts): | def overridelog(orig, ui, repo, *pats, **opts): | ||||
| def overridematchandpats( | def overridematchandpats( | ||||
| orig, | orig, | ||||
| ctx, | ctx, | ||||
| pats=(), | pats=(), | ||||
| return orig(ui, repo, **opts) | return orig(ui, repo, **opts) | ||||
| finally: | finally: | ||||
| repo._lfstatuswriters.pop() | repo._lfstatuswriters.pop() | ||||
| repo._lfcommithooks.pop() | repo._lfcommithooks.pop() | ||||
| @eh.wrapcommand(b'archive') | @eh.wrapcommand(b'archive') | ||||
| def overridearchivecmd(orig, ui, repo, dest, **opts): | def overridearchivecmd(orig, ui, repo, dest, **opts): | ||||
| repo.unfiltered().lfstatus = True | with lfstatus(repo.unfiltered()): | ||||
| try: | |||||
| return orig(ui, repo.unfiltered(), dest, **opts) | return orig(ui, repo.unfiltered(), dest, **opts) | ||||
| finally: | |||||
| repo.unfiltered().lfstatus = False | |||||
| @eh.wrapfunction(webcommands, b'archive') | @eh.wrapfunction(webcommands, b'archive') | ||||
| def hgwebarchive(orig, web): | def hgwebarchive(orig, web): | ||||
| web.repo.lfstatus = True | with lfstatus(web.repo): | ||||
| try: | |||||
| return orig(web) | return orig(web) | ||||
| finally: | |||||
| web.repo.lfstatus = False | |||||
| @eh.wrapfunction(archival, b'archive') | @eh.wrapfunction(archival, b'archive') | ||||
| def overridearchive( | def overridearchive( | ||||
| orig, | orig, | ||||
| repo, | repo, | ||||
| dest, | dest, | ||||
| node, | node, | ||||
| # If a largefile is modified, the change is not reflected in its | # If a largefile is modified, the change is not reflected in its | ||||
| # standin until a commit. cmdutil.bailifchanged() raises an exception | # standin until a commit. cmdutil.bailifchanged() raises an exception | ||||
| # if the repo has uncommitted changes. Wrap it to also check if | # if the repo has uncommitted changes. Wrap it to also check if | ||||
| # largefiles were changed. This is used by bisect, backout and fetch. | # largefiles were changed. This is used by bisect, backout and fetch. | ||||
| @eh.wrapfunction(cmdutil, b'bailifchanged') | @eh.wrapfunction(cmdutil, b'bailifchanged') | ||||
| def overridebailifchanged(orig, repo, *args, **kwargs): | def overridebailifchanged(orig, repo, *args, **kwargs): | ||||
| orig(repo, *args, **kwargs) | orig(repo, *args, **kwargs) | ||||
| repo.lfstatus = True | with lfstatus(repo): | ||||
| s = repo.status() | s = repo.status() | ||||
| repo.lfstatus = False | |||||
| if s.modified or s.added or s.removed or s.deleted: | if s.modified or s.added or s.removed or s.deleted: | ||||
| raise error.Abort(_(b'uncommitted changes')) | raise error.Abort(_(b'uncommitted changes')) | ||||
| @eh.wrapfunction(cmdutil, b'postcommitstatus') | @eh.wrapfunction(cmdutil, b'postcommitstatus') | ||||
| def postcommitstatus(orig, repo, *args, **kwargs): | def postcommitstatus(orig, repo, *args, **kwargs): | ||||
| repo.lfstatus = True | with lfstatus(repo): | ||||
| try: | |||||
| return orig(repo, *args, **kwargs) | return orig(repo, *args, **kwargs) | ||||
| finally: | |||||
| repo.lfstatus = False | |||||
| @eh.wrapfunction(cmdutil, b'forget') | @eh.wrapfunction(cmdutil, b'forget') | ||||
| def cmdutilforget( | def cmdutilforget( | ||||
| orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive | orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive | ||||
| ): | ): | ||||
| normalmatcher = composenormalfilematcher(match, repo[None].manifest()) | normalmatcher = composenormalfilematcher(match, repo[None].manifest()) | ||||
| bad, forgot = orig( | bad, forgot = orig( | ||||
| ui, | ui, | ||||
| repo, | repo, | ||||
| normalmatcher, | normalmatcher, | ||||
| prefix, | prefix, | ||||
| uipathfn, | uipathfn, | ||||
| explicitonly, | explicitonly, | ||||
| dryrun, | dryrun, | ||||
| interactive, | interactive, | ||||
| ) | ) | ||||
| m = composelargefilematcher(match, repo[None].manifest()) | m = composelargefilematcher(match, repo[None].manifest()) | ||||
| try: | with lfstatus(repo): | ||||
| repo.lfstatus = True | |||||
| s = repo.status(match=m, clean=True) | s = repo.status(match=m, clean=True) | ||||
| finally: | |||||
| repo.lfstatus = False | |||||
| manifest = repo[None].manifest() | manifest = repo[None].manifest() | ||||
| forget = sorted(s.modified + s.added + s.deleted + s.clean) | forget = sorted(s.modified + s.added + s.deleted + s.clean) | ||||
| forget = [f for f in forget if lfutil.standin(f) in manifest] | forget = [f for f in forget if lfutil.standin(f) in manifest] | ||||
| for f in forget: | for f in forget: | ||||
| fstandin = lfutil.standin(f) | fstandin = lfutil.standin(f) | ||||
| if fstandin not in repo.dirstate and not repo.wvfs.isdir(fstandin): | if fstandin not in repo.dirstate and not repo.wvfs.isdir(fstandin): | ||||
| ui.warn( | ui.warn( | ||||
| % (len(lfhashes), len(toupload)) | % (len(lfhashes), len(toupload)) | ||||
| ) | ) | ||||
| @eh.wrapcommand( | @eh.wrapcommand( | ||||
| b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))] | b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))] | ||||
| ) | ) | ||||
| def overridesummary(orig, ui, repo, *pats, **opts): | def overridesummary(orig, ui, repo, *pats, **opts): | ||||
| try: | with lfstatus(repo): | ||||
| repo.lfstatus = True | |||||
| orig(ui, repo, *pats, **opts) | orig(ui, repo, *pats, **opts) | ||||
| finally: | |||||
| repo.lfstatus = False | |||||
| @eh.wrapfunction(scmutil, b'addremove') | @eh.wrapfunction(scmutil, b'addremove') | ||||
| def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None): | def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None): | ||||
| if opts is None: | if opts is None: | ||||
| opts = {} | opts = {} | ||||
| if not lfutil.islfilesrepo(repo): | if not lfutil.islfilesrepo(repo): | ||||
| return orig(repo, matcher, prefix, uipathfn, opts) | return orig(repo, matcher, prefix, uipathfn, opts) | ||||