~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Matthieu Moy
  • Date: 2006-07-08 19:32:30 UTC
  • mfrom: (1845 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1857.
  • Revision ID: Matthieu.Moy@imag.fr-20060708193230-3eb72d871471bd5b
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
                            delete_any)
27
27
from bzrlib.progress import DummyProgress, ProgressPhase
28
28
from bzrlib.trace import mutter, warning
 
29
from bzrlib import tree
29
30
import bzrlib.ui 
 
31
import bzrlib.urlutils as urlutils
30
32
 
31
33
 
32
34
ROOT_PARENT = "root-parent"
79
81
        self._tree.lock_write()
80
82
        try:
81
83
            control_files = self._tree._control_files
82
 
            self._limbodir = control_files.controlfilename('limbo')
 
84
            self._limbodir = urlutils.local_path_from_url(
 
85
                control_files.controlfilename('limbo'))
83
86
            try:
84
87
                os.mkdir(self._limbodir)
85
88
            except OSError, e:
257
260
        New file takes the permissions of any existing file with that id,
258
261
        unless mode_id is specified.
259
262
        """
260
 
        f = file(self._limbo_name(trans_id), 'wb')
261
 
        unique_add(self._new_contents, trans_id, 'file')
262
 
        for segment in contents:
263
 
            f.write(segment)
264
 
        f.close()
 
263
        name = self._limbo_name(trans_id)
 
264
        f = open(name, 'wb')
 
265
        try:
 
266
            try:
 
267
                unique_add(self._new_contents, trans_id, 'file')
 
268
            except:
 
269
                # Clean up the file, it never got registered so
 
270
                # TreeTransform.finalize() won't clean it up.
 
271
                f.close()
 
272
                os.unlink(name)
 
273
                raise
 
274
 
 
275
            for segment in contents:
 
276
                f.write(segment)
 
277
        finally:
 
278
            f.close()
265
279
        self._set_mode(trans_id, mode_id, S_ISREG)
266
280
 
267
281
    def _set_mode(self, trans_id, mode_id, typefunc):
537
551
        if child_id is None:
538
552
            return lexists(self._tree.abspath(childpath))
539
553
        else:
540
 
            if tt.final_parent(child_id) != parent_id:
 
554
            if self.final_parent(child_id) != parent_id:
541
555
                return False
542
 
            if child_id in tt._removed_contents:
 
556
            if child_id in self._removed_contents:
543
557
                # XXX What about dangling file-ids?
544
558
                return False
545
559
            else:
845
859
        parent_id is the transaction id of the parent directory of the file.
846
860
        contents is an iterator of bytestrings, which will be used to produce
847
861
        the file.
848
 
        file_id is the inventory ID of the file, if it is to be versioned.
 
862
        :param file_id: The inventory ID of the file, if it is to be versioned.
 
863
        :param executable: Only valid when a file_id has been supplied.
849
864
        """
850
865
        trans_id = self._new_entry(name, parent_id, file_id)
 
866
        # TODO: rather than scheduling a set_executable call,
 
867
        # have create_file create the file with the right mode.
851
868
        self.create_file(contents, trans_id)
852
869
        if executable is not None:
853
870
            self.set_executability(executable, trans_id)
982
999
 
983
1000
def find_interesting(working_tree, target_tree, filenames):
984
1001
    """Find the ids corresponding to specified filenames."""
985
 
    if not filenames:
986
 
        interesting_ids = None
987
 
    else:
988
 
        interesting_ids = set()
989
 
        for tree_path in filenames:
990
 
            not_found = True
991
 
            for tree in (working_tree, target_tree):
992
 
                file_id = tree.inventory.path2id(tree_path)
993
 
                if file_id is not None:
994
 
                    interesting_ids.add(file_id)
995
 
                    not_found = False
996
 
            if not_found:
997
 
                raise NotVersionedError(path=tree_path)
998
 
    return interesting_ids
 
1002
    trees = (working_tree, target_tree)
 
1003
    return tree.find_ids_across_trees(filenames, trees)
999
1004
 
1000
1005
 
1001
1006
def change_entry(tt, file_id, working_tree, target_tree, 
1061
1066
    try:
1062
1067
        working_kind = working_tree.kind(file_id)
1063
1068
        has_contents = True
1064
 
    except OSError, e:
1065
 
        if e.errno != errno.ENOENT:
1066
 
            raise
 
1069
    except NoSuchFile:
1067
1070
        has_contents = False
1068
1071
        contents_mod = True
1069
1072
        meta_mod = False