@@ -27,6 +27,7 @@ import bzrlib.generate_ids
27
27
import bzrlib .transport
28
28
import bzrlib .errors
29
29
import bzrlib .ui
30
+ import bzrlib .urlutils
30
31
31
32
import sys
32
33
import os
@@ -250,12 +251,13 @@ def export_files(tree, files):
250
251
251
252
return final
252
253
253
- def export_branch (branch , name ):
254
+ def export_branch (repo , name ):
254
255
global prefix
255
256
256
257
ref = '%s/heads/%s' % (prefix , name )
257
258
tip = marks .get_tip (name )
258
259
260
+ branch = branches [name ]
259
261
repo = branch .repository
260
262
261
263
branch .lock_read ()
@@ -323,7 +325,7 @@ def export_branch(branch, name):
323
325
324
326
count += 1
325
327
if (count % 100 == 0 ):
326
- print "progress revision %s (%d/%d)" % (revid , count , len (revs ))
328
+ print "progress revision %s '%s' (%d/%d)" % (revid , name , count , len (revs ))
327
329
print "#############################################################"
328
330
329
331
branch .unlock ()
@@ -348,7 +350,7 @@ def export_tag(repo, name):
348
350
def do_import (parser ):
349
351
global dirname
350
352
351
- branch = parser .repo
353
+ repo = parser .repo
352
354
path = os .path .join (dirname , 'marks-git' )
353
355
354
356
print "feature done"
@@ -362,10 +364,10 @@ def do_import(parser):
362
364
ref = parser [1 ]
363
365
if ref .startswith ('refs/heads/' ):
364
366
name = ref [len ('refs/heads/' ):]
365
- export_branch (branch , name )
367
+ export_branch (repo , name )
366
368
if ref .startswith ('refs/tags/' ):
367
369
name = ref [len ('refs/tags/' ):]
368
- export_tag (branch , name )
370
+ export_tag (repo , name )
369
371
parser .next ()
370
372
371
373
print 'done'
@@ -551,8 +553,11 @@ def parse_commit(parser):
551
553
ref = parser [1 ]
552
554
parser .next ()
553
555
554
- if ref != 'refs/heads/master' :
555
- die ("bzr doesn't support multiple branches; use 'master'" )
556
+ if ref .startswith ('refs/heads/' ):
557
+ name = ref [len ('refs/heads/' ):]
558
+ branch = branches [name ]
559
+ else :
560
+ die ('unknown ref' )
556
561
557
562
commit_mark = parser .get_mark ()
558
563
parser .next ()
@@ -588,8 +593,6 @@ def parse_commit(parser):
588
593
path = c_style_unescape (path ).decode ('utf-8' )
589
594
files [path ] = f
590
595
591
- branch = parser .repo
592
-
593
596
committer , date , tz = committer
594
597
parents = [str (mark_to_rev (p )) for p in parents ]
595
598
revid = bzrlib .generate_ids .gen_revision_id (committer , date )
@@ -621,9 +624,6 @@ def parse_reset(parser):
621
624
ref = parser [1 ]
622
625
parser .next ()
623
626
624
- if ref != 'refs/heads/master' :
625
- die ("bzr doesn't support multiple branches; use 'master'" )
626
-
627
627
# ugh
628
628
if parser .check ('commit' ):
629
629
parse_commit (parser )
@@ -636,7 +636,7 @@ def parse_reset(parser):
636
636
parsed_refs [ref ] = mark_to_rev (from_mark )
637
637
638
638
def do_export (parser ):
639
- global parsed_refs , dirname , peer
639
+ global parsed_refs , dirname
640
640
641
641
parser .next ()
642
642
@@ -654,23 +654,24 @@ def do_export(parser):
654
654
else :
655
655
die ('unhandled export command: %s' % line )
656
656
657
- branch = parser .repo
658
-
659
657
for ref , revid in parsed_refs .iteritems ():
660
- if ref == 'refs/heads/master' :
661
- branch .generate_revision_history (revid , marks .get_tip ('master' ))
662
- if peer :
663
- try :
664
- branch .push (peer , stop_revision = revid )
665
- except bzrlib .errors .DivergedBranches :
666
- print "error %s non-fast forward" % ref
667
- continue
658
+ name = ref [len ('refs/heads/' ):]
659
+ branch = branches [name ]
660
+ branch .generate_revision_history (revid , marks .get_tip (name ))
668
661
662
+ if name in peers :
663
+ peer = peers [name ]
669
664
try :
670
- wt = branch .bzrdir .open_workingtree ()
671
- wt .update ()
672
- except bzrlib .errors .NoWorkingTree :
673
- pass
665
+ peer .bzrdir .push_branch (branch , revision_id = revid )
666
+ except bzrlib .errors .DivergedBranches :
667
+ print "error %s non-fast forward" % ref
668
+ continue
669
+
670
+ try :
671
+ wt = branch .bzrdir .open_workingtree ()
672
+ wt .update ()
673
+ except bzrlib .errors .NoWorkingTree :
674
+ pass
674
675
675
676
print "ok %s" % ref
676
677
@@ -697,9 +698,15 @@ def ref_is_valid(name):
697
698
698
699
def do_list (parser ):
699
700
global tags
700
- print "? refs/heads/%s" % 'master'
701
701
702
- branch = parser .repo
702
+ master_branch = None
703
+
704
+ for name in branches :
705
+ if not master_branch :
706
+ master_branch = name
707
+ print "? refs/heads/%s" % name
708
+
709
+ branch = branches [master_branch ]
703
710
branch .lock_read ()
704
711
for tag , revid in branch .tags .get_tag_dict ().items ():
705
712
try :
@@ -711,41 +718,77 @@ def do_list(parser):
711
718
print "? refs/tags/%s" % tag
712
719
tags [tag ] = revid
713
720
branch .unlock ()
714
- print "@refs/heads/%s HEAD" % 'master'
721
+
722
+ print "@refs/heads/%s HEAD" % master_branch
715
723
print
716
724
725
+ def get_remote_branch (origin , remote_branch , name ):
726
+ global dirname , peers
727
+
728
+ branch_path = os .path .join (dirname , 'clone' , name )
729
+ if os .path .exists (branch_path ):
730
+ # pull
731
+ d = bzrlib .bzrdir .BzrDir .open (branch_path )
732
+ branch = d .open_branch ()
733
+ try :
734
+ branch .pull (remote_branch , [], None , False )
735
+ except bzrlib .errors .DivergedBranches :
736
+ # use remote branch for now
737
+ return remote_branch
738
+ else :
739
+ # clone
740
+ d = origin .sprout (branch_path , None ,
741
+ hardlink = True , create_tree_if_local = False ,
742
+ force_new_repo = False ,
743
+ source_branch = remote_branch )
744
+ branch = d .open_branch ()
745
+
746
+ return branch
747
+
717
748
def get_repo (url , alias ):
718
- global dirname , peer
749
+ global dirname , peer , branches
719
750
751
+ normal_url = bzrlib .urlutils .normalize_url (url )
720
752
origin = bzrlib .bzrdir .BzrDir .open (url )
721
- branch = origin .open_branch ()
722
-
723
- if not isinstance (origin .transport , bzrlib .transport .local .LocalTransport ):
724
- clone_path = os .path .join (dirname , 'clone' )
725
- remote_branch = branch
726
- if os .path .exists (clone_path ):
727
- # pull
728
- d = bzrlib .bzrdir .BzrDir .open (clone_path )
729
- branch = d .open_branch ()
730
- try :
731
- result = branch .pull (remote_branch , [], None , False )
732
- except bzrlib .errors .DivergedBranches :
733
- # use remote branch for now
734
- peer = None
735
- return remote_branch
753
+ is_local = isinstance (origin .transport , bzrlib .transport .local .LocalTransport )
754
+
755
+ clone_path = os .path .join (dirname , 'clone' )
756
+
757
+ try :
758
+ repo = origin .open_repository ()
759
+ except bzrlib .errors .NoRepositoryPresent :
760
+ # branch
761
+
762
+ name = 'master'
763
+ branch = origin .open_branch ()
764
+
765
+ if not is_local :
766
+ if not os .path .exists (clone_path ):
767
+ os .mkdir (clone_path )
768
+ peers [name ] = branch
769
+ branches [name ] = get_remote_branch (origin , branch , name )
736
770
else :
737
- # clone
738
- d = origin .sprout (clone_path , None ,
739
- hardlink = True , create_tree_if_local = False ,
740
- source_branch = remote_branch )
741
- branch = d .open_branch ()
742
- branch .bind (remote_branch )
743
-
744
- peer = remote_branch
771
+ branches [name ] = branch
772
+
773
+ return branch .repository
745
774
else :
746
- peer = None
775
+ # repository
747
776
748
- return branch
777
+ if not is_local and not os .path .exists (clone_path ):
778
+ clonedir = bzrlib .bzrdir .BzrDir .create (clone_path )
779
+
780
+ for branch in repo .find_branches ():
781
+
782
+ name = repo .user_transport .relpath (branch .base )
783
+ name = name if name != '' else 'master'
784
+
785
+ if not is_local :
786
+ peers [name ] = branch
787
+ branches [name ] = get_remote_branch (origin , branch , name )
788
+ else :
789
+ branches [name ] = branch
790
+
791
+ return repo
749
792
750
793
def fix_path (alias , orig_url ):
751
794
url = urlparse .urlparse (orig_url , 'file' )
@@ -762,6 +805,7 @@ def main(args):
762
805
global parsed_refs
763
806
global files_cache
764
807
global is_tmp
808
+ global branches , peers
765
809
766
810
alias = args [1 ]
767
811
url = args [2 ]
@@ -772,6 +816,8 @@ def main(args):
772
816
parsed_refs = {}
773
817
files_cache = {}
774
818
marks = None
819
+ branches = {}
820
+ peers = {}
775
821
776
822
if alias [5 :] == url :
777
823
is_tmp = True
0 commit comments