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
19
from pybaz.backends.baz import sequence_cmd
22
__docformat__ = "restructuredtext"
23
__doc__ = "Utility functions to be used by commands"
25
def direct_merges(merges):
26
"""Get a list of direct merges, from a list of direct and indirect
28
:param merges: Iterator of merge patchlogs
29
:type merges: iter of `pybaz.Patchlog`
30
:return: The direct merges
31
:rtype: list of `pybaz.Patchlog`
39
indirect.extend([f for f in log.new_patches if f != log.revision])
40
if log.continuation_of is not None:
41
# continuations list everything in new_patches
45
ancestor = log.revision.ancestor
46
except pybaz.errors.ExecProblem:
49
if log.revision.patchlevel != 'version-0':
50
ancestor = namespace_previous(log.revision)
54
# ancestor might be in the tree
55
for tree_log in pybaz.WorkingTree(log.tree).iter_logs(
56
log.revision.version, reverse=True):
58
ancestor = tree_log.revision
60
if tree_log.revision == log.revision:
62
print "ancestor of %s is %s" % (log.revision, ancestor)
63
if ancestor is not None:
64
indirect.append(ancestor)
65
return [log for log in logs if not log.revision in indirect]
67
def namespace_previous(revision):
68
if revision.patchlevel == 'base-0':
70
if revision.patchlevel == 'patch-1':
71
return revision.version['base-0']
72
if revision.patchlevel.startswith('patch'):
73
level = int(revision.patchlevel[len('patch-'):]) -1
74
return revision.version['patch-%d' % level]
75
if revision.patchlevel == 'version-0':
76
raise RuntimeError("cannot determine prior namespace level for a "
77
"version-0 patch ('%s')" % revision)
78
if revision.patchlevel == 'versionfix-1':
79
return revision.version['version-0']
80
if revision.patchlevel.startswith('versionfix'):
81
level = int(revision.patchlevel[len('versionfix-'):]) -1
82
return revision.version['versionfix-%d' % level]
83
raise NotImplementedError
85
def iter_new_merges(tree, version, reverse=False):
86
"""List patchlogs that are new in this tree since the last commit.
88
:param tree: The working tree to calculate new revisions in
90
:param version: The version to use when determining new logs
92
:param reverse: If true, list backwards, from newest to oldest
94
:return: An iterator for new revision logs in this tree
95
:rtype: Iterator of `pybaz.Patchlog`
97
assert (isinstance(version, pybaz.Version))
98
for line in _iter_new_merges(tree, version.fullname, reverse):
99
yield pybaz.Patchlog(line, tree)
101
def _iter_new_merges(directory, version, reverse):
102
"""List patchlogs that are new in this tree since the last commit.
104
:param directory: The working tree to calculate new revisions in
106
:param version: The version to use when determining new logs
108
:param reverse: If true, list backwards, from newest to oldest
110
:return: An iterator for names of revisions new in this tree
111
:rtype: Iterator of str
113
args = [ 'new-merges', '--dir', directory ]
115
args.append('--reverse')
117
return sequence_cmd(args)