Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG73e6d3346e4f: largefiles: move lfstatus context manager to lfutil
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/largefiles/lfutil.py (11 lines) | |||
M | hgext/largefiles/overrides.py (13 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
1f21803644cb | 8d5489b048b7 | Martin von Zweigbergk | Oct 18 2019, 8:46 PM |
Status | Author | Revision | |
---|---|---|---|
Abandoned | martinvonz | ||
Abandoned | martinvonz | ||
Abandoned | martinvonz | ||
Abandoned | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
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. | ||||
'''largefiles utility code: must not import other modules in this package.''' | '''largefiles utility code: must not import other modules in this package.''' | ||||
from __future__ import absolute_import | from __future__ import absolute_import | ||||
import contextlib | |||||
import copy | import copy | ||||
import hashlib | import hashlib | ||||
import os | import os | ||||
import stat | import stat | ||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial.node import hex | from mercurial.node import hex | ||||
from mercurial.pycompat import open | from mercurial.pycompat import open | ||||
shortname = b'.hglf' | shortname = b'.hglf' | ||||
shortnameslash = shortname + b'/' | shortnameslash = shortname + b'/' | ||||
longname = b'largefiles' | longname = b'largefiles' | ||||
# -- Private worker functions ------------------------------------------ | # -- Private worker functions ------------------------------------------ | ||||
@contextlib.contextmanager | |||||
def lfstatus(repo): | |||||
oldvalue = getattr(repo, 'lfstatus', False) | |||||
repo.lfstatus = True | |||||
try: | |||||
yield | |||||
finally: | |||||
repo.lfstatus = oldvalue | |||||
def getminsize(ui, assumelfiles, opt, default=10): | def getminsize(ui, assumelfiles, opt, default=10): | ||||
lfsize = opt | lfsize = opt | ||||
if not lfsize and assumelfiles: | if not lfsize and assumelfiles: | ||||
lfsize = ui.config(longname, b'minsize', default=default) | lfsize = ui.config(longname, b'minsize', default=default) | ||||
if lfsize: | if lfsize: | ||||
try: | try: | ||||
lfsize = float(lfsize) | lfsize = float(lfsize) | ||||
except ValueError: | except ValueError: |
# 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 | ||||
from . import ( | from . import ( | ||||
lfcommands, | lfcommands, | ||||
lfutil, | lfutil, | ||||
storefactory, | storefactory, | ||||
) | ) | ||||
eh = exthelper.exthelper() | eh = exthelper.exthelper() | ||||
lfstatus = lfutil.lfstatus | |||||
# -- Utility functions: commonly/repeatedly needed functionality --------------- | # -- Utility functions: commonly/repeatedly needed functionality --------------- | ||||
def composelargefilematcher(match, manifest): | def composelargefilematcher(match, manifest): | ||||
'''create a matcher that matches only the largefiles in the original | '''create a matcher that matches only the largefiles in the original | ||||
matcher''' | matcher''' | ||||
m = copy.copy(match) | m = copy.copy(match) | ||||
lfile = lambda f: lfutil.standin(f) in manifest | lfile = lambda f: lfutil.standin(f) in manifest | ||||
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): | |||||
oldvalue = getattr(repo, 'lfstatus', False) | |||||
repo.lfstatus = True | |||||
try: | |||||
yield | |||||
finally: | |||||
repo.lfstatus = oldvalue | |||||
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()) | ||||
with lfstatus(repo): | with lfstatus(repo): | ||||
s = repo.status(match=m, clean=not isaddremove) | s = repo.status(match=m, clean=not isaddremove) | ||||
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] |