/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

Merge Pieter de Bie's export-fixes branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
 
111
111
    * experimental - enable experimental mode, i.e. use features
112
112
      not yet fully tested.
 
113
 
 
114
    * import-marks - name of file to read to load mark information from
 
115
 
 
116
    * export-marks - name of file to write to save mark information to
113
117
    """
114
118
 
115
119
    known_params = [
120
124
        'inv-cache',
121
125
        'inv-fulltext',
122
126
        'experimental',
 
127
        'import-marks',
 
128
        'export-marks',
123
129
        ]
124
130
 
125
131
    def note(self, msg, *args):
142
148
        """Time of day as a string."""
143
149
        # Note: this is a separate method so tests can patch in a fixed value
144
150
        return time.strftime("%H:%M:%S")
 
151
 
 
152
    def _import_marks(self, filename):
 
153
        try:
 
154
            f = file(filename)
 
155
        except IOError:
 
156
            self.warning(
 
157
                "Could not open import-marks file, not importing marks")
 
158
            return
 
159
 
 
160
        firstline = f.readline()
 
161
        match = re.match(r'^format=(\d+)$', firstline)
 
162
        if not match:
 
163
            print >>sys.stderr, "%r doesn't look like a mark file" % \
 
164
                (filename,)
 
165
            sys.exit(1)
 
166
        elif match.group(1) != '1':
 
167
            print >>sys.stderr, 'format version in mark file not supported'
 
168
            sys.exit(1)
 
169
 
 
170
        for string in f.readline().rstrip('\n').split('\0'):
 
171
            if not string:
 
172
                continue
 
173
            name, integer = string.rsplit('.', 1)
 
174
            # We really can't do anything with the branch information, so we
 
175
            # just skip it
 
176
            
 
177
        self.cache_mgr.revision_ids = {}
 
178
        for line in f:
 
179
            line = line.rstrip('\n')
 
180
            mark, revid = line.split(' ', 1)
 
181
            self.cache_mgr.revision_ids[mark] = revid
 
182
        f.close()
145
183
    
 
184
    def export_marks(self, filename):
 
185
        try:
 
186
            f = file(filename, 'w')
 
187
        except IOError:
 
188
            self.warning(
 
189
                "Could not open export-marks file, not exporting marks")
 
190
            return
 
191
        f.write('format=1\n')
 
192
        f.write('\0tmp.0\n')
 
193
        for mark, revid in self.cache_mgr.revision_ids.iteritems():
 
194
            f.write('%s %s\n' % (mark, revid))
 
195
        f.close()
 
196
        
146
197
    def pre_process(self):
147
198
        self._start_time = time.time()
148
199
        self._load_info_and_params()
149
200
        self.cache_mgr = GenericCacheManager(self.info, self.verbose,
150
201
            self.inventory_cache_size)
151
 
        self.skip_total = self._init_id_map()
152
 
        if self.skip_total:
153
 
            self.note("Found %d commits already loaded - "
154
 
                "skipping over these ...", self.skip_total)
 
202
        
 
203
        if self.params.get("import-marks") is not None:
 
204
            self._import_marks(self.params.get("import-marks"))
 
205
            self.skip_total = False
 
206
            self.first_incremental_commit = True
 
207
        else:
 
208
            self.first_incremental_commit = False
 
209
            self.skip_total = self._init_id_map()
 
210
            if self.skip_total:
 
211
                self.note("Found %d commits already loaded - "
 
212
                    "skipping over these ...", self.skip_total)
155
213
        self._revision_count = 0
156
214
 
157
215
        # mapping of tag name to revision_id
267
325
        self.repo.commit_write_group()
268
326
        self._save_id_map()
269
327
 
 
328
        if self.params.get("export-marks") is not None:
 
329
            self.export_marks(self.params.get("export-marks"))
 
330
 
270
331
        # Update the branches
271
332
        self.note("Updating branch information ...")
272
333
        updater = GenericBranchUpdater(self.repo, self.branch, self.cache_mgr,
414
475
                self.note("Generated the file-ids cache - %d entries",
415
476
                    len(self.cache_mgr.file_ids.keys()))
416
477
            return
 
478
        if self.first_incremental_commit:
 
479
            self.first_incremental_commit = None
 
480
            parents = _track_heads(cmd, self.cache_mgr)
 
481
            self._gen_file_ids_cache(parents)
417
482
 
418
483
        # 'Commit' the revision and report progress
419
484
        handler = GenericCommitHandler(cmd, self.repo, self.cache_mgr,
433
498
                self._revision_count)
434
499
            self.checkpoint_handler(None)
435
500
 
436
 
    def _gen_file_ids_cache(self):
 
501
    def _gen_file_ids_cache(self, revs=False):
437
502
        """Generate the file-id cache by searching repository inventories.
438
503
        """
439
504
        # Get the interesting revisions - the heads
440
 
        head_ids = self.cache_mgr.heads.keys()
 
505
        if revs:
 
506
            head_ids = revs
 
507
        else:
 
508
            head_ids = self.cache_mgr.heads.keys()
441
509
        revision_ids = [self.cache_mgr.revision_ids[h] for h in head_ids]
442
510
 
443
511
        # Update the fileid cache