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

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
 
17
from bzrlib.delta import compare_trees
 
18
from bzrlib.errors import BzrError
 
19
from bzrlib.symbol_versioning import *
17
20
from bzrlib.trace import mutter
18
 
from bzrlib.errors import BzrError
19
 
from bzrlib.delta import compare_trees
20
21
 
21
22
# TODO: Rather than building a changeset object, we should probably
22
23
# invoke callbacks on an object.  That object can either accumulate a
141
142
        oldtmpf.close()                 # and delete
142
143
        newtmpf.close()
143
144
 
 
145
 
 
146
@deprecated_function(zero_eight)
144
147
def show_diff(b, from_spec, specific_files, external_diff_options=None,
145
148
              revision2=None, output=None, b2=None):
146
149
    """Shortcut for showing the diff to the working tree.
147
150
 
 
151
    Please use show_diff_trees instead.
 
152
 
148
153
    b
149
154
        Branch.
150
155
 
159
164
        output = sys.stdout
160
165
 
161
166
    if from_spec is None:
 
167
        old_tree = b.bzrdir.open_workingtree()
162
168
        if b2 is None:
163
 
            old_tree = b.basis_tree()
164
 
        else:
165
 
            old_tree = b.working_tree()
 
169
            old_tree = old_tree = old_tree.basis_tree()
166
170
    else:
167
171
        old_tree = b.repository.revision_tree(from_spec.in_history(b).rev_id)
168
172
 
169
173
    if revision2 is None:
170
174
        if b2 is None:
171
 
            new_tree = b.working_tree()
 
175
            new_tree = b.bzrdir.open_workingtree()
172
176
        else:
173
 
            new_tree = b2.working_tree()
 
177
            new_tree = b2.bzrdir.open_workingtree()
174
178
    else:
175
179
        new_tree = b.repository.revision_tree(revision2.in_history(b).rev_id)
176
180
 
178
182
                           external_diff_options)
179
183
 
180
184
 
 
185
def diff_cmd_helper(tree, specific_files, external_diff_options, 
 
186
                    old_revision_spec=None, new_revision_spec=None):
 
187
    """Helper for cmd_diff.
 
188
 
 
189
   tree 
 
190
        A WorkingTree
 
191
 
 
192
    specific_files
 
193
        The specific files to compare, or None
 
194
 
 
195
    external_diff_options
 
196
        If non-None, run an external diff, and pass it these options
 
197
 
 
198
    old_revision_spec
 
199
        If None, use basis tree as old revision, otherwise use the tree for
 
200
        the specified revision. 
 
201
 
 
202
    new_revision_spec
 
203
        If None, use working tree as new revision, otherwise use the tree for
 
204
        the specified revision.
 
205
    
 
206
    The more general form is show_diff_trees(), where the caller
 
207
    supplies any two trees.
 
208
    """
 
209
    import sys
 
210
    output = sys.stdout
 
211
    def spec_tree(spec):
 
212
        revision_id = spec.in_store(tree.branch).rev_id
 
213
        return tree.branch.repository.revision_tree(revision_id)
 
214
    if old_revision_spec is None:
 
215
        old_tree = tree.basis_tree()
 
216
    else:
 
217
        old_tree = spec_tree(old_revision_spec)
 
218
 
 
219
    if new_revision_spec is None:
 
220
        new_tree = tree
 
221
    else:
 
222
        new_tree = spec_tree(new_revision_spec)
 
223
 
 
224
    return show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
 
225
                           external_diff_options)
 
226
 
181
227
 
182
228
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
183
229
                    external_diff_options=None):
205
251
def _show_diff_trees(old_tree, new_tree, to_file,
206
252
                     specific_files, external_diff_options):
207
253
 
208
 
    # TODO: Options to control putting on a prefix or suffix, perhaps as a format string
209
 
    old_label = ''
210
 
    new_label = ''
 
254
    # TODO: Options to control putting on a prefix or suffix, perhaps
 
255
    # as a format string?
 
256
    old_label = 'a/'
 
257
    new_label = 'b/'
211
258
 
212
259
    DEVNULL = '/dev/null'
213
260
    # Windows users, don't panic about this filename -- it is a
232
279
    has_changes = 0
233
280
    for path, file_id, kind in delta.removed:
234
281
        has_changes = 1
235
 
        print >>to_file, '=== removed %s %r' % (kind, path)
 
282
        print >>to_file, '=== removed %s %r' % (kind, old_label + path)
236
283
        old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
237
284
                                         DEVNULL, None, None, to_file)
238
285
    for path, file_id, kind in delta.added:
239
286
        has_changes = 1
240
 
        print >>to_file, '=== added %s %r' % (kind, path)
 
287
        print >>to_file, '=== added %s %r' % (kind, new_label + path)
241
288
        new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
242
289
                                         DEVNULL, None, None, to_file, 
243
290
                                         reverse=True)
246
293
        has_changes = 1
247
294
        prop_str = get_prop_change(meta_modified)
248
295
        print >>to_file, '=== renamed %s %r => %r%s' % (
249
 
                          kind, old_path, new_path, prop_str)
 
296
                    kind, old_label + old_path, new_label + new_path, prop_str)
250
297
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
251
298
                                    new_label, new_path, new_tree,
252
299
                                    text_modified, kind, to_file, diff_file)
253
300
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
254
301
        has_changes = 1
255
302
        prop_str = get_prop_change(meta_modified)
256
 
        print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
 
303
        print >>to_file, '=== modified %s %r%s' % (kind, old_label + path,
 
304
                    prop_str)
257
305
        if text_modified:
258
306
            _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
259
307
                                        new_label, path, new_tree,