/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to processors/generic_processor.py

  • Committer: Pieter de Bie
  • Date: 2008-06-04 20:21:39 UTC
  • mto: (0.64.82 fastimport_trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: pdebie@ai.rug.nl-20080604202139-tz639171b55udfxp
Add importing and exporting of marks to bzr-fastimport

This extends the GenericProcessor to be able to import and export revision
marks. This is useful when you want to do an incremental import of another
repository without rerunning the whole import all the time.

The file format used for the marks is the same as in bzr-fast-export. By
sharing each other's marks files, it is possible to set up a bidirectional
gateway with another repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
        'count',
114
114
        'inv-cache',
115
115
        'experimental',
 
116
        'import-marks',
 
117
        'export-marks',
116
118
        ]
117
119
 
118
120
    def note(self, msg, *args):
135
137
        """Time of day as a string."""
136
138
        # Note: this is a separate method so tests can patch in a fixed value
137
139
        return time.strftime("%H:%M:%S")
 
140
 
 
141
    def _import_marks(self, filename):
 
142
        try:
 
143
            f = file(filename)
 
144
        except IOError:
 
145
            self.warning("Could not open import-marks file, not importing marks")
 
146
            return
 
147
 
 
148
        firstline = f.readline()
 
149
        match = re.match(r'^format=(\d+)$', firstline)
 
150
 
 
151
        if not match:
 
152
            print >>sys.stderr, "%r doesn't look like a mark file" % (filename,)
 
153
            sys.exit(1)
 
154
        elif match.group(1) != '1':
 
155
            print >>sys.stderr, 'format version in mark file not supported'
 
156
            sys.exit(1)
 
157
 
 
158
        for string in f.readline().rstrip('\n').split('\0'):
 
159
            if not string:
 
160
                continue
 
161
            name, integer = string.rsplit('.', 1)
 
162
            # We really can't do anything with the branch information, so we
 
163
            # just skip it
 
164
            
 
165
        self.cache_mgr.revision_ids = {}
 
166
        for line in f:
 
167
            line = line.rstrip('\n')
 
168
            mark, revid = line.split(' ', 1)
 
169
 
 
170
            self.cache_mgr.revision_ids[mark] = revid
138
171
    
 
172
    def export_marks(self, filename):
 
173
        f = file(filename, 'w')
 
174
        f.write('format=1\n')
 
175
 
 
176
        f.write('\0tmp.0\n')
 
177
 
 
178
        for mark, revid in self.cache_mgr.revision_ids.iteritems():
 
179
            f.write('%s %s\n' % (mark, revid))
 
180
 
 
181
        f.close()
 
182
        
139
183
    def pre_process(self):
140
184
        self._start_time = time.time()
141
185
        self._load_info_and_params()
142
186
        self.cache_mgr = GenericCacheManager(self.info, self.verbose,
143
187
            self.inventory_cache_size)
144
 
        self.skip_total = self._init_id_map()
145
 
        if self.skip_total:
146
 
            self.note("Found %d commits already loaded - "
147
 
                "skipping over these ...", self.skip_total)
148
 
        self._revision_count = 0
 
188
        
 
189
        if self.params.get("import-marks"):
 
190
            self._import_marks(self.params.get("import-marks"))
 
191
            self.skip_total = False
 
192
            self._revision_count = 0
 
193
            self.first_incremental_commit = True
 
194
        else:
 
195
            self.first_incremental_commit = False
 
196
            self.skip_total = self._init_id_map()
 
197
 
 
198
            if self.skip_total:
 
199
                self.note("Found %d commits already loaded - "
 
200
                    "skipping over these ...", self.skip_total)
 
201
            self._revision_count = 0
149
202
 
150
203
        # mapping of tag name to revision_id
151
204
        self.tags = {}
235
288
        self.repo.commit_write_group()
236
289
        self._save_id_map()
237
290
 
 
291
        if self.params.get("export-marks"):
 
292
            self.export_marks(self.params.get("export-marks"))
 
293
 
238
294
        # Update the branches
239
295
        self.note("Updating branch information ...")
240
296
        updater = GenericBranchUpdater(self.repo, self.branch, self.cache_mgr,
382
438
                self.note("Generated the file-ids cache - %d entries",
383
439
                    len(self.cache_mgr.file_ids.keys()))
384
440
            return
 
441
        if self.first_incremental_commit:
 
442
            self.first_incremental_commit = None
 
443
            parents = _track_heads(cmd, self.cache_mgr)
 
444
            self._gen_file_ids_cache(parents)
385
445
 
386
446
        # 'Commit' the revision and report progress
387
447
        handler = GenericCommitHandler(cmd, self.repo, self.cache_mgr,
401
461
                self._revision_count)
402
462
            self.checkpoint_handler(None)
403
463
 
404
 
    def _gen_file_ids_cache(self):
 
464
    def _gen_file_ids_cache(self, revs = False):
405
465
        """Generate the file-id cache by searching repository inventories.
406
466
        """
407
467
        # Get the interesting revisions - the heads
408
 
        head_ids = self.cache_mgr.heads.keys()
 
468
        if revs:
 
469
            head_ids = revs
 
470
        else:
 
471
            head_ids = self.cache_mgr.heads.keys()
409
472
        revision_ids = [self.cache_mgr.revision_ids[h] for h in head_ids]
410
473
 
411
474
        # Update the fileid cache