1
# based on Robert Collins code
3
"""Show all 'heads' in a repository"""
6
from bzrlib.commands import Command, display_command, register_command
7
from bzrlib.option import Option
10
class cmd_heads(Command):
11
"""Show all revisions in a repository not having descendants.
13
takes_options = [Option('by-date', help='Sort heads by date (descending)'),
16
encoding_type = "replace"
19
def run(self, by_date=False):
20
from bzrlib import errors
21
from bzrlib.osutils import format_date
22
import bzrlib.repository
27
repo = bzrlib.branch.Branch.open_containing('.')[0].repository
28
except errors.NotBranchError:
30
repo = bzrlib.repository.Repository.open('.')
31
except errors.NotBranchError:
33
("You need to run this command "
34
"either from the root of a shared repository,\n"
38
g = repo.get_revision_graph()
39
possible_heads = set(g.keys())
41
for parents in g.values():
42
not_heads.update(set(parents))
44
heads = possible_heads.difference(not_heads)
46
# TODO: use different sorting schemes instead of alphabetical sort
53
rev = repo.get_revision(head)
54
timestamp = rev.timestamp
55
dates[timestamp] = head
61
heads.append(dates[k])
64
show_timezone = 'original'
67
print >>to_file, "revision-id:", head
68
rev = repo.get_revision(head)
69
# borrowed from LongLogFormatter
70
print >>to_file, indent+'committer:', rev.committer
72
print >>to_file, indent+'branch nick: %s' % \
73
rev.properties['branch-nick']
76
date_str = format_date(rev.timestamp,
79
print >>to_file, indent+'timestamp: %s' % date_str
81
print >>to_file, indent+'message:'
83
print >>to_file, indent+' (no message)'
85
message = rev.message.rstrip('\r\n')
86
for l in message.split('\n'):
87
print >>to_file, indent+' ' + l
91
print >>to_file, 'No heads found'
96
register_command(cmd_heads)