76
90
return self._lookup_revno(self.new_revid)
79
class LocalGitTagDict(tag.BasicTags):
80
"""Dictionary with tags in a local repository."""
93
class GitTags(tag.BasicTags):
94
"""Ref-based tag dictionary."""
82
96
def __init__(self, branch):
83
97
self.branch = branch
84
98
self.repository = branch.repository
100
def get_refs_container(self):
101
raise NotImplementedError(self.get_refs_container)
103
def _iter_tag_refs(self, refs):
104
"""Iterate over the tag refs.
106
:param refs: Refs dictionary (name -> git sha1)
107
:return: iterator over (name, peeled_sha1, unpeeled_sha1, bzr_revid)
109
for k, unpeeled in refs.as_dict().iteritems():
111
tag_name = ref_to_tag_name(k)
112
except (ValueError, UnicodeDecodeError):
114
peeled = refs.get_peeled(k)
116
peeled = self.repository.bzrdir._git.object_store.peel_sha(unpeeled).id
117
yield (tag_name, peeled, unpeeled,
118
self.branch.lookup_foreign_revision_id(peeled))
120
def _merge_to_remote_git(self, target_repo, new_refs, overwrite=False):
123
def get_changed_refs(old_refs):
125
for k, v in new_refs.iteritems():
128
name = ref_to_tag_name(k)
129
if old_refs.get(k) == v:
131
elif overwrite or not k in old_refs:
133
updates[name] = target_repo.lookup_foreign_revision_id(v)
135
conflicts.append((name, v, old_refs[k]))
137
target_repo.bzrdir.send_pack(get_changed_refs, lambda have, want: [])
138
return updates, conflicts
140
def _merge_to_local_git(self, target_repo, refs, overwrite=False):
143
for k, unpeeled in refs.as_dict().iteritems():
146
name = ref_to_tag_name(k)
147
peeled = self.repository.bzrdir.get_peeled(k)
148
if target_repo._git.refs.get(k) == unpeeled:
150
elif overwrite or not k in target_repo._git.refs:
151
target_repo._git.refs[k] = unpeeled or peeled
152
updates[name] = target_repo.lookup_foreign_revision_id(peeled)
154
conflicts.append((name, peeled, target_repo._git.refs[k]))
155
return updates, conflicts
157
def _merge_to_git(self, to_tags, refs, overwrite=False):
158
target_repo = to_tags.repository
159
if self.repository.has_same_location(target_repo):
161
if getattr(target_repo, "_git", None):
162
return self._merge_to_local_git(target_repo, refs, overwrite)
164
return self._merge_to_remote_git(target_repo, refs, overwrite)
166
def _merge_to_non_git(self, to_tags, refs, overwrite=False):
167
unpeeled_map = defaultdict(set)
170
result = dict(to_tags.get_tag_dict())
171
for n, peeled, unpeeled, bzr_revid in self._iter_tag_refs(refs):
172
if unpeeled is not None:
173
unpeeled_map[peeled].add(unpeeled)
174
if result.get(n) == bzr_revid:
176
elif n not in result or overwrite:
177
result[n] = bzr_revid
178
updates[n] = bzr_revid
180
conflicts.append((n, result[n], bzr_revid))
181
to_tags._set_tag_dict(result)
182
if len(unpeeled_map) > 0:
183
map_file = UnpeelMap.from_repository(to_tags.branch.repository)
184
map_file.update(unpeeled_map)
185
map_file.save_in_repository(to_tags.branch.repository)
186
return updates, conflicts
188
def merge_to(self, to_tags, overwrite=False, ignore_master=False,
190
"""See Tags.merge_to."""
191
if source_refs is None:
192
source_refs = self.get_refs_container()
195
if isinstance(to_tags, GitTags):
196
return self._merge_to_git(to_tags, source_refs,
202
master = to_tags.branch.get_master_branch()
203
updates, conflicts = self._merge_to_non_git(to_tags, source_refs,
205
if master is not None:
206
extra_updates, extra_conflicts = self.merge_to(
207
master.tags, overwrite=overwrite,
208
source_refs=source_refs,
209
ignore_master=ignore_master)
210
updates.update(extra_updates)
211
conflicts += extra_conflicts
212
return updates, conflicts
86
214
def get_tag_dict(self):
88
for k,v in extract_tags(self.repository._git.get_refs()).iteritems():
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)
216
refs = self.get_refs_container()
217
for (name, peeled, unpeeled, bzr_revid) in self._iter_tag_refs(refs):
218
ret[name] = bzr_revid
222
class LocalGitTagDict(GitTags):
223
"""Dictionary with tags in a local repository."""
225
def __init__(self, branch):
226
super(LocalGitTagDict, self).__init__(branch)
227
self.refs = self.repository.bzrdir._git.refs
229
def get_refs_container(self):
104
232
def _set_tag_dict(self, to_dict):
105
extra = set(self.repository._git.get_refs().keys())
233
extra = set(self.refs.allkeys())
106
234
for k, revid in to_dict.iteritems():
107
235
name = tag_name_to_ref(k)
108
236
if name in extra:
109
237
extra.remove(name)
110
238
self.set_tag(k, revid)
111
239
for name in extra:
112
if name.startswith("refs/tags/"):
113
241
del self.repository._git[name]
115
243
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):
245
git_sha, mapping = self.branch.lookup_bzr_revision_id(revid)
246
except errors.NoSuchRevision:
247
raise errors.GhostTagsNotSupported(self)
248
self.refs[tag_name_to_ref(name)] = git_sha
251
class DictTagDict(tag.BasicTags):
122
253
def __init__(self, branch, tags):
123
254
super(DictTagDict, self).__init__(branch)
373
def get_config(self):
374
return GitBranchConfig(self)
376
def get_config_stack(self):
377
return GitBranchStack(self)
194
379
def _get_nick(self, local=False, possible_master_transports=None):
195
380
"""Find the nick name for this branch.
197
382
:return: Branch nick
199
return self.name or "HEAD"
384
cs = self.repository._git.get_config_stack()
386
return cs.get(("branch", self.name), "nick")
389
return self.name.encode('utf-8') or "HEAD"
201
391
def _set_nick(self, nick):
202
raise NotImplementedError
392
cf = self.repository._git.get_config()
393
cf.set(("branch", self.name), "nick", nick)
396
self.bzrdir.control_transport.put_bytes('config', f.getvalue())
204
398
nick = property(_get_nick, _set_nick)
206
400
def __repr__(self):
207
401
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
210
404
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)
405
if revid == NULL_REVISION:
408
# FIXME: Check that old_revid is in the ancestry of revid
409
newhead, self.mapping = self.repository.lookup_bzr_revision_id(revid)
410
if self.mapping is None:
213
412
self._set_head(newhead)
215
def lock_write(self):
216
self.control_files.lock_write()
414
def lock_write(self, token=None):
415
if token is not None:
416
raise errors.TokenLockingNotSupported(self)
418
if self._lock_mode == 'r':
419
raise errors.ReadOnlyError(self)
420
self._lock_count += 1
422
self._lock_mode = 'w'
424
self.repository.lock_write()
217
425
return GitWriteLock(self.unlock)
427
def leave_lock_in_place(self):
428
raise NotImplementedError(self.leave_lock_in_place)
430
def dont_leave_lock_in_place(self):
431
raise NotImplementedError(self.dont_leave_lock_in_place)
219
433
def get_stacked_on_url(self):
220
434
# Git doesn't do stacking (yet...)
221
435
raise errors.UnstackableBranchFormat(self._format, self.base)
427
693
def _get_branch_formats_to_test():
695
default_format = branch.format_registry.get_default()
696
except AttributeError:
697
default_format = branch.BranchFormat._default_format
699
(GitBranchFormat(), GitBranchFormat()),
700
(GitBranchFormat(), default_format)]
431
703
def _get_interrepo(self, source, target):
432
return repository.InterRepository.get(source.repository,
704
return _mod_repository.InterRepository.get(source.repository, target.repository)
436
707
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.
708
if not isinstance(source, GitBranch):
710
if isinstance(target, GitBranch):
711
# InterLocalGitRemoteGitBranch or InterToGitBranch should be used
713
if getattr(cls._get_interrepo(source, target), "fetch_objects", None) is None:
714
# fetch_objects is necessary for this to work
718
def fetch(self, stop_revision=None, fetch_tags=None, limit=None):
719
self.fetch_objects(stop_revision, fetch_tags=fetch_tags, limit=limit)
721
def fetch_objects(self, stop_revision, fetch_tags, limit=None):
449
722
interrepo = self._get_interrepo(self.source, self.target)
723
if fetch_tags is None:
724
c = self.source.get_config()
725
fetch_tags = c.get_user_option_as_bool('branch.fetch_tags')
450
726
def determine_wants(heads):
451
727
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:
454
self._last_revid = stop_revision
455
head, mapping = self.source.repository.lookup_bzr_revision_id(
728
raise NoSuchRef(self.source.ref, self.source.user_url, heads.keys())
730
if stop_revision is None:
458
731
if self.source.ref is not None:
459
732
head = heads[self.source.ref]
461
734
head = heads["HEAD"]
462
735
self._last_revid = self.source.lookup_foreign_revision_id(head)
463
if self.target.repository.has_revision(self._last_revid):
737
self._last_revid = stop_revision
738
real = interrepo.get_determine_wants_revids(
739
[self._last_revid], include_tags=fetch_tags)
466
741
pack_hint, head, refs = interrepo.fetch_objects(
467
742
determine_wants, self.source.mapping, limit=limit)
468
743
if (pack_hint is not None and
469
744
self.target.repository._format.pack_compresses):
470
745
self.target.repository.pack(hint=pack_hint)
472
self._last_revid = self.source.lookup_foreign_revision_id(head)
748
def _update_revisions(self, stop_revision=None, overwrite=False):
749
head, refs = self.fetch_objects(stop_revision, fetch_tags=None)
474
751
prev_last_revid = None
476
753
prev_last_revid = self.target.last_revision()
477
754
self.target.generate_revision_history(self._last_revid,
755
prev_last_revid, self.source)
481
def update_revisions(self, stop_revision=None, overwrite=False,
483
"""See InterBranch.update_revisions()."""
484
self._update_revisions(stop_revision, overwrite, graph)
758
def _basic_pull(self, stop_revision, overwrite, run_hooks,
759
_override_hook_target, _hook_master):
760
result = GitBranchPullResult()
761
result.source_branch = self.source
762
if _override_hook_target is None:
763
result.target_branch = self.target
765
result.target_branch = _override_hook_target
766
self.source.lock_read()
768
self.target.lock_write()
770
# We assume that during 'pull' the target repository is closer than
772
(result.old_revno, result.old_revid) = \
773
self.target.last_revision_info()
774
result.new_git_head, remote_refs = self._update_revisions(
775
stop_revision, overwrite=overwrite)
776
tags_ret = self.source.tags.merge_to(
777
self.target.tags, overwrite)
778
if isinstance(tags_ret, tuple):
779
result.tag_updates, result.tag_conflicts = tags_ret
781
result.tag_conflicts = tags_ret
782
(result.new_revno, result.new_revid) = \
783
self.target.last_revision_info()
785
result.master_branch = _hook_master
786
result.local_branch = result.target_branch
788
result.master_branch = result.target_branch
789
result.local_branch = None
791
for hook in branch.Branch.hooks['post_pull']:
486
799
def pull(self, overwrite=False, stop_revision=None,
487
800
possible_transports=None, _hook_master=None, run_hooks=True,
488
_override_hook_target=None, local=False, limit=None):
801
_override_hook_target=None, local=False):
489
802
"""See Branch.pull.
491
804
:param _hook_master: Private parameter - set the branch to
495
808
so it should not run its hooks.
496
809
:param _override_hook_target: Private parameter - set the branch to be
497
810
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
812
# This type of branch can't be bound.
813
bound_location = self.target.get_bound_location()
814
if local and not bound_location:
503
815
raise errors.LocalRequiresBoundBranch()
504
result = GitBranchPullResult()
505
result.source_branch = self.source
506
if _override_hook_target is None:
507
result.target_branch = self.target
509
result.target_branch = _override_hook_target
817
source_is_master = False
510
818
self.source.lock_read()
820
# bound_location comes from a config file, some care has to be
821
# taken to relate it to source.user_url
822
normalized = urlutils.normalize_url(bound_location)
824
relpath = self.source.user_transport.relpath(normalized)
825
source_is_master = (relpath == '')
826
except (errors.PathNotChild, errors.InvalidURL):
827
source_is_master = False
828
if not local and bound_location and not source_is_master:
829
# not pulling from master, so we need to update master.
830
master_branch = self.target.get_master_branch(possible_transports)
831
master_branch.lock_write()
512
# We assume that during 'pull' the target repository is closer than
514
graph = self.target.repository.get_graph(self.source.repository)
515
(result.old_revno, result.old_revid) = \
516
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,
521
(result.new_revno, result.new_revid) = \
522
self.target.last_revision_info()
524
result.master_branch = _hook_master
525
result.local_branch = result.target_branch
527
result.master_branch = result.target_branch
528
result.local_branch = None
530
for hook in branch.Branch.hooks['post_pull']:
835
# pull from source into master.
836
master_branch.pull(self.source, overwrite, stop_revision,
838
result = self._basic_pull(stop_revision, overwrite, run_hooks,
839
_override_hook_target, _hook_master=master_branch)
844
master_branch.unlock()
536
847
def _basic_push(self, overwrite=False, stop_revision=None):
537
848
result = branch.BranchPushResult()
538
849
result.source_branch = self.source
539
850
result.target_branch = self.target
540
graph = self.target.repository.get_graph(self.source.repository)
541
851
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,
852
result.new_git_head, remote_refs = self._update_revisions(
853
stop_revision, overwrite=overwrite)
854
tags_ret = self.source.tags.merge_to(self.target.tags,
856
if isinstance(tags_ret, tuple):
857
(result.tag_updates, result.tag_conflicts) = tags_ret
859
result.tag_conflicts = tags_ret
546
860
result.new_revno, result.new_revid = self.target.last_revision_info()
587
class InterGitRemoteLocalBranch(InterGitBranch):
905
class InterGitLocalGitBranch(InterGitBranch):
588
906
"""InterBranch that copies from a remote to a local git branch."""
591
909
def _get_branch_formats_to_test():
595
914
def is_compatible(self, source, target):
596
from bzrlib.plugins.git.remote import RemoteGitBranch
597
return (isinstance(source, RemoteGitBranch) and
915
return (isinstance(source, GitBranch) and
598
916
isinstance(target, LocalGitBranch))
918
def fetch(self, stop_revision=None, fetch_tags=None, limit=None):
919
interrepo = _mod_repository.InterRepository.get(self.source.repository,
920
self.target.repository)
921
if stop_revision is None:
922
stop_revision = self.source.last_revision()
923
determine_wants = interrepo.get_determine_wants_revids(
924
[stop_revision], include_tags=fetch_tags)
925
interrepo.fetch_objects(determine_wants, limit=limit)
600
927
def _basic_push(self, overwrite=False, stop_revision=None):
601
result = branch.BranchPushResult()
928
result = GitBranchPushResult()
602
929
result.source_branch = self.source
603
930
result.target_branch = self.target
604
931
result.old_revid = self.target.last_revision()
605
932
refs, stop_revision = self.update_refs(stop_revision)
606
933
self.target.generate_revision_history(stop_revision, result.old_revid)
607
self.update_tags(refs)
934
tags_ret = self.source.tags.merge_to(self.target.tags,
935
source_refs=refs, overwrite=overwrite)
936
if isinstance(tags_ret, tuple):
937
(result.tag_updates, result.tag_conflicts) = tags_ret
939
result.tag_conflicts = tags_ret
608
940
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
943
def update_refs(self, stop_revision=None):
617
interrepo = repository.InterRepository.get(self.source.repository,
944
interrepo = _mod_repository.InterRepository.get(self.source.repository,
618
945
self.target.repository)
619
946
if stop_revision is None:
620
947
refs = interrepo.fetch(branches=["HEAD"])
631
958
result = GitPullResult()
632
959
result.source_branch = self.source
633
960
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()
961
self.source.lock_read()
963
self.target.lock_write()
965
result.old_revid = self.target.last_revision()
966
refs, stop_revision = self.update_refs(stop_revision)
967
self.target.generate_revision_history(stop_revision, result.old_revid)
968
tags_ret = self.source.tags.merge_to(self.target.tags,
969
overwrite=overwrite, source_refs=refs)
970
if isinstance(tags_ret, tuple):
971
(result.tag_updates, result.tag_conflicts) = tags_ret
973
result.tag_conflicts = tags_ret
974
result.new_revid = self.target.last_revision()
975
result.local_branch = None
976
result.master_branch = result.target_branch
978
for hook in branch.Branch.hooks['post_pull']:
642
987
class InterToGitBranch(branch.GenericInterBranch):
643
"""InterBranch implementation that pulls from Git into bzr."""
988
"""InterBranch implementation that pulls into a Git branch."""
645
990
def __init__(self, source, target):
646
991
super(InterToGitBranch, self).__init__(source, target)
647
self.interrepo = repository.InterRepository.get(source.repository,
992
self.interrepo = _mod_repository.InterRepository.get(source.repository,
648
993
target.repository)
651
996
def _get_branch_formats_to_test():
998
default_format = branch.format_registry.get_default()
999
except AttributeError:
1000
default_format = branch.BranchFormat._default_format
1001
return [(default_format, GitBranchFormat())]
655
1004
def is_compatible(self, source, target):
656
1005
return (not isinstance(source, GitBranch) and
657
1006
isinstance(target, GitBranch))
659
def update_revisions(self, *args, **kwargs):
660
raise NoPushSupport()
662
def _get_new_refs(self, stop_revision=None):
1008
def _get_new_refs(self, stop_revision=None, fetch_tags=None):
1009
assert self.source.is_locked()
663
1010
if stop_revision is None:
664
stop_revision = self.source.last_revision()
1011
(stop_revno, stop_revision) = self.source.last_revision_info()
1013
stop_revno = self.source.revision_id_to_revno(stop_revision)
665
1014
assert type(stop_revision) is str
666
1015
main_ref = self.target.ref or "refs/heads/master"
667
1016
refs = { main_ref: (None, stop_revision) }
1017
if fetch_tags is None:
1018
c = self.source.get_config()
1019
fetch_tags = c.get_user_option_as_bool('branch.fetch_tags')
668
1020
for name, revid in self.source.tags.get_tag_dict().iteritems():
669
1021
if self.source.repository.has_revision(revid):
670
refs[tag_name_to_ref(name)] = (None, revid)
671
return refs, main_ref
1022
ref = tag_name_to_ref(name)
1023
if not check_ref_format(ref):
1024
warning("skipping tag with invalid characters %s (%s)",
1028
# FIXME: Skip tags that are not in the ancestry
1029
refs[ref] = (None, revid)
1030
return refs, main_ref, (stop_revno, stop_revision)
1032
def _update_refs(self, result, old_refs, new_refs, overwrite):
1033
mutter("updating refs. old refs: %r, new refs: %r",
1035
result.tag_updates = {}
1036
result.tag_conflicts = []
1037
ret = dict(old_refs)
1038
def ref_equals(refs, ref, git_sha, revid):
1043
if (value[0] is not None and
1044
git_sha is not None and
1045
value[0] == git_sha):
1047
if (value[1] is not None and
1048
revid is not None and
1051
# FIXME: If one side only has the git sha available and the other only
1052
# has the bzr revid, then this will cause us to show a tag as updated
1053
# that hasn't actually been updated.
1055
# FIXME: Check for diverged branches
1056
for ref, (git_sha, revid) in new_refs.iteritems():
1057
if ref_equals(ret, ref, git_sha, revid):
1058
# Already up to date
1060
git_sha = old_refs[ref][0]
1062
revid = old_refs[ref][1]
1063
ret[ref] = new_refs[ref] = (git_sha, revid)
1064
elif ref not in ret or overwrite:
1066
tag_name = ref_to_tag_name(ref)
1070
result.tag_updates[tag_name] = revid
1071
ret[ref] = (git_sha, revid)
1073
# FIXME: Check diverged
1077
name = ref_to_tag_name(ref)
1081
result.tag_conflicts.append((name, revid, ret[name][1]))
1083
ret[ref] = (git_sha, revid)
1086
def fetch(self, stop_revision=None, fetch_tags=None, lossy=False, limit=None):
1087
assert limit is None
1088
if stop_revision is None:
1089
stop_revision = self.source.last_revision()
1092
for k, v in self.source.tags.get_tag_dict().iteritems():
1093
ret.append((None, v))
1094
ret.append((None, stop_revision))
1095
self.interrepo.fetch_objects(ret, lossy=lossy)
673
1097
def pull(self, overwrite=False, stop_revision=None, local=False,
674
possible_transports=None):
675
from dulwich.protocol import ZERO_SHA
1098
possible_transports=None, run_hooks=True):
676
1099
result = GitBranchPullResult()
677
1100
result.source_branch = self.source
678
1101
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]
1102
self.source.lock_read()
1104
self.target.lock_write()
1106
new_refs, main_ref, stop_revinfo = self._get_new_refs(
1108
def update_refs(old_refs):
1109
return self._update_refs(result, old_refs, new_refs, overwrite)
1111
result.revidmap, old_refs, new_refs = self.interrepo.fetch_refs(
1112
update_refs, lossy=False)
1113
except NoPushSupport:
1114
raise errors.NoRoundtrippingSupport(self.source, self.target)
1115
(old_sha1, result.old_revid) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
1116
if result.old_revid is None:
1117
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
1118
result.new_revid = new_refs[main_ref][1]
1119
result.local_branch = None
1120
result.master_branch = self.target
1122
for hook in branch.Branch.hooks['post_pull']:
1125
self.target.unlock()
1127
self.source.unlock()
691
def push(self, overwrite=False, stop_revision=None,
1130
def push(self, overwrite=False, stop_revision=None, lossy=False,
692
1131
_override_hook_source_branch=None):
693
from dulwich.protocol import ZERO_SHA
694
1132
result = GitBranchPushResult()
695
1133
result.source_branch = self.source
696
1134
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]
1135
result.local_branch = None
1136
result.master_branch = result.target_branch
1137
self.source.lock_read()
1139
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
1140
def update_refs(old_refs):
1141
return self._update_refs(result, old_refs, new_refs, overwrite)
1143
result.revidmap, old_refs, new_refs = self.interrepo.fetch_refs(
1144
update_refs, lossy=lossy)
1145
except NoPushSupport:
1146
raise errors.NoRoundtrippingSupport(self.source, self.target)
1147
(old_sha1, result.old_revid) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
1148
if result.old_revid is None:
1149
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
1150
result.new_revid = new_refs[main_ref][1]
1151
(result.new_original_revno, result.new_original_revid) = stop_revinfo
1152
for hook in branch.Branch.hooks['post_push']:
1155
self.source.unlock()
710
1158
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)
1159
# For compatibility with bzr < 2.4
1160
return self.push(lossy=True, stop_revision=stop_revision)
1163
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
728
1164
branch.InterBranch.register_optimiser(InterFromGitBranch)
729
1165
branch.InterBranch.register_optimiser(InterToGitBranch)
730
branch.InterBranch.register_optimiser(InterGitLocalRemoteBranch)
1166
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)