Patchwork D7136: largefiles: add context manager for setting/clearing "lfstatus" attribute

login
register
mail settings
Submitter phabricator
Date Oct. 19, 2019, 5:13 a.m.
Message ID <1d35324ff3f631ff02b6ef301e059abf@localhost.localdomain>
Download mbox | patch
Permalink /patch/42483/
State Not Applicable
Headers show

Comments

phabricator - Oct. 19, 2019, 5:13 a.m.
Closed by commit rHG03dae1044edd: largefiles: add context manager for setting/clearing &quot;lfstatus&quot; attribute (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7136?vs=17345&id=17348

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7136/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7136

AFFECTED FILES
  hgext/largefiles/overrides.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -9,6 +9,7 @@ 
 '''Overridden Mercurial commands and functions for the largefiles extension'''
 from __future__ import absolute_import
 
+import contextlib
 import copy
 import os
 
@@ -157,14 +158,20 @@ 
     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):
     after = opts.get(r'after')
     m = composelargefilematcher(matcher, repo[None].manifest())
-    try:
-        repo.lfstatus = True
+    with lfstatus(repo):
         s = repo.status(match=m, clean=not isaddremove)
-    finally:
-        repo.lfstatus = False
     manifest = repo[None].manifest()
     modified, added, deleted, clean = [
         [f for f in list if lfutil.standin(f) in manifest]
@@ -308,29 +315,20 @@ 
 
 @eh.wrapfunction(subrepo.hgsubrepo, b'status')
 def overridestatusfn(orig, repo, rev2, **opts):
-    try:
-        repo._repo.lfstatus = True
+    with lfstatus(repo._repo):
         return orig(repo, rev2, **opts)
-    finally:
-        repo._repo.lfstatus = False
 
 
 @eh.wrapcommand(b'status')
 def overridestatus(orig, ui, repo, *pats, **opts):
-    try:
-        repo.lfstatus = True
+    with lfstatus(repo):
         return orig(ui, repo, *pats, **opts)
-    finally:
-        repo.lfstatus = False
 
 
 @eh.wrapfunction(subrepo.hgsubrepo, b'dirty')
 def overridedirty(orig, repo, ignoreupdate=False, missing=False):
-    try:
-        repo._repo.lfstatus = True
+    with lfstatus(repo._repo):
         return orig(repo, ignoreupdate=ignoreupdate, missing=missing)
-    finally:
-        repo._repo.lfstatus = False
 
 
 @eh.wrapcommand(b'log')
@@ -1117,22 +1115,14 @@ 
 
 @eh.wrapcommand(b'archive')
 def overridearchivecmd(orig, ui, repo, dest, **opts):
-    repo.unfiltered().lfstatus = True
-
-    try:
+    with lfstatus(repo.unfiltered()):
         return orig(ui, repo.unfiltered(), dest, **opts)
-    finally:
-        repo.unfiltered().lfstatus = False
 
 
 @eh.wrapfunction(webcommands, b'archive')
 def hgwebarchive(orig, web):
-    web.repo.lfstatus = True
-
-    try:
+    with lfstatus(web.repo):
         return orig(web)
-    finally:
-        web.repo.lfstatus = False
 
 
 @eh.wrapfunction(archival, b'archive')
@@ -1286,20 +1276,16 @@ 
 @eh.wrapfunction(cmdutil, b'bailifchanged')
 def overridebailifchanged(orig, repo, *args, **kwargs):
     orig(repo, *args, **kwargs)
-    repo.lfstatus = True
-    s = repo.status()
-    repo.lfstatus = False
+    with lfstatus(repo):
+        s = repo.status()
     if s.modified or s.added or s.removed or s.deleted:
         raise error.Abort(_(b'uncommitted changes'))
 
 
 @eh.wrapfunction(cmdutil, b'postcommitstatus')
 def postcommitstatus(orig, repo, *args, **kwargs):
-    repo.lfstatus = True
-    try:
+    with lfstatus(repo):
         return orig(repo, *args, **kwargs)
-    finally:
-        repo.lfstatus = False
 
 
 @eh.wrapfunction(cmdutil, b'forget')
@@ -1319,11 +1305,8 @@ 
     )
     m = composelargefilematcher(match, repo[None].manifest())
 
-    try:
-        repo.lfstatus = True
+    with lfstatus(repo):
         s = repo.status(match=m, clean=True)
-    finally:
-        repo.lfstatus = False
     manifest = repo[None].manifest()
     forget = sorted(s.modified + s.added + s.deleted + s.clean)
     forget = [f for f in forget if lfutil.standin(f) in manifest]
@@ -1473,11 +1456,8 @@ 
     b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))]
 )
 def overridesummary(orig, ui, repo, *pats, **opts):
-    try:
-        repo.lfstatus = True
+    with lfstatus(repo):
         orig(ui, repo, *pats, **opts)
-    finally:
-        repo.lfstatus = False
 
 
 @eh.wrapfunction(scmutil, b'addremove')