[PATCH 1 of 1] convert: implement two hooks in builtin cvsps

Frank Kingswood frank at kingswood-consulting.co.uk
Wed Dec 16 20:51:21 CST 2009


# HG changeset patch
# User Frank Kingswood <frank at kingswood-consulting.co.uk>
# Date 1260873443 0
# Node ID e6b6aefc17c1ba2bedf0fbd6589432f4f4279f2e
# Parent  25919ebaba017e4395709a8c6d96f2b7370f6d02
convert: implement two hooks in builtin cvsps

diff -r 25919ebaba01 -r e6b6aefc17c1 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py	Mon Dec 14 23:14:50 2009 +0100
+++ b/hgext/convert/__init__.py	Tue Dec 15 10:37:23 2009 +0000
@@ -165,6 +165,15 @@
         matched. If a match occurs, then the conversion process will
         add the most recent revision on the branch indicated in the
         regex as the second parent of the changeset.
+    --config hook.cvslog
+        Specify a Python function to be called at the end of gathering
+        the CVS log. The function is passed a list with the log entries,
+        and can modify the entries in-place, or add or delete them.
+    --config hook.cvschangesets
+        Specify a Python function to be called after the changesets
+        are calculated from the the CVS log. The function is passed
+        a list with the changeset entries, and can modify the changesets
+        in-place, or add or delete them.
 
     An additional "debugcvsps" Mercurial command allows the builtin
     changeset merging code to be run without doing a conversion. Its
diff -r 25919ebaba01 -r e6b6aefc17c1 hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py	Mon Dec 14 23:14:50 2009 +0100
+++ b/hgext/convert/cvsps.py	Tue Dec 15 10:37:23 2009 +0000
@@ -11,6 +11,7 @@
 import cPickle as pickle
 from mercurial import util
 from mercurial.i18n import _
+from mercurial import hook
 
 class logentry(object):
     '''Class logentry has the following attributes:
@@ -444,6 +445,8 @@
 
     ui.status(_('%d log entries\n') % len(log))
 
+    hook.hook(ui, None, "cvslog", True, log=log)
+
     return log
 
 
@@ -730,6 +733,8 @@
 
     ui.status(_('%d changeset entries\n') % len(changesets))
 
+    hook.hook(ui, None, "cvschangesets", True, changesets=changesets)
+
     return changesets
 
 
diff -r 25919ebaba01 -r e6b6aefc17c1 tests/test-convert-cvs
--- a/tests/test-convert-cvs	Mon Dec 14 23:14:50 2009 +0100
+++ b/tests/test-convert-cvs	Tue Dec 15 10:37:23 2009 +0000
@@ -16,10 +16,23 @@
 echo "convert = " >> $HGRCPATH
 echo "graphlog = " >> $HGRCPATH
 
+cat > cvshooks.py <<EOF
+def cvslog(ui,repo,hooktype,log):
+    print "%s hook: %d entries"%(hooktype,len(log))
+
+def cvschangesets(ui,repo,hooktype,changesets):
+    print "%s hook: %d changesets"%(hooktype,len(changesets))
+EOF
+hookpath=$PWD
+
+echo "[hooks]" >> $HGRCPATH
+echo "cvslog=python:$hookpath/cvshooks.py:cvslog" >> $HGRCPATH
+echo "cvschangesets=python:$hookpath/cvshooks.py:cvschangesets" >> $HGRCPATH
+
 echo % create cvs repository
 mkdir cvsrepo
 cd cvsrepo
-CVSROOT=`pwd`
+CVSROOT=$PWD
 export CVSROOT
 CVS_OPTIONS=-f
 export CVS_OPTIONS
diff -r 25919ebaba01 -r e6b6aefc17c1 tests/test-convert-cvs.out
--- a/tests/test-convert-cvs.out	Mon Dec 14 23:14:50 2009 +0100
+++ b/tests/test-convert-cvs.out	Tue Dec 15 10:37:23 2009 +0000
@@ -17,8 +17,10 @@
 scanning source...
 collecting CVS rlog
 5 log entries
+cvslog hook: 5 entries
 creating changesets
 3 changeset entries
+cvschangesets hook: 3 changesets
 sorting...
 converting...
 2 Initial revision
@@ -34,8 +36,10 @@
 scanning source...
 collecting CVS rlog
 5 log entries
+cvslog hook: 5 entries
 creating changesets
 3 changeset entries
+cvschangesets hook: 3 changesets
 sorting...
 converting...
 2 Initial revision
@@ -57,8 +61,10 @@
 scanning source...
 collecting CVS rlog
 7 log entries
+cvslog hook: 7 entries
 creating changesets
 4 changeset entries
+cvschangesets hook: 4 changesets
 sorting...
 converting...
 0 ci1
@@ -72,8 +78,10 @@
 scanning source...
 collecting CVS rlog
 7 log entries
+cvslog hook: 7 entries
 creating changesets
 4 changeset entries
+cvschangesets hook: 4 changesets
 sorting...
 converting...
 0 ci1
@@ -94,8 +102,10 @@
 scanning source...
 collecting CVS rlog
 8 log entries
+cvslog hook: 8 entries
 creating changesets
 5 changeset entries
+cvschangesets hook: 5 changesets
 sorting...
 converting...
 0 ci2
@@ -106,8 +116,10 @@
 scanning source...
 collecting CVS rlog
 8 log entries
+cvslog hook: 8 entries
 creating changesets
 5 changeset entries
+cvschangesets hook: 5 changesets
 sorting...
 converting...
 0 ci2
@@ -125,8 +137,10 @@
 scanning source...
 collecting CVS rlog
 9 log entries
+cvslog hook: 9 entries
 creating changesets
 6 changeset entries
+cvschangesets hook: 6 changesets
 sorting...
 converting...
 0 funny
@@ -148,8 +162,10 @@
 % testing debugcvsps
 collecting CVS rlog
 9 log entries
+cvslog hook: 9 entries
 creating changesets
 8 changeset entries
+cvschangesets hook: 8 changesets
 ---------------------
 PatchSet 1 
 Date:
diff -r 25919ebaba01 -r e6b6aefc17c1 tests/test-convert.out
--- a/tests/test-convert.out	Mon Dec 14 23:14:50 2009 +0100
+++ b/tests/test-convert.out	Tue Dec 15 10:37:23 2009 +0000
@@ -140,6 +140,15 @@
         If a match occurs, then the conversion process will add the most
         recent revision on the branch indicated in the regex as the second
         parent of the changeset.
+    --config hook.cvslog
+        Specify a Python function to be called at the end of gathering the CVS
+        log. The function is passed a list with the log entries, and can
+        modify the entries in-place, or add or delete them.
+    --config hook.cvschangesets
+        Specify a Python function to be called after the changesets are
+        calculated from the the CVS log. The function is passed a list with
+        the changeset entries, and can modify the changesets in-place, or add
+        or delete them.
 
     An additional "debugcvsps" Mercurial command allows the builtin changeset
     merging code to be run without doing a conversion. Its parameters and


More information about the Mercurial-devel mailing list