76
110
return self._lookup_revno(self.new_revid)
79
class LocalGitTagDict(tag.BasicTags):
80
"""Dictionary with tags in a local repository."""
113
class InterTagsFromGitToRemoteGit(InterTags):
116
def is_compatible(klass, source, target):
117
if not isinstance(source, GitTags):
119
if not isinstance(target, GitTags):
121
if getattr(target.branch.repository, "_git", None) is not None:
125
def merge(self, overwrite=False, ignore_master=False, selector=None):
126
if self.source.branch.repository.has_same_location(self.target.branch.repository):
130
source_tag_refs = self.source.branch.get_tag_refs()
133
def get_changed_refs(old_refs):
135
for ref_name, tag_name, peeled, unpeeled in (
136
source_tag_refs.iteritems()):
137
if selector and not selector(tag_name):
139
if old_refs.get(ref_name) == unpeeled:
141
elif overwrite or ref_name not in old_refs:
142
ret[ref_name] = unpeeled
143
updates[tag_name] = self.target.branch.repository.lookup_foreign_revision_id(
145
ref_to_tag_map[ref_name] = tag_name
146
self.target.branch._tag_refs = None
150
self.repository.lookup_foreign_revision_id(peeled),
151
self.target.branch.repository.lookup_foreign_revision_id(
152
old_refs[ref_name])))
154
result = self.target.branch.repository.controldir.send_pack(
155
get_changed_refs, lambda have, want: [])
156
if result is not None and not isinstance(result, dict):
157
for ref, error in result.ref_status.items():
159
warning('unable to update ref %s: %s',
161
del updates[ref_to_tag_map[ref]]
162
return updates, set(conflicts)
165
class InterTagsFromGitToLocalGit(InterTags):
168
def is_compatible(klass, source, target):
169
if not isinstance(source, GitTags):
171
if not isinstance(target, GitTags):
173
if getattr(target.branch.repository, "_git", None) is None:
177
def merge(self, overwrite=False, ignore_master=False, selector=None):
178
if self.source.branch.repository.has_same_location(self.target.branch.repository):
183
source_tag_refs = self.source.branch.get_tag_refs()
185
target_repo = self.target.branch.repository
187
for ref_name, tag_name, peeled, unpeeled in source_tag_refs:
188
if selector and not selector(tag_name):
190
if target_repo._git.refs.get(ref_name) == unpeeled:
192
elif overwrite or ref_name not in target_repo._git.refs:
194
updates[tag_name] = (
195
target_repo.lookup_foreign_revision_id(peeled))
197
trace.warning('%s does not point to a valid object',
200
except NotCommitError:
201
trace.warning('%s points to a non-commit object',
204
target_repo._git.refs[ref_name] = unpeeled or peeled
205
self.target.branch._tag_refs = None
208
source_revid = self.source.branch.repository.lookup_foreign_revision_id(
210
target_revid = target_repo.lookup_foreign_revision_id(
211
target_repo._git.refs[ref_name])
213
trace.warning('%s does not point to a valid object',
216
except NotCommitError:
217
trace.warning('%s points to a non-commit object',
220
conflicts.append((tag_name, source_revid, target_revid))
221
return updates, set(conflicts)
224
class InterTagsFromGitToNonGit(InterTags):
227
def is_compatible(klass, source, target):
228
if not isinstance(source, GitTags):
230
if isinstance(target, GitTags):
234
def merge(self, overwrite=False, ignore_master=False, selector=None):
235
"""See Tags.merge_to."""
236
source_tag_refs = self.source.branch.get_tag_refs()
240
master = self.target.branch.get_master_branch()
241
with contextlib.ExitStack() as es:
242
if master is not None:
243
es.enter_context(master.lock_write())
244
updates, conflicts = self._merge_to(
245
self.target, source_tag_refs, overwrite=overwrite,
247
if master is not None:
248
extra_updates, extra_conflicts = self._merge_to(
249
master.tags, overwrite=overwrite,
250
source_tag_refs=source_tag_refs,
251
ignore_master=ignore_master, selector=selector)
252
updates.update(extra_updates)
253
conflicts.update(extra_conflicts)
254
return updates, conflicts
256
def _merge_to(self, to_tags, source_tag_refs, overwrite=False,
258
unpeeled_map = defaultdict(set)
261
result = dict(to_tags.get_tag_dict())
262
for ref_name, tag_name, peeled, unpeeled in source_tag_refs:
263
if selector and not selector(tag_name):
265
if unpeeled is not None:
266
unpeeled_map[peeled].add(unpeeled)
268
bzr_revid = self.source.branch.lookup_foreign_revision_id(peeled)
269
except NotCommitError:
271
if result.get(tag_name) == bzr_revid:
273
elif tag_name not in result or overwrite:
274
result[tag_name] = bzr_revid
275
updates[tag_name] = bzr_revid
277
conflicts.append((tag_name, bzr_revid, result[tag_name]))
278
to_tags._set_tag_dict(result)
279
if len(unpeeled_map) > 0:
280
map_file = UnpeelMap.from_repository(to_tags.branch.repository)
281
map_file.update(unpeeled_map)
282
map_file.save_in_repository(to_tags.branch.repository)
283
return updates, set(conflicts)
286
InterTags.register_optimiser(InterTagsFromGitToRemoteGit)
287
InterTags.register_optimiser(InterTagsFromGitToLocalGit)
288
InterTags.register_optimiser(InterTagsFromGitToNonGit)
292
"""Ref-based tag dictionary."""
82
294
def __init__(self, branch):
83
295
self.branch = branch
86
298
def get_tag_dict(self):
88
for k,v in extract_tags(self.repository._git.get_refs()).iteritems():
300
for (ref_name, tag_name, peeled, unpeeled) in (
301
self.branch.get_tag_refs()):
90
obj = self.repository._git[v]
92
mutter("Tag %s points at unknown object %s, ignoring", v, obj)
94
while isinstance(obj, Tag):
96
obj = self.repository._git[v]
97
if not isinstance(obj, Commit):
98
mutter("Tag %s points at object %r that is not a commit, "
101
ret[k] = self.branch.lookup_foreign_revision_id(v)
303
bzr_revid = self.branch.lookup_foreign_revision_id(peeled)
304
except NotCommitError:
307
ret[tag_name] = bzr_revid
310
def lookup_tag(self, tag_name):
311
"""Return the referent string of a tag"""
312
# TODO(jelmer): Replace with something more efficient for local tags.
313
td = self.get_tag_dict()
317
raise errors.NoSuchTag(tag_name)
320
class LocalGitTagDict(GitTags):
321
"""Dictionary with tags in a local repository."""
323
def __init__(self, branch):
324
super(LocalGitTagDict, self).__init__(branch)
325
self.refs = self.repository.controldir._git.refs
104
327
def _set_tag_dict(self, to_dict):
105
extra = set(self.repository._git.get_refs().keys())
106
for k, revid in to_dict.iteritems():
328
extra = set(self.refs.allkeys())
329
for k, revid in to_dict.items():
107
330
name = tag_name_to_ref(k)
108
331
if name in extra:
109
332
extra.remove(name)
110
self.set_tag(k, revid)
334
self.set_tag(k, revid)
335
except errors.GhostTagsNotSupported:
111
337
for name in extra:
112
if name.startswith("refs/tags/"):
113
339
del self.repository._git[name]
115
341
def set_tag(self, name, revid):
116
self.repository._git.refs[tag_name_to_ref(name)], _ = \
117
self.branch.lookup_bzr_revision_id(revid)
120
class DictTagDict(LocalGitTagDict):
122
def __init__(self, branch, tags):
123
super(DictTagDict, self).__init__(branch)
126
def get_tag_dict(self):
343
git_sha, mapping = self.branch.lookup_bzr_revision_id(revid)
344
except errors.NoSuchRevision:
345
raise errors.GhostTagsNotSupported(self)
346
self.refs[tag_name_to_ref(name)] = git_sha
347
self.branch._tag_refs = None
349
def delete_tag(self, name):
350
ref = tag_name_to_ref(name)
351
if ref not in self.refs:
352
raise errors.NoSuchTag(name)
354
self.branch._tag_refs = None
130
357
class GitBranchFormat(branch.BranchFormat):
132
def get_format_description(self):
135
359
def network_name(self):
138
362
def supports_tags(self):
365
def supports_leaving_lock(self):
368
def supports_tags_referencing_ghosts(self):
371
def tags_are_versioned(self):
141
374
def get_foreign_tests_branch_factory(self):
142
from bzrlib.plugins.git.tests.test_branch import ForeignTestsBranchFactory
375
from .tests.test_branch import ForeignTestsBranchFactory
143
376
return ForeignTestsBranchFactory()
145
378
def make_tags(self, branch):
146
if getattr(branch.repository, "get_refs", None) is not None:
147
from bzrlib.plugins.git.remote import RemoteGitTagDict
381
except AttributeError:
383
if getattr(branch.repository, "_git", None) is None:
384
from .remote import RemoteGitTagDict
148
385
return RemoteGitTagDict(branch)
150
387
return LocalGitTagDict(branch)
153
class GitReadLock(object):
155
def __init__(self, unlock):
159
class GitWriteLock(object):
161
def __init__(self, unlock):
389
def initialize(self, a_controldir, name=None, repository=None,
390
append_revisions_only=None):
391
raise NotImplementedError(self.initialize)
393
def get_reference(self, controldir, name=None):
394
return controldir.get_branch_reference(name=name)
396
def set_reference(self, controldir, name, target):
397
return controldir.set_branch_reference(target, name)
399
def stores_revno(self):
400
"""True if this branch format store revision numbers."""
403
supports_reference_locations = False
406
class LocalGitBranchFormat(GitBranchFormat):
408
def get_format_description(self):
409
return 'Local Git Branch'
412
def _matchingcontroldir(self):
413
from .dir import LocalGitControlDirFormat
414
return LocalGitControlDirFormat()
416
def initialize(self, a_controldir, name=None, repository=None,
417
append_revisions_only=None):
418
from .dir import LocalGitDir
419
if not isinstance(a_controldir, LocalGitDir):
420
raise errors.IncompatibleFormat(self, a_controldir._format)
421
return a_controldir.create_branch(
422
repository=repository, name=name,
423
append_revisions_only=append_revisions_only)
165
426
class GitBranch(ForeignBranch):
166
427
"""An adapter to git repositories for bzr Branch objects."""
168
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
430
def control_transport(self):
431
return self._control_transport
434
def user_transport(self):
435
return self._user_transport
437
def __init__(self, controldir, repository, ref, format):
169
438
self.repository = repository
170
self._format = GitBranchFormat()
171
self.control_files = lockfiles
439
self._format = format
440
self.controldir = controldir
441
self._lock_mode = None
173
443
super(GitBranch, self).__init__(repository.get_mapping())
174
if tagsdict is not None:
175
self.tags = DictTagDict(self, tagsdict)
177
self.name = ref_to_branch_name(ref)
178
445
self._head = None
179
self.base = bzrdir.root_transport.base
446
self._user_transport = controldir.user_transport.clone('.')
447
self._control_transport = controldir.control_transport.clone('.')
448
self._tag_refs = None
451
self.name = ref_to_branch_name(ref)
454
if self.ref is not None:
455
params = {"ref": urlutils.escape(self.ref)}
458
params = {"branch": urlutils.escape(self.name)}
459
for k, v in params.items():
460
self._user_transport.set_segment_parameter(k, v)
461
self._control_transport.set_segment_parameter(k, v)
462
self.base = controldir.user_transport.base
181
def _get_checkout_format(self):
464
def _get_checkout_format(self, lightweight=False):
182
465
"""Return the most suitable metadir for a checkout of this branch.
183
466
Weaves are used if this branch's repository uses weaves.
185
return bzrdir.format_registry.make_bzrdir("default")
469
return controldir.format_registry.make_controldir("git")
471
return controldir.format_registry.make_controldir("default")
187
473
def get_child_submit_format(self):
188
474
"""Return the preferred format of submissions to this branch."""
189
ret = self.get_config().get_user_option("child_submit_format")
475
ret = self.get_config_stack().get("child_submit_format")
190
476
if ret is not None:
480
def get_config(self):
481
from .config import GitBranchConfig
482
return GitBranchConfig(self)
484
def get_config_stack(self):
485
from .config import GitBranchStack
486
return GitBranchStack(self)
194
488
def _get_nick(self, local=False, possible_master_transports=None):
195
489
"""Find the nick name for this branch.
197
491
:return: Branch nick
199
return self.name or "HEAD"
493
if getattr(self.repository, '_git', None):
494
cs = self.repository._git.get_config_stack()
496
return cs.get((b"branch", self.name.encode('utf-8')),
497
b"nick").decode("utf-8")
500
return self.name or u"HEAD"
201
502
def _set_nick(self, nick):
202
raise NotImplementedError
503
cf = self.repository._git.get_config()
504
cf.set((b"branch", self.name.encode('utf-8')),
505
b"nick", nick.encode("utf-8"))
508
self.repository._git._put_named_file('config', f.getvalue())
204
510
nick = property(_get_nick, _set_nick)
206
512
def __repr__(self):
207
513
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
210
def generate_revision_history(self, revid, old_revid=None):
211
# FIXME: Check that old_revid is in the ancestry of revid
212
newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
213
self._set_head(newhead)
215
def lock_write(self):
216
self.control_files.lock_write()
217
return GitWriteLock(self.unlock)
516
def generate_revision_history(self, revid, last_rev=None,
518
if last_rev is not None:
519
graph = self.repository.get_graph()
520
if not graph.is_ancestor(last_rev, revid):
521
# our previous tip is not merged into stop_revision
522
raise errors.DivergedBranches(self, other_branch)
524
self.set_last_revision(revid)
526
def lock_write(self, token=None):
527
if token is not None:
528
raise errors.TokenLockingNotSupported(self)
530
if self._lock_mode == 'r':
531
raise errors.ReadOnlyError(self)
532
self._lock_count += 1
535
self._lock_mode = 'w'
537
self.repository.lock_write()
538
return lock.LogicalLockResult(self.unlock)
540
def leave_lock_in_place(self):
541
raise NotImplementedError(self.leave_lock_in_place)
543
def dont_leave_lock_in_place(self):
544
raise NotImplementedError(self.dont_leave_lock_in_place)
219
546
def get_stacked_on_url(self):
220
547
# Git doesn't do stacking (yet...)
221
raise errors.UnstackableBranchFormat(self._format, self.base)
223
def get_parent(self):
548
raise branch.UnstackableBranchFormat(self._format, self.base)
550
def _get_push_origin(self, cs):
551
"""Get the name for the push origin.
553
The exact behaviour is documented in the git-config(1) manpage.
556
return cs.get((b'branch', self.name.encode('utf-8')), b'pushRemote')
559
return cs.get((b'branch', ), b'remote')
562
return cs.get((b'branch', self.name.encode('utf-8')), b'remote')
566
def _get_origin(self, cs):
568
return cs.get((b'branch', self.name.encode('utf-8')), b'remote')
572
def _get_related_push_branch(self, cs):
573
remote = self._get_push_origin(cs)
575
location = cs.get((b"remote", remote), b"url")
579
return git_url_to_bzr_url(location.decode('utf-8'), ref=self.ref)
581
def _get_related_merge_branch(self, cs):
582
remote = self._get_origin(cs)
584
location = cs.get((b"remote", remote), b"url")
589
ref = cs.get((b"branch", remote), b"merge")
593
return git_url_to_bzr_url(location.decode('utf-8'), ref=ref)
595
def _get_parent_location(self):
224
596
"""See Branch.get_parent()."""
225
# FIXME: Set "origin" url from .git/config ?
228
def set_parent(self, url):
229
# FIXME: Set "origin" url in .git/config ?
597
cs = self.repository._git.get_config_stack()
598
return self._get_related_merge_branch(cs)
600
def _write_git_config(self, cs):
603
self.repository._git._put_named_file('config', f.getvalue())
605
def set_parent(self, location):
606
cs = self.repository._git.get_config()
607
remote = self._get_origin(cs)
608
this_url = urlutils.strip_segment_parameters(self.user_url)
609
target_url, branch, ref = bzr_url_to_git_url(location)
610
location = urlutils.relative_url(this_url, target_url)
611
cs.set((b"remote", remote), b"url", location)
613
cs.set((b"branch", remote), b"merge", branch_name_to_ref(branch))
615
cs.set((b"branch", remote), b"merge", ref)
617
# TODO(jelmer): Maybe unset rather than setting to HEAD?
618
cs.set((b"branch", remote), b"merge", b'HEAD')
619
self._write_git_config(cs)
621
def break_lock(self):
622
raise NotImplementedError(self.break_lock)
232
624
def lock_read(self):
233
self.control_files.lock_read()
234
return GitReadLock(self.unlock)
626
if self._lock_mode not in ('r', 'w'):
627
raise ValueError(self._lock_mode)
628
self._lock_count += 1
630
self._lock_mode = 'r'
632
self.repository.lock_read()
633
return lock.LogicalLockResult(self.unlock)
635
def peek_lock_mode(self):
636
return self._lock_mode
236
638
def is_locked(self):
237
return self.control_files.is_locked()
639
return (self._lock_mode is not None)
644
def _unlock_ref(self):
239
647
def unlock(self):
240
self.control_files.unlock()
648
"""See Branch.unlock()."""
649
if self._lock_count == 0:
650
raise errors.LockNotHeld(self)
652
self._lock_count -= 1
653
if self._lock_count == 0:
654
if self._lock_mode == 'w':
656
self._lock_mode = None
657
self._clear_cached_state()
659
self.repository.unlock()
242
661
def get_physical_lock_status(self):
246
664
def last_revision(self):
247
# perhaps should escape this ?
248
if self.head is None:
249
return revision.NULL_REVISION
250
return self.lookup_foreign_revision_id(self.head)
665
with self.lock_read():
666
# perhaps should escape this ?
667
if self.head is None:
668
return revision.NULL_REVISION
669
return self.lookup_foreign_revision_id(self.head)
252
def _basic_push(self, target, overwrite=False, stop_revision=None):
671
def _basic_push(self, target, overwrite=False, stop_revision=None,
253
673
return branch.InterBranch.get(self, target)._basic_push(
254
overwrite, stop_revision)
674
overwrite, stop_revision, tag_selector=tag_selector)
256
676
def lookup_foreign_revision_id(self, foreign_revid):
257
return self.repository.lookup_foreign_revision_id(foreign_revid,
678
return self.repository.lookup_foreign_revision_id(foreign_revid,
682
return self.mapping.revision_id_foreign_to_bzr(foreign_revid)
260
684
def lookup_bzr_revision_id(self, revid):
261
685
return self.repository.lookup_bzr_revision_id(
262
686
revid, mapping=self.mapping)
688
def get_unshelver(self, tree):
689
raise errors.StoringUncommittedNotSupported(self)
691
def _clear_cached_state(self):
692
super(GitBranch, self)._clear_cached_state()
693
self._tag_refs = None
695
def _iter_tag_refs(self, refs):
696
"""Iterate over the tag refs.
698
:param refs: Refs dictionary (name -> git sha1)
699
:return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
701
raise NotImplementedError(self._iter_tag_refs)
703
def get_tag_refs(self):
704
with self.lock_read():
705
if self._tag_refs is None:
706
self._tag_refs = list(self._iter_tag_refs())
707
return self._tag_refs
709
def import_last_revision_info_and_tags(self, source, revno, revid,
711
"""Set the last revision info, importing from another repo if necessary.
713
This is used by the bound branch code to upload a revision to
714
the master branch first before updating the tip of the local branch.
715
Revisions referenced by source's tags are also transferred.
717
:param source: Source branch to optionally fetch from
718
:param revno: Revision number of the new tip
719
:param revid: Revision id of the new tip
720
:param lossy: Whether to discard metadata that can not be
722
:return: Tuple with the new revision number and revision id
723
(should only be different from the arguments when lossy=True)
725
push_result = source.push(
726
self, stop_revision=revid, lossy=lossy, _stop_revno=revno)
727
return (push_result.new_revno, push_result.new_revid)
729
def reconcile(self, thorough=True):
730
"""Make sure the data stored in this branch is consistent."""
731
from ..reconcile import ReconcileResult
733
return ReconcileResult()
265
736
class LocalGitBranch(GitBranch):
266
737
"""A local Git branch."""
268
def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
269
super(LocalGitBranch, self).__init__(bzrdir, repository, name,
271
refs = repository._git.get_refs()
272
if not (name in refs.keys() or "HEAD" in refs.keys()):
273
raise errors.NotBranchError(self.base)
739
def __init__(self, controldir, repository, ref):
740
super(LocalGitBranch, self).__init__(controldir, repository, ref,
741
LocalGitBranchFormat())
275
743
def create_checkout(self, to_location, revision_id=None, lightweight=False,
276
accelerator_tree=None, hardlink=False):
744
accelerator_tree=None, hardlink=False):
745
t = transport.get_transport(to_location)
747
format = self._get_checkout_format(lightweight=lightweight)
748
checkout = format.initialize_on_transport(t)
278
t = transport.get_transport(to_location)
280
format = self._get_checkout_format()
281
checkout = format.initialize_on_transport(t)
282
from_branch = branch.BranchReferenceFormat().initialize(checkout,
284
tree = checkout.create_workingtree(revision_id,
285
from_branch=from_branch, hardlink=hardlink)
750
from_branch = checkout.set_branch_reference(target_branch=self)
288
return self._create_heavyweight_checkout(to_location, revision_id,
291
def _create_heavyweight_checkout(self, to_location, revision_id=None,
293
"""Create a new heavyweight checkout of this branch.
295
:param to_location: URL of location to create the new checkout in.
296
:param revision_id: Revision that should be the tip of the checkout.
297
:param hardlink: Whether to hardlink
298
:return: WorkingTree object of checkout.
300
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
301
to_location, force_new_tree=False)
302
checkout = checkout_branch.bzrdir
303
checkout_branch.bind(self)
304
# pull up to the specified revision_id to set the initial
305
# branch tip correctly, and seed it with history.
306
checkout_branch.pull(self, stop_revision=revision_id)
307
return checkout.create_workingtree(revision_id, hardlink=hardlink)
752
policy = checkout.determine_repository_policy()
753
policy.acquire_repository()
754
checkout_branch = checkout.create_branch()
755
checkout_branch.bind(self)
756
checkout_branch.pull(self, stop_revision=revision_id)
758
return checkout.create_workingtree(
759
revision_id, from_branch=from_branch, hardlink=hardlink)
762
self._ref_lock = self.repository._git.refs.lock_ref(self.ref)
764
def _unlock_ref(self):
765
self._ref_lock.unlock()
767
def break_lock(self):
768
self.repository._git.refs.unlock_ref(self.ref)
309
770
def _gen_revision_history(self):
310
771
if self.head is None:
312
ret = list(self.repository.iter_reverse_revision_history(
313
self.last_revision()))
773
last_revid = self.last_revision()
774
graph = self.repository.get_graph()
776
ret = list(graph.iter_lefthand_ancestry(
777
last_revid, (revision.NULL_REVISION, )))
778
except errors.RevisionNotPresent as e:
779
raise errors.GhostRevisionsHaveNoRevno(last_revid, e.revision_id)
317
783
def _get_head(self):
319
return self.repository._git.ref(self.ref or "HEAD")
785
return self.repository._git.refs[self.ref]
323
def set_last_revision_info(self, revno, revid):
324
self.set_last_revision(revid)
789
def _read_last_revision_info(self):
790
last_revid = self.last_revision()
791
graph = self.repository.get_graph()
793
revno = graph.find_distance_to_null(
794
last_revid, [(revision.NULL_REVISION, 0)])
795
except errors.GhostRevisionsHaveNoRevno:
797
return revno, last_revid
799
def set_last_revision_info(self, revno, revision_id):
800
self.set_last_revision(revision_id)
801
self._last_revision_info_cache = revno, revision_id
326
803
def set_last_revision(self, revid):
327
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(revid)
804
if not revid or not isinstance(revid, bytes):
805
raise errors.InvalidRevisionId(revision_id=revid, branch=self)
806
if revid == NULL_REVISION:
809
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(
811
if self.mapping is None:
813
self._set_head(newhead)
330
815
def _set_head(self, value):
816
if value == ZERO_SHA:
817
raise ValueError(value)
331
818
self._head = value
332
self.repository._git.refs[self.ref or "HEAD"] = self._head
820
del self.repository._git.refs[self.ref]
822
self.repository._git.refs[self.ref] = self._head
333
823
self._clear_cached_state()
335
825
head = property(_get_head, _set_head)
337
def get_config(self):
338
return GitBranchConfig(self)
340
827
def get_push_location(self):
341
828
"""See Branch.get_push_location."""
342
push_loc = self.get_config().get_user_option('push_location')
829
push_loc = self.get_config_stack().get('push_location')
830
if push_loc is not None:
832
cs = self.repository._git.get_config_stack()
833
return self._get_related_push_branch(cs)
345
835
def set_push_location(self, location):
346
836
"""See Branch.set_push_location."""
427
961
def _get_branch_formats_to_test():
963
default_format = branch.format_registry.get_default()
964
except AttributeError:
965
default_format = branch.BranchFormat._default_format
966
from .remote import RemoteGitBranchFormat
968
(RemoteGitBranchFormat(), default_format),
969
(LocalGitBranchFormat(), default_format)]
431
972
def _get_interrepo(self, source, target):
432
return repository.InterRepository.get(source.repository,
973
return _mod_repository.InterRepository.get(
974
source.repository, target.repository)
436
977
def is_compatible(cls, source, target):
437
return (isinstance(source, GitBranch) and
438
not isinstance(target, GitBranch) and
439
(getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
441
def _update_revisions(self, stop_revision=None, overwrite=False,
442
graph=None, limit=None):
443
"""Like InterBranch.update_revisions(), but with additions.
445
Compared to the `update_revisions()` below, this function takes a
446
`limit` argument that limits how many git commits will be converted
447
and returns the new git head.
978
if not isinstance(source, GitBranch):
980
if isinstance(target, GitBranch):
981
# InterLocalGitRemoteGitBranch or InterToGitBranch should be used
983
if (getattr(cls._get_interrepo(source, target), "fetch_objects", None)
985
# fetch_objects is necessary for this to work
989
def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
991
stop_revision, fetch_tags=fetch_tags, limit=limit, lossy=lossy)
992
return _mod_repository.FetchResult()
994
def fetch_objects(self, stop_revision, fetch_tags, limit=None, lossy=False, tag_selector=None):
449
995
interrepo = self._get_interrepo(self.source, self.target)
996
if fetch_tags is None:
997
c = self.source.get_config_stack()
998
fetch_tags = c.get('branch.fetch_tags')
450
1000
def determine_wants(heads):
451
if self.source.ref is not None and not self.source.ref in heads:
452
raise NoSuchRef(self.source.ref, heads.keys())
453
if stop_revision is not None:
1001
if stop_revision is None:
1003
head = heads[self.source.ref]
1005
self._last_revid = revision.NULL_REVISION
1007
self._last_revid = self.source.lookup_foreign_revision_id(
454
1010
self._last_revid = stop_revision
455
head, mapping = self.source.repository.lookup_bzr_revision_id(
458
if self.source.ref is not None:
459
head = heads[self.source.ref]
462
self._last_revid = self.source.lookup_foreign_revision_id(head)
463
if self.target.repository.has_revision(self._last_revid):
1011
real = interrepo.get_determine_wants_revids(
1012
[self._last_revid], include_tags=fetch_tags, tag_selector=tag_selector)
466
1014
pack_hint, head, refs = interrepo.fetch_objects(
467
determine_wants, self.source.mapping, limit=limit)
1015
determine_wants, self.source.mapping, limit=limit,
468
1017
if (pack_hint is not None and
469
self.target.repository._format.pack_compresses):
1018
self.target.repository._format.pack_compresses):
470
1019
self.target.repository.pack(hint=pack_hint)
472
self._last_revid = self.source.lookup_foreign_revision_id(head)
1022
def _update_revisions(self, stop_revision=None, overwrite=False, tag_selector=None):
1023
head, refs = self.fetch_objects(stop_revision, fetch_tags=None, tag_selector=tag_selector)
474
1025
prev_last_revid = None
476
1027
prev_last_revid = self.target.last_revision()
477
self.target.generate_revision_history(self._last_revid,
481
def update_revisions(self, stop_revision=None, overwrite=False,
483
"""See InterBranch.update_revisions()."""
484
self._update_revisions(stop_revision, overwrite, graph)
486
def pull(self, overwrite=False, stop_revision=None,
487
possible_transports=None, _hook_master=None, run_hooks=True,
488
_override_hook_target=None, local=False, limit=None):
491
:param _hook_master: Private parameter - set the branch to
492
be supplied as the master to pull hooks.
493
:param run_hooks: Private parameter - if false, this branch
494
is being called because it's the master of the primary branch,
495
so it should not run its hooks.
496
:param _override_hook_target: Private parameter - set the branch to be
497
supplied as the target_branch to pull hooks.
498
:param limit: Only import this many revisons. `None`, the default,
499
means import all revisions.
501
# This type of branch can't be bound.
503
raise errors.LocalRequiresBoundBranch()
1028
self.target.generate_revision_history(
1029
self._last_revid, last_rev=prev_last_revid,
1030
other_branch=self.source)
1033
def update_references(self, revid=None):
1035
revid = self.target.last_revision()
1036
tree = self.target.repository.revision_tree(revid)
1038
with tree.get_file('.gitmodules') as f:
1039
for path, url, section in parse_submodules(
1040
GitConfigFile.from_file(f)):
1041
self.target.set_reference_info(
1042
tree.path2id(path.decode('utf-8')), url.decode('utf-8'),
1043
path.decode('utf-8'))
1044
except errors.NoSuchFile:
1047
def _basic_pull(self, stop_revision, overwrite, run_hooks,
1048
_override_hook_target, _hook_master, tag_selector=None):
1049
if overwrite is True:
1050
overwrite = set(["history", "tags"])
504
1053
result = GitBranchPullResult()
505
1054
result.source_branch = self.source
506
1055
if _override_hook_target is None:
507
1056
result.target_branch = self.target
509
1058
result.target_branch = _override_hook_target
510
self.source.lock_read()
1059
with self.target.lock_write(), self.source.lock_read():
512
1060
# We assume that during 'pull' the target repository is closer than
513
1061
# the source one.
514
graph = self.target.repository.get_graph(self.source.repository)
515
1062
(result.old_revno, result.old_revid) = \
516
1063
self.target.last_revision_info()
517
result.new_git_head = self._update_revisions(
518
stop_revision, overwrite=overwrite, graph=graph, limit=limit)
519
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
1064
result.new_git_head, remote_refs = self._update_revisions(
1065
stop_revision, overwrite=("history" in overwrite),
1066
tag_selector=tag_selector)
1067
tags_ret = self.source.tags.merge_to(
1068
self.target.tags, ("tags" in overwrite), ignore_master=True)
1069
if isinstance(tags_ret, tuple):
1070
result.tag_updates, result.tag_conflicts = tags_ret
1072
result.tag_conflicts = tags_ret
521
1073
(result.new_revno, result.new_revid) = \
522
1074
self.target.last_revision_info()
1075
self.update_references(revid=result.new_revid)
523
1076
if _hook_master:
524
1077
result.master_branch = _hook_master
525
1078
result.local_branch = result.target_branch
530
1083
for hook in branch.Branch.hooks['post_pull']:
536
def _basic_push(self, overwrite=False, stop_revision=None):
1087
def pull(self, overwrite=False, stop_revision=None,
1088
possible_transports=None, _hook_master=None, run_hooks=True,
1089
_override_hook_target=None, local=False, tag_selector=None):
1092
:param _hook_master: Private parameter - set the branch to
1093
be supplied as the master to pull hooks.
1094
:param run_hooks: Private parameter - if false, this branch
1095
is being called because it's the master of the primary branch,
1096
so it should not run its hooks.
1097
:param _override_hook_target: Private parameter - set the branch to be
1098
supplied as the target_branch to pull hooks.
1100
# This type of branch can't be bound.
1101
bound_location = self.target.get_bound_location()
1102
if local and not bound_location:
1103
raise errors.LocalRequiresBoundBranch()
1104
source_is_master = False
1105
with contextlib.ExitStack() as es:
1106
es.enter_context(self.source.lock_read())
1108
# bound_location comes from a config file, some care has to be
1109
# taken to relate it to source.user_url
1110
normalized = urlutils.normalize_url(bound_location)
1112
relpath = self.source.user_transport.relpath(normalized)
1113
source_is_master = (relpath == '')
1114
except (errors.PathNotChild, urlutils.InvalidURL):
1115
source_is_master = False
1116
if not local and bound_location and not source_is_master:
1117
# not pulling from master, so we need to update master.
1118
master_branch = self.target.get_master_branch(possible_transports)
1119
es.enter_context(master_branch.lock_write())
1120
# pull from source into master.
1121
master_branch.pull(self.source, overwrite, stop_revision,
1124
master_branch = None
1125
return self._basic_pull(stop_revision, overwrite, run_hooks,
1126
_override_hook_target,
1127
_hook_master=master_branch,
1128
tag_selector=tag_selector)
1130
def _basic_push(self, overwrite, stop_revision, tag_selector=None):
1131
if overwrite is True:
1132
overwrite = set(["history", "tags"])
537
1135
result = branch.BranchPushResult()
538
1136
result.source_branch = self.source
539
1137
result.target_branch = self.target
540
graph = self.target.repository.get_graph(self.source.repository)
541
1138
result.old_revno, result.old_revid = self.target.last_revision_info()
542
result.new_git_head = self._update_revisions(
543
stop_revision, overwrite=overwrite, graph=graph)
544
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
1139
result.new_git_head, remote_refs = self._update_revisions(
1140
stop_revision, overwrite=("history" in overwrite),
1141
tag_selector=tag_selector)
1142
tags_ret = self.source.tags.merge_to(
1143
self.target.tags, "tags" in overwrite, ignore_master=True,
1144
selector=tag_selector)
1145
(result.tag_updates, result.tag_conflicts) = tags_ret
546
1146
result.new_revno, result.new_revid = self.target.last_revision_info()
1147
self.update_references(revid=result.new_revid)
550
1151
class InterGitBranch(branch.GenericInterBranch):
551
1152
"""InterBranch implementation that pulls between Git branches."""
554
class InterGitLocalRemoteBranch(InterGitBranch):
1154
def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
1155
raise NotImplementedError(self.fetch)
1158
class InterLocalGitRemoteGitBranch(InterGitBranch):
555
1159
"""InterBranch that copies from a local to a remote git branch."""
558
1162
def _get_branch_formats_to_test():
1163
from .remote import RemoteGitBranchFormat
1165
(LocalGitBranchFormat(), RemoteGitBranchFormat())]
562
1168
def is_compatible(self, source, target):
563
from bzrlib.plugins.git.remote import RemoteGitBranch
1169
from .remote import RemoteGitBranch
564
1170
return (isinstance(source, LocalGitBranch) and
565
1171
isinstance(target, RemoteGitBranch))
567
def _basic_push(self, overwrite=False, stop_revision=None):
568
from dulwich.protocol import ZERO_SHA
1173
def _basic_push(self, overwrite, stop_revision, tag_selector=None):
1174
from .remote import RemoteGitError
569
1175
result = GitBranchPushResult()
570
1176
result.source_branch = self.source
571
1177
result.target_branch = self.target
572
1178
if stop_revision is None:
573
1179
stop_revision = self.source.last_revision()
574
# FIXME: Check for diverged branches
575
1181
def get_changed_refs(old_refs):
576
result.old_revid = self.target.lookup_foreign_revision_id(old_refs.get(self.target.ref, ZERO_SHA))
577
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
1182
old_ref = old_refs.get(self.target.ref, None)
1184
result.old_revid = revision.NULL_REVISION
1186
result.old_revid = self.target.lookup_foreign_revision_id(
1188
new_ref = self.source.repository.lookup_bzr_revision_id(
1191
if remote_divergence(
1193
self.source.repository._git.object_store):
1194
raise errors.DivergedBranches(self.source, self.target)
1195
refs = {self.target.ref: new_ref}
578
1196
result.new_revid = stop_revision
579
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
1198
self.source.repository._git.refs.as_dict(b"refs/tags").items()):
1199
if tag_selector and not tag_selector(name):
1201
if sha not in self.source.repository._git:
1202
trace.mutter('Ignoring missing SHA: %s', sha)
580
1204
refs[tag_name_to_ref(name)] = sha
582
self.target.repository.send_pack(get_changed_refs,
583
self.source.repository._git.object_store.generate_pack_contents)
1206
dw_result = self.target.repository.send_pack(
1208
self.source.repository._git.generate_pack_data)
1209
if dw_result is not None and not isinstance(dw_result, dict):
1210
error = dw_result.ref_status.get(self.target.ref)
1212
raise RemoteGitError(error)
1213
for ref, error in dw_result.ref_status.items():
1215
trace.warning('unable to open ref %s: %s',
587
class InterGitRemoteLocalBranch(InterGitBranch):
1220
class InterGitLocalGitBranch(InterGitBranch):
588
1221
"""InterBranch that copies from a remote to a local git branch."""
591
1224
def _get_branch_formats_to_test():
1225
from .remote import RemoteGitBranchFormat
1227
(RemoteGitBranchFormat(), LocalGitBranchFormat()),
1228
(LocalGitBranchFormat(), LocalGitBranchFormat())]
595
1231
def is_compatible(self, source, target):
596
from bzrlib.plugins.git.remote import RemoteGitBranch
597
return (isinstance(source, RemoteGitBranch) and
1232
return (isinstance(source, GitBranch) and
598
1233
isinstance(target, LocalGitBranch))
600
def _basic_push(self, overwrite=False, stop_revision=None):
601
result = branch.BranchPushResult()
1235
def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
1236
interrepo = _mod_repository.InterRepository.get(
1237
self.source.repository, self.target.repository)
1238
if stop_revision is None:
1239
stop_revision = self.source.last_revision()
1240
if fetch_tags is None:
1241
c = self.source.get_config_stack()
1242
fetch_tags = c.get('branch.fetch_tags')
1243
determine_wants = interrepo.get_determine_wants_revids(
1244
[stop_revision], include_tags=fetch_tags)
1245
interrepo.fetch_objects(determine_wants, limit=limit, lossy=lossy)
1246
return _mod_repository.FetchResult()
1248
def _basic_push(self, overwrite=False, stop_revision=None, tag_selector=None):
1249
if overwrite is True:
1250
overwrite = set(["history", "tags"])
1253
result = GitBranchPushResult()
602
1254
result.source_branch = self.source
603
1255
result.target_branch = self.target
604
1256
result.old_revid = self.target.last_revision()
605
1257
refs, stop_revision = self.update_refs(stop_revision)
606
self.target.generate_revision_history(stop_revision, result.old_revid)
607
self.update_tags(refs)
1258
self.target.generate_revision_history(
1260
(result.old_revid if ("history" not in overwrite) else None),
1261
other_branch=self.source)
1262
tags_ret = self.source.tags.merge_to(
1264
overwrite=("tags" in overwrite),
1265
selector=tag_selector)
1266
if isinstance(tags_ret, tuple):
1267
(result.tag_updates, result.tag_conflicts) = tags_ret
1269
result.tag_conflicts = tags_ret
608
1270
result.new_revid = self.target.last_revision()
611
def update_tags(self, refs):
612
for name, v in extract_tags(refs).iteritems():
613
revid = self.target.lookup_foreign_revision_id(v)
614
self.target.tags.set_tag(name, revid)
616
1273
def update_refs(self, stop_revision=None):
617
interrepo = repository.InterRepository.get(self.source.repository,
618
self.target.repository)
1274
interrepo = _mod_repository.InterRepository.get(
1275
self.source.repository, self.target.repository)
1276
c = self.source.get_config_stack()
1277
fetch_tags = c.get('branch.fetch_tags')
619
1279
if stop_revision is None:
620
refs = interrepo.fetch(branches=["HEAD"])
621
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
1280
result = interrepo.fetch(branches=[self.source.ref], include_tags=fetch_tags)
1282
head = result.refs[self.source.ref]
1284
stop_revision = revision.NULL_REVISION
1286
stop_revision = self.target.lookup_foreign_revision_id(head)
623
refs = interrepo.fetch(revision_id=stop_revision)
624
return refs, stop_revision
1288
result = interrepo.fetch(
1289
revision_id=stop_revision, include_tags=fetch_tags)
1290
return result.refs, stop_revision
626
1292
def pull(self, stop_revision=None, overwrite=False,
627
possible_transports=None, run_hooks=True,local=False):
1293
possible_transports=None, run_hooks=True, local=False,
628
1295
# This type of branch can't be bound.
630
1297
raise errors.LocalRequiresBoundBranch()
1298
if overwrite is True:
1299
overwrite = set(["history", "tags"])
631
1303
result = GitPullResult()
632
1304
result.source_branch = self.source
633
1305
result.target_branch = self.target
634
result.old_revid = self.target.last_revision()
635
refs, stop_revision = self.update_refs(stop_revision)
636
self.target.generate_revision_history(stop_revision, result.old_revid)
637
self.update_tags(refs)
638
result.new_revid = self.target.last_revision()
1306
with self.target.lock_write(), self.source.lock_read():
1307
result.old_revid = self.target.last_revision()
1308
refs, stop_revision = self.update_refs(stop_revision)
1309
self.target.generate_revision_history(
1311
(result.old_revid if ("history" not in overwrite) else None),
1312
other_branch=self.source)
1313
tags_ret = self.source.tags.merge_to(
1314
self.target.tags, overwrite=("tags" in overwrite),
1315
selector=tag_selector)
1316
if isinstance(tags_ret, tuple):
1317
(result.tag_updates, result.tag_conflicts) = tags_ret
1319
result.tag_conflicts = tags_ret
1320
result.new_revid = self.target.last_revision()
1321
result.local_branch = None
1322
result.master_branch = result.target_branch
1324
for hook in branch.Branch.hooks['post_pull']:
642
1329
class InterToGitBranch(branch.GenericInterBranch):
643
"""InterBranch implementation that pulls from Git into bzr."""
1330
"""InterBranch implementation that pulls into a Git branch."""
645
1332
def __init__(self, source, target):
646
1333
super(InterToGitBranch, self).__init__(source, target)
647
self.interrepo = repository.InterRepository.get(source.repository,
1334
self.interrepo = _mod_repository.InterRepository.get(source.repository,
651
1338
def _get_branch_formats_to_test():
1340
default_format = branch.format_registry.get_default()
1341
except AttributeError:
1342
default_format = branch.BranchFormat._default_format
1343
from .remote import RemoteGitBranchFormat
1345
(default_format, LocalGitBranchFormat()),
1346
(default_format, RemoteGitBranchFormat())]
655
1349
def is_compatible(self, source, target):
656
1350
return (not isinstance(source, GitBranch) and
657
1351
isinstance(target, GitBranch))
659
def update_revisions(self, *args, **kwargs):
660
raise NoPushSupport()
662
def _get_new_refs(self, stop_revision=None):
1353
def _get_new_refs(self, stop_revision=None, fetch_tags=None,
1355
if not self.source.is_locked():
1356
raise errors.ObjectNotLocked(self.source)
663
1357
if stop_revision is None:
664
stop_revision = self.source.last_revision()
665
assert type(stop_revision) is str
666
main_ref = self.target.ref or "refs/heads/master"
667
refs = { main_ref: (None, stop_revision) }
668
for name, revid in self.source.tags.get_tag_dict().iteritems():
1358
(stop_revno, stop_revision) = self.source.last_revision_info()
1359
elif stop_revno is None:
1361
stop_revno = self.source.revision_id_to_revno(stop_revision)
1362
except errors.NoSuchRevision:
1364
if not isinstance(stop_revision, bytes):
1365
raise TypeError(stop_revision)
1366
main_ref = self.target.ref
1367
refs = {main_ref: (None, stop_revision)}
1368
if fetch_tags is None:
1369
c = self.source.get_config_stack()
1370
fetch_tags = c.get('branch.fetch_tags')
1371
for name, revid in self.source.tags.get_tag_dict().items():
669
1372
if self.source.repository.has_revision(revid):
670
refs[tag_name_to_ref(name)] = (None, revid)
671
return refs, main_ref
1373
ref = tag_name_to_ref(name)
1374
if not check_ref_format(ref):
1375
warning("skipping tag with invalid characters %s (%s)",
1379
# FIXME: Skip tags that are not in the ancestry
1380
refs[ref] = (None, revid)
1381
return refs, main_ref, (stop_revno, stop_revision)
1383
def _update_refs(self, result, old_refs, new_refs, overwrite, tag_selector):
1384
mutter("updating refs. old refs: %r, new refs: %r",
1386
result.tag_updates = {}
1387
result.tag_conflicts = []
1388
ret = dict(old_refs)
1390
def ref_equals(refs, ref, git_sha, revid):
1395
if (value[0] is not None and
1396
git_sha is not None and
1397
value[0] == git_sha):
1399
if (value[1] is not None and
1400
revid is not None and
1403
# FIXME: If one side only has the git sha available and the other
1404
# only has the bzr revid, then this will cause us to show a tag as
1405
# updated that hasn't actually been updated.
1407
# FIXME: Check for diverged branches
1408
for ref, (git_sha, revid) in new_refs.items():
1409
if ref_equals(ret, ref, git_sha, revid):
1410
# Already up to date
1412
git_sha = old_refs[ref][0]
1414
revid = old_refs[ref][1]
1415
ret[ref] = new_refs[ref] = (git_sha, revid)
1416
elif ref not in ret or overwrite:
1418
tag_name = ref_to_tag_name(ref)
1422
if tag_selector and not tag_selector(tag_name):
1424
result.tag_updates[tag_name] = revid
1425
ret[ref] = (git_sha, revid)
1427
# FIXME: Check diverged
1431
name = ref_to_tag_name(ref)
1435
result.tag_conflicts.append(
1436
(name, revid, ret[name][1]))
1438
ret[ref] = (git_sha, revid)
1441
def fetch(self, stop_revision=None, fetch_tags=None, lossy=False,
1443
if stop_revision is None:
1444
stop_revision = self.source.last_revision()
1447
for k, v in self.source.tags.get_tag_dict().items():
1448
ret.append((None, v))
1449
ret.append((None, stop_revision))
1451
revidmap = self.interrepo.fetch_objects(ret, lossy=lossy, limit=limit)
1452
except NoPushSupport:
1453
raise errors.NoRoundtrippingSupport(self.source, self.target)
1454
return _mod_repository.FetchResult(revidmap={
1455
old_revid: new_revid
1456
for (old_revid, (new_sha, new_revid)) in revidmap.items()})
673
1458
def pull(self, overwrite=False, stop_revision=None, local=False,
674
possible_transports=None):
675
from dulwich.protocol import ZERO_SHA
1459
possible_transports=None, run_hooks=True, _stop_revno=None,
676
1461
result = GitBranchPullResult()
677
1462
result.source_branch = self.source
678
1463
result.target_branch = self.target
679
new_refs, main_ref = self._get_new_refs(stop_revision)
680
def update_refs(old_refs):
681
refs = dict(old_refs)
682
# FIXME: Check for diverged branches
683
refs.update(new_refs)
685
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
686
result.old_revid = self.target.lookup_foreign_revision_id(
687
old_refs.get(main_ref, ZERO_SHA))
688
result.new_revid = new_refs[main_ref]
691
def push(self, overwrite=False, stop_revision=None,
692
_override_hook_source_branch=None):
693
from dulwich.protocol import ZERO_SHA
694
result = GitBranchPushResult()
695
result.source_branch = self.source
696
result.target_branch = self.target
697
new_refs, main_ref = self._get_new_refs(stop_revision)
698
def update_refs(old_refs):
699
refs = dict(old_refs)
700
# FIXME: Check for diverged branches
701
refs.update(new_refs)
703
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
704
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
705
if result.old_revid is None:
706
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
707
result.new_revid = new_refs[main_ref]
710
def lossy_push(self, stop_revision=None):
711
result = GitBranchPushResult()
712
result.source_branch = self.source
713
result.target_branch = self.target
714
new_refs, main_ref = self._get_new_refs(stop_revision)
715
def update_refs(old_refs):
716
refs = dict(old_refs)
717
# FIXME: Check for diverged branches
718
refs.update(new_refs)
720
result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
722
result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
723
result.new_revid = new_refs[main_ref][1]
727
branch.InterBranch.register_optimiser(InterGitRemoteLocalBranch)
1464
with self.source.lock_read(), self.target.lock_write():
1465
new_refs, main_ref, stop_revinfo = self._get_new_refs(
1466
stop_revision, stop_revno=_stop_revno)
1468
def update_refs(old_refs):
1469
return self._update_refs(result, old_refs, new_refs, overwrite, tag_selector)
1471
result.revidmap, old_refs, new_refs = (
1472
self.interrepo.fetch_refs(update_refs, lossy=False))
1473
except NoPushSupport:
1474
raise errors.NoRoundtrippingSupport(self.source, self.target)
1475
(old_sha1, result.old_revid) = old_refs.get(
1476
main_ref, (ZERO_SHA, NULL_REVISION))
1477
if result.old_revid is None:
1478
result.old_revid = self.target.lookup_foreign_revision_id(
1480
result.new_revid = new_refs[main_ref][1]
1481
result.local_branch = None
1482
result.master_branch = self.target
1484
for hook in branch.Branch.hooks['post_pull']:
1488
def push(self, overwrite=False, stop_revision=None, lossy=False,
1489
_override_hook_source_branch=None, _stop_revno=None,
1491
result = GitBranchPushResult()
1492
result.source_branch = self.source
1493
result.target_branch = self.target
1494
result.local_branch = None
1495
result.master_branch = result.target_branch
1496
with self.source.lock_read(), self.target.lock_write():
1497
new_refs, main_ref, stop_revinfo = self._get_new_refs(
1498
stop_revision, stop_revno=_stop_revno)
1500
def update_refs(old_refs):
1501
return self._update_refs(result, old_refs, new_refs, overwrite, tag_selector)
1503
result.revidmap, old_refs, new_refs = (
1504
self.interrepo.fetch_refs(
1505
update_refs, lossy=lossy, overwrite=overwrite))
1506
except NoPushSupport:
1507
raise errors.NoRoundtrippingSupport(self.source, self.target)
1508
(old_sha1, result.old_revid) = old_refs.get(
1509
main_ref, (ZERO_SHA, NULL_REVISION))
1510
if lossy or result.old_revid is None:
1511
result.old_revid = self.target.lookup_foreign_revision_id(
1513
result.new_revid = new_refs[main_ref][1]
1514
(result.new_original_revno,
1515
result.new_original_revid) = stop_revinfo
1516
for hook in branch.Branch.hooks['post_push']:
1521
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
728
1522
branch.InterBranch.register_optimiser(InterFromGitBranch)
729
1523
branch.InterBranch.register_optimiser(InterToGitBranch)
730
branch.InterBranch.register_optimiser(InterGitLocalRemoteBranch)
1524
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)