##// END OF EJS Templates
convert: cvsps - User interface to CVS changeset code in cvsps.py
Frank Kingswood -
r6689:d2ac53fe default
parent child Browse files
Show More
@@ -0,0 +1,154 b''
1 #!/usr/bin/env python
2 #
3 # Commandline front-end for cvsps.py
4 #
5 # Copyright 2008, Frank Kingswood <frank@kingswood-consulting.co.uk>
6 #
7 # This software may be used and distributed according to the terms
8 # of the GNU General Public License, incorporated herein by reference.
9
10 import sys
11 from mercurial import util
12 from mercurial.i18n import _
13 from optparse import OptionParser, SUPPRESS_HELP
14 from hgext.convert.cvsps import createlog, createchangeset, logerror
15
16 def main():
17 '''Main program to mimic cvsps.'''
18
19 op = OptionParser(usage='%prog [-bpruvxz] path',
20 description='Read CVS rlog for current directory or named '
21 'path in repository, and convert the log to changesets '
22 'based on matching commit log entries and dates.')
23
24 # Options that are ignored for compatibility with cvsps-2.1
25 op.add_option('-A', dest='Ignore', action='store_true', help=SUPPRESS_HELP)
26 op.add_option('--cvs-direct', dest='Ignore', action='store_true', help=SUPPRESS_HELP)
27 op.add_option('-q', dest='Ignore', action='store_true', help=SUPPRESS_HELP)
28
29 # Main options shared with cvsps-2.1
30 op.add_option('-b', dest='Branches', action='append', default=[],
31 help='Only return changes on specified branches')
32 op.add_option('-p', dest='Prefix', action='store', default='',
33 help='Prefix to remove from file names')
34 op.add_option('-r', dest='Revisions', action='append', default=[],
35 help='Only return changes after or between specified tags')
36 op.add_option('-u', dest='Cache', action='store_const', const='update',
37 help="Update cvs log cache")
38 op.add_option('-v', dest='Verbose', action='count', default=0,
39 help='Be verbose')
40 op.add_option('-x', dest='Cache', action='store_const', const='write',
41 help="Create new cvs log cache")
42 op.add_option('-z', dest='Fuzz', action='store', type='int', default=60,
43 help='Set commit time fuzz', metavar='seconds')
44 op.add_option('--root', dest='Root', action='store', default='',
45 help='Specify cvsroot', metavar='cvsroot')
46
47 # Options specific to this version
48 op.add_option('--parents', dest='Parents', action='store_true',
49 help='Show parent changesets')
50 op.add_option('--ancestors', dest='Ancestors', action='store_true',
51 help='Show current changeset in ancestor branches')
52
53 options, args = op.parse_args()
54
55 # Create a ui object for printing progress messages
56 class UI:
57 def __init__(self, verbose):
58 if verbose:
59 self.status = self.message
60 if verbose>1:
61 self.note = self.message
62 if verbose>2:
63 self.debug = self.message
64 def message(self, msg):
65 sys.stderr.write(msg)
66 def nomessage(self, msg):
67 pass
68 status = nomessage
69 note = nomessage
70 debug = nomessage
71 ui = UI(options.Verbose)
72
73 try:
74 if args:
75 log = []
76 for d in args:
77 log += createlog(ui, d, root=options.Root, cache=options.Cache)
78 else:
79 log = createlog(ui, root=options.Root, cache=options.Cache)
80 except logerror, e:
81 print e
82 return
83
84 changesets = createchangeset(ui, log, options.Fuzz)
85 del log
86
87 # Print changesets (optionally filtered)
88
89 off = len(options.Revisions)
90 branches = {} # latest version number in each branch
91 ancestors = {} # parent branch
92 for cs in changesets:
93
94 if options.Ancestors:
95 if cs.branch not in branches and cs.parents and cs.parents[0].id:
96 ancestors[cs.branch] = changesets[cs.parents[0].id-1].branch, cs.parents[0].id
97 branches[cs.branch] = cs.id
98
99 # limit by branches
100 if options.Branches and (cs.branch or 'HEAD') not in options.Branches:
101 continue
102
103 if not off:
104 # Note: trailing spaces on several lines here are needed to have
105 # bug-for-bug compatibility with cvsps.
106 print '---------------------'
107 print 'PatchSet %d ' % cs.id
108 print 'Date: %s' % util.datestr(cs.date, '%Y/%m/%d %H:%M:%S %1%2')
109 print 'Author: %s' % cs.author
110 print 'Branch: %s' % (cs.branch or 'HEAD')
111 print 'Tag%s: %s ' % (['', 's'][len(cs.tags)>1],
112 ','.join(cs.tags) or '(none)')
113 if options.Parents and cs.parents:
114 if len(cs.parents)>1:
115 print 'Parents: %s' % (','.join([str(p.id) for p in cs.parents]))
116 else:
117 print 'Parent: %d' % cs.parents[0].id
118
119 if options.Ancestors:
120 b = cs.branch
121 r = []
122 while b:
123 b, c = ancestors[b]
124 r.append('%s:%d:%d' % (b or "HEAD", c, branches[b]))
125 if r:
126 print 'Ancestors: %s' % (','.join(r))
127
128 print 'Log:'
129 print cs.comment
130 print
131 print 'Members: '
132 for f in cs.entries:
133 fn = f.file
134 if fn.startswith(options.Prefix):
135 fn = fn[len(options.Prefix):]
136 print '\t%s:%s->%s%s ' % (fn, '.'.join([str(x) for x in f.parent]) or 'INITIAL',
137 '.'.join([str(x) for x in f.revision]), ['', '(DEAD)'][f.dead])
138 print
139
140 # have we seen the start tag?
141 if options.Revisions and off:
142 if options.Revisions[0] == str(cs.id) or \
143 options.Revisions[0] in cs.tags:
144 off = False
145
146 # see if we reached the end tag
147 if len(options.Revisions)>1 and not off:
148 if options.Revisions[1] == str(cs.id) or \
149 options.Revisions[1] in cs.tags:
150 break
151
152
153 if __name__ == '__main__':
154 main()
General Comments 0
You need to be logged in to leave comments. Login now