bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2
by Jelmer Vernooij
Refresh copyright headers, add my email. |
1 |
# Copyright (C) 2012-2018 Jelmer Vernooij <jelmer@jelmer.uk>
|
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
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
|
|
0.358.1
by Jelmer Vernooij
Fix FSF address. |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
16 |
|
17 |
||
18 |
"""Support for pristine tar deltas."""
|
|
19 |
||
0.358.3
by Jelmer Vernooij
Enable absolute import. |
20 |
from __future__ import absolute_import |
21 |
||
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
22 |
from base64 import ( |
23 |
standard_b64decode, |
|
24 |
)
|
|
25 |
||
0.277.4
by Jelmer Vernooij
Add function for storing git pristine tar delta files. |
26 |
from dulwich.objects import ( |
27 |
Blob, |
|
28 |
Tree, |
|
29 |
)
|
|
30 |
||
31 |
import stat |
|
32 |
||
33 |
README_CONTENTS = """\ |
|
34 |
This branch contains delta files that pristine-tar can use to
|
|
35 |
regenerate tarballs for its own releases.
|
|
36 |
"""
|
|
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
37 |
|
38 |
def revision_pristine_tar_data(rev): |
|
39 |
"""Export the pristine tar data from a revision.""" |
|
40 |
if 'deb-pristine-delta' in rev.properties: |
|
41 |
uuencoded = rev.properties['deb-pristine-delta'] |
|
0.277.6
by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command. |
42 |
kind = 'gz' |
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
43 |
elif 'deb-pristine-delta-bz2' in rev.properties: |
44 |
uuencoded = rev.properties['deb-pristine-delta-bz2'] |
|
0.277.6
by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command. |
45 |
kind = 'bz2' |
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
46 |
elif 'deb-pristine-delta-xz' in rev.properties: |
47 |
uuencoded = rev.properties['deb-pristine-delta-xz'] |
|
0.277.6
by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command. |
48 |
kind = 'xz' |
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
49 |
else: |
0.277.6
by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command. |
50 |
raise KeyError(rev.revision_id) |
0.277.1
by Jelmer Vernooij
Add function for extracting pristine tar data. |
51 |
|
0.277.6
by Jelmer Vernooij
Add 'bzr git-push-pristine-tar' command. |
52 |
return (standard_b64decode(uuencoded), kind) |
0.277.3
by Jelmer Vernooij
Add function for reading pristine tar data from a git repo. |
53 |
|
54 |
||
55 |
def get_pristine_tar_tree(repo): |
|
56 |
"""Retrieve the pristine tar tree for a repository. |
|
57 |
||
58 |
"""
|
|
59 |
try: |
|
60 |
cid = repo.refs["refs/heads/pristine-tar"] |
|
61 |
except KeyError: |
|
62 |
return Tree() |
|
63 |
tid = repo.object_store[cid].tree |
|
64 |
return repo.object_store[tid] |
|
65 |
||
66 |
||
67 |
def read_git_pristine_tar_data(repo, filename): |
|
68 |
"""Read pristine data from a Git repository. |
|
69 |
||
70 |
:param repo: Git repository to read from
|
|
71 |
:param filename: Name of file to read
|
|
72 |
:return: Tuple with delta and id
|
|
73 |
"""
|
|
74 |
tree = get_pristine_tar_tree(repo) |
|
75 |
delta = tree[filename + ".delta"][1] |
|
76 |
gitid = tree[filename + ".id"][1] |
|
77 |
return (repo.object_store[delta].data, |
|
78 |
repo.object_store[gitid].data) |
|
0.277.4
by Jelmer Vernooij
Add function for storing git pristine tar delta files. |
79 |
|
80 |
||
81 |
def store_git_pristine_tar_data(repo, filename, delta, gitid, |
|
82 |
message=None, **kwargs): |
|
83 |
"""Add pristine tar data to a Git repository. |
|
84 |
||
85 |
:param repo: Git repository to add data to
|
|
86 |
:param filename: Name of file to store for
|
|
87 |
:param delta: pristine-tar delta
|
|
88 |
:param gitid: Git id the pristine tar delta is generated against
|
|
89 |
"""
|
|
90 |
delta_ob = Blob.from_string(delta) |
|
91 |
delta_name = filename + ".delta" |
|
92 |
id_ob = Blob.from_string(gitid) |
|
93 |
id_name = filename + ".id" |
|
94 |
objects = [ |
|
95 |
(delta_ob, delta_name), |
|
96 |
(id_ob, id_name)] |
|
97 |
tree = get_pristine_tar_tree(repo) |
|
98 |
tree.add(delta_name, stat.S_IFREG | 0644, delta_ob.id) |
|
99 |
tree.add(id_name, stat.S_IFREG | 0644, id_ob.id) |
|
100 |
if not "README" in tree: |
|
101 |
readme_ob = Blob.from_string(README_CONTENTS) |
|
102 |
objects.append((readme_ob, "README")) |
|
103 |
tree.add("README", stat.S_IFREG | 0644, readme_ob.id) |
|
104 |
objects.append((tree, "")) |
|
105 |
repo.object_store.add_objects(objects) |
|
106 |
if message is None: |
|
107 |
message = 'pristine-tar data for %s' % filename |
|
108 |
return repo.do_commit(ref='refs/heads/pristine-tar', tree=tree.id, |
|
109 |
message=message, **kwargs) |