~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

 * bzr add now lists how many files were ignored per glob.  add --verbose
   lists the specific files.  (Aaron Bentley)

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.trace import mutter
 
18
from bzrlib.errors import BzrError
17
19
from bzrlib.delta import compare_trees
18
 
from bzrlib.errors import BzrError
19
 
from bzrlib.symbol_versioning import *
20
 
from bzrlib.trace import mutter
21
20
 
22
21
# TODO: Rather than building a changeset object, we should probably
23
22
# invoke callbacks on an object.  That object can either accumulate a
142
141
        oldtmpf.close()                 # and delete
143
142
        newtmpf.close()
144
143
 
145
 
 
146
 
@deprecated_function(zero_eight)
147
144
def show_diff(b, from_spec, specific_files, external_diff_options=None,
148
145
              revision2=None, output=None, b2=None):
149
146
    """Shortcut for showing the diff to the working tree.
150
147
 
151
 
    Please use show_diff_trees instead.
152
 
 
153
148
    b
154
149
        Branch.
155
150
 
164
159
        output = sys.stdout
165
160
 
166
161
    if from_spec is None:
167
 
        old_tree = b.bzrdir.open_workingtree()
168
162
        if b2 is None:
169
 
            old_tree = old_tree = old_tree.basis_tree()
 
163
            old_tree = b.basis_tree()
 
164
        else:
 
165
            old_tree = b.working_tree()
170
166
    else:
171
 
        old_tree = b.repository.revision_tree(from_spec.in_history(b).rev_id)
 
167
        old_tree = b.revision_tree(from_spec.in_history(b).rev_id)
172
168
 
173
169
    if revision2 is None:
174
170
        if b2 is None:
175
 
            new_tree = b.bzrdir.open_workingtree()
 
171
            new_tree = b.working_tree()
176
172
        else:
177
 
            new_tree = b2.bzrdir.open_workingtree()
 
173
            new_tree = b2.working_tree()
178
174
    else:
179
 
        new_tree = b.repository.revision_tree(revision2.in_history(b).rev_id)
 
175
        new_tree = b.revision_tree(revision2.in_history(b).rev_id)
180
176
 
181
177
    return show_diff_trees(old_tree, new_tree, output, specific_files,
182
178
                           external_diff_options)
183
179
 
184
180
 
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
 
 
227
181
 
228
182
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
229
183
                    external_diff_options=None):
236
190
        If set, use an external GNU diff and pass these options.
237
191
    """
238
192
 
239
 
    old_tree.lock_read()
240
 
    try:
241
 
        new_tree.lock_read()
242
 
        try:
243
 
            return _show_diff_trees(old_tree, new_tree, to_file,
244
 
                                    specific_files, external_diff_options)
245
 
        finally:
246
 
            new_tree.unlock()
247
 
    finally:
248
 
        old_tree.unlock()
249
 
 
250
 
 
251
 
def _show_diff_trees(old_tree, new_tree, to_file,
252
 
                     specific_files, external_diff_options):
253
 
 
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/'
 
193
    # TODO: Options to control putting on a prefix or suffix, perhaps as a format string
 
194
    old_label = ''
 
195
    new_label = ''
258
196
 
259
197
    DEVNULL = '/dev/null'
260
198
    # Windows users, don't panic about this filename -- it is a
279
217
    has_changes = 0
280
218
    for path, file_id, kind in delta.removed:
281
219
        has_changes = 1
282
 
        print >>to_file, '=== removed %s %r' % (kind, old_label + path)
 
220
        print >>to_file, '=== removed %s %r' % (kind, path)
283
221
        old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
284
222
                                         DEVNULL, None, None, to_file)
285
223
    for path, file_id, kind in delta.added:
286
224
        has_changes = 1
287
 
        print >>to_file, '=== added %s %r' % (kind, new_label + path)
 
225
        print >>to_file, '=== added %s %r' % (kind, path)
288
226
        new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
289
227
                                         DEVNULL, None, None, to_file, 
290
228
                                         reverse=True)
293
231
        has_changes = 1
294
232
        prop_str = get_prop_change(meta_modified)
295
233
        print >>to_file, '=== renamed %s %r => %r%s' % (
296
 
                    kind, old_label + old_path, new_label + new_path, prop_str)
 
234
                          kind, old_path, new_path, prop_str)
297
235
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
298
236
                                    new_label, new_path, new_tree,
299
237
                                    text_modified, kind, to_file, diff_file)
300
238
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
301
239
        has_changes = 1
302
240
        prop_str = get_prop_change(meta_modified)
303
 
        print >>to_file, '=== modified %s %r%s' % (kind, old_label + path,
304
 
                    prop_str)
 
241
        print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
305
242
        if text_modified:
306
243
            _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
307
244
                                        new_label, path, new_tree,