bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.1613
by Jelmer Vernooij
Handle encoding better in working tree iter changes. |
1 |
# Copyright (C) 2007,2012 Canonical Ltd
|
2 |
# Copyright (C) 2009-2012 Jelmer Vernooij <jelmer@samba.org>
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
3 |
#
|
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.
|
|
8 |
#
|
|
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.
|
|
13 |
#
|
|
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
|
|
17 |
||
18 |
"""An adapter between a Git Branch and a Bazaar Branch"""
|
|
19 |
||
|
0.200.1594
by Jelmer Vernooij
Use absolute_import everywhere. |
20 |
from __future__ import absolute_import |
21 |
||
|
0.200.1547
by Jelmer Vernooij
Support setting branch nicks. |
22 |
from cStringIO import StringIO |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
23 |
from collections import defaultdict |
24 |
||
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
25 |
from dulwich.objects import ( |
|
0.200.1153
by Jelmer Vernooij
Import ZERO_SHA from dulwich.objects. |
26 |
ZERO_SHA, |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
27 |
)
|
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
28 |
from dulwich.repo import check_ref_format |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
29 |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
30 |
from ... import ( |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
31 |
branch, |
32 |
config, |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
33 |
controldir, |
|
0.200.446
by Jelmer Vernooij
Support new 'local' argument. |
34 |
errors, |
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
35 |
lock, |
|
0.200.1097
by Jelmer Vernooij
Implement GitBranchFormat.initialize. |
36 |
repository as _mod_repository, |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
37 |
revision, |
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
38 |
tag, |
|
0.230.1
by Jelmer Vernooij
Support lightweight checkouts. |
39 |
transport, |
|
0.200.1414
by Jelmer Vernooij
Fix pulling into bound branches. |
40 |
urlutils, |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
41 |
)
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
42 |
from ...revision import ( |
|
0.200.969
by Jelmer Vernooij
Use tuples with bzr revid and git sha to avoid lookups. |
43 |
NULL_REVISION, |
44 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
45 |
from ...trace import ( |
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
46 |
is_quiet, |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
47 |
mutter, |
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
48 |
warning, |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
49 |
)
|
50 |
||
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
51 |
from .config import ( |
|
0.200.386
by Jelmer Vernooij
Move config to a separate file, support BranchConfig.username(). |
52 |
GitBranchConfig, |
|
0.200.1472
by Jelmer Vernooij
Provide basic implementation of Branch.get_config_stack. |
53 |
GitBranchStack, |
|
0.200.386
by Jelmer Vernooij
Move config to a separate file, support BranchConfig.username(). |
54 |
)
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
55 |
from .errors import ( |
|
0.200.472
by Jelmer Vernooij
Fix printing error when user attempts to push into git. |
56 |
NoPushSupport, |
|
0.200.278
by Jelmer Vernooij
Update branch head appropriately during dpull. |
57 |
NoSuchRef, |
58 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
59 |
from .refs import ( |
|
0.200.1061
by Jelmer Vernooij
Add support for using unpeel map. |
60 |
is_tag, |
|
0.200.872
by Jelmer Vernooij
Move refs code to separate module. |
61 |
ref_to_branch_name, |
|
0.200.1061
by Jelmer Vernooij
Add support for using unpeel map. |
62 |
ref_to_tag_name, |
|
0.200.875
by Jelmer Vernooij
Use new tag_name_to_ref function. |
63 |
tag_name_to_ref, |
|
0.200.1292
by Jelmer Vernooij
Fix repeeling objects when determining what to send. |
64 |
)
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
65 |
from .unpeel_map import ( |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
66 |
UnpeelMap, |
|
0.200.872
by Jelmer Vernooij
Move refs code to separate module. |
67 |
)
|
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
68 |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
69 |
from ...foreign import ForeignBranch |
|
0.200.388
by Jelmer Vernooij
Support bzr 1.14 as well. |
70 |
|
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
71 |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
72 |
class GitPullResult(branch.PullResult): |
|
0.200.956
by Jelmer Vernooij
Add some more format tests. |
73 |
"""Result of a pull from a Git branch.""" |
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
74 |
|
75 |
def _lookup_revno(self, revid): |
|
76 |
assert isinstance(revid, str), "was %r" % revid |
|
77 |
# Try in source branch first, it'll be faster
|
|
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
78 |
with self.target_branch.lock_read(): |
|
0.200.1362
by Jelmer Vernooij
Add locking. |
79 |
return self.target_branch.revision_id_to_revno(revid) |
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
80 |
|
81 |
@property
|
|
82 |
def old_revno(self): |
|
83 |
return self._lookup_revno(self.old_revid) |
|
84 |
||
85 |
@property
|
|
86 |
def new_revno(self): |
|
87 |
return self._lookup_revno(self.new_revid) |
|
88 |
||
89 |
||
|
0.200.1064
by Jelmer Vernooij
Use common base class for tags. |
90 |
class GitTags(tag.BasicTags): |
91 |
"""Ref-based tag dictionary.""" |
|
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
92 |
|
|
0.200.89
by Jelmer Vernooij
Support sprouting branches. |
93 |
def __init__(self, branch): |
94 |
self.branch = branch |
|
95 |
self.repository = branch.repository |
|
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
96 |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
97 |
def get_refs_container(self): |
98 |
raise NotImplementedError(self.get_refs_container) |
|
|
0.200.1066
by Jelmer Vernooij
Add GitTags.get_refs. |
99 |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
100 |
def _iter_tag_refs(self, refs): |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
101 |
"""Iterate over the tag refs. |
102 |
||
103 |
:param refs: Refs dictionary (name -> git sha1)
|
|
104 |
:return: iterator over (name, peeled_sha1, unpeeled_sha1, bzr_revid)
|
|
105 |
"""
|
|
106 |
for k, unpeeled in refs.as_dict().iteritems(): |
|
107 |
try: |
|
108 |
tag_name = ref_to_tag_name(k) |
|
109 |
except (ValueError, UnicodeDecodeError): |
|
110 |
continue
|
|
111 |
peeled = refs.get_peeled(k) |
|
112 |
if peeled is None: |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
113 |
peeled = self.repository.controldir._git.object_store.peel_sha(unpeeled).id |
|
0.200.1580
by Jelmer Vernooij
Add assertion. |
114 |
assert type(tag_name) is unicode |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
115 |
yield (tag_name, peeled, unpeeled, |
116 |
self.branch.lookup_foreign_revision_id(peeled)) |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
117 |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
118 |
def _merge_to_remote_git(self, target_repo, new_refs, overwrite=False): |
119 |
updates = {} |
|
120 |
conflicts = [] |
|
121 |
def get_changed_refs(old_refs): |
|
122 |
ret = dict(old_refs) |
|
123 |
for k, v in new_refs.iteritems(): |
|
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
124 |
if not is_tag(k): |
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
125 |
continue
|
126 |
name = ref_to_tag_name(k) |
|
127 |
if old_refs.get(k) == v: |
|
128 |
pass
|
|
129 |
elif overwrite or not k in old_refs: |
|
130 |
ret[k] = v |
|
131 |
updates[name] = target_repo.lookup_foreign_revision_id(v) |
|
132 |
else: |
|
133 |
conflicts.append((name, v, old_refs[k])) |
|
134 |
return ret |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
135 |
target_repo.controldir.send_pack(get_changed_refs, lambda have, want: []) |
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
136 |
return updates, conflicts |
137 |
||
138 |
def _merge_to_local_git(self, target_repo, refs, overwrite=False): |
|
139 |
conflicts = [] |
|
140 |
updates = {} |
|
|
0.200.1489
by Jelmer Vernooij
More fixes to peel handling. |
141 |
for k, unpeeled in refs.as_dict().iteritems(): |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
142 |
if not is_tag(k): |
143 |
continue
|
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
144 |
name = ref_to_tag_name(k) |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
145 |
peeled = self.repository.controldir.get_peeled(k) |
|
0.200.1489
by Jelmer Vernooij
More fixes to peel handling. |
146 |
if target_repo._git.refs.get(k) == unpeeled: |
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
147 |
pass
|
148 |
elif overwrite or not k in target_repo._git.refs: |
|
|
0.200.1460
by Jelmer Vernooij
Improve pulling into local git branches. |
149 |
target_repo._git.refs[k] = unpeeled or peeled |
150 |
updates[name] = target_repo.lookup_foreign_revision_id(peeled) |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
151 |
else: |
|
0.200.1493
by Jelmer Vernooij
Test fixes. |
152 |
conflicts.append((name, peeled, target_repo._git.refs[k])) |
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
153 |
return updates, conflicts |
154 |
||
155 |
def _merge_to_git(self, to_tags, refs, overwrite=False): |
|
156 |
target_repo = to_tags.repository |
|
157 |
if self.repository.has_same_location(target_repo): |
|
158 |
return {}, [] |
|
159 |
if getattr(target_repo, "_git", None): |
|
160 |
return self._merge_to_local_git(target_repo, refs, overwrite) |
|
161 |
else: |
|
162 |
return self._merge_to_remote_git(target_repo, refs, overwrite) |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
163 |
|
164 |
def _merge_to_non_git(self, to_tags, refs, overwrite=False): |
|
165 |
unpeeled_map = defaultdict(set) |
|
166 |
conflicts = [] |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
167 |
updates = {} |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
168 |
result = dict(to_tags.get_tag_dict()) |
169 |
for n, peeled, unpeeled, bzr_revid in self._iter_tag_refs(refs): |
|
170 |
if unpeeled is not None: |
|
171 |
unpeeled_map[peeled].add(unpeeled) |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
172 |
if result.get(n) == bzr_revid: |
173 |
pass
|
|
174 |
elif n not in result or overwrite: |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
175 |
result[n] = bzr_revid |
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
176 |
updates[n] = bzr_revid |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
177 |
else: |
|
0.200.1707
by Jelmer Vernooij
Fix test. |
178 |
conflicts.append((n, bzr_revid, result[n])) |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
179 |
to_tags._set_tag_dict(result) |
180 |
if len(unpeeled_map) > 0: |
|
181 |
map_file = UnpeelMap.from_repository(to_tags.branch.repository) |
|
182 |
map_file.update(unpeeled_map) |
|
183 |
map_file.save_in_repository(to_tags.branch.repository) |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
184 |
return updates, conflicts |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
185 |
|
186 |
def merge_to(self, to_tags, overwrite=False, ignore_master=False, |
|
187 |
source_refs=None): |
|
|
0.200.1113
by Jelmer Vernooij
Fix Tags.merge_to. |
188 |
"""See Tags.merge_to.""" |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
189 |
if source_refs is None: |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
190 |
source_refs = self.get_refs_container() |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
191 |
if self == to_tags: |
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
192 |
return {}, [] |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
193 |
if isinstance(to_tags, GitTags): |
194 |
return self._merge_to_git(to_tags, source_refs, |
|
195 |
overwrite=overwrite) |
|
196 |
else: |
|
197 |
if ignore_master: |
|
198 |
master = None |
|
199 |
else: |
|
200 |
master = to_tags.branch.get_master_branch() |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
201 |
updates, conflicts = self._merge_to_non_git(to_tags, source_refs, |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
202 |
overwrite=overwrite) |
203 |
if master is not None: |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
204 |
extra_updates, extra_conflicts = self.merge_to( |
205 |
master.tags, overwrite=overwrite, |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
206 |
source_refs=source_refs, |
207 |
ignore_master=ignore_master) |
|
|
0.200.1396
by Jelmer Vernooij
Support updating tags in remote branches during pull. |
208 |
updates.update(extra_updates) |
209 |
conflicts += extra_conflicts |
|
210 |
return updates, conflicts |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
211 |
|
212 |
def get_tag_dict(self): |
|
213 |
ret = {} |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
214 |
refs = self.get_refs_container() |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
215 |
for (name, peeled, unpeeled, bzr_revid) in self._iter_tag_refs(refs): |
216 |
ret[name] = bzr_revid |
|
217 |
return ret |
|
218 |
||
|
0.200.1064
by Jelmer Vernooij
Use common base class for tags. |
219 |
|
220 |
class LocalGitTagDict(GitTags): |
|
221 |
"""Dictionary with tags in a local repository.""" |
|
222 |
||
223 |
def __init__(self, branch): |
|
224 |
super(LocalGitTagDict, self).__init__(branch) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
225 |
self.refs = self.repository.controldir._git.refs |
|
0.200.1064
by Jelmer Vernooij
Use common base class for tags. |
226 |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
227 |
def get_refs_container(self): |
228 |
return self.refs |
|
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
229 |
|
|
0.200.711
by Jelmer Vernooij
Support merging tags to a local Git repository. |
230 |
def _set_tag_dict(self, to_dict): |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
231 |
extra = set(self.refs.allkeys()) |
|
0.200.711
by Jelmer Vernooij
Support merging tags to a local Git repository. |
232 |
for k, revid in to_dict.iteritems(): |
|
0.200.875
by Jelmer Vernooij
Use new tag_name_to_ref function. |
233 |
name = tag_name_to_ref(k) |
|
0.200.711
by Jelmer Vernooij
Support merging tags to a local Git repository. |
234 |
if name in extra: |
235 |
extra.remove(name) |
|
236 |
self.set_tag(k, revid) |
|
237 |
for name in extra: |
|
|
0.200.1061
by Jelmer Vernooij
Add support for using unpeel map. |
238 |
if is_tag(name): |
|
0.200.711
by Jelmer Vernooij
Support merging tags to a local Git repository. |
239 |
del self.repository._git[name] |
|
0.200.956
by Jelmer Vernooij
Add some more format tests. |
240 |
|
|
0.200.86
by Jelmer Vernooij
Clearer error when setting tags. |
241 |
def set_tag(self, name, revid): |
|
0.200.1369
by Jelmer Vernooij
Clarify that ghost tags are not supported. |
242 |
try: |
243 |
git_sha, mapping = self.branch.lookup_bzr_revision_id(revid) |
|
244 |
except errors.NoSuchRevision: |
|
245 |
raise errors.GhostTagsNotSupported(self) |
|
246 |
self.refs[tag_name_to_ref(name)] = git_sha |
|
|
0.200.86
by Jelmer Vernooij
Clearer error when setting tags. |
247 |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
248 |
|
|
0.200.1078
by Jelmer Vernooij
Fix git-import from remote repositories. |
249 |
class DictTagDict(tag.BasicTags): |
|
0.239.1
by Jelmer Vernooij
Avoid re-connecting to fetch tags we already know. |
250 |
|
251 |
def __init__(self, branch, tags): |
|
252 |
super(DictTagDict, self).__init__(branch) |
|
253 |
self._tags = tags |
|
254 |
||
255 |
def get_tag_dict(self): |
|
256 |
return self._tags |
|
257 |
||
258 |
||
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
259 |
class GitSymrefBranchFormat(branch.BranchFormat): |
260 |
||
261 |
def get_format_description(self): |
|
262 |
return 'Git Symbolic Reference Branch' |
|
263 |
||
264 |
def network_name(self): |
|
265 |
return "git" |
|
266 |
||
267 |
def get_reference(self, controldir, name=None): |
|
268 |
return controldir.get_branch_reference(name) |
|
269 |
||
270 |
def set_reference(self, controldir, name, target): |
|
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
271 |
return controldir.set_branch_reference(target, name) |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
272 |
|
273 |
||
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
274 |
class GitBranchFormat(branch.BranchFormat): |
275 |
||
|
0.200.70
by Jelmer Vernooij
Implement GitBranchFormat.get_format_description. |
276 |
def get_format_description(self): |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
277 |
return 'Git Branch' |
278 |
||
|
0.243.1
by Jelmer Vernooij
Use foreign branch testing infrastructure. |
279 |
def network_name(self): |
280 |
return "git" |
|
281 |
||
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
282 |
def supports_tags(self): |
283 |
return True |
|
284 |
||
|
0.200.1105
by Jelmer Vernooij
Don't claim to support leaving locks. |
285 |
def supports_leaving_lock(self): |
286 |
return False |
|
287 |
||
|
0.200.1369
by Jelmer Vernooij
Clarify that ghost tags are not supported. |
288 |
def supports_tags_referencing_ghosts(self): |
289 |
return False |
|
290 |
||
291 |
def tags_are_versioned(self): |
|
292 |
return False |
|
293 |
||
|
0.200.1091
by Jelmer Vernooij
Provide _matchingbzrdir for testing. |
294 |
@property
|
|
0.200.1665
by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir. |
295 |
def _matchingcontroldir(self): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
296 |
from .dir import LocalGitControlDirFormat |
|
0.200.1091
by Jelmer Vernooij
Provide _matchingbzrdir for testing. |
297 |
return LocalGitControlDirFormat() |
298 |
||
|
0.243.1
by Jelmer Vernooij
Use foreign branch testing infrastructure. |
299 |
def get_foreign_tests_branch_factory(self): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
300 |
from .tests.test_branch import ForeignTestsBranchFactory |
|
0.243.1
by Jelmer Vernooij
Use foreign branch testing infrastructure. |
301 |
return ForeignTestsBranchFactory() |
302 |
||
|
0.200.246
by Jelmer Vernooij
Cope with API changes in 1.13. |
303 |
def make_tags(self, branch): |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
304 |
try: |
305 |
return branch.tags |
|
306 |
except AttributeError: |
|
307 |
pass
|
|
|
0.200.1433
by Jelmer Vernooij
Fix fetching between git repositories. |
308 |
if getattr(branch.repository, "_git", None) is None: |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
309 |
from .remote import RemoteGitTagDict |
|
0.228.3
by Jelmer Vernooij
Fix tags when fetching from remotes. |
310 |
return RemoteGitTagDict(branch) |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
311 |
else: |
312 |
return LocalGitTagDict(branch) |
|
|
0.200.246
by Jelmer Vernooij
Cope with API changes in 1.13. |
313 |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
314 |
def initialize(self, a_controldir, name=None, repository=None, |
|
0.200.1378
by Jelmer Vernooij
Fix branch. |
315 |
append_revisions_only=None): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
316 |
from .dir import LocalGitDir |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
317 |
if not isinstance(a_controldir, LocalGitDir): |
318 |
raise errors.IncompatibleFormat(self, a_controldir._format) |
|
319 |
return a_controldir.create_branch(repository=repository, name=name, |
|
|
0.200.1378
by Jelmer Vernooij
Fix branch. |
320 |
append_revisions_only=append_revisions_only) |
|
0.200.1097
by Jelmer Vernooij
Implement GitBranchFormat.initialize. |
321 |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
322 |
|
|
0.200.388
by Jelmer Vernooij
Support bzr 1.14 as well. |
323 |
class GitBranch(ForeignBranch): |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
324 |
"""An adapter to git repositories for bzr Branch objects.""" |
325 |
||
|
0.200.1129
by Jelmer Vernooij
Implement GitBranch.control_transport. |
326 |
@property
|
327 |
def control_transport(self): |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
328 |
return self.controldir.control_transport |
|
0.200.1129
by Jelmer Vernooij
Implement GitBranch.control_transport. |
329 |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
330 |
def __init__(self, controldir, repository, ref): |
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
331 |
self.repository = repository |
|
0.200.246
by Jelmer Vernooij
Cope with API changes in 1.13. |
332 |
self._format = GitBranchFormat() |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
333 |
self.controldir = controldir |
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
334 |
self._lock_mode = None |
335 |
self._lock_count = 0 |
|
|
0.231.1
by Jelmer Vernooij
Check that regenerated objects have the expected sha1. |
336 |
super(GitBranch, self).__init__(repository.get_mapping()) |
|
0.200.770
by Jelmer Vernooij
Proper branch names. |
337 |
self.ref = ref |
|
0.200.1708
by Jelmer Vernooij
Fix to colocated branch tests. |
338 |
self._head = None |
|
0.200.1361
by Jelmer Vernooij
Support branches where the ref can't be mapped back to a branch name. |
339 |
try: |
340 |
self.name = ref_to_branch_name(ref) |
|
341 |
except ValueError: |
|
342 |
self.name = None |
|
|
0.200.1708
by Jelmer Vernooij
Fix to colocated branch tests. |
343 |
if self.ref is not None: |
344 |
self.user_transport.set_segment_parameter( |
|
345 |
"ref", urlutils.escape(self.ref)) |
|
346 |
else: |
|
347 |
if self.name != "": |
|
348 |
self.user_transport.set_segment_parameter( |
|
349 |
"branch", urlutils.escape(self.name)) |
|
350 |
self.base = self.user_transport.base |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
351 |
|
|
0.200.1360
by Jelmer Vernooij
Support lighweight argument to _get_checkout_format. |
352 |
def _get_checkout_format(self, lightweight=False): |
|
0.239.8
by Jelmer Vernooij
Support checkouts. |
353 |
"""Return the most suitable metadir for a checkout of this branch. |
354 |
Weaves are used if this branch's repository uses weaves.
|
|
355 |
"""
|
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
356 |
return controldir.format_registry.make_controldir("default") |
|
0.239.8
by Jelmer Vernooij
Support checkouts. |
357 |
|
|
0.238.3
by Jelmer Vernooij
Remove svn references, prefer git send format when submitting changes against a git branch. |
358 |
def get_child_submit_format(self): |
359 |
"""Return the preferred format of submissions to this branch.""" |
|
|
0.200.1584
by Jelmer Vernooij
Use config stacks in a few more places. |
360 |
ret = self.get_config_stack().get("child_submit_format") |
|
0.238.3
by Jelmer Vernooij
Remove svn references, prefer git send format when submitting changes against a git branch. |
361 |
if ret is not None: |
362 |
return ret |
|
363 |
return "git" |
|
364 |
||
|
0.200.1397
by Jelmer Vernooij
Fix use of get_config() for RemoteGitBranch. |
365 |
def get_config(self): |
366 |
return GitBranchConfig(self) |
|
367 |
||
|
0.200.1472
by Jelmer Vernooij
Provide basic implementation of Branch.get_config_stack. |
368 |
def get_config_stack(self): |
369 |
return GitBranchStack(self) |
|
370 |
||
|
0.200.293
by Jelmer Vernooij
Fix branch nicks. |
371 |
def _get_nick(self, local=False, possible_master_transports=None): |
372 |
"""Find the nick name for this branch. |
|
373 |
||
374 |
:return: Branch nick
|
|
375 |
"""
|
|
|
0.200.1547
by Jelmer Vernooij
Support setting branch nicks. |
376 |
cs = self.repository._git.get_config_stack() |
377 |
try: |
|
|
0.200.1694
by Jelmer Vernooij
Fix nick test. |
378 |
return cs.get((b"branch", self.name.encode('utf-8')), b"nick").decode("utf-8") |
|
0.200.1547
by Jelmer Vernooij
Support setting branch nicks. |
379 |
except KeyError: |
380 |
pass
|
|
|
0.200.1694
by Jelmer Vernooij
Fix nick test. |
381 |
return self.name or u"HEAD" |
|
0.200.293
by Jelmer Vernooij
Fix branch nicks. |
382 |
|
|
0.200.331
by Jelmer Vernooij
Add stub for setting nick function. |
383 |
def _set_nick(self, nick): |
|
0.200.1547
by Jelmer Vernooij
Support setting branch nicks. |
384 |
cf = self.repository._git.get_config() |
|
0.200.1694
by Jelmer Vernooij
Fix nick test. |
385 |
cf.set((b"branch", self.name.encode('utf-8')), b"nick", nick.encode("utf-8")) |
|
0.200.1547
by Jelmer Vernooij
Support setting branch nicks. |
386 |
f = StringIO() |
387 |
cf.write_to_file(f) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
388 |
self.controldir.control_transport.put_bytes('config', f.getvalue()) |
|
0.200.331
by Jelmer Vernooij
Add stub for setting nick function. |
389 |
|
390 |
nick = property(_get_nick, _set_nick) |
|
|
0.200.293
by Jelmer Vernooij
Fix branch nicks. |
391 |
|
|
0.200.412
by Jelmer Vernooij
Implement GitBranch.__repr__. |
392 |
def __repr__(self): |
|
0.200.770
by Jelmer Vernooij
Proper branch names. |
393 |
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base, |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
394 |
self.name) |
|
0.200.412
by Jelmer Vernooij
Implement GitBranch.__repr__. |
395 |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
396 |
def generate_revision_history(self, revid, old_revid=None): |
|
0.200.1103
by Jelmer Vernooij
Support generate_revision_history(NULL_REVISION). |
397 |
if revid == NULL_REVISION: |
398 |
newhead = ZERO_SHA |
|
399 |
else: |
|
400 |
# FIXME: Check that old_revid is in the ancestry of revid
|
|
|
0.200.1324
by Jelmer Vernooij
More work on roundtripping support. |
401 |
newhead, self.mapping = self.repository.lookup_bzr_revision_id(revid) |
|
0.200.1218
by Jelmer Vernooij
Support set_last_revision('null:'). |
402 |
if self.mapping is None: |
403 |
raise AssertionError |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
404 |
self._set_head(newhead) |
405 |
||
|
0.200.1199
by Jelmer Vernooij
Support 'token' argument to Branch.lock_write. |
406 |
def lock_write(self, token=None): |
407 |
if token is not None: |
|
408 |
raise errors.TokenLockingNotSupported(self) |
|
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
409 |
if self._lock_mode: |
|
0.200.1369
by Jelmer Vernooij
Clarify that ghost tags are not supported. |
410 |
if self._lock_mode == 'r': |
411 |
raise errors.ReadOnlyError(self) |
|
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
412 |
self._lock_count += 1 |
413 |
else: |
|
414 |
self._lock_mode = 'w' |
|
415 |
self._lock_count = 1 |
|
416 |
self.repository.lock_write() |
|
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
417 |
return lock.LogicalLockResult(self.unlock) |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
418 |
|
|
0.200.1453
by Jelmer Vernooij
Provide Branch.leave_lock_in_place and Branch.dont_leave_lock_in_place. |
419 |
def leave_lock_in_place(self): |
420 |
raise NotImplementedError(self.leave_lock_in_place) |
|
421 |
||
422 |
def dont_leave_lock_in_place(self): |
|
423 |
raise NotImplementedError(self.dont_leave_lock_in_place) |
|
424 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
425 |
def get_stacked_on_url(self): |
426 |
# Git doesn't do stacking (yet...)
|
|
|
0.200.1660
by Jelmer Vernooij
Fix imports. |
427 |
raise branch.UnstackableBranchFormat(self._format, self.base) |
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
428 |
|
429 |
def get_parent(self): |
|
430 |
"""See Branch.get_parent().""" |
|
|
0.200.312
by Jelmer Vernooij
Add notes about parent locations. |
431 |
# FIXME: Set "origin" url from .git/config ?
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
432 |
return None |
433 |
||
|
0.200.175
by Jelmer Vernooij
Add optimized handling when fetching from git to git. |
434 |
def set_parent(self, url): |
|
0.200.312
by Jelmer Vernooij
Add notes about parent locations. |
435 |
# FIXME: Set "origin" url in .git/config ?
|
|
0.200.175
by Jelmer Vernooij
Add optimized handling when fetching from git to git. |
436 |
pass
|
437 |
||
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
438 |
def break_lock(self): |
439 |
raise NotImplementedError(self.break_lock) |
|
440 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
441 |
def lock_read(self): |
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
442 |
if self._lock_mode: |
443 |
assert self._lock_mode in ('r', 'w') |
|
444 |
self._lock_count += 1 |
|
445 |
else: |
|
446 |
self._lock_mode = 'r' |
|
447 |
self._lock_count = 1 |
|
448 |
self.repository.lock_read() |
|
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
449 |
return lock.LogicalLockResult(self.unlock) |
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
450 |
|
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
451 |
def peek_lock_mode(self): |
452 |
return self._lock_mode |
|
453 |
||
|
0.200.432
by Jelmer Vernooij
Support Branch.is_locked, required for loggerhead. |
454 |
def is_locked(self): |
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
455 |
return (self._lock_mode is not None) |
|
0.200.432
by Jelmer Vernooij
Support Branch.is_locked, required for loggerhead. |
456 |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
457 |
def unlock(self): |
|
0.200.1250
by Jelmer Vernooij
Simplify lock handling. |
458 |
"""See Branch.unlock().""" |
459 |
self._lock_count -= 1 |
|
460 |
if self._lock_count == 0: |
|
461 |
self._lock_mode = None |
|
462 |
self._clear_cached_state() |
|
463 |
self.repository.unlock() |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
464 |
|
465 |
def get_physical_lock_status(self): |
|
466 |
return False |
|
467 |
||
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
468 |
def last_revision(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
469 |
with self.lock_read(): |
470 |
# perhaps should escape this ?
|
|
471 |
if self.head is None: |
|
472 |
return revision.NULL_REVISION |
|
473 |
return self.lookup_foreign_revision_id(self.head) |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
474 |
|
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
475 |
def _basic_push(self, target, overwrite=False, stop_revision=None): |
476 |
return branch.InterBranch.get(self, target)._basic_push( |
|
477 |
overwrite, stop_revision) |
|
478 |
||
|
0.252.49
by Jelmer Vernooij
Avoid trying to set HEAD for remote branches. |
479 |
def lookup_foreign_revision_id(self, foreign_revid): |
|
0.200.956
by Jelmer Vernooij
Add some more format tests. |
480 |
return self.repository.lookup_foreign_revision_id(foreign_revid, |
|
0.252.49
by Jelmer Vernooij
Avoid trying to set HEAD for remote branches. |
481 |
self.mapping) |
482 |
||
|
0.200.1030
by Jelmer Vernooij
More work on supporting roundtripping push. |
483 |
def lookup_bzr_revision_id(self, revid): |
484 |
return self.repository.lookup_bzr_revision_id( |
|
485 |
revid, mapping=self.mapping) |
|
486 |
||
|
0.200.1678
by Jelmer Vernooij
Fix tests. |
487 |
def get_unshelver(self, tree): |
488 |
raise errors.StoringUncommittedNotSupported(self) |
|
489 |
||
|
0.200.692
by Jelmer Vernooij
Refuse pulling into non-rich-root branches rather than erroring out with an AttributeError. |
490 |
|
|
0.200.465
by Jelmer Vernooij
Use dulwich standard functionality for finding missing revisions. |
491 |
class LocalGitBranch(GitBranch): |
492 |
"""A local Git branch.""" |
|
493 |
||
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
494 |
def __init__(self, controldir, repository, ref): |
495 |
super(LocalGitBranch, self).__init__(controldir, repository, ref) |
|
496 |
refs = controldir.get_refs_container() |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
497 |
if not (ref in refs or "HEAD" in refs): |
|
0.200.763
by Jelmer Vernooij
Provide proper colocated branch support. |
498 |
raise errors.NotBranchError(self.base) |
499 |
||
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
500 |
def create_checkout(self, to_location, revision_id=None, lightweight=False, |
501 |
accelerator_tree=None, hardlink=False): |
|
|
0.200.210
by Jelmer Vernooij
properly error out about not support lightweight checkouts. |
502 |
if lightweight: |
|
0.230.1
by Jelmer Vernooij
Support lightweight checkouts. |
503 |
t = transport.get_transport(to_location) |
504 |
t.ensure_base() |
|
|
0.200.1360
by Jelmer Vernooij
Support lighweight argument to _get_checkout_format. |
505 |
format = self._get_checkout_format(lightweight=True) |
|
0.230.1
by Jelmer Vernooij
Support lightweight checkouts. |
506 |
checkout = format.initialize_on_transport(t) |
|
0.200.1662
by Jelmer Vernooij
Fix import. |
507 |
from breezy.bzr.branch import BranchReferenceFormat |
|
0.200.1695
by Jelmer Vernooij
Fix initialization of lightweight checkouts. |
508 |
from_branch = BranchReferenceFormat().initialize( |
509 |
checkout, target_branch=self) |
|
|
0.230.1
by Jelmer Vernooij
Support lightweight checkouts. |
510 |
tree = checkout.create_workingtree(revision_id, |
511 |
from_branch=from_branch, hardlink=hardlink) |
|
512 |
return tree |
|
513 |
else: |
|
514 |
return self._create_heavyweight_checkout(to_location, revision_id, |
|
|
0.257.1
by Jelmer Vernooij
use transport repo objects even for local access. |
515 |
hardlink) |
|
0.200.210
by Jelmer Vernooij
properly error out about not support lightweight checkouts. |
516 |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
517 |
def _create_heavyweight_checkout(self, to_location, revision_id=None, |
|
0.200.210
by Jelmer Vernooij
properly error out about not support lightweight checkouts. |
518 |
hardlink=False): |
519 |
"""Create a new heavyweight checkout of this branch. |
|
520 |
||
521 |
:param to_location: URL of location to create the new checkout in.
|
|
522 |
:param revision_id: Revision that should be the tip of the checkout.
|
|
523 |
:param hardlink: Whether to hardlink
|
|
524 |
:return: WorkingTree object of checkout.
|
|
525 |
"""
|
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
526 |
checkout_branch = controldir.ControlDir.create_branch_convenience( |
|
0.200.1360
by Jelmer Vernooij
Support lighweight argument to _get_checkout_format. |
527 |
to_location, force_new_tree=False, |
528 |
format=self._get_checkout_format(lightweight=False)) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
529 |
checkout = checkout_branch.controldir |
|
0.200.210
by Jelmer Vernooij
properly error out about not support lightweight checkouts. |
530 |
checkout_branch.bind(self) |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
531 |
# pull up to the specified revision_id to set the initial
|
|
0.200.210
by Jelmer Vernooij
properly error out about not support lightweight checkouts. |
532 |
# branch tip correctly, and seed it with history.
|
533 |
checkout_branch.pull(self, stop_revision=revision_id) |
|
534 |
return checkout.create_workingtree(revision_id, hardlink=hardlink) |
|
535 |
||
|
0.200.1493
by Jelmer Vernooij
Test fixes. |
536 |
def fetch(self, from_branch, last_revision=None, limit=None): |
537 |
return branch.InterBranch.get(from_branch, self).fetch( |
|
538 |
stop_revision=last_revision, limit=limit) |
|
539 |
||
|
0.200.57
by Jelmer Vernooij
Fix more tests. |
540 |
def _gen_revision_history(self): |
|
0.200.58
by Jelmer Vernooij
Fix remaining tests. |
541 |
if self.head is None: |
542 |
return [] |
|
|
0.200.1279
by Jelmer Vernooij
Avoid using deprecated Repository.iter_reverse_revision_history. |
543 |
graph = self.repository.get_graph() |
544 |
ret = list(graph.iter_lefthand_ancestry(self.last_revision(), |
|
545 |
(revision.NULL_REVISION, ))) |
|
|
0.200.59
by Jelmer Vernooij
Add more tests, fix revision history. |
546 |
ret.reverse() |
|
0.200.57
by Jelmer Vernooij
Fix more tests. |
547 |
return ret |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
548 |
|
|
0.200.461
by Jelmer Vernooij
Reduce number of round trips when fetching from Git. |
549 |
def _get_head(self): |
|
0.200.480
by Jelmer Vernooij
Cope with API changes in Dulwich. |
550 |
try: |
|
0.280.1
by Martin Pitt
Fix deprecated Repo.ref(), to make testsuite succeed again. |
551 |
return self.repository._git.refs[self.ref or "HEAD"] |
|
0.200.480
by Jelmer Vernooij
Cope with API changes in Dulwich. |
552 |
except KeyError: |
553 |
return None |
|
|
0.200.461
by Jelmer Vernooij
Reduce number of round trips when fetching from Git. |
554 |
|
|
0.200.1228
by Jelmer Vernooij
Provide Branch._read_last_revision_info. |
555 |
def _read_last_revision_info(self): |
556 |
last_revid = self.last_revision() |
|
557 |
graph = self.repository.get_graph() |
|
558 |
revno = graph.find_distance_to_null(last_revid, |
|
559 |
[(revision.NULL_REVISION, 0)]) |
|
560 |
return revno, last_revid |
|
561 |
||
562 |
def set_last_revision_info(self, revno, revision_id): |
|
563 |
self.set_last_revision(revision_id) |
|
564 |
self._last_revision_info_cache = revno, revision_id |
|
|
0.200.507
by Jelmer Vernooij
Implement set_last_revision{_info,}. |
565 |
|
566 |
def set_last_revision(self, revid): |
|
|
0.200.1233
by Jelmer Vernooij
Implement Repository.iter_files_bytes. |
567 |
if not revid or not isinstance(revid, basestring): |
568 |
raise errors.InvalidRevisionId(revision_id=revid, branch=self) |
|
|
0.200.1218
by Jelmer Vernooij
Support set_last_revision('null:'). |
569 |
if revid == NULL_REVISION: |
570 |
newhead = ZERO_SHA |
|
571 |
else: |
|
572 |
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(revid) |
|
573 |
if self.mapping is None: |
|
574 |
raise AssertionError |
|
575 |
self._set_head(newhead) |
|
|
0.200.507
by Jelmer Vernooij
Implement set_last_revision{_info,}. |
576 |
|
|
0.200.461
by Jelmer Vernooij
Reduce number of round trips when fetching from Git. |
577 |
def _set_head(self, value): |
578 |
self._head = value |
|
|
0.200.918
by Jelmer Vernooij
Cope with 'self.ref is None' in a couple more places. |
579 |
self.repository._git.refs[self.ref or "HEAD"] = self._head |
|
0.200.461
by Jelmer Vernooij
Reduce number of round trips when fetching from Git. |
580 |
self._clear_cached_state() |
581 |
||
582 |
head = property(_get_head, _set_head) |
|
583 |
||
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
584 |
def get_push_location(self): |
585 |
"""See Branch.get_push_location.""" |
|
|
0.200.1584
by Jelmer Vernooij
Use config stacks in a few more places. |
586 |
push_loc = self.get_config_stack().get('push_location') |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
587 |
return push_loc |
588 |
||
589 |
def set_push_location(self, location): |
|
590 |
"""See Branch.set_push_location.""" |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
591 |
self.get_config().set_user_option('push_location', location, |
|
0.217.54
by John Carr
set_user_option breaks - doesnt have a local option in BranchConfig. Follow the bzr.dev syntax instead. |
592 |
store=config.STORE_LOCATION) |
|
0.200.43
by David Allouche
Ultra-experimental support for "bzr pull". No test. No sanity. |
593 |
|
594 |
def supports_tags(self): |
|
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
595 |
return True |
|
0.200.956
by Jelmer Vernooij
Add some more format tests. |
596 |
|
|
0.200.1681
by Jelmer Vernooij
Provide Branch.store_uncommitted. |
597 |
def store_uncommitted(self, creator): |
598 |
raise errors.StoringUncommittedNotSupported(self) |
|
599 |
||
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
600 |
|
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
601 |
def _quick_lookup_revno(local_branch, remote_branch, revid): |
602 |
assert isinstance(revid, str), "was %r" % revid |
|
603 |
# Try in source branch first, it'll be faster
|
|
|
0.200.1362
by Jelmer Vernooij
Add locking. |
604 |
local_branch.lock_read() |
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
605 |
try: |
606 |
try: |
|
|
0.200.1362
by Jelmer Vernooij
Add locking. |
607 |
return local_branch.revision_id_to_revno(revid) |
608 |
except errors.NoSuchRevision: |
|
609 |
graph = local_branch.repository.get_graph() |
|
610 |
try: |
|
611 |
return graph.find_distance_to_null(revid, |
|
612 |
[(revision.NULL_REVISION, 0)]) |
|
613 |
except errors.GhostRevisionsHaveNoRevno: |
|
614 |
# FIXME: Check using graph.find_distance_to_null() ?
|
|
615 |
remote_branch.lock_read() |
|
616 |
try: |
|
617 |
return remote_branch.revision_id_to_revno(revid) |
|
618 |
finally: |
|
619 |
remote_branch.unlock() |
|
620 |
finally: |
|
621 |
local_branch.unlock() |
|
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
622 |
|
623 |
||
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
624 |
class GitBranchPullResult(branch.PullResult): |
625 |
||
|
0.252.36
by Jelmer Vernooij
Fix pull. |
626 |
def __init__(self): |
627 |
super(GitBranchPullResult, self).__init__() |
|
628 |
self.new_git_head = None |
|
629 |
self._old_revno = None |
|
630 |
self._new_revno = None |
|
631 |
||
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
632 |
def report(self, to_file): |
633 |
if not is_quiet(): |
|
634 |
if self.old_revid == self.new_revid: |
|
635 |
to_file.write('No revisions to pull.\n') |
|
|
0.200.728
by Jelmer Vernooij
Fix pulling when all revisions are already in the repo. |
636 |
elif self.new_git_head is not None: |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
637 |
to_file.write('Now on revision %d (git sha: %s).\n' % |
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
638 |
(self.new_revno, self.new_git_head)) |
|
0.200.728
by Jelmer Vernooij
Fix pulling when all revisions are already in the repo. |
639 |
else: |
640 |
to_file.write('Now on revision %d.\n' % (self.new_revno,)) |
|
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
641 |
self._show_tag_conficts(to_file) |
642 |
||
|
0.252.36
by Jelmer Vernooij
Fix pull. |
643 |
def _lookup_revno(self, revid): |
|
0.200.1185
by Jelmer Vernooij
Some formatting fixes. |
644 |
return _quick_lookup_revno(self.target_branch, self.source_branch, |
|
0.200.1513
by Jelmer Vernooij
Cope with zero shas. |
645 |
revid) |
|
0.252.36
by Jelmer Vernooij
Fix pull. |
646 |
|
647 |
def _get_old_revno(self): |
|
648 |
if self._old_revno is not None: |
|
649 |
return self._old_revno |
|
650 |
return self._lookup_revno(self.old_revid) |
|
651 |
||
652 |
def _set_old_revno(self, revno): |
|
653 |
self._old_revno = revno |
|
654 |
||
655 |
old_revno = property(_get_old_revno, _set_old_revno) |
|
656 |
||
657 |
def _get_new_revno(self): |
|
658 |
if self._new_revno is not None: |
|
659 |
return self._new_revno |
|
660 |
return self._lookup_revno(self.new_revid) |
|
661 |
||
662 |
def _set_new_revno(self, revno): |
|
663 |
self._new_revno = revno |
|
|
0.200.956
by Jelmer Vernooij
Add some more format tests. |
664 |
|
|
0.252.36
by Jelmer Vernooij
Fix pull. |
665 |
new_revno = property(_get_new_revno, _set_new_revno) |
666 |
||
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
667 |
|
|
0.200.504
by Jelmer Vernooij
Lazily find revno's for git branches. |
668 |
class GitBranchPushResult(branch.BranchPushResult): |
669 |
||
670 |
def _lookup_revno(self, revid): |
|
|
0.200.1185
by Jelmer Vernooij
Some formatting fixes. |
671 |
return _quick_lookup_revno(self.source_branch, self.target_branch, |
672 |
revid) |
|
|
0.200.504
by Jelmer Vernooij
Lazily find revno's for git branches. |
673 |
|
674 |
@property
|
|
675 |
def old_revno(self): |
|
676 |
return self._lookup_revno(self.old_revid) |
|
677 |
||
678 |
@property
|
|
679 |
def new_revno(self): |
|
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
680 |
new_original_revno = getattr(self, "new_original_revno", None) |
681 |
if new_original_revno: |
|
682 |
return new_original_revno |
|
683 |
if getattr(self, "new_original_revid", None) is not None: |
|
684 |
return self._lookup_revno(self.new_original_revid) |
|
|
0.200.504
by Jelmer Vernooij
Lazily find revno's for git branches. |
685 |
return self._lookup_revno(self.new_revid) |
686 |
||
687 |
||
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
688 |
class InterFromGitBranch(branch.GenericInterBranch): |
|
0.200.261
by Jelmer Vernooij
More formatting fixes. |
689 |
"""InterBranch implementation that pulls from Git into bzr.""" |
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
690 |
|
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
691 |
@staticmethod
|
692 |
def _get_branch_formats_to_test(): |
|
|
0.200.1100
by Jelmer Vernooij
Provide test combinations for InterBranch implementations. |
693 |
try: |
694 |
default_format = branch.format_registry.get_default() |
|
695 |
except AttributeError: |
|
696 |
default_format = branch.BranchFormat._default_format |
|
697 |
return [ |
|
698 |
(GitBranchFormat(), GitBranchFormat()), |
|
699 |
(GitBranchFormat(), default_format)] |
|
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
700 |
|
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
701 |
@classmethod
|
|
0.200.692
by Jelmer Vernooij
Refuse pulling into non-rich-root branches rather than erroring out with an AttributeError. |
702 |
def _get_interrepo(self, source, target): |
|
0.200.1097
by Jelmer Vernooij
Implement GitBranchFormat.initialize. |
703 |
return _mod_repository.InterRepository.get(source.repository, target.repository) |
|
0.200.692
by Jelmer Vernooij
Refuse pulling into non-rich-root branches rather than erroring out with an AttributeError. |
704 |
|
705 |
@classmethod
|
|
706 |
def is_compatible(cls, source, target): |
|
|
0.200.1222
by Jelmer Vernooij
Better checks in is_compatible methods. |
707 |
if not isinstance(source, GitBranch): |
708 |
return False |
|
709 |
if isinstance(target, GitBranch): |
|
710 |
# InterLocalGitRemoteGitBranch or InterToGitBranch should be used
|
|
711 |
return False |
|
712 |
if getattr(cls._get_interrepo(source, target), "fetch_objects", None) is None: |
|
713 |
# fetch_objects is necessary for this to work
|
|
714 |
return False |
|
715 |
return True |
|
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
716 |
|
|
0.200.1305
by Jelmer Vernooij
Only actually fetch tags if "branch.fetch_tags" is set to true. |
717 |
def fetch(self, stop_revision=None, fetch_tags=None, limit=None): |
|
0.200.1265
by Jelmer Vernooij
Support limit option to Branch.fetch. |
718 |
self.fetch_objects(stop_revision, fetch_tags=fetch_tags, limit=limit) |
|
0.260.1
by Jelmer Vernooij
Fix fetch from remote during merge. |
719 |
|
|
0.200.1265
by Jelmer Vernooij
Support limit option to Branch.fetch. |
720 |
def fetch_objects(self, stop_revision, fetch_tags, limit=None): |
|
0.200.692
by Jelmer Vernooij
Refuse pulling into non-rich-root branches rather than erroring out with an AttributeError. |
721 |
interrepo = self._get_interrepo(self.source, self.target) |
|
0.200.1305
by Jelmer Vernooij
Only actually fetch tags if "branch.fetch_tags" is set to true. |
722 |
if fetch_tags is None: |
|
0.200.1584
by Jelmer Vernooij
Use config stacks in a few more places. |
723 |
c = self.source.get_config_stack() |
724 |
fetch_tags = c.get('branch.fetch_tags') |
|
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
725 |
def determine_wants(heads): |
|
0.200.917
by Jelmer Vernooij
Cope with implicit branches during pull. |
726 |
if self.source.ref is not None and not self.source.ref in heads: |
|
0.200.1386
by Jelmer Vernooij
Friendlier message if HEAD is not found. |
727 |
raise NoSuchRef(self.source.ref, self.source.user_url, heads.keys()) |
|
0.259.6
by Jelmer Vernooij
Fetch tags during pull. |
728 |
|
729 |
if stop_revision is None: |
|
|
0.200.917
by Jelmer Vernooij
Cope with implicit branches during pull. |
730 |
if self.source.ref is not None: |
731 |
head = heads[self.source.ref] |
|
732 |
else: |
|
733 |
head = heads["HEAD"] |
|
|
0.252.44
by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped. |
734 |
self._last_revid = self.source.lookup_foreign_revision_id(head) |
|
0.259.6
by Jelmer Vernooij
Fetch tags during pull. |
735 |
else: |
736 |
self._last_revid = stop_revision |
|
737 |
real = interrepo.get_determine_wants_revids( |
|
|
0.260.1
by Jelmer Vernooij
Fix fetch from remote during merge. |
738 |
[self._last_revid], include_tags=fetch_tags) |
|
0.259.6
by Jelmer Vernooij
Fetch tags during pull. |
739 |
return real(heads) |
|
0.200.1002
by Jelmer Vernooij
Fix regression in git-import. |
740 |
pack_hint, head, refs = interrepo.fetch_objects( |
|
0.200.1265
by Jelmer Vernooij
Support limit option to Branch.fetch. |
741 |
determine_wants, self.source.mapping, limit=limit) |
|
0.252.45
by Jelmer Vernooij
Finish fetching roundtripped revisions back into bzr. |
742 |
if (pack_hint is not None and |
743 |
self.target.repository._format.pack_compresses): |
|
|
0.248.5
by Jelmer Vernooij
Reformatting, fix dpush. |
744 |
self.target.repository.pack(hint=pack_hint) |
|
0.260.1
by Jelmer Vernooij
Fix fetch from remote during merge. |
745 |
return head, refs |
746 |
||
|
0.200.1219
by Jelmer Vernooij
Remove InterBranch.update_revisions. |
747 |
def _update_revisions(self, stop_revision=None, overwrite=False): |
|
0.200.1305
by Jelmer Vernooij
Only actually fetch tags if "branch.fetch_tags" is set to true. |
748 |
head, refs = self.fetch_objects(stop_revision, fetch_tags=None) |
|
0.200.313
by Jelmer Vernooij
Support overwrite parameter. |
749 |
if overwrite: |
|
0.200.314
by Jelmer Vernooij
Support stop_revision. |
750 |
prev_last_revid = None |
|
0.200.313
by Jelmer Vernooij
Support overwrite parameter. |
751 |
else: |
|
0.200.314
by Jelmer Vernooij
Support stop_revision. |
752 |
prev_last_revid = self.target.last_revision() |
|
0.248.5
by Jelmer Vernooij
Reformatting, fix dpush. |
753 |
self.target.generate_revision_history(self._last_revid, |
|
0.259.6
by Jelmer Vernooij
Fetch tags during pull. |
754 |
prev_last_revid, self.source) |
|
0.200.1062
by Jelmer Vernooij
Pass remote refs along in _update_revisions. |
755 |
return head, refs |
|
0.200.225
by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches. |
756 |
|
|
0.200.1423
by Jelmer Vernooij
Fix space. |
757 |
def _basic_pull(self, stop_revision, overwrite, run_hooks, |
|
0.200.1414
by Jelmer Vernooij
Fix pulling into bound branches. |
758 |
_override_hook_target, _hook_master): |
|
0.200.342
by Jelmer Vernooij
Report git sha during pull. |
759 |
result = GitBranchPullResult() |
|
0.200.338
by Jelmer Vernooij
Fix dpushing without changes necessary. |
760 |
result.source_branch = self.source |
761 |
if _override_hook_target is None: |
|
762 |
result.target_branch = self.target |
|
763 |
else: |
|
764 |
result.target_branch = _override_hook_target |
|
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
765 |
with self.target.lock_write(), self.source.lock_read(): |
766 |
# We assume that during 'pull' the target repository is closer than
|
|
767 |
# the source one.
|
|
768 |
(result.old_revno, result.old_revid) = \ |
|
769 |
self.target.last_revision_info() |
|
770 |
result.new_git_head, remote_refs = self._update_revisions( |
|
771 |
stop_revision, overwrite=overwrite) |
|
772 |
tags_ret = self.source.tags.merge_to( |
|
773 |
self.target.tags, overwrite, ignore_master=True) |
|
774 |
if isinstance(tags_ret, tuple): |
|
775 |
result.tag_updates, result.tag_conflicts = tags_ret |
|
776 |
else: |
|
777 |
result.tag_conflicts = tags_ret |
|
778 |
(result.new_revno, result.new_revid) = \ |
|
779 |
self.target.last_revision_info() |
|
780 |
if _hook_master: |
|
781 |
result.master_branch = _hook_master |
|
782 |
result.local_branch = result.target_branch |
|
783 |
else: |
|
784 |
result.master_branch = result.target_branch |
|
785 |
result.local_branch = None |
|
786 |
if run_hooks: |
|
787 |
for hook in branch.Branch.hooks['post_pull']: |
|
788 |
hook(result) |
|
789 |
return result |
|
|
0.200.1414
by Jelmer Vernooij
Fix pulling into bound branches. |
790 |
|
791 |
def pull(self, overwrite=False, stop_revision=None, |
|
792 |
possible_transports=None, _hook_master=None, run_hooks=True, |
|
793 |
_override_hook_target=None, local=False): |
|
794 |
"""See Branch.pull. |
|
795 |
||
796 |
:param _hook_master: Private parameter - set the branch to
|
|
797 |
be supplied as the master to pull hooks.
|
|
798 |
:param run_hooks: Private parameter - if false, this branch
|
|
799 |
is being called because it's the master of the primary branch,
|
|
800 |
so it should not run its hooks.
|
|
801 |
:param _override_hook_target: Private parameter - set the branch to be
|
|
802 |
supplied as the target_branch to pull hooks.
|
|
803 |
"""
|
|
804 |
# This type of branch can't be bound.
|
|
805 |
bound_location = self.target.get_bound_location() |
|
806 |
if local and not bound_location: |
|
807 |
raise errors.LocalRequiresBoundBranch() |
|
808 |
master_branch = None |
|
809 |
source_is_master = False |
|
810 |
self.source.lock_read() |
|
811 |
if bound_location: |
|
812 |
# bound_location comes from a config file, some care has to be
|
|
813 |
# taken to relate it to source.user_url
|
|
814 |
normalized = urlutils.normalize_url(bound_location) |
|
815 |
try: |
|
816 |
relpath = self.source.user_transport.relpath(normalized) |
|
817 |
source_is_master = (relpath == '') |
|
|
0.200.1660
by Jelmer Vernooij
Fix imports. |
818 |
except (errors.PathNotChild, urlutils.InvalidURL): |
|
0.200.1414
by Jelmer Vernooij
Fix pulling into bound branches. |
819 |
source_is_master = False |
820 |
if not local and bound_location and not source_is_master: |
|
821 |
# not pulling from master, so we need to update master.
|
|
822 |
master_branch = self.target.get_master_branch(possible_transports) |
|
823 |
master_branch.lock_write() |
|
824 |
try: |
|
825 |
try: |
|
826 |
if master_branch: |
|
827 |
# pull from source into master.
|
|
828 |
master_branch.pull(self.source, overwrite, stop_revision, |
|
829 |
run_hooks=False) |
|
830 |
result = self._basic_pull(stop_revision, overwrite, run_hooks, |
|
831 |
_override_hook_target, _hook_master=master_branch) |
|
832 |
finally: |
|
833 |
self.source.unlock() |
|
834 |
finally: |
|
835 |
if master_branch: |
|
836 |
master_branch.unlock() |
|
|
0.200.338
by Jelmer Vernooij
Fix dpushing without changes necessary. |
837 |
return result |
838 |
||
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
839 |
def _basic_push(self, overwrite=False, stop_revision=None): |
840 |
result = branch.BranchPushResult() |
|
841 |
result.source_branch = self.source |
|
842 |
result.target_branch = self.target |
|
843 |
result.old_revno, result.old_revid = self.target.last_revision_info() |
|
|
0.200.1219
by Jelmer Vernooij
Remove InterBranch.update_revisions. |
844 |
result.new_git_head, remote_refs = self._update_revisions( |
845 |
stop_revision, overwrite=overwrite) |
|
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
846 |
tags_ret = self.source.tags.merge_to(self.target.tags, |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
847 |
overwrite) |
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
848 |
if isinstance(tags_ret, tuple): |
849 |
(result.tag_updates, result.tag_conflicts) = tags_ret |
|
850 |
else: |
|
851 |
result.tag_conflicts = tags_ret |
|
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
852 |
result.new_revno, result.new_revid = self.target.last_revision_info() |
853 |
return result |
|
854 |
||
|
0.200.338
by Jelmer Vernooij
Fix dpushing without changes necessary. |
855 |
|
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
856 |
class InterGitBranch(branch.GenericInterBranch): |
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
857 |
"""InterBranch implementation that pulls between Git branches.""" |
858 |
||
|
0.200.1493
by Jelmer Vernooij
Test fixes. |
859 |
def fetch(self, stop_revision=None, fetch_tags=None, limit=None): |
860 |
raise NotImplementedError(self.fetch) |
|
861 |
||
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
862 |
|
|
0.200.1176
by Jelmer Vernooij
Fix fetch return value for inter git fetching. |
863 |
class InterLocalGitRemoteGitBranch(InterGitBranch): |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
864 |
"""InterBranch that copies from a local to a remote git branch.""" |
865 |
||
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
866 |
@staticmethod
|
867 |
def _get_branch_formats_to_test(): |
|
|
0.200.1100
by Jelmer Vernooij
Provide test combinations for InterBranch implementations. |
868 |
# FIXME
|
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
869 |
return [] |
870 |
||
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
871 |
@classmethod
|
872 |
def is_compatible(self, source, target): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
873 |
from .remote import RemoteGitBranch |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
874 |
return (isinstance(source, LocalGitBranch) and |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
875 |
isinstance(target, RemoteGitBranch)) |
876 |
||
877 |
def _basic_push(self, overwrite=False, stop_revision=None): |
|
878 |
result = GitBranchPushResult() |
|
879 |
result.source_branch = self.source |
|
880 |
result.target_branch = self.target |
|
881 |
if stop_revision is None: |
|
882 |
stop_revision = self.source.last_revision() |
|
883 |
# FIXME: Check for diverged branches
|
|
884 |
def get_changed_refs(old_refs): |
|
|
0.200.1300
by Jelmer Vernooij
Fix formatting. |
885 |
old_ref = old_refs.get(self.target.ref, ZERO_SHA) |
886 |
result.old_revid = self.target.lookup_foreign_revision_id(old_ref) |
|
|
0.200.822
by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush. |
887 |
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] } |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
888 |
result.new_revid = stop_revision |
889 |
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems(): |
|
|
0.200.875
by Jelmer Vernooij
Use new tag_name_to_ref function. |
890 |
refs[tag_name_to_ref(name)] = sha |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
891 |
return refs |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
892 |
self.target.repository.send_pack(get_changed_refs, |
|
0.200.726
by Jelmer Vernooij
Factor out conversion of branch names to refs. |
893 |
self.source.repository._git.object_store.generate_pack_contents) |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
894 |
return result |
895 |
||
896 |
||
|
0.200.1176
by Jelmer Vernooij
Fix fetch return value for inter git fetching. |
897 |
class InterGitLocalGitBranch(InterGitBranch): |
|
0.200.512
by Jelmer Vernooij
Support pushing git->git. |
898 |
"""InterBranch that copies from a remote to a local git branch.""" |
899 |
||
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
900 |
@staticmethod
|
901 |
def _get_branch_formats_to_test(): |
|
|
0.200.1100
by Jelmer Vernooij
Provide test combinations for InterBranch implementations. |
902 |
# FIXME
|
|
0.200.996
by Jelmer Vernooij
Fix test run of InterBranches. |
903 |
return [] |
904 |
||
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
905 |
@classmethod
|
906 |
def is_compatible(self, source, target): |
|
|
0.200.1176
by Jelmer Vernooij
Fix fetch return value for inter git fetching. |
907 |
return (isinstance(source, GitBranch) and |
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
908 |
isinstance(target, LocalGitBranch)) |
909 |
||
|
0.200.1534
by Jelmer Vernooij
Implement fetch between git branches, encode nicks. |
910 |
def fetch(self, stop_revision=None, fetch_tags=None, limit=None): |
911 |
interrepo = _mod_repository.InterRepository.get(self.source.repository, |
|
912 |
self.target.repository) |
|
913 |
if stop_revision is None: |
|
914 |
stop_revision = self.source.last_revision() |
|
915 |
determine_wants = interrepo.get_determine_wants_revids( |
|
916 |
[stop_revision], include_tags=fetch_tags) |
|
917 |
interrepo.fetch_objects(determine_wants, limit=limit) |
|
918 |
||
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
919 |
def _basic_push(self, overwrite=False, stop_revision=None): |
|
0.200.1325
by Jelmer Vernooij
More test fixes. |
920 |
result = GitBranchPushResult() |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
921 |
result.source_branch = self.source |
922 |
result.target_branch = self.target |
|
923 |
result.old_revid = self.target.last_revision() |
|
924 |
refs, stop_revision = self.update_refs(stop_revision) |
|
925 |
self.target.generate_revision_history(stop_revision, result.old_revid) |
|
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
926 |
tags_ret = self.source.tags.merge_to(self.target.tags, |
|
0.200.1065
by Jelmer Vernooij
Don't peel tags automatically when pushing back. |
927 |
source_refs=refs, overwrite=overwrite) |
|
0.200.1402
by Jelmer Vernooij
Cope with tag changes in bzr. |
928 |
if isinstance(tags_ret, tuple): |
929 |
(result.tag_updates, result.tag_conflicts) = tags_ret |
|
930 |
else: |
|
931 |
result.tag_conflicts = tags_ret |
|
|
0.200.505
by Jelmer Vernooij
Remove duplicate code. |
932 |
result.new_revid = self.target.last_revision() |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
933 |
return result |
934 |
||
935 |
def update_refs(self, stop_revision=None): |
|
|
0.200.1097
by Jelmer Vernooij
Implement GitBranchFormat.initialize. |
936 |
interrepo = _mod_repository.InterRepository.get(self.source.repository, |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
937 |
self.target.repository) |
938 |
if stop_revision is None: |
|
|
0.200.940
by Jelmer Vernooij
Avoid confusion between different fetch functions with different semantics. |
939 |
refs = interrepo.fetch(branches=["HEAD"]) |
|
0.252.44
by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped. |
940 |
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"]) |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
941 |
else: |
|
0.200.940
by Jelmer Vernooij
Avoid confusion between different fetch functions with different semantics. |
942 |
refs = interrepo.fetch(revision_id=stop_revision) |
|
0.200.501
by Jelmer Vernooij
Support push from git into bzr. |
943 |
return refs, stop_revision |
944 |
||
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
945 |
def pull(self, stop_revision=None, overwrite=False, |
|
0.200.732
by Jelmer Vernooij
Support run_hooks argument to InterGitRemoteLocalBranch.pull(). |
946 |
possible_transports=None, run_hooks=True,local=False): |
|
0.200.446
by Jelmer Vernooij
Support new 'local' argument. |
947 |
# This type of branch can't be bound.
|
948 |
if local: |
|
949 |
raise errors.LocalRequiresBoundBranch() |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
950 |
result = GitPullResult() |
951 |
result.source_branch = self.source |
|
952 |
result.target_branch = self.target |
|
|
0.200.1670
by Jelmer Vernooij
Fix compatibility with newer versions of bzr. |
953 |
with self.target.lock_write(), self.source.lock_read(): |
954 |
result.old_revid = self.target.last_revision() |
|
955 |
refs, stop_revision = self.update_refs(stop_revision) |
|
956 |
self.target.generate_revision_history(stop_revision, result.old_revid) |
|
957 |
tags_ret = self.source.tags.merge_to(self.target.tags, |
|
958 |
overwrite=overwrite, source_refs=refs) |
|
959 |
if isinstance(tags_ret, tuple): |
|
960 |
(result.tag_updates, result.tag_conflicts) = tags_ret |
|
961 |
else: |
|
962 |
result.tag_conflicts = tags_ret |
|
963 |
result.new_revid = self.target.last_revision() |
|
964 |
result.local_branch = None |
|
965 |
result.master_branch = result.target_branch |
|
966 |
if run_hooks: |
|
967 |
for hook in branch.Branch.hooks['post_pull']: |
|
968 |
hook(result) |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
969 |
return result |
970 |
||
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
971 |
|
|
0.200.960
by Jelmer Vernooij
Use GenericInterBranch. |
972 |
class InterToGitBranch(branch.GenericInterBranch): |
|
0.200.1185
by Jelmer Vernooij
Some formatting fixes. |
973 |
"""InterBranch implementation that pulls into a Git branch.""" |
|
0.200.468
by Jelmer Vernooij
Move dpush logic onto InterBranch. |
974 |
|
|
0.200.939
by Jelmer Vernooij
Use InterRepo directly. |
975 |
def __init__(self, source, target): |
976 |
super(InterToGitBranch, self).__init__(source, target) |
|
|
0.200.1097
by Jelmer Vernooij
Implement GitBranchFormat.initialize. |
977 |
self.interrepo = _mod_repository.InterRepository.get(source.repository, |
|
0.200.939
by Jelmer Vernooij
Use InterRepo directly. |
978 |
target.repository) |
979 |
||
|
0.200.631
by Jelmer Vernooij
Raise proper exception in Branch.get_stacked_on_url(). |
980 |
@staticmethod
|
981 |
def _get_branch_formats_to_test(): |
|
|
0.200.1100
by Jelmer Vernooij
Provide test combinations for InterBranch implementations. |
982 |
try: |
983 |
default_format = branch.format_registry.get_default() |
|
984 |
except AttributeError: |
|
985 |
default_format = branch.BranchFormat._default_format |
|
986 |
return [(default_format, GitBranchFormat())] |
|
|
0.200.631
by Jelmer Vernooij
Raise proper exception in Branch.get_stacked_on_url(). |
987 |
|
|
0.200.468
by Jelmer Vernooij
Move dpush logic onto InterBranch. |
988 |
@classmethod
|
989 |
def is_compatible(self, source, target): |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
990 |
return (not isinstance(source, GitBranch) and |
|
0.200.468
by Jelmer Vernooij
Move dpush logic onto InterBranch. |
991 |
isinstance(target, GitBranch)) |
992 |
||
|
0.200.1363
by Jelmer Vernooij
Only fetch tags if requested in config. |
993 |
def _get_new_refs(self, stop_revision=None, fetch_tags=None): |
|
0.200.1398
by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation. |
994 |
assert self.source.is_locked() |
|
0.252.38
by Jelmer Vernooij
Minor cleanups. |
995 |
if stop_revision is None: |
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
996 |
(stop_revno, stop_revision) = self.source.last_revision_info() |
|
0.263.1
by Jelmer Vernooij
Fix dpush for certain branches. |
997 |
else: |
998 |
stop_revno = self.source.revision_id_to_revno(stop_revision) |
|
|
0.200.969
by Jelmer Vernooij
Use tuples with bzr revid and git sha to avoid lookups. |
999 |
assert type(stop_revision) is str |
|
0.200.916
by Jelmer Vernooij
Set refs/heads/master if no ref is set yet. |
1000 |
main_ref = self.target.ref or "refs/heads/master" |
|
0.200.969
by Jelmer Vernooij
Use tuples with bzr revid and git sha to avoid lookups. |
1001 |
refs = { main_ref: (None, stop_revision) } |
|
0.200.1363
by Jelmer Vernooij
Only fetch tags if requested in config. |
1002 |
if fetch_tags is None: |
|
0.200.1584
by Jelmer Vernooij
Use config stacks in a few more places. |
1003 |
c = self.source.get_config_stack() |
1004 |
fetch_tags = c.get('branch.fetch_tags') |
|
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
1005 |
for name, revid in self.source.tags.get_tag_dict().iteritems(): |
1006 |
if self.source.repository.has_revision(revid): |
|
1007 |
ref = tag_name_to_ref(name) |
|
1008 |
if not check_ref_format(ref): |
|
1009 |
warning("skipping tag with invalid characters %s (%s)", |
|
1010 |
name, ref) |
|
1011 |
continue
|
|
|
0.200.1398
by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation. |
1012 |
if fetch_tags: |
1013 |
# FIXME: Skip tags that are not in the ancestry
|
|
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
1014 |
refs[ref] = (None, revid) |
|
0.200.1048
by Jelmer Vernooij
Make lookup of revno's after push/pull as efficient as possible. |
1015 |
return refs, main_ref, (stop_revno, stop_revision) |
|
0.252.37
by Jelmer Vernooij
Factor out some common code for finding refs to send. |
1016 |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1017 |
def _update_refs(self, result, old_refs, new_refs, overwrite): |
1018 |
mutter("updating refs. old refs: %r, new refs: %r", |
|
1019 |
old_refs, new_refs) |
|
1020 |
result.tag_updates = {} |
|
1021 |
result.tag_conflicts = [] |
|
1022 |
ret = dict(old_refs) |
|
1023 |
def ref_equals(refs, ref, git_sha, revid): |
|
1024 |
try: |
|
1025 |
value = refs[ref] |
|
1026 |
except KeyError: |
|
1027 |
return False |
|
1028 |
if (value[0] is not None and |
|
1029 |
git_sha is not None and |
|
|
0.200.1479
by Jelmer Vernooij
Simplify branch ref handling. |
1030 |
value[0] == git_sha): |
1031 |
return True |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1032 |
if (value[1] is not None and |
1033 |
revid is not None and |
|
|
0.200.1479
by Jelmer Vernooij
Simplify branch ref handling. |
1034 |
value[1] == revid): |
1035 |
return True |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1036 |
# FIXME: If one side only has the git sha available and the other only
|
1037 |
# has the bzr revid, then this will cause us to show a tag as updated
|
|
|
0.200.1636
by Jelmer Vernooij
Some formatting fixes. |
1038 |
# that hasn't actually been updated.
|
|
0.200.1479
by Jelmer Vernooij
Simplify branch ref handling. |
1039 |
return False |
|
0.200.1474
by Jelmer Vernooij
Cope with refs when pushing. |
1040 |
# FIXME: Check for diverged branches
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1041 |
for ref, (git_sha, revid) in new_refs.iteritems(): |
|
0.200.1479
by Jelmer Vernooij
Simplify branch ref handling. |
1042 |
if ref_equals(ret, ref, git_sha, revid): |
1043 |
# Already up to date
|
|
1044 |
if git_sha is None: |
|
1045 |
git_sha = old_refs[ref][0] |
|
1046 |
if revid is None: |
|
1047 |
revid = old_refs[ref][1] |
|
1048 |
ret[ref] = new_refs[ref] = (git_sha, revid) |
|
1049 |
elif ref not in ret or overwrite: |
|
1050 |
try: |
|
1051 |
tag_name = ref_to_tag_name(ref) |
|
1052 |
except ValueError: |
|
1053 |
pass
|
|
1054 |
else: |
|
1055 |
result.tag_updates[tag_name] = revid |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1056 |
ret[ref] = (git_sha, revid) |
1057 |
else: |
|
|
0.200.1474
by Jelmer Vernooij
Cope with refs when pushing. |
1058 |
# FIXME: Check diverged
|
1059 |
diverged = False |
|
1060 |
if diverged: |
|
1061 |
try: |
|
1062 |
name = ref_to_tag_name(ref) |
|
1063 |
except ValueError: |
|
1064 |
pass
|
|
1065 |
else: |
|
1066 |
result.tag_conflicts.append((name, revid, ret[name][1])) |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1067 |
else: |
|
0.200.1474
by Jelmer Vernooij
Cope with refs when pushing. |
1068 |
ret[ref] = (git_sha, revid) |
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1069 |
return ret |
1070 |
||
|
0.200.1493
by Jelmer Vernooij
Test fixes. |
1071 |
def fetch(self, stop_revision=None, fetch_tags=None, lossy=False, limit=None): |
1072 |
assert limit is None |
|
1073 |
if stop_revision is None: |
|
1074 |
stop_revision = self.source.last_revision() |
|
1075 |
ret = [] |
|
1076 |
if fetch_tags: |
|
1077 |
for k, v in self.source.tags.get_tag_dict().iteritems(): |
|
1078 |
ret.append((None, v)) |
|
1079 |
ret.append((None, stop_revision)) |
|
|
0.200.1509
by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings. |
1080 |
self.interrepo.fetch_objects(ret, lossy=lossy) |
|
0.200.1493
by Jelmer Vernooij
Test fixes. |
1081 |
|
|
0.252.36
by Jelmer Vernooij
Fix pull. |
1082 |
def pull(self, overwrite=False, stop_revision=None, local=False, |
|
0.200.1131
by Jelmer Vernooij
Accept run_hooks argument to InterToGitBranch.pull(). |
1083 |
possible_transports=None, run_hooks=True): |
|
0.252.36
by Jelmer Vernooij
Fix pull. |
1084 |
result = GitBranchPullResult() |
1085 |
result.source_branch = self.source |
|
1086 |
result.target_branch = self.target |
|
|
0.200.1353
by Jelmer Vernooij
Run various hooks. |
1087 |
self.source.lock_read() |
|
0.200.1156
by Jelmer Vernooij
Disable push. |
1088 |
try: |
|
0.200.1353
by Jelmer Vernooij
Run various hooks. |
1089 |
self.target.lock_write() |
1090 |
try: |
|
|
0.200.1389
by Jelmer Vernooij
Some more tag fixes. |
1091 |
new_refs, main_ref, stop_revinfo = self._get_new_refs( |
1092 |
stop_revision) |
|
|
0.200.1353
by Jelmer Vernooij
Run various hooks. |
1093 |
def update_refs(old_refs): |
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1094 |
return self._update_refs(result, old_refs, new_refs, overwrite) |
|
0.200.1353
by Jelmer Vernooij
Run various hooks. |
1095 |
try: |
1096 |
result.revidmap, old_refs, new_refs = self.interrepo.fetch_refs( |
|
1097 |
update_refs, lossy=False) |
|
1098 |
except NoPushSupport: |
|
1099 |
raise errors.NoRoundtrippingSupport(self.source, self.target) |
|
|
0.200.1513
by Jelmer Vernooij
Cope with zero shas. |
1100 |
(old_sha1, result.old_revid) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION)) |
|
0.200.1353
by Jelmer Vernooij
Run various hooks. |
1101 |
if result.old_revid is None: |
1102 |
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1) |
|
1103 |
result.new_revid = new_refs[main_ref][1] |
|
1104 |
result.local_branch = None |
|
1105 |
result.master_branch = self.target |
|
1106 |
if run_hooks: |
|
1107 |
for hook in branch.Branch.hooks['post_pull']: |
|
1108 |
hook(result) |
|
1109 |
finally: |
|
1110 |
self.target.unlock() |
|
1111 |
finally: |
|
1112 |
self.source.unlock() |
|
|
0.252.36
by Jelmer Vernooij
Fix pull. |
1113 |
return result |
1114 |
||
|
0.200.1260
by Jelmer Vernooij
Cope with new lossy argument. |
1115 |
def push(self, overwrite=False, stop_revision=None, lossy=False, |
|
0.200.472
by Jelmer Vernooij
Fix printing error when user attempts to push into git. |
1116 |
_override_hook_source_branch=None): |
|
0.252.5
by Jelmer Vernooij
enable 'bzr push'. |
1117 |
result = GitBranchPushResult() |
1118 |
result.source_branch = self.source |
|
1119 |
result.target_branch = self.target |
|
|
0.200.1356
by Jelmer Vernooij
Fix result properties for hook. |
1120 |
result.local_branch = None |
1121 |
result.master_branch = result.target_branch |
|
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
1122 |
self.source.lock_read() |
|
0.200.1323
by Jelmer Vernooij
Simplify push handling. |
1123 |
try: |
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
1124 |
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision) |
1125 |
def update_refs(old_refs): |
|
|
0.200.1392
by Jelmer Vernooij
Preserve existing refs. |
1126 |
return self._update_refs(result, old_refs, new_refs, overwrite) |
|
0.200.1391
by Jelmer Vernooij
Warn on (and skip) invalid tags. |
1127 |
try: |
1128 |
result.revidmap, old_refs, new_refs = self.interrepo.fetch_refs( |
|
1129 |
update_refs, lossy=lossy) |
|
1130 |
except NoPushSupport: |
|
1131 |
raise errors.NoRoundtrippingSupport(self.source, self.target) |
|
1132 |
(old_sha1, result.old_revid) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION)) |
|
1133 |
if result.old_revid is None: |
|
1134 |
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1) |
|
1135 |
result.new_revid = new_refs[main_ref][1] |
|
1136 |
(result.new_original_revno, result.new_original_revid) = stop_revinfo |
|
1137 |
for hook in branch.Branch.hooks['post_push']: |
|
1138 |
hook(result) |
|
1139 |
finally: |
|
1140 |
self.source.unlock() |
|
|
0.252.5
by Jelmer Vernooij
enable 'bzr push'. |
1141 |
return result |
|
0.200.472
by Jelmer Vernooij
Fix printing error when user attempts to push into git. |
1142 |
|
|
0.200.334
by Jelmer Vernooij
Support pulling from git to git. |
1143 |
|
|
0.200.1176
by Jelmer Vernooij
Fix fetch return value for inter git fetching. |
1144 |
branch.InterBranch.register_optimiser(InterGitLocalGitBranch) |
|
0.200.468
by Jelmer Vernooij
Move dpush logic onto InterBranch. |
1145 |
branch.InterBranch.register_optimiser(InterFromGitBranch) |
1146 |
branch.InterBranch.register_optimiser(InterToGitBranch) |
|
|
0.200.1176
by Jelmer Vernooij
Fix fetch return value for inter git fetching. |
1147 |
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch) |