~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patch.py

  • Committer: ghigo
  • Date: 2006-03-13 18:34:29 UTC
  • mto: This revision was merged to the branch mainline in revision 330.
  • Revision ID: ghigo@venice-20060313183429-5b0cb1426d53eb3e
Inform bzr of a renaming

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from subprocess import Popen, PIPE
19
19
from bzrlib.transport import get_transport
20
20
from urlparse import urlsplit, urlunsplit
 
21
from bzrlib.workingtree import WorkingTree
 
22
import bzrlib.add
21
23
 
22
24
class BzrTagProc:
23
25
    """This class handle the additional bazaar diff tags
25
27
        TODO:
26
28
          error handling
27
29
    """
28
 
    def __init__(self):
 
30
    def __init__(self, tree):
29
31
        self.renamed = None
30
32
        self.link = None
 
33
        self.tree = tree
31
34
 
32
35
    def _extractname(self, s):
33
36
        x = s[0]
65
68
    def flush(self):
66
69
        self.process( )
67
70
 
 
71
    def add(self,name):
 
72
        action = bzrlib.add.add_action_add_and_print
 
73
        added, ignored = bzrlib.add.smart_add([name], False, action)
 
74
 
68
75
    def process(self, cmd = None):
69
76
        if self.renamed:
70
77
            os.rename(self.renamed[0], self.renamed[1])
77
84
 
78
85
            target = self.extractname(cmd)
79
86
            print "removing '%s'"%target
80
 
            os.unlink(target)
 
87
            if not cmd.startswith("removed file"):
 
88
                os.unlink(target)
 
89
            self.tree.remove([target])
81
90
 
82
91
        elif cmd.startswith("removed directory"):
83
92
 
84
93
            target = self.extractname(cmd)
85
94
            print "removing '%s'"%target
86
95
            os.rmdir(target)
 
96
            self.tree.remove([target])
87
97
 
88
98
        elif cmd.startswith("added file"):
89
99
            target = self.extractname(cmd)
90
100
            print "adding '%s'"%target
91
101
            f = open(target,"w")
92
102
            f.close( )
 
103
            self.add(target)
93
104
 
94
105
        elif cmd.startswith("added directory"):
95
106
            target = self.extractname(cmd)
96
107
            print "adding '%s'"%target
97
108
            os.mkdir(target)
 
109
            self.add(target)
98
110
 
99
111
        elif cmd.startswith("added symlink"):
100
112
            assert(not self.link)
102
114
 
103
115
        elif cmd.startswith("target is"):
104
116
            assert(self.link)
105
 
            source = self.extractname(cmd)
106
 
            print "symlinking '%s' => '%s'"%(source, self.link)
107
 
            os.symlink(source, self.link)
 
117
            target = self.extractname(cmd)
 
118
            print "symlinking '%s' => '%s'"%(target, self.link)
 
119
            os.symlink(target, self.link)
108
120
            self.link = None
 
121
            self.add(self.link)
109
122
 
110
123
        elif ( cmd.startswith("renamed symlink") or
111
124
               cmd.startswith("renamed file") or
116
129
            source,dest = self.extractnames(cmd[space+1:])
117
130
            print "renaming '%s' => '%s'"%(source,dest)
118
131
 
119
 
            os.rename(source,dest)
 
132
            #os.rename(source,dest)
 
133
            self.tree.rename_one(source,dest)
120
134
 
121
135
        else:
122
136
            sys.stderr.write("Unsupported tag: '%s'\n"%cmd)
146
160
        child_proc.stdin.close()
147
161
        r = child_proc.wait()
148
162
    else:
149
 
        bzr_tags_proc = BzrTagProc( )
 
163
        bzr_tags_proc = BzrTagProc(WorkingTree.open_containing(u'.')[0])
150
164
        child_proc = None
151
165
        for line in my_file:
152
166
            if line.startswith("=== "):