112
by James Westby
Add some more tests of merge_upstream. |
1 |
# merge_upstream.py -- Merge new upstream versions of packages.
|
2 |
# Copyright (C) 2007 Reinhard Tartler <siretart@tauware.de>
|
|
3 |
# 2007 James Westby <jw+debian@jameswestby.net>
|
|
226.9.8
by Jelmer Vernooij
Add some tests. |
4 |
# 2008 Jelmer Vernooij <jelmer@samba.org>
|
148
by James Westby
Fix up some copyright notices. |
5 |
#
|
6 |
# Code is also taken from bzrtools, which is
|
|
7 |
# (C) 2005, 2006, 2007 Aaron Bentley <aaron.bentley@utoronto.ca>
|
|
8 |
# (C) 2005, 2006 Canonical Limited.
|
|
9 |
# (C) 2006 Michael Ellerman.
|
|
10 |
# and distributed under the GPL, version 2 or later.
|
|
112
by James Westby
Add some more tests of merge_upstream. |
11 |
#
|
12 |
# This file is part of bzr-builddeb.
|
|
13 |
#
|
|
14 |
# bzr-builddeb is free software; you can redistribute it and/or modify
|
|
15 |
# it under the terms of the GNU General Public License as published by
|
|
16 |
# the Free Software Foundation; either version 2 of the License, or
|
|
17 |
# (at your option) any later version.
|
|
18 |
#
|
|
19 |
# bzr-builddeb is distributed in the hope that it will be useful,
|
|
20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 |
# GNU General Public License for more details.
|
|
23 |
#
|
|
24 |
# You should have received a copy of the GNU General Public License
|
|
25 |
# along with bzr-builddeb; if not, write to the Free Software
|
|
26 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
27 |
#
|
|
28 |
||
285.1.1
by Jelmer Vernooij
Be a bit smarter about what debian version to suggest when merging upstream. |
29 |
import itertools |
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
30 |
|
31 |
from debian_bundle.changelog import Version |
|
32 |
||
226.12.7
by Jelmer Vernooij
Fix increasing existing svn snapshot. |
33 |
from bzrlib.revisionspec import RevisionSpec |
110
by James Westby
Add the start of a testsuite for the merge upstream code. |
34 |
|
226.12.6
by Jelmer Vernooij
Also trim history while determining upstream version string when in svn branch. |
35 |
from bzrlib.plugins.builddeb.util import get_snapshot_revision |
125
by James Westby
Start using tags to mark the upstream imports. |
36 |
|
178.1.29
by James Westby
Add support for incremental import dsc. |
37 |
|
38 |
TAG_PREFIX = "upstream-" |
|
39 |
||
226.12.2
by Jelmer Vernooij
Move looking up of revision suffix to a separate function. |
40 |
|
321.1.9
by James Westby
Make merge_upstream with just a branch guess a version number again. |
41 |
def upstream_version_add_revision(upstream_branch, version_string, revid): |
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
42 |
"""Update the revision in a upstream version string.
|
321.1.9
by James Westby
Make merge_upstream with just a branch guess a version number again. |
43 |
|
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
44 |
:param branch: Branch in which the revision can be found
|
45 |
:param version_string: Original version string
|
|
46 |
:param revid: Revision id of the revision
|
|
47 |
"""
|
|
48 |
revno = upstream_branch.revision_id_to_revno(revid) |
|
321.1.9
by James Westby
Make merge_upstream with just a branch guess a version number again. |
49 |
|
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
50 |
if "+bzr" in version_string: |
51 |
return "%s+bzr%d" % (version_string[:version_string.rfind("+bzr")], revno) |
|
52 |
||
53 |
if "~bzr" in version_string: |
|
54 |
return "%s~bzr%d" % (version_string[:version_string.rfind("~bzr")], revno) |
|
55 |
||
56 |
rev = upstream_branch.repository.get_revision(revid) |
|
57 |
svn_revmeta = getattr(rev, "svn_meta", None) |
|
58 |
if svn_revmeta is not None: |
|
59 |
svn_revno = svn_revmeta.revnum |
|
60 |
||
61 |
if "+svn" in version_string: |
|
62 |
return "%s+svn%d" % (version_string[:version_string.rfind("+svn")], svn_revno) |
|
63 |
if "~svn" in version_string: |
|
64 |
return "%s~svn%d" % (version_string[:version_string.rfind("~svn")], svn_revno) |
|
65 |
return "%s+svn%d" % (version_string, svn_revno) |
|
66 |
||
67 |
return "%s+bzr%d" % (version_string, revno) |
|
321.1.9
by James Westby
Make merge_upstream with just a branch guess a version number again. |
68 |
|
69 |
||
70 |
def _upstream_branch_version(revhistory, reverse_tag_dict, package, |
|
226.12.5
by Jelmer Vernooij
Support merging from upstream Subversion branches. |
71 |
previous_version, add_rev): |
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
72 |
"""Determine the version string of an upstream branch.
|
73 |
||
74 |
The upstream version is determined from the most recent tag
|
|
75 |
in the upstream branch. If that tag does not point at the last revision,
|
|
76 |
the revision number is added to it (<version>+bzr<revno>).
|
|
77 |
||
78 |
If there are no tags set on the upstream branch, the previous Debian
|
|
79 |
version is used and combined with the bzr revision number
|
|
80 |
(usually <version>+bzr<revno>).
|
|
81 |
||
82 |
:param revhistory: Branch revision history.
|
|
83 |
:param reverse_tag_dict: Reverse tag dictionary (revid -> list of tags)
|
|
84 |
:param package: Name of package.
|
|
85 |
:param previous_version: Previous upstream version in debian changelog.
|
|
86 |
:param add_rev: Function that can add a revision suffix to a version string.
|
|
87 |
:return: Name of the upstream revision.
|
|
88 |
"""
|
|
89 |
if revhistory == []: |
|
90 |
# No new version to merge
|
|
91 |
return Version(previous_version) |
|
92 |
for r in reversed(revhistory): |
|
93 |
if r in reverse_tag_dict: |
|
94 |
# If there is a newer version tagged in branch,
|
|
95 |
# convert to upstream version
|
|
96 |
# return <upstream_version>+bzr<revno>
|
|
97 |
for tag in reverse_tag_dict[r]: |
|
98 |
upstream_version = upstream_tag_to_version(tag, |
|
226.12.1
by Jelmer Vernooij
Simplify upstream version string code. |
99 |
package=package) |
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
100 |
if upstream_version is not None: |
101 |
if r != revhistory[-1]: |
|
102 |
upstream_version.upstream_version = add_rev( |
|
103 |
upstream_version.upstream_version, revhistory[-1]) |
|
104 |
return upstream_version |
|
105 |
return Version(add_rev(previous_version, revhistory[-1])) |
|
226.12.5
by Jelmer Vernooij
Support merging from upstream Subversion branches. |
106 |
|
107 |
||
321.1.9
by James Westby
Make merge_upstream with just a branch guess a version number again. |
108 |
def upstream_branch_version(upstream_branch, upstream_revision, package, |
109 |
previous_version): |
|
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
110 |
dotted_revno = upstream_branch.revision_id_to_dotted_revno(upstream_revision) |
111 |
if len(dotted_revno) > 1: |
|
112 |
revno = -2 |
|
113 |
else: |
|
114 |
revno = dotted_revno[0] |
|
115 |
revhistory = upstream_branch.revision_history() |
|
116 |
previous_revision = get_snapshot_revision(previous_version) |
|
117 |
if previous_revision is not None: |
|
118 |
previous_revspec = RevisionSpec.from_string(previous_revision) |
|
119 |
previous_revno, _ = previous_revspec.in_history(upstream_branch) |
|
120 |
# Trim revision history - we don't care about any revisions
|
|
121 |
# before the revision of the previous version
|
|
122 |
else: |
|
123 |
previous_revno = 0 |
|
124 |
revhistory = revhistory[previous_revno:revno+1] |
|
125 |
return _upstream_branch_version(revhistory, |
|
126 |
upstream_branch.tags.get_reverse_tag_dict(), package, |
|
127 |
previous_version, |
|
128 |
lambda version, revision: upstream_version_add_revision(upstream_branch, version, revision)) |
|
178.1.29
by James Westby
Add support for incremental import dsc. |
129 |
|
130 |
||
226.9.5
by Jelmer Vernooij
Determine upstream version when merging from branch. |
131 |
def upstream_tag_to_version(tag_name, package=None): |
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
132 |
"""Take a tag name and return the upstream version, or None."""
|
133 |
if tag_name.startswith(TAG_PREFIX): |
|
134 |
return Version(tag_name[len(TAG_PREFIX):]) |
|
135 |
if (package is not None and ( |
|
136 |
tag_name.startswith("%s-" % package) or |
|
137 |
tag_name.startswith("%s_" % package))): |
|
138 |
return Version(tag_name[len(package)+1:]) |
|
139 |
if tag_name.startswith("release-"): |
|
140 |
return Version(tag_name[len("release-"):]) |
|
141 |
if tag_name[0] == "v" and tag_name[1].isdigit(): |
|
142 |
return Version(tag_name[1:]) |
|
143 |
if all([c.isdigit() or c in (".", "~") for c in tag_name]): |
|
144 |
return Version(tag_name) |
|
145 |
return None |
|
117
by James Westby
Fast forward the import when possible. |
146 |
|
285.1.1
by Jelmer Vernooij
Be a bit smarter about what debian version to suggest when merging upstream. |
147 |
|
148 |
def package_version(merged_version, distribution_name): |
|
330
by James Westby
Throw out old, unused, merge_upstream and import_dsc code. |
149 |
"""Determine the package version from the merged version.
|
150 |
||
151 |
:param merged_version: Merged version string
|
|
152 |
:param distribution_name: Distribution the package is for
|
|
153 |
"""
|
|
154 |
ret = Version(merged_version) |
|
155 |
if merged_version.debian_version is not None: |
|
156 |
prev_packaging_revnum = int("".join(itertools.takewhile( |
|
157 |
lambda x: x.isdigit(), |
|
158 |
merged_version.debian_version))) |
|
159 |
else: |
|
160 |
prev_packaging_revnum = 0 |
|
161 |
if distribution_name == "ubuntu": |
|
162 |
ret.debian_version = "%dubuntu1" % prev_packaging_revnum |
|
163 |
else: |
|
164 |
ret.debian_version = "%d" % (prev_packaging_revnum+1) |
|
165 |
return ret |