/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/send.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with this program; if not, write to the Free Software
19
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 
21
 
"""Support in "bzr send" for git-am style patches."""
 
21
"""Support in "brz send" for git-am style patches."""
22
22
 
23
23
from __future__ import absolute_import
24
24
 
25
25
import time
26
 
from .. import __version__ as bzr_version
 
26
from .. import __version__ as brz_version
27
27
from .. import (
28
28
    branch as _mod_branch,
29
29
    diff as _mod_diff,
34
34
 
35
35
from ..merge_directive import BaseMergeDirective
36
36
 
37
 
from . import (
38
 
    version_info as bzr_git_version_info,
39
 
    )
40
37
from .mapping import (
41
38
    object_mode,
42
39
    )
53
50
    )
54
51
 
55
52
 
56
 
version_tail = "bzr %s, bzr-git %d.%d.%d, dulwich %d.%d.%d" % (
57
 
    (bzr_version, ) + bzr_git_version_info[:3] + dulwich_version[:3])
 
53
version_tail = "Breezy %s, dulwich %d.%d.%d" % (
 
54
    (brz_version, ) + dulwich_version[:3])
58
55
 
59
56
 
60
57
class GitDiffTree(_mod_diff.DiffTree):
62
59
 
63
60
    def _show_diff(self, specific_files, extra_trees):
64
61
        from dulwich.patch import write_blob_diff
65
 
        iterator = self.new_tree.iter_changes(self.old_tree,
66
 
            specific_files=specific_files, extra_trees=extra_trees,
67
 
            require_versioned=True)
 
62
        iterator = self.new_tree.iter_changes(
 
63
            self.old_tree, specific_files=specific_files,
 
64
            extra_trees=extra_trees, require_versioned=True)
68
65
        has_changes = 0
 
66
 
69
67
        def get_encoded_path(path):
70
68
            if path is not None:
71
69
                return path.encode(self.path_encoding, "replace")
 
70
 
72
71
        def get_file_mode(tree, path, kind, executable):
73
72
            if path is None:
74
73
                return 0
75
74
            return object_mode(kind, executable)
 
75
 
76
76
        def get_blob(present, tree, path):
77
77
            if present:
78
78
                with tree.get_file(path) as f:
100
100
                    get_file_mode(trees[1], path_encoded[1],
101
101
                                  kind[1], executable[1]))
102
102
            write_blob_diff(self.to_file,
103
 
                (path_encoded[0], mode[0], contents[0]),
104
 
                (path_encoded[1], mode[1], contents[1]))
 
103
                            (path_encoded[0], mode[0], contents[0]),
 
104
                            (path_encoded[1], mode[1], contents[1]))
105
105
            has_changes |= (changed_content or renamed)
106
106
        return has_changes
107
107
 
117
117
    def __init__(self, revision_id, testament_sha1, time, timezone,
118
118
                 target_branch, source_branch=None, message=None,
119
119
                 patches=None, local_target_branch=None):
120
 
        super(GitMergeDirective, self).__init__(revision_id=revision_id,
121
 
            testament_sha1=testament_sha1, time=time, timezone=timezone,
122
 
            target_branch=target_branch, patch=None,
123
 
            source_branch=source_branch, message=message,
124
 
            bundle=None)
 
120
        super(GitMergeDirective, self).__init__(
 
121
            revision_id=revision_id, testament_sha1=testament_sha1, time=time,
 
122
            timezone=timezone, target_branch=target_branch, patch=None,
 
123
            source_branch=source_branch, message=message, bundle=None)
125
124
        self.patches = patches
126
125
 
127
126
    def to_lines(self):
144
143
        tree_1 = repository.revision_tree(lhs_parent)
145
144
        tree_2 = repository.revision_tree(revision_id)
146
145
        contents = BytesIO()
147
 
        differ = GitDiffTree.from_trees_options(tree_1, tree_2,
148
 
                contents, 'utf8', None, 'a/', 'b/', None)
 
146
        differ = GitDiffTree.from_trees_options(
 
147
            tree_1, tree_2, contents, 'utf8', None, 'a/', 'b/', None)
149
148
        differ.show_diff(None, None)
150
149
        write_commit_patch(s, commit, contents.getvalue(), (num, total),
151
150
                           version_tail)
165
164
            todo = graph.find_difference(submit_revision_id, revision_id)[1]
166
165
            total = len(todo)
167
166
            for i, revid in enumerate(graph.iter_topo_order(todo)):
168
 
                patches.append(cls._generate_commit(repository, revid, i+1,
169
 
                    total))
 
167
                patches.append(cls._generate_commit(repository, revid, i + 1,
 
168
                                                    total))
170
169
        return cls(revision_id, None, time, timezone,
171
 
            target_branch=target_branch, source_branch=public_branch,
172
 
            message=message, patches=patches)
173
 
 
174
 
 
175
 
def send_git(branch, revision_id, submit_branch, public_branch, no_patch, no_bundle, message, base_revision_id, local_target_branch=None):
 
170
                   target_branch=target_branch, source_branch=public_branch,
 
171
                   message=message, patches=patches)
 
172
 
 
173
 
 
174
def send_git(branch, revision_id, submit_branch, public_branch, no_patch,
 
175
             no_bundle, message, base_revision_id, local_target_branch=None):
176
176
    if no_patch:
177
 
        raise errors.BzrCommandError("no patch not supported for git-am style patches")
 
177
        raise errors.BzrCommandError(
 
178
            "no patch not supported for git-am style patches")
178
179
    if no_bundle:
179
 
        raise errors.BzrCommandError("no bundle not supported for git-am style patches")
 
180
        raise errors.BzrCommandError(
 
181
            "no bundle not supported for git-am style patches")
180
182
    return GitMergeDirective.from_objects(
181
183
        branch.repository, revision_id, time.time(),
182
184
        osutils.local_time_offset(), submit_branch,