[PATCH 2 of 3] convert: cvsps - User interface to CVS changeset code in cvsps.py

Frank Kingswood frank at kingswood-consulting.co.uk
Sat Jun 7 05:20:29 CDT 2008


# HG changeset patch
# User Frank Kingswood <frank at kingswood-consulting.co.uk>
# Date 1209062068 -3600
# Node ID 69b67d6de865c70ecab814faf5a78acac6647627
# Parent  ee80565b41869608fec812164a922541b8f7e277
convert: cvsps - User interface to CVS changeset code in cvsps.py

diff -r ee80565b4186 -r 69b67d6de865 hgext/convert/cvsps
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext/convert/cvsps	Thu Apr 24 19:34:28 2008 +0100
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+#
+# Commandline front-end for cvsps.py
+#
+# Copyright 2008, Frank Kingswood <frank at kingswood-consulting.co.uk>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+import sys
+from mercurial import util
+from mercurial.i18n import _
+from optparse import OptionParser,SUPPRESS_HELP
+from hgext.convert.cvsps import cvsps_create_log,cvsps_create_changeset,cvsps_log_error
+
+def main():
+   '''Main program to mimic cvsps.'''
+
+   op=OptionParser(usage='%prog [-bpruvxz] path',
+                   description='Read CVS rlog for current directory or named '
+                               'path in repository, and convert the log to changesets '
+                               'based on matching commit log entries and dates.')
+
+   # Options that are ignored for compatibility with cvsps-2.1
+   op.add_option('-A',dest='Ignore',action='store_true',help=SUPPRESS_HELP)
+   op.add_option('--cvs-direct',dest='Ignore',action='store_true',help=SUPPRESS_HELP)
+   op.add_option('-q',dest='Ignore',action='store_true',help=SUPPRESS_HELP)
+
+   # Main options shared with cvsps-2.1
+   op.add_option('-b',dest='Branches',action='append',default=[],
+                 help='Only return changes on specified branches')
+   op.add_option('-p',dest='Prefix',action='store',default='',
+                 help='Prefix to remove from file names')
+   op.add_option('-r',dest='Revisions',action='append',default=[],
+                 help='Only return changes after or between specified tags')
+   op.add_option('-u',dest='Cache',action='store_const',const='update',
+                 help="Update cvs log cache")
+   op.add_option('-v',dest='Verbose',action='count',default=0,
+                 help='Be verbose')
+   op.add_option('-x',dest='Cache',action='store_const',const='write',
+                 help="Create new cvs log cache")
+   op.add_option('-z',dest='Fuzz',action='store',type='int',default=60,
+                 help='Set commit time fuzz',metavar='seconds')
+   op.add_option('--root',dest='Root',action='store',
+                 help='Specify cvsroot',metavar='cvsroot')
+
+   # Options specific to this version
+   op.add_option('--parents',dest='Parents',action='store_true',
+                 help='Show parent changesets')
+   op.add_option('--ancestors',dest='Ancestors',action='store_true',
+                 help='Show current changeset in ancestor branches')
+
+   options,args=op.parse_args()
+
+   # Create a ui object for printing progress messages
+   class UI:
+      def __init__(self,verbose):
+      	 if verbose:
+            self.status=self.message
+      	 if verbose>1:
+            self.debug=self.message
+      def message(self,msg):
+         sys.stderr.write(msg)
+      def nomessage(self,msg):
+         pass
+      status=nomessage
+      debug=nomessage
+   ui=UI(options.Verbose)
+
+   try:
+      if args:
+         log=[]
+         for d in args:
+            log+=cvsps_create_log(ui,d,root=options.Root,cache=options.Cache)
+      else:
+         log=cvsps_create_log(ui,root=options.Root,cache=options.Cache)
+   except cvsps_log_error,e:
+      print e
+      return
+
+   changeset=cvsps_create_changeset(ui,log,options.Fuzz)
+   del log
+
+   # Print changesets (optionally filtered)
+
+   off=len(options.Revisions)
+   branches={}    # latest version number in each branch
+   ancestors={}   # parent branch
+   for cs in changeset:
+
+      if options.Ancestors:
+         if cs.Branch not in branches and cs.Parents and cs.Parents[0].Id:
+            ancestors[cs.Branch]=changeset[cs.Parents[0].Id-1].Branch,cs.Parents[0].Id
+         branches[cs.Branch]=cs.Id
+
+      # limit by branches
+      if options.Branches and (cs.Branch or 'HEAD') not in options.Branches:
+         continue
+
+      if not off:
+         # Note: trailing spaces on several lines here are needed to have
+         #       bug-for-bug compatibility with cvsps.
+         print '---------------------'
+         print 'PatchSet %d '%cs.Id
+         print 'Date: %s'%util.datestr(cs.Date,'%Y/%m/%d %H:%M:%S %1%2')
+         print 'Author: %s'%cs.Author
+         print 'Branch: %s'%(cs.Branch or 'HEAD')
+         print 'Tag%s: %s '%(['','s'][len(cs.Tags)>1],
+                             ','.join(cs.Tags) or '(none)')
+         if options.Parents and cs.Parents:
+            if len(cs.Parents)>1:
+               print 'Parents: %s'%(','.join([str(p.Id) for p in cs.Parents]))
+            else:
+               print 'Parent: %d'%cs.Parents[0].Id
+
+         if options.Ancestors:
+            b=cs.Branch
+            r=[]
+            while b:
+               b,c=ancestors[b]
+               r.append('%s:%d:%d'%(b or "HEAD",c,branches[b]))
+            if r:
+               print 'Ancestors: %s'%(','.join(r))
+
+         print 'Log:'
+         print cs.Comment
+         print
+         print 'Members: '
+         for f in cs.Entries:
+            fn=f.File
+            if fn.startswith(options.Prefix):
+               fn=fn[len(options.Prefix):]
+            print '\t%s:%s->%s%s '%(fn,'.'.join([str(x) for x in f.Parent]) or 'INITIAL',
+                                    '.'.join([str(x) for x in f.Revision]),['','(DEAD)'][f.Dead])
+         print
+
+      # have we seen the start tag?
+      if options.Revisions and off:
+         if options.Revisions[0]==str(cs.Id) or \
+            options.Revisions[0] in cs.Tags:
+            off=False
+
+      # see if we reached the end tag
+      if len(options.Revisions)>1 and not off:
+         if options.Revisions[1]==str(cs.Id) or \
+            options.Revisions[1] in cs.Tags:
+            break
+
+
+if __name__=='__main__':
+   main()


More information about the Mercurial-devel mailing list