~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: Aaron Bentley
  • Date: 2005-09-29 21:07:17 UTC
  • mfrom: (1393.1.6)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20050929210717-cd73981590f17017
Merged the weave changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import patch
19
19
import stat
20
20
from bzrlib.trace import mutter
 
21
from bzrlib.osutils import rename
21
22
 
22
23
# XXX: mbp: I'm not totally convinced that we should handle conflicts
23
24
# as part of changeset application, rather than only in the merge
42
43
        newdict[value] = key
43
44
    return newdict
44
45
 
45
 
 
46
46
       
47
47
class ChangeUnixPermissions(object):
48
48
    """This is two-way change, suitable for file modification, creation,
92
92
    def __ne__(self, other):
93
93
        return not (self == other)
94
94
 
 
95
 
95
96
def dir_create(filename, conflict_handler, reverse):
96
97
    """Creates the directory, or deletes it if reverse is true.  Intended to be
97
98
    used with ReplaceContents.
117
118
        try:
118
119
            os.rmdir(filename)
119
120
        except OSError, e:
120
 
            if e.errno != 39:
 
121
            if e.errno != errno.ENOTEMPTY:
121
122
                raise
122
123
            if conflict_handler.rmdir_non_empty(filename) == "skip":
123
124
                return
124
125
            os.rmdir(filename)
125
126
 
126
 
                
127
 
            
128
127
 
129
128
class SymlinkCreate(object):
130
129
    """Creates or deletes a symlink (for use with ReplaceContents)"""
353
352
        status = patch.diff3(new_file, filename, base, other)
354
353
        if status == 0:
355
354
            os.chmod(new_file, os.stat(filename).st_mode)
356
 
            os.rename(new_file, filename)
 
355
            rename(new_file, filename)
357
356
            return
358
357
        else:
359
358
            assert(status == 1)
626
625
                return None
627
626
            return self.path
628
627
 
629
 
    def summarize_name(self, changeset, reverse=False):
 
628
    def summarize_name(self, reverse=False):
630
629
        """Produce a one-line summary of the filename.  Indicates renames as
631
630
        old => new, indicates creation as None => new, indicates deletion as
632
631
        old => None.
663
662
        :type reverse: bool
664
663
        :rtype: str
665
664
        """
666
 
        mutter("Finding new path for %s" % self.summarize_name(changeset))
 
665
        mutter("Finding new path for %s" % self.summarize_name())
667
666
        if reverse:
668
667
            parent = self.parent
669
668
            to_dir = self.dir
831
830
            if src_path is not None:
832
831
                src_path = os.path.join(dir, src_path)
833
832
                try:
834
 
                    os.rename(src_path, to_name)
 
833
                    rename(src_path, to_name)
835
834
                    temp_name[entry.id] = to_name
836
835
                except OSError, e:
837
836
                    if e.errno != errno.ENOENT:
874
873
            if old_path is None:
875
874
                continue
876
875
            try:
877
 
                os.rename(old_path, new_path)
 
876
                rename(old_path, new_path)
878
877
                changed_inventory[entry.id] = new_tree_path
879
878
            except OSError, e:
880
879
                raise Exception ("%s is missing" % new_path)
1003
1002
    descend from this class if they have a better way to handle some or
1004
1003
    all types of conflict.
1005
1004
    """
1006
 
    def __init__(self, dir):
1007
 
        self.dir = dir
1008
 
    
1009
1005
    def missing_parent(self, pathname):
1010
1006
        parent = os.path.dirname(pathname)
1011
1007
        raise Exception("Parent directory missing for %s" % pathname)
1065
1061
    def new_contents_conflict(self, filename, other_contents):
1066
1062
        raise NewContentsConflict(filename)
1067
1063
 
1068
 
    def finalize():
 
1064
    def finalize(self):
1069
1065
        pass
1070
1066
 
1071
1067
def apply_changeset(changeset, inventory, dir, conflict_handler=None, 
1084
1080
    :rtype: Dictionary
1085
1081
    """
1086
1082
    if conflict_handler is None:
1087
 
        conflict_handler = ExceptionConflictHandler(dir)
 
1083
        conflict_handler = ExceptionConflictHandler()
1088
1084
    temp_dir = os.path.join(dir, "bzr-tree-change")
1089
1085
    try:
1090
1086
        os.mkdir(temp_dir)
1329
1325
            yield self.get_entry(file_id, tree)
1330
1326
 
1331
1327
    def get_entry(self, file_id, tree):
1332
 
        if file_id not in tree:
 
1328
        if not tree.has_or_had_id(file_id):
1333
1329
            return None
1334
1330
        return tree.tree.inventory[file_id]
1335
1331
 
1339
1335
        return entry.parent_id
1340
1336
 
1341
1337
    def get_path(self, file_id, tree):
1342
 
        if not tree.has_id(file_id):
 
1338
        if not tree.has_or_had_id(file_id):
1343
1339
            return None
1344
1340
        path = tree.id2path(file_id)
1345
1341
        if path == '':
1397
1393
        full_path_b = self.tree_b.readonly_path(id)
1398
1394
        stat_a = self.lstat(full_path_a)
1399
1395
        stat_b = self.lstat(full_path_b)
1400
 
        if stat_b is None:
1401
 
            cs_entry.new_parent = None
1402
 
            cs_entry.new_path = None
1403
1396
        
1404
1397
        cs_entry.metadata_change = self.make_mode_change(stat_a, stat_b)
1405
1398
        cs_entry.contents_change = self.make_contents_change(full_path_a,