bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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 |
||
17 |
def show_log(branch, show_timezone='original', verbose=False, |
|
18 |
show_ids=False, |
|
19 |
to_file=None): |
|
20 |
"""Write out human-readable log of commits to this branch. |
|
21 |
||
22 |
show_timezone
|
|
23 |
'original' (committer's timezone),
|
|
24 |
'utc' (universal time), or
|
|
25 |
'local' (local user's timezone)
|
|
26 |
||
27 |
verbose
|
|
28 |
If true show added/changed/deleted/renamed files.
|
|
29 |
||
30 |
show_ids
|
|
31 |
If true, show revision and file ids.
|
|
32 |
||
33 |
to_file
|
|
34 |
File to send log to; by default stdout.
|
|
35 |
"""
|
|
36 |
from osutils import format_date |
|
37 |
from errors import BzrCheckError |
|
38 |
from diff import diff_trees |
|
39 |
from textui import show_status |
|
40 |
||
41 |
if to_file == None: |
|
42 |
import sys |
|
43 |
to_file = sys.stdout |
|
44 |
||
45 |
branch._need_readlock() |
|
46 |
revno = 1 |
|
47 |
precursor = None |
|
48 |
for revision_id in branch.revision_history(): |
|
49 |
print '-' * 40 |
|
50 |
print 'revno:', revno |
|
51 |
rev = branch.get_revision(revision_id) |
|
52 |
if show_ids: |
|
53 |
print 'revision-id:', revision_id |
|
54 |
print 'committer:', rev.committer |
|
55 |
print 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0, |
|
56 |
show_timezone)) |
|
57 |
||
58 |
## opportunistic consistency check, same as check_patch_chaining
|
|
59 |
if rev.precursor != precursor: |
|
60 |
raise BzrCheckError("mismatched precursor!") |
|
61 |
||
62 |
print 'message:' |
|
63 |
if not rev.message: |
|
64 |
print ' (no message)' |
|
65 |
else: |
|
66 |
for l in rev.message.split('\n'): |
|
67 |
print ' ' + l |
|
68 |
||
69 |
if verbose and precursor: |
|
70 |
# TODO: Group as added/deleted/renamed instead
|
|
71 |
# TODO: Show file ids
|
|
72 |
print 'changed files:' |
|
73 |
tree = branch.revision_tree(revision_id) |
|
74 |
prevtree = branch.revision_tree(precursor) |
|
75 |
||
76 |
for file_state, fid, old_name, new_name, kind in \ |
|
77 |
diff_trees(prevtree, tree, ): |
|
78 |
if file_state == 'A' or file_state == 'M': |
|
79 |
show_status(file_state, kind, new_name) |
|
80 |
elif file_state == 'D': |
|
81 |
show_status(file_state, kind, old_name) |
|
82 |
elif file_state == 'R': |
|
83 |
show_status(file_state, kind, |
|
84 |
old_name + ' => ' + new_name) |
|
85 |
||
86 |
revno += 1 |
|
87 |
precursor = revision_id |