[PATCH 0 of 2 ] revset, fileset: add "subrepo" symbol

0 views
Skip to first unread message

Angel Ezquerra

unread,
Mar 22, 2012, 6:17:03 PM3/22/12
to mercuri...@selenic.com
Added a subrepo() symbol to both revsets and filesets, which can be used to find those revisions in which a subrepo matching a given glob pattern were modified, or those subrepos that match a given glob pattern.
_______________________________________________
Mercurial-devel mailing list
Mercuri...@selenic.com
http://selenic.com/mailman/listinfo/mercurial-devel

Angel Ezquerra

unread,
Mar 22, 2012, 6:17:04 PM3/22/12
to mercuri...@selenic.com
# HG changeset patch
# User Angel Ezquerra <angel.e...@gmail.com>
# Date 1332447135 -3600
# Node ID 698737a841b9d4f28eb6849a836ab90d70fff174
# Parent 54df21ce2c2cc39481697a42f06b5f873f1cc075
revset: add "subrepo" revset symbol

This new revset symbol finds those revisions in which any subrepo whose path
matches a given glob pattern were modified (e.g. "subrepo(my*repo)").

If no argument is passed, find those revisions in which any subrepo was
modified.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -5,7 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

-import re
+import re, fnmatch
import parser, util, error, discovery, hbisect, phases
import node as nodemod
import bookmarks as bookmarksmod
@@ -935,6 +935,28 @@
l.sort()
return [e[-1] for e in l]

+def subrepo(repo, subset, x):
+ """``subrepo([path])``
+ Find revisions where the selected subrepo has been modified.
+ With no argument, find revisions where any subrepo has been modified.
+ """
+ # i18n: "subrepo" is a keyword
+ if x:
+ pat = encoding.lower(
+ getstring(x, _("subrepo requires a string or no arguments")))
+
+ def matchpat(pat, subs):
+ for sub in subs:
+ if fnmatch.fnmatch(sub, pat):
+ return True
+ return False
+
+ # Note that fnmatch, which is used in matchpat, caches patterns so
+ # repeatedly calling fnmatch.fnmatch with the same pattern is efficient
+ return [r for r in subset if matchpat(pat, repo[r].substate)]
+ else:
+ return [r for r in subset if repo[r].substate]
+
def tag(repo, subset, x):
"""``tag([name])``
The specified tag by name, or all tagged revisions if no name is given.
@@ -1019,6 +1041,7 @@
"roots": roots,
"sort": sort,
"secret": secret,
+ "subrepo": subrepo,
"tag": tag,
"tagged": tagged,
"user": user,

Reply all
Reply to author
Forward
0 new messages