~astukalov/bzr-difftools/modes_n_metaargs

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Stephen Ward
  • Date: 2006-11-10 19:08:15 UTC
  • mfrom: (26.1.2 bzr_difftools)
  • Revision ID: sward@localhost-20061110190815-82d21a8062aa48b1
Merge import fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
external tool (and by changing the 'decorate' option on register_command).
35
35
"""
36
36
 
 
37
from bzrlib import (
 
38
    builtins,
 
39
    osutils,
 
40
    )
37
41
from bzrlib.commands import register_command
38
42
from bzrlib.option import Option
39
43
from bzrlib.workingtree import WorkingTree
42
46
from bzrlib.errors import (BzrError, BzrCommandError, NotVersionedError,
43
47
                           PathNotChild, FileInWrongBranch, NotLocalUrl,
44
48
                           NoWorkingTree)
45
 
from bzrlib.osutils import pathjoin, basename, getcwd, normpath, relpath
46
 
from bzrlib.export import export
47
49
from bzrlib.transport import get_transport
48
50
from bzrlib.transport.local import LocalTransport
49
 
import bzrlib.builtins
50
51
 
51
52
from difftool import (register_diff_tool, find_diff_tool, 
52
53
                      TreeDiffTool, ListDiffTool)
53
54
from tempdir import NamedTemporaryDir
54
55
 
 
56
 
55
57
class NoDifferencesFound(Exception):
56
58
  pass
57
59
 
58
60
 
59
 
class cmd_diff(bzrlib.builtins.cmd_diff):
 
61
class cmd_diff(builtins.cmd_diff):
60
62
  """
61
63
  The '--using TOOL' option can be used to run an external diff tool.
62
64
 
74
76
  """
75
77
 
76
78
  # Add a new option to the builtin 'diff' command:
77
 
  bzrlib.builtins.cmd_diff.takes_options.append(
78
 
                  Option('using', type=str, help='use alternate diff tool'))
 
79
  takes_options = builtins.cmd_diff.takes_options + [
 
80
                  Option('using', type=str, help='use alternate diff tool')]
79
81
 
80
82
  # Override the inherited run() and help() methods:
81
83
 
114
116
    
115
117
    # Default to current working directory:
116
118
    if (not file_list or len(file_list) == 0):
117
 
      file_list = [ getcwd() ]
 
119
      file_list = [ osutils.getcwd() ]
118
120
 
119
121
    # Pick the right comparison to perform:
120
122
    if revision:
173
175
    if in_subdir:
174
176
      adjust_path = work_tree1.inventory.id2path(file_ids1[0])
175
177
    else:
176
 
      adjust_path = basename(file_list[0])
 
178
      adjust_path = osutils.basename(file_list[0])
177
179
  else:
178
180
    adjust_path = ''
179
181
 
196
198
      new_hint = "-rev%d" % rev2.in_history(b1).revno
197
199
      new_tmp_dir = NamedTemporaryDir(tmp_prefix, new_hint)
198
200
      new_tmp_dir.write_stuff(new_tree, file_ids1, use_tree)
199
 
      new_path = pathjoin(new_tmp_dir.path, adjust_path)
 
201
      new_path = osutils.pathjoin(new_tmp_dir.path, adjust_path)
200
202
    elif b2:
201
203
      # Files from two different branches:
202
204
      delta = get_diffs_or_stop(old_tree, work_tree2, file_ids2)
203
205
      new_hint = '-' + b2.nick
204
206
      new_tmp_dir = NamedTemporaryDir(tmp_prefix, new_hint)
205
207
      new_tmp_dir.write_stuff(work_tree2, file_ids2, use_tree)
206
 
      new_path = pathjoin(new_tmp_dir.path, adjust_path)
 
208
      new_path = osutils.pathjoin(new_tmp_dir.path, adjust_path)
207
209
    elif not in_working_tree:
208
210
      # Repository branch or remote branch, but only one revision:
209
211
      new_tree = b1.basis_tree()
211
213
      new_hint = "-basis"
212
214
      new_tmp_dir = NamedTemporaryDir(tmp_prefix, new_hint)
213
215
      new_tmp_dir.write_stuff(new_tree, file_ids1, use_tree)
214
 
      new_path = pathjoin(new_tmp_dir.path, adjust_path)
 
216
      new_path = osutils.pathjoin(new_tmp_dir.path, adjust_path)
215
217
    else:
216
218
      # Item(s) in working tree, just diff it in place:
217
219
      delta = get_diffs_or_stop(old_tree, work_tree1, file_ids1)
223
225
    # No exceptions yet, so we really do need to extract the old version:
224
226
    old_tmp_dir = NamedTemporaryDir(tmp_prefix, old_hint)
225
227
    old_tmp_dir.write_stuff(old_tree, file_ids1, use_tree)
226
 
    old_path = pathjoin(old_tmp_dir.path, adjust_path)
 
228
    old_path = osutils.pathjoin(old_tmp_dir.path, adjust_path)
227
229
  
228
230
    # Run the comparison:
229
231
    if (tool.supports('recursive')):
264
266
  try:
265
267
    (tree, rel_path) = WorkingTree.open_containing(file_list[0])
266
268
    branch = tree.branch
267
 
    base_path = normpath(tree.id2abspath(tree.get_root_id()))
 
269
    base_path = osutils.normpath(tree.id2abspath(tree.get_root_id()))
268
270
  except NoWorkingTree:
269
271
    (branch, rel_path) = Branch.open_containing(file_list[0])
270
272
    tree = branch.basis_tree()
271
 
    base_path = normpath(branch.base)
 
273
    base_path = osutils.normpath(branch.base)
272
274
  except NotLocalUrl:
273
275
    (branch, rel_path) = Branch.open_containing(file_list[0])
274
276
    tree = branch.basis_tree()
279
281
    try:
280
282
      if i > 0:
281
283
        if base_path:
282
 
          rpath = relpath(base_path, file_name)
 
284
          rpath = osutils.relpath(base_path, file_name)
283
285
        else:
284
286
          (branch2, rpath) = Branch.open_containing(file_name)
285
287
          if branch2.base != branch.base: