[PATCH 2 of 2] commit: cleanup, by moving subrepo setup to it's own method
Jason Harris
jason.f.harris at gmail.com
Thu Jan 26 05:31:35 CST 2012
# HG changeset patch
# User Jason Harris <jason at jasonfharris.com>
# Date 1327576946 -3600
# Branch stable
# Node ID 4a93a15b2e4a14d64f592a1ff9bde202e884c54b
# Parent 410354c0ee27ac8afd192f138aa9c205d1d17898
commit: cleanup, by moving subrepo setup to it's own method
The sub repository setup was taking a large chunk of the commit
method and was getting highly indented, so move it to it's
own setup method. No effective functionality change.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1060,6 +1060,42 @@
return fparent1
+ # set up the subrepo information (if applicable) for a commit
+ def _subssetup(self, wctx, changes, match):
+ subs = []
+ removedsubs = set()
+ if not self.ui.configbool('ui', 'excludesubrepos'):
+ if '.hgsub' in wctx:
+ # only manage subrepos and .hgsubstate if .hgsub is present
+ for p in wctx.parents():
+ removedsubs.update(s for s in p.substate if match(s))
+ for s in wctx.substate:
+ removedsubs.discard(s)
+ if match(s) and wctx.sub(s).dirty():
+ subs.append(s)
+ if (subs or removedsubs):
+ if (not match('.hgsub') and
+ '.hgsub' in (wctx.modified() + wctx.added())):
+ raise util.Abort(
+ _("can't commit subrepos without .hgsub"))
+ if '.hgsubstate' not in changes[0]:
+ changes[0].insert(0, '.hgsubstate')
+ if '.hgsubstate' in changes[2]:
+ changes[2].remove('.hgsubstate')
+ elif '.hgsub' in changes[2]:
+ # clean up .hgsubstate when .hgsub is removed
+ if ('.hgsubstate' in wctx and
+ '.hgsubstate' not in changes[0] + changes[1] + changes[2]):
+ changes[2].insert(0, '.hgsubstate')
+
+ if subs and not self.ui.configbool('ui', 'commitsubrepos', False):
+ changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
+ if changedsubs:
+ raise util.Abort(_("uncommitted changes in subrepo %s")
+ % changedsubs[0],
+ hint=_("use --subrepos for recursive commit"))
+ return subs, removedsubs
+
def commit(self, text="", user=None, date=None, match=None, force=False,
editor=False, extra={}):
"""Add a new revision to current repository.
@@ -1095,39 +1131,7 @@
changes[0].extend(changes[6]) # mq may commit unchanged files
# check subrepos
- subs = []
- removedsubs = set()
- if not self.ui.configbool('ui', 'excludesubrepos'):
- if '.hgsub' in wctx:
- # only manage subrepos and .hgsubstate if .hgsub is present
- for p in wctx.parents():
- removedsubs.update(s for s in p.substate if match(s))
- for s in wctx.substate:
- removedsubs.discard(s)
- if match(s) and wctx.sub(s).dirty():
- subs.append(s)
- if (subs or removedsubs):
- if (not match('.hgsub') and
- '.hgsub' in (wctx.modified() + wctx.added())):
- raise util.Abort(
- _("can't commit subrepos without .hgsub"))
- if '.hgsubstate' not in changes[0]:
- changes[0].insert(0, '.hgsubstate')
- if '.hgsubstate' in changes[2]:
- changes[2].remove('.hgsubstate')
- elif '.hgsub' in changes[2]:
- # clean up .hgsubstate when .hgsub is removed
- if ('.hgsubstate' in wctx and '.hgsubstate' not in
- changes[0] + changes[1] + changes[2]):
- changes[2].insert(0, '.hgsubstate')
-
- if subs and not self.ui.configbool('ui', 'commitsubrepos',
- False):
- changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
- if changedsubs:
- raise util.Abort(_("uncommitted changes in subrepo %s")
- % changedsubs[0],
- hint=_("use --subrepos for recursive commit"))
+ subs, removedsubs = self._subssetup(wctx, changes, match)
# make sure all explicit patterns are matched
if not force and match.files():
More information about the Mercurial-devel
mailing list