/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 fetch.py

Support non-ascii characters in tag names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    else:
107
107
        cls = InventoryFile
108
108
    ie = cls(file_id, name.decode("utf-8"), parent_id)
109
 
    ie.executable = mode_is_executable(mode)
 
109
    if ie.kind == "file":
 
110
        ie.executable = mode_is_executable(mode)
110
111
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
111
112
        base_ie = base_inv[base_inv.path2id(path)]
112
113
        ie.text_size = base_ie.text_size
113
114
        ie.text_sha1 = base_ie.text_sha1
114
 
        ie.symlink_target = base_ie.symlink_target
 
115
        if ie.kind == "symlink":
 
116
            ie.symlink_target = base_ie.symlink_target
115
117
        if ie.executable == base_ie.executable:
116
118
            ie.revision = base_ie.revision
117
119
        else:
121
123
        if ie.kind == "symlink":
122
124
            ie.revision = None
123
125
            ie.symlink_target = blob.data
124
 
            ie.text_size = None
125
 
            ie.text_sha1 = None
126
126
        else:
127
127
            ie.text_size = sum(imap(len, blob.chunked))
128
128
            ie.text_sha1 = osutils.sha_strings(blob.chunked)
155
155
                tuple(parent_keys), ie.text_sha1, chunks)])
156
156
    invdelta = []
157
157
    if base_hexsha is not None:
158
 
        old_path = path # Renames are not supported yet
 
158
        old_path = path.decode("utf-8") # Renames are not supported yet
159
159
        if stat.S_ISDIR(base_mode):
160
160
            invdelta.extend(remove_disappeared_children(base_inv, old_path,
161
161
                lookup_object(base_hexsha), [], lookup_object))
162
162
    else:
163
163
        old_path = None
164
 
    invdelta.append((old_path, path, file_id, ie))
 
164
    new_path = path.decode("utf-8")
 
165
    invdelta.append((old_path, new_path, file_id, ie))
165
166
    if base_hexsha != hexsha:
166
167
        store_updater.add_object(blob, ie, path)
167
168
    return invdelta
197
198
 
198
199
    :param base_inv: Base inventory against which to generate the 
199
200
        inventory delta.
200
 
    :param path: Path to process
 
201
    :param path: Path to process (unicode)
201
202
    :param base_tree: Git Tree base object
202
203
    :param existing_children: Children that still exist
203
204
    :param lookup_object: Lookup a git object by its SHA1
204
205
    :return: Inventory delta, as list
205
206
    """
 
207
    assert type(path) is unicode
206
208
    ret = []
207
209
    for name, mode, hexsha in base_tree.iteritems():
208
210
        if name in existing_children:
224
226
    """Import a git tree object into a bzr repository.
225
227
 
226
228
    :param texts: VersionedFiles object to add to
227
 
    :param path: Path in the tree
 
229
    :param path: Path in the tree (str)
 
230
    :param name: Name of the tree (str)
228
231
    :param tree: A git tree object
229
232
    :param base_inv: Base inventory against which to return inventory delta
230
233
    :return: Inventory delta for this subtree
231
234
    """
 
235
    assert type(path) is str
 
236
    assert type(name) is str
232
237
    if base_hexsha == hexsha and base_mode == mode:
233
238
        # If nothing has changed since the base revision, we're done
234
239
        return [], {}
242
247
        old_path = None # Newly appeared here
243
248
    else:
244
249
        base_tree = lookup_object(base_hexsha)
245
 
        old_path = path # Renames aren't supported yet
 
250
        old_path = path.decode("utf-8") # Renames aren't supported yet
 
251
    new_path = path.decode("utf-8")
246
252
    if base_tree is None or type(base_tree) is not Tree:
247
253
        ie.revision = revision_id
248
 
        invdelta.append((old_path, path, ie.file_id, ie))
 
254
        invdelta.append((old_path, new_path, ie.file_id, ie))
249
255
        texts.insert_record_stream([
250
256
            ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
251
257
    # Remember for next time
289
295
            child_modes[child_path] = child_mode
290
296
    # Remove any children that have disappeared
291
297
    if base_tree is not None and type(base_tree) is Tree:
292
 
        invdelta.extend(remove_disappeared_children(base_inv, old_path, 
 
298
        invdelta.extend(remove_disappeared_children(base_inv, old_path,
293
299
            base_tree, existing_children, lookup_object))
294
300
    store_updater.add_object(tree, ie, path)
295
301
    return invdelta, child_modes
351
357
        base_mode = stat.S_IFDIR
352
358
    store_updater = target_git_object_retriever._get_updater(rev)
353
359
    store_updater.add_object(o, None, None)
354
 
    lookup_file_id = mapping.get_fileid_map(lookup_object, o.tree).lookup_file_id
 
360
    fileid_map = mapping.get_fileid_map(lookup_object, o.tree)
355
361
    inv_delta, unusual_modes = import_git_tree(repo.texts,
356
 
            mapping, "", u"", (base_tree, o.tree), base_inv, 
 
362
            mapping, "", "", (base_tree, o.tree), base_inv,
357
363
            None, rev.revision_id, [p.inventory for p in parent_trees],
358
364
            lookup_object, (base_mode, stat.S_IFDIR), store_updater,
359
 
            lookup_file_id,
 
365
            fileid_map.lookup_file_id,
360
366
            allow_submodules=getattr(repo._format, "supports_tree_reference", False))
361
367
    store_updater.finish()
362
368
    if unusual_modes != {}:
369
375
        basis_id = NULL_REVISION
370
376
        base_inv = None
371
377
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
372
 
              inv_delta, rev.revision_id, rev.parent_ids,
373
 
              base_inv)
 
378
              inv_delta, rev.revision_id, rev.parent_ids, base_inv)
374
379
    ret_tree = RevisionTree(repo, inv, rev.revision_id)
375
380
    trees_cache.add(ret_tree)
376
381
    repo.add_revision(rev.revision_id, rev)
474
479
    """Base InterRepository that copies revisions from a Git into a non-Git
475
480
    repository."""
476
481
 
 
482
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
 
483
        """Fetch objects from a remote server.
 
484
 
 
485
        :param determine_wants: determine_wants callback
 
486
        :param mapping: BzrGitMapping to use
 
487
        :param pb: Optional progress bar
 
488
        :param limit: Maximum number of commits to import.
 
489
        :return: Tuple with pack hint, last imported revision id and remote refs
 
490
        """
 
491
        raise NotImplementedError(self.fetch_objects)
 
492
 
477
493
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
478
494
              mapping=None, fetch_spec=None):
479
495
        if mapping is None:
484
500
            interesting_heads = fetch_spec.heads
485
501
        else:
486
502
            interesting_heads = None
487
 
        self._refs = {}
488
503
        def determine_wants(refs):
489
 
            self._refs = refs
490
504
            if interesting_heads is None:
491
505
                ret = [sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")]
492
506
            else:
493
507
                ret = [self.source.lookup_bzr_revision_id(revid)[0] for revid in interesting_heads if revid not in (None, NULL_REVISION)]
494
508
            return [rev for rev in ret if not self.target.has_revision(self.source.lookup_foreign_revision_id(rev))]
495
 
        (pack_hint, _) = self.fetch_objects(determine_wants, mapping, pb)
 
509
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants, mapping, pb)
496
510
        if pack_hint is not None and self.target._format.pack_compresses:
497
511
            self.target.pack(hint=pack_hint)
498
 
        return self._refs
 
512
        return remote_refs
499
513
 
500
514
 
501
515
_GIT_PROGRESS_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
509
523
        pb.update(text, 0, 0)
510
524
 
511
525
 
 
526
class DetermineWantsRecorder(object):
 
527
 
 
528
    def __init__(self, actual):
 
529
        self.actual = actual
 
530
        self.wants = []
 
531
        self.remote_refs = {}
 
532
 
 
533
    def __call__(self, refs):
 
534
        self.remote_refs = refs
 
535
        self.wants = self.actual(refs)
 
536
        return self.wants
 
537
 
 
538
 
512
539
class InterRemoteGitNonGitRepository(InterGitNonGitRepository):
513
540
    """InterRepository that copies revisions from a remote Git into a non-Git
514
541
    repository."""
522
549
        return set(all_revs) - all_parents
523
550
 
524
551
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
 
552
        """See `InterGitNonGitRepository`."""
525
553
        def progress(text):
526
554
            report_git_progress(pb, text)
527
555
        store = BazaarObjectStore(self.target, mapping)
530
558
            heads = self.get_target_heads()
531
559
            graph_walker = store.get_graph_walker(
532
560
                    [store._lookup_revision_sha1(head) for head in heads])
533
 
            recorded_wants = []
534
 
 
535
 
            def record_determine_wants(heads):
536
 
                wants = determine_wants(heads)
537
 
                recorded_wants.extend(wants)
538
 
                return wants
 
561
            wants_recorder = DetermineWantsRecorder(determine_wants)
539
562
 
540
563
            create_pb = None
541
564
            if pb is None:
542
565
                create_pb = pb = ui.ui_factory.nested_progress_bar()
543
566
            try:
544
 
                objects_iter = self.source.fetch_objects(record_determine_wants,
545
 
                    graph_walker, store.get_raw, progress)
546
 
                return import_git_objects(self.target, mapping,
547
 
                    objects_iter, store, recorded_wants, pb, limit)
 
567
                objects_iter = self.source.fetch_objects(
 
568
                    wants_recorder, graph_walker, store.get_raw,
 
569
                    progress)
 
570
                (pack_hint, last_rev) = import_git_objects(self.target, mapping,
 
571
                    objects_iter, store, wants_recorder.wants, pb, limit)
 
572
                return (pack_hint, last_rev, wants_recorder.remote_refs)
548
573
            finally:
549
574
                if create_pb:
550
575
                    create_pb.finished()
565
590
    repository."""
566
591
 
567
592
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
568
 
        """Fetch objects.
569
 
        """
570
 
        wants = determine_wants(self.source._git.get_refs())
 
593
        """See `InterGitNonGitRepository`."""
 
594
        remote_refs = self.source._git.get_refs()
 
595
        wants = determine_wants(remote_refs)
571
596
        create_pb = None
572
597
        if pb is None:
573
598
            create_pb = pb = ui.ui_factory.nested_progress_bar()
575
600
        try:
576
601
            self.target.lock_write()
577
602
            try:
578
 
                return import_git_objects(self.target, mapping,
 
603
                (pack_hint, last_rev) = import_git_objects(self.target, mapping,
579
604
                    self.source._git.object_store,
580
605
                    target_git_object_retriever, wants, pb, limit)
 
606
                return (pack_hint, last_rev, remote_refs)
581
607
            finally:
582
608
                self.target.unlock()
583
609
        finally:
602
628
        graphwalker = self.target._git.get_graph_walker()
603
629
        if (isinstance(self.source, LocalGitRepository) and
604
630
            isinstance(self.target, LocalGitRepository)):
605
 
            return self.source._git.fetch(self.target._git, determine_wants,
 
631
            refs = self.source._git.fetch(self.target._git, determine_wants,
606
632
                progress)
 
633
            return (None, None, refs)
607
634
        elif (isinstance(self.source, LocalGitRepository) and
608
635
              isinstance(self.target, RemoteGitRepository)):
609
636
            raise NotImplementedError
611
638
              isinstance(self.target, LocalGitRepository)):
612
639
            f, commit = self.target._git.object_store.add_thin_pack()
613
640
            try:
614
 
                refs = self.source._git.fetch_pack(determine_wants,
615
 
                    graphwalker, f.write, progress)
 
641
                refs = self.source.bzrdir.root_transport.fetch_pack(
 
642
                    determine_wants, graphwalker, f.write, progress)
616
643
                commit()
617
 
                return refs
 
644
                return (None, None, refs)
618
645
            except:
619
646
                f.close()
620
647
                raise
636
663
            determine_wants = r.object_store.determine_wants_all
637
664
        else:
638
665
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
639
 
        return self.fetch_objects(determine_wants, mapping)[0]
640
 
 
 
666
        self.fetch_objects(determine_wants, mapping)
641
667
 
642
668
    @staticmethod
643
669
    def is_compatible(source, target):