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