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

Merge deprecate-get-parser-file into simplify-test-config-building

Show diffs side-by-side

added added

removed removed

Lines of Context:
1266
1266
                # absolute path
1267
1267
                fap = from_dir_abspath + '/' + f
1268
1268
 
1269
 
                f_ie = inv.get_child(from_dir_id, f)
 
1269
                dir_ie = inv[from_dir_id]
 
1270
                if dir_ie.kind == 'directory':
 
1271
                    f_ie = dir_ie.children.get(f)
 
1272
                else:
 
1273
                    f_ie = None
1270
1274
                if f_ie:
1271
1275
                    c = 'V'
1272
1276
                elif self.is_ignored(fp[1:]):
1273
1277
                    c = 'I'
1274
1278
                else:
1275
 
                    # we may not have found this file, because of a unicode issue
 
1279
                    # we may not have found this file, because of a unicode
 
1280
                    # issue, or because the directory was actually a symlink.
1276
1281
                    f_norm, can_access = osutils.normalized_filename(f)
1277
1282
                    if f == f_norm or not can_access:
1278
1283
                        # No change, so treat this file normally
2019
2024
 
2020
2025
        inv_delta = []
2021
2026
 
2022
 
        new_files=set()
 
2027
        all_files = set() # specified and nested files 
2023
2028
        unknown_nested_files=set()
2024
2029
        if to_file is None:
2025
2030
            to_file = sys.stdout
2026
2031
 
 
2032
        files_to_backup = []
 
2033
 
2027
2034
        def recurse_directory_to_add_files(directory):
2028
2035
            # Recurse directory and add all files
2029
2036
            # so we can check if they have changed.
2030
2037
            for parent_info, file_infos in self.walkdirs(directory):
2031
2038
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
2032
2039
                    # Is it versioned or ignored?
2033
 
                    if self.path2id(relpath) or self.is_ignored(relpath):
 
2040
                    if self.path2id(relpath):
2034
2041
                        # Add nested content for deletion.
2035
 
                        new_files.add(relpath)
 
2042
                        all_files.add(relpath)
2036
2043
                    else:
2037
 
                        # Files which are not versioned and not ignored
 
2044
                        # Files which are not versioned
2038
2045
                        # should be treated as unknown.
2039
 
                        unknown_nested_files.add((relpath, None, kind))
 
2046
                        files_to_backup.append(relpath)
2040
2047
 
2041
2048
        for filename in files:
2042
2049
            # Get file name into canonical form.
2043
2050
            abspath = self.abspath(filename)
2044
2051
            filename = self.relpath(abspath)
2045
2052
            if len(filename) > 0:
2046
 
                new_files.add(filename)
 
2053
                all_files.add(filename)
2047
2054
                recurse_directory_to_add_files(filename)
2048
2055
 
2049
 
        files = list(new_files)
 
2056
        files = list(all_files)
2050
2057
 
2051
2058
        if len(files) == 0:
2052
2059
            return # nothing to do
2056
2063
 
2057
2064
        # Bail out if we are going to delete files we shouldn't
2058
2065
        if not keep_files and not force:
2059
 
            has_changed_files = len(unknown_nested_files) > 0
2060
 
            if not has_changed_files:
2061
 
                for (file_id, path, content_change, versioned, parent_id, name,
2062
 
                     kind, executable) in self.iter_changes(self.basis_tree(),
2063
 
                         include_unchanged=True, require_versioned=False,
2064
 
                         want_unversioned=True, specific_files=files):
2065
 
                    if versioned == (False, False):
2066
 
                        # The record is unknown ...
2067
 
                        if not self.is_ignored(path[1]):
2068
 
                            # ... but not ignored
2069
 
                            has_changed_files = True
2070
 
                            break
2071
 
                    elif (content_change and (kind[1] is not None) and
2072
 
                            osutils.is_inside_any(files, path[1])):
2073
 
                        # Versioned and changed, but not deleted, and still
2074
 
                        # in one of the dirs to be deleted.
2075
 
                        has_changed_files = True
2076
 
                        break
 
2066
            for (file_id, path, content_change, versioned, parent_id, name,
 
2067
                 kind, executable) in self.iter_changes(self.basis_tree(),
 
2068
                     include_unchanged=True, require_versioned=False,
 
2069
                     want_unversioned=True, specific_files=files):
 
2070
                if versioned[0] == False:
 
2071
                    # The record is unknown or newly added
 
2072
                    files_to_backup.append(path[1])
 
2073
                elif (content_change and (kind[1] is not None) and
 
2074
                        osutils.is_inside_any(files, path[1])):
 
2075
                    # Versioned and changed, but not deleted, and still
 
2076
                    # in one of the dirs to be deleted.
 
2077
                    files_to_backup.append(path[1])
2077
2078
 
2078
 
            if has_changed_files:
2079
 
                # Make delta show ALL applicable changes in error message.
2080
 
                tree_delta = self.changes_from(self.basis_tree(),
2081
 
                    require_versioned=False, want_unversioned=True,
2082
 
                    specific_files=files)
2083
 
                for unknown_file in unknown_nested_files:
2084
 
                    if unknown_file not in tree_delta.unversioned:
2085
 
                        tree_delta.unversioned.extend((unknown_file,))
2086
 
                raise errors.BzrRemoveChangedFilesError(tree_delta)
 
2079
        def backup(file_to_backup):
 
2080
            backup_name = self.bzrdir.generate_backup_name(file_to_backup)
 
2081
            osutils.rename(abs_path, self.abspath(backup_name))
 
2082
            return "removed %s (but kept a copy: %s)" % (file_to_backup, backup_name)
2087
2083
 
2088
2084
        # Build inv_delta and delete files where applicable,
2089
2085
        # do this before any modifications to inventory.
2113
2109
                        len(os.listdir(abs_path)) > 0):
2114
2110
                        if force:
2115
2111
                            osutils.rmtree(abs_path)
 
2112
                            message = "deleted %s" % (f,)
2116
2113
                        else:
2117
 
                            message = "%s is not an empty directory "\
2118
 
                                "and won't be deleted." % (f,)
 
2114
                            message = backup(f)
2119
2115
                    else:
2120
 
                        osutils.delete_any(abs_path)
2121
 
                        message = "deleted %s" % (f,)
 
2116
                        if f in files_to_backup:
 
2117
                            message = backup(f)
 
2118
                        else:
 
2119
                            osutils.delete_any(abs_path)
 
2120
                            message = "deleted %s" % (f,)
2122
2121
                elif message is not None:
2123
2122
                    # Only care if we haven't done anything yet.
2124
2123
                    message = "%s does not exist." % (f,)