1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#ensure that the parent directory is in the path (for epydoc)
22
sys.path=[os.path.realpath(os.path.dirname(__file__)+"/..")]+sys.path
31
__docformat__ = "restructuredtext"
32
__doc__ = "command template"
34
class Annotate(commands.BaseCommand):
35
"""Print an annotated version of a file"""
37
self.description = self.__doc__
39
# override get_completer if you want custom completion
40
# def get_completer(self, arg, index):
41
# return cmdutil.iter_dir_completions(arg)
43
def do_command(self, cmdargs):
44
parser=self.get_parser()
45
(options, args) = parser.parse_args(cmdargs)
47
if len(args) < 1 or len(args) > 2:
48
raise pylon.errors.GetHelp
50
tree = arch.tree_root(".")
52
revision = cmdutil.determine_revision_tree(tree, args[1])
54
revision = pylon.tree_latest(tree)
56
lines = pylon.annotate_file(tree, revision, file)
58
raise pylon.errors.CommandFailedWrapper(e)
64
line.log = pylon.merge_blame(line.log, file,
65
pylon.tree_cwd(tree)+"/"+file,
67
if options.baz_style or options.patchlevels:
69
ancestors = list(pylon.iter_ancestry(tree))
73
name_map["UNKNOWN"] = str(ancestors[-1])
74
if (options.patchlevels):
76
for revision in ancestors:
77
if anc_level == 0 and revision.version != tree.tree_version:
80
name_map[str(revision)] = "ances-%i" % anc_level
83
name_map[str(revision)] = revision.patchlevel
84
baz_display(lines, name_map)
86
colorized_display(lines, options)
90
parser = cmdutil.CmdOptionParser("annotate FILE [REVISION]")
91
parser.add_option("-s", "--summary", action="store_true",
92
dest="summary", help="Show patchlog summary")
93
parser.add_option("-D", "--date", action="store_true",
94
dest="date", help="Show patchlog date")
95
parser.add_option("-c", "--creator", action="store_true",
96
dest="creator", help="Show the id that committed the"
98
parser.add_option("-b", "--baz", action="store_true", dest="baz_style",
99
help="Show annotations in baz style")
100
parser.add_option("-p", "--patchlevels", action="store_true",
102
help="Show patchlevels (and ances for ancestor"
104
parser.add_option("--notws", action="store_true",
106
help="Show, but don't annotate whitespace lines")
107
parser.add_option("", "--deep", action="store_true",
109
help="Assign blame to merged revisions")
112
def help(self, parser=None):
114
Prints a help message.
116
:param parser: If supplied, the parser to use for generating help. If \
117
not supplied, it is retrieved.
118
:type parser: cmdutil.CmdOptionParser
121
parser=self.get_parser()
124
Annotate will print up a version of a file, showing which revision added
127
Lines whose derivation cannot be determined as listed as UNASSIGNED.
129
The --deep option attempts to determine which merge inserted a line, but
130
because merges are inexact patching, it can be confused by lines which are
131
repeated more than once in a revision's diff (e.g. whitespace).
133
def baz_display(lines, name_map={}):
136
revision_text = "UNKNOWN"
138
revision_text = str(line.log.revision)
141
revision_text = name_map[revision_text]
144
print "%s: %s" % (revision_text, line.text.rstrip("\n"))
147
def colorized_display(lines, options):
150
if last is None or str(line.log) != str(last.log):
151
if options.notws and line.text.strip() == "":
154
print terminal.colorstring("UNASSIGNED", 'blue')
156
print terminal.colorstring(str(line.log.revision), 'blue')
158
print terminal.colorstring(" %s" % line.log.creator,
161
print terminal.colorstring(" %s" % \
162
time.strftime('%Y-%m-%d %H:%M:%S %Z',
163
line.log.date), 'yellow')
164
if options.summary and line.log.summary != "":
165
print terminal.colorstring(" %s" % line.log.summary,
168
print(line.text.rstrip("\n"))
171
#This function assigns the command class to a user command name
172
def add_command(commands):
173
commands["annotate"] = Annotate
177
# arch-tag: c9833e6f-0ebe-4cb9-a799-d9ec2e50674e