/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 bzrlib/mutabletree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-05 14:47:26 UTC
  • mfrom: (5752.2.11 2.4-windows-lfstat)
  • Revision ID: pqm@pqm.ubuntu.com-20110405144726-zi3lj2kwvjml4kx5
(jameinel) Add osutils.lstat/fstat so that even on Windows lstat(fname) ==
 fstat(open(fname).fileno()) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
32
32
    hooks,
33
33
    osutils,
34
34
    revisiontree,
35
 
    symbol_versioning,
 
35
    inventory,
36
36
    trace,
37
37
    tree,
38
38
    )
79
79
        # used on media which doesn't differentiate the case of names.
80
80
        self.case_sensitive = True
81
81
 
 
82
    def is_control_filename(self, filename):
 
83
        """True if filename is the name of a control file in this tree.
 
84
 
 
85
        :param filename: A filename within the tree. This is a relative path
 
86
        from the root of this tree.
 
87
 
 
88
        This is true IF and ONLY IF the filename is part of the meta data
 
89
        that bzr controls in this tree. I.E. a random .bzr directory placed
 
90
        on disk will not be a control file for this tree.
 
91
        """
 
92
        raise NotImplementedError(self.is_control_filename)
 
93
 
82
94
    @needs_tree_write_lock
83
95
    def add(self, files, ids=None, kinds=None):
84
96
        """Add paths to the set of versioned paths.
375
387
        This is designed more towards DWIM for humans than API clarity.
376
388
        For the specific behaviour see the help for cmd_add().
377
389
 
 
390
        :param file_list: List of zero or more paths.  *NB: these are 
 
391
            interpreted relative to the process cwd, not relative to the 
 
392
            tree.*  (Add and most other tree methods use tree-relative
 
393
            paths.)
378
394
        :param action: A reporter to be called with the inventory, parent_ie,
379
395
            path and kind of the path being added. It may return a file_id if
380
396
            a specific one should be used.
411
427
            for c in self.conflicts():
412
428
                conflicts_related.update(c.associated_filenames())
413
429
 
 
430
        # expand any symlinks in the directory part, while leaving the
 
431
        # filename alone
 
432
        # only expanding if symlinks are supported avoids windows path bugs
 
433
        if osutils.has_symlinks():
 
434
            file_list = map(osutils.normalizepath, file_list)
 
435
 
414
436
        # validate user file paths and convert all paths to tree
415
437
        # relative : it's cheaper to make a tree relative path an abspath
416
438
        # than to convert an abspath to tree relative, and it's cheaper to
536
558
                        this_ie = None
537
559
                    else:
538
560
                        this_ie = inv[this_id]
 
561
                        # Same as in _add_one below, if the inventory doesn't
 
562
                        # think this is a directory, update the inventory
 
563
                        if this_ie.kind != 'directory':
 
564
                            this_ie = inventory.make_entry('directory',
 
565
                                this_ie.name, this_ie.parent_id, this_id)
 
566
                            del inv[this_id]
 
567
                            inv.add(this_ie)
539
568
 
540
569
                for subf in sorted(os.listdir(abspath)):
541
570
                    # here we could use TreeDirectory rather than
622
651
        """Create the default hooks.
623
652
 
624
653
        """
625
 
        hooks.Hooks.__init__(self)
626
 
        self.create_hook(hooks.HookPoint('start_commit',
 
654
        hooks.Hooks.__init__(self, "bzrlib.mutabletree", "MutableTree.hooks")
 
655
        self.add_hook('start_commit',
627
656
            "Called before a commit is performed on a tree. The start commit "
628
657
            "hook is able to change the tree before the commit takes place. "
629
658
            "start_commit is called with the bzrlib.mutabletree.MutableTree "
630
 
            "that the commit is being performed on.", (1, 4), None))
631
 
        self.create_hook(hooks.HookPoint('post_commit',
 
659
            "that the commit is being performed on.", (1, 4))
 
660
        self.add_hook('post_commit',
632
661
            "Called after a commit is performed on a tree. The hook is "
633
662
            "called with a bzrlib.mutabletree.PostCommitHookParams object. "
634
663
            "The mutable tree the commit was performed on is available via "
635
 
            "the mutable_tree attribute of that object.", (2, 0), None))
 
664
            "the mutable_tree attribute of that object.", (2, 0))
636
665
 
637
666
 
638
667
# install the default hooks into the MutableTree class.
715
744
        file_id or None to generate a new file id
716
745
    :returns: None
717
746
    """
 
747
    # if the parent exists, but isn't a directory, we have to do the
 
748
    # kind change now -- really the inventory shouldn't pretend to know
 
749
    # the kind of wt files, but it does.
 
750
    if parent_ie.kind != 'directory':
 
751
        # nb: this relies on someone else checking that the path we're using
 
752
        # doesn't contain symlinks.
 
753
        new_parent_ie = inventory.make_entry('directory', parent_ie.name,
 
754
            parent_ie.parent_id, parent_ie.file_id)
 
755
        del inv[parent_ie.file_id]
 
756
        inv.add(new_parent_ie)
 
757
        parent_ie = new_parent_ie
718
758
    file_id = file_id_callback(inv, parent_ie, path, kind)
719
759
    entry = inv.make_entry(kind, path.base_path, parent_ie.file_id,
720
760
        file_id=file_id)