changeset 10095:69ce7a10e593

convert: implement two hooks in builtin cvsps
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Tue, 15 Dec 2009 10:37:23 +0000
parents a43ae5777221
children a223894ca044
files hgext/convert/__init__.py hgext/convert/cvsps.py tests/test-convert-cvs tests/test-convert-cvs.out tests/test-convert.out
diffstat 5 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Thu Dec 17 00:32:26 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
--- a/hgext/convert/cvsps.py	Thu Dec 17 00:32:26 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
 
 
--- a/tests/test-convert-cvs	Thu Dec 17 00:32:26 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
--- a/tests/test-convert-cvs.out	Thu Dec 17 00:32:26 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:
--- a/tests/test-convert.out	Thu Dec 17 00:32:26 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