~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-03 20:18:35 UTC
  • mfrom: (1185.82.137 w-changeset)
  • Revision ID: pqm@pqm.ubuntu.com-20060603201835-1c9a1725641ccd24
Implement bundles

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
30
29
import bzrlib.ui 
31
 
import bzrlib.urlutils as urlutils
32
30
 
33
31
 
34
32
ROOT_PARENT = "root-parent"
81
79
        self._tree.lock_write()
82
80
        try:
83
81
            control_files = self._tree._control_files
84
 
            self._limbodir = urlutils.local_path_from_url(
85
 
                control_files.controlfilename('limbo'))
 
82
            self._limbodir = control_files.controlfilename('limbo')
86
83
            try:
87
84
                os.mkdir(self._limbodir)
88
85
            except OSError, e:
260
257
        New file takes the permissions of any existing file with that id,
261
258
        unless mode_id is specified.
262
259
        """
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()
 
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()
279
265
        self._set_mode(trans_id, mode_id, S_ISREG)
280
266
 
281
267
    def _set_mode(self, trans_id, mode_id, typefunc):
507
493
                        self.tree_kind(t) == 'directory'])
508
494
        for trans_id in self._removed_id:
509
495
            file_id = self.tree_file_id(trans_id)
510
 
            if self._tree.inventory[file_id].kind == 'directory':
 
496
            if self._tree.inventory[file_id].kind in ('directory', 
 
497
                                                      'root_directory'):
511
498
                parents.append(trans_id)
512
499
 
513
500
        for parent_id in parents:
550
537
        if child_id is None:
551
538
            return lexists(self._tree.abspath(childpath))
552
539
        else:
553
 
            if self.final_parent(child_id) != parent_id:
 
540
            if tt.final_parent(child_id) != parent_id:
554
541
                return False
555
 
            if child_id in self._removed_contents:
 
542
            if child_id in tt._removed_contents:
556
543
                # XXX What about dangling file-ids?
557
544
                return False
558
545
            else:
858
845
        parent_id is the transaction id of the parent directory of the file.
859
846
        contents is an iterator of bytestrings, which will be used to produce
860
847
        the file.
861
 
        :param file_id: The inventory ID of the file, if it is to be versioned.
862
 
        :param executable: Only valid when a file_id has been supplied.
 
848
        file_id is the inventory ID of the file, if it is to be versioned.
863
849
        """
864
850
        trans_id = self._new_entry(name, parent_id, file_id)
865
 
        # TODO: rather than scheduling a set_executable call,
866
 
        # have create_file create the file with the right mode.
867
851
        self.create_file(contents, trans_id)
868
852
        if executable is not None:
869
853
            self.set_executability(executable, trans_id)
998
982
 
999
983
def find_interesting(working_tree, target_tree, filenames):
1000
984
    """Find the ids corresponding to specified filenames."""
1001
 
    trees = (working_tree, target_tree)
1002
 
    return tree.find_ids_across_trees(filenames, trees)
 
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
1003
999
 
1004
1000
 
1005
1001
def change_entry(tt, file_id, working_tree, target_tree, 
1065
1061
    try:
1066
1062
        working_kind = working_tree.kind(file_id)
1067
1063
        has_contents = True
1068
 
    except NoSuchFile:
 
1064
    except OSError, e:
 
1065
        if e.errno != errno.ENOENT:
 
1066
            raise
1069
1067
        has_contents = False
1070
1068
        contents_mod = True
1071
1069
        meta_mod = False
1072
1070
    if has_contents is True:
1073
 
        if entry.kind != working_kind:
 
1071
        real_e_kind = entry.kind
 
1072
        if real_e_kind == 'root_directory':
 
1073
            real_e_kind = 'directory'
 
1074
        if real_e_kind != working_kind:
1074
1075
            contents_mod, meta_mod = True, False
1075
1076
        else:
1076
1077
            cur_entry._read_tree_state(working_tree.id2path(file_id),