1
# Copyright (C) 2012-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Support for pristine tar deltas."""
20
from __future__ import absolute_import
26
from dulwich.objects import (
33
README_CONTENTS = """\
34
This branch contains delta files that pristine-tar can use to
35
regenerate tarballs for its own releases.
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']
43
elif 'deb-pristine-delta-bz2' in rev.properties:
44
uuencoded = rev.properties['deb-pristine-delta-bz2']
46
elif 'deb-pristine-delta-xz' in rev.properties:
47
uuencoded = rev.properties['deb-pristine-delta-xz']
50
raise KeyError(rev.revision_id)
52
return (standard_b64decode(uuencoded), kind)
55
def get_pristine_tar_tree(repo):
56
"""Retrieve the pristine tar tree for a repository.
60
cid = repo.refs["refs/heads/pristine-tar"]
63
tid = repo.object_store[cid].tree
64
return repo.object_store[tid]
67
def read_git_pristine_tar_data(repo, filename):
68
"""Read pristine data from a Git repository.
70
:param repo: Git repository to read from
71
:param filename: Name of file to read
72
:return: Tuple with delta and id
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)
81
def store_git_pristine_tar_data(repo, filename, delta, gitid,
82
message=None, **kwargs):
83
"""Add pristine tar data to a Git repository.
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
90
delta_ob = Blob.from_string(delta)
91
delta_name = filename + ".delta"
92
id_ob = Blob.from_string(gitid)
93
id_name = filename + ".id"
95
(delta_ob, delta_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)
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)