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