1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# Copyright (C) 2005 Canonical Ltd
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
def find_touching_revisions(branch, file_id):
"""Yield a description of revisions which affect the file_id.
Each returned element is (revno, revision_id, description)
This is the list of revisions where the file is either added,
modified, renamed or deleted.
Revisions are returned in chronological order.
TODO: Perhaps some way to limit this to only particular revisions,
or to traverse a non-branch set of revisions?
TODO: If a directory is given, then by default look for all
changes under that directory.
"""
last_ie = None
last_path = None
revno = 1
for revision_id in branch.revision_history():
this_inv = branch.get_revision_inventory(revision_id)
if file_id in this_inv:
this_ie = this_inv[file_id]
this_path = this_inv.id2path(file_id)
else:
this_ie = this_path = None
# now we know how it was last time, and how it is in this revision.
# are those two states effectively the same or not?
if not this_ie and not last_ie:
# not present in either
pass
elif this_ie and not last_ie:
yield revno, revision_id, "added " + this_path
elif not this_ie and last_ie:
# deleted here
yield revno, revision_id, "deleted " + last_path
elif this_path != last_path:
yield revno, revision_id, ("renamed %s => %s" % (last_path, this_path))
elif (this_ie.text_size != last_ie.text_size
or this_ie.text_sha1 != last_ie.text_sha1):
yield revno, revision_id, "modified " + this_path
last_ie = this_ie
last_path = this_path
revno += 1
def show_log(branch,
filename=None,
show_timezone='original',
verbose=False,
show_ids=False,
to_file=None):
"""Write out human-readable log of commits to this branch.
filename
If true, list only the commits affecting the specified
file, rather than all commits.
show_timezone
'original' (committer's timezone),
'utc' (universal time), or
'local' (local user's timezone)
verbose
If true show added/changed/deleted/renamed files.
show_ids
If true, show revision and file ids.
to_file
File to send log to; by default stdout.
"""
from osutils import format_date
from errors import BzrCheckError
from diff import compare_inventories
from textui import show_status
from inventory import Inventory
if to_file == None:
import sys
to_file = sys.stdout
if filename:
file_id = branch.read_working_inventory().path2id(filename)
def which_revs():
for revno, revid, why in find_touching_revisions(branch, file_id):
yield revno, revid
else:
def which_revs():
for i, revid in enumerate(branch.revision_history()):
yield i+1, revid
branch._need_readlock()
precursor = None
if verbose:
prev_inv = Inventory()
for revno, revision_id in which_revs():
print >>to_file, '-' * 60
print >>to_file, 'revno:', revno
rev = branch.get_revision(revision_id)
if show_ids:
print >>to_file, 'revision-id:', revision_id
print >>to_file, 'committer:', rev.committer
print >>to_file, 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
show_timezone))
if revision_id != rev.revision_id:
raise BzrCheckError("retrieved wrong revision: %r"
% (revision_id, rev.revision_id))
print >>to_file, 'message:'
if not rev.message:
print >>to_file, ' (no message)'
else:
for l in rev.message.split('\n'):
print >>to_file, ' ' + l
# Don't show a list of changed files if we were asked about
# one specific file.
if verbose and not filename:
this_inv = branch.get_inventory(rev.inventory_id)
delta = compare_inventories(prev_inv, this_inv)
if delta.removed:
print >>to_file, 'removed files:'
for path, fid in delta.removed:
if show_ids:
print >>to_file, ' %-30s %s' % (path, fid)
else:
print >>to_file, ' ', path
if delta.added:
print >>to_file, 'added files:'
for path, fid in delta.added:
if show_ids:
print >>to_file, ' %-30s %s' % (path, fid)
else:
print >>to_file, ' ' + path
if delta.renamed:
print >>to_file, 'renamed files:'
for oldpath, newpath, fid in delta.renamed:
if show_ids:
print >>to_file, ' %s => %s %s' % (oldpath, newpath, fid)
else:
print >>to_file, ' %s => %s' % (oldpath, newpath)
if delta.modified:
print >>to_file, 'modified files:'
for path, fid in delta.modified:
if show_ids:
print >>to_file, ' %-30s %s' % (path, fid)
else:
print >>to_file, ' ' + path
prev_inv = this_inv
precursor = revision_id
|