Commits

Anonymous committed 8ba5fed

Introduce the hgban.revsets configuration key

A new configuration key has been added. This configuration key is called
"revsets" and must be placed on the new "hgban" section. This key can be used
as a complementary way to specify the banned revsets. The extension will check
any revsets specified in the .hgban file _or_ on the hgban.revsets key.

This is useful when you want to ban a certain revset but you do not want to
track the fact that you ban that revset in your repository history.

Comments (0)

Files changed (1)

 revision sets the entire changegroup is be rejected, and the push, pull or
 bundle operation is aborted.
 
-"banned" revisions are specified in a file called ".hgban" which must be
-placed at the root of the repository. Each line in that file corresponds to
-a banned revision set. A banned revision set can be specified as simple
-revision id or a a complex revision set query.
+Setting up the list of banned revision sets
+===========================================
 
-You can add comments to your .hgban file by beginning a line with
-a "#" character. You can put spaces in front of or after a revision set or
-comment and they will be ignored.
+There are two complementary ways to specify the list of banned revision sets:
 
-Enable the hgban extension just like any other Mercurial extension by adding
-the following to your hgrc:
+1. Create a file called ".hgban" at the root of the repository.
+   Each line in that file corresponds to a banned revision set.
+   A banned revision set can be specified as simple revision id
+   or a a complex revision set query.
+
+   You can add comments to your .hgban file by beginning a line with
+   a "#" character. You can put spaces in front of or after a revision
+   set or comment and they will be ignored.
+   
+   The .hgban file does not need to be committed, although in practice
+   it usually makes sense to do so.
+
+2. Set a hgban.revsets key to one of your mecurial configuration files
+   (i.e. add a "hgban" section, and in it set a "revsets" key).
+   In order to ban more than one revset using this method you must create a
+   multi-line configuration key as explained in
+   (http://www.selenic.com/mercurial/hgrc.5.html#syntax). Note that you can
+   add comments to this key, but you cannot add empty lines between revsets
+   (see below for an example)
+
+   This is useful when you want to ban a certain revset but you do not want
+   to track the fact that you ban that revset in your repository history.
+
+Note that the extension will match new revisions against any revsets specified
+in the .hgban file or on the hgban.revsets key (i.e. using one method does not
+exclude using the other).
+
+Enabling the extension
+======================
+
+You can enable the hgban extension just like any other Mercurial extension by
+adding the following to your hgrc:
 
 [extensions]
 hgban = /path/to/hgban.py
+
+Configuration Examples
+======================
+
+Using this extension you could for example ban the revision id with
+the following hash:
+
+ce3b00de97cf04655227554a13be8b077d5a3d2f
+
+by creating a file called ".hgban" at the root of your repo
+with the following contents:
+
+ce3b00de97cf04655227554a13be8b077d5a3d2f
+
+You could _also_ ban any revisions commited by "John Doe" by
+adding an additional line to the .hgban file:
+
+ce3b00de97cf04655227554a13be8b077d5a3d2f
+author("John Doe")
+
+Note that you could also add comments as follows:
+
+# Ban changeset that adds nuclear launch keys
+ce3b00de97cf04655227554a13be8b077d5a3d2f
+
+# Do not allow John Doe to push any of its changes
+author("John Doe")
+
+Alternativelly, instead of using the .hgban file you could set
+the hgban.revsets configuration key as follows:
+
+[hgban]
+revsets = # Ban changeset that adds nuclear launch keys
+          ce3b00de97cf04655227554a13be8b077d5a3d2f
+          # Do not allow John Doe to push any of its changes
+          author("John Doe")
+
+Note that each line on the revsets key (except the first one)
+_must_ be indented, and that while you can add comments you cannot
+add empty lines.
+
+You could have combined the use of the .hgban file and of the
+hgban.revsets key to achieved the same result:
+
+[hgban]
+revsets = # Ban changeset that adds nuclear launch keys
+          ce3b00de97cf04655227554a13be8b077d5a3d2f
+
+".hgban" file:
+
+# Do not allow John Doe to push any of its changes
+author("John Doe")
 '''
 
 import os.path, re
                 if rset:
                     banned.add(rset)
         f.close()
+    except:
+        banned = set()
 
-        return banned
-    except:
-        return set()
+    # Get the banned revsets defined in the mercurial configuration files
+    rcbanned = repo.ui.config('hgban', 'revsets', '').strip()
+    if rcbanned:
+        rcbanned = set(rcbanned.splitlines())
+
+    banned = banned.union(rcbanned)
+
+    return banned
 
 def getreposetfunc():
     '''