~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
***************
*** 738,777 ****
          revisions = []
          pb = ProgressBar(show_spinner=True)
          total = len(revision_ids)
-         for i,f in enumerate(revision_ids):
-             revisions.append(other.get_revision(f))
-             pb.update('retrieving revisions', i+1, total)
-         pb.clear()
-         
-         needed_texts = sets.Set()
- 
-         for index, rev in enumerate(revisions):
-             pb.update('Scanning revisions for file contents', index, total)
-             inv = other.get_inventory(str(rev.inventory_id))
-             for key, entry in inv.iter_entries():
-                 if entry.text_id is None:
-                     continue
-                 if entry.text_id not in self.text_store:
-                     needed_texts.add(entry.text_id)
-         pb.clear()
-         count = self.text_store.copy_multi(other.text_store, needed_texts, pb,
-                                            "Copying file contents")
-         pb.clear()
-         print "Added %d file contents." % count 
-         inventory_ids = [ f.inventory_id for f in revisions ]
-         count = self.inventory_store.copy_multi(other.inventory_store, 
-                                                 inventory_ids, pb,
-                                                 "Copying inventories")
-         pb.clear()
-         print "Added %d inventories." % count 
-         revision_ids = [ f.revision_id for f in revisions]
-         count = self.revision_store.copy_multi(other.revision_store, 
-                                                revision_ids, pb, 
-                                                "Copying revisions")
-         pb.clear()
-         for revision_id in revision_ids:
-             self.append_revision(revision_id)
-         print "Added %d revisions." % count
                      
          
      def commit(self, *args, **kw):
--- 738,799 ----
          revisions = []
          pb = ProgressBar(show_spinner=True)
          total = len(revision_ids)
+         tmp_dir = tempfile.mkdtemp(prefix = "temp-stores-")
+         try:
+             tmp_rev_dir = os.path.join(tmp_dir, "revisions")
+             os.mkdir(tmp_rev_dir)
+             tmp_revs = ImmutableStore(tmp_rev_dir)
+             count = tmp_revs.copy_multi(other.revision_store, revision_ids, pb, 
+                                         "Caching revisions")
+             #EVIL! Substituting a local partial store for a complete one
+             #This is a significant performance boost when complete one is
+             #a remote store. 
+             other.revision_store = tmp_revs
+             pb.clear()
+ 
+             for i,f in enumerate(revision_ids):
+                 revisions.append(other.get_revision(f))
+                 pb.update("Parsing revisions", i, len(revision_ids))
+             
+             needed_texts = sets.Set()
+ 
+             #Again with the EVIL.
+             tmp_rev_dir = os.path.join(tmp_dir, "inventories")
+             os.mkdir(tmp_rev_dir)
+             inv_ids = [r.inventory_id for r in revisions]
+             tmp_revs = ImmutableStore(tmp_rev_dir)
+             count = tmp_revs.copy_multi(other.inventory_store, inv_ids, pb, 
+                                         "Caching inventories")
+             other.inventory_store = tmp_revs
+             pb.clear()
+             for index, rev in enumerate(revisions):
+                 pb.update('Scanning revisions for file contents', index, total)
+                 inv = other.get_inventory(str(rev.inventory_id))
+                 for key, entry in inv.iter_entries():
+                     if entry.text_id is None:
+                         continue
+                     if entry.text_id not in self.text_store:
+                         needed_texts.add(entry.text_id)
+             pb.clear()
+             count = self.text_store.copy_multi(other.text_store, needed_texts, pb,
+                                                "Copying file contents")
+             pb.clear()
+             print "Added %d file contents." % count 
+             inventory_ids = [ f.inventory_id for f in revisions ]
+             count = self.inventory_store.copy_multi(other.inventory_store, 
+                                                     inventory_ids, pb,
+                                                     "Copying inventories")
+             pb.clear()
+             print "Added %d inventories." % count 
+             revision_ids = [ f.revision_id for f in revisions]
+             count = self.revision_store.copy_multi(other.revision_store, 
+                                                    revision_ids)
+             pb.clear()
+             for revision_id in revision_ids:
+                 self.append_revision(revision_id)
+             print "Added %d revisions." % count
+         finally:
+             shutil.rmtree(tmp_dir)
                      
          
      def commit(self, *args, **kw):