~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2005-05-25 00:48:22 UTC
  • Revision ID: mbp@sourcefrog.net-20050525004822-7665484961d59734
- Refactor diff code into one that works purely on 
  Tree objects

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    print >>to_file
66
66
 
67
67
 
 
68
 
68
69
def show_diff(b, revision, specific_files):
69
70
    import sys
70
71
 
75
76
        
76
77
    new_tree = b.working_tree()
77
78
 
 
79
    show_diff_trees(old_tree, new_tree, sys.stdout, specific_files)
 
80
 
 
81
 
 
82
 
 
83
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None):
 
84
    """Show in text form the changes from one tree to another.
 
85
 
 
86
    to_files
 
87
        If set, include only changes to these files.
 
88
    """
 
89
 
78
90
    # TODO: Options to control putting on a prefix or suffix, perhaps as a format string
79
91
    old_label = ''
80
92
    new_label = ''
95
107
        if kind == 'file':
96
108
            _diff_one(old_tree.get_file(file_id).readlines(),
97
109
                   [],
98
 
                   sys.stdout,
 
110
                   to_file,
99
111
                   fromfile=old_label + path,
100
112
                   tofile=DEVNULL)
101
113
 
104
116
        if kind == 'file':
105
117
            _diff_one([],
106
118
                   new_tree.get_file(file_id).readlines(),
107
 
                   sys.stdout,
 
119
                   to_file,
108
120
                   fromfile=DEVNULL,
109
121
                   tofile=new_label + path)
110
122
 
113
125
        if text_modified:
114
126
            _diff_one(old_tree.get_file(file_id).readlines(),
115
127
                   new_tree.get_file(file_id).readlines(),
116
 
                   sys.stdout,
 
128
                   to_file,
117
129
                   fromfile=old_label + old_path,
118
130
                   tofile=new_label + new_path)
119
131
 
122
134
        if kind == 'file':
123
135
            _diff_one(old_tree.get_file(file_id).readlines(),
124
136
                   new_tree.get_file(file_id).readlines(),
125
 
                   sys.stdout,
 
137
                   to_file,
126
138
                   fromfile=old_label + path,
127
139
                   tofile=new_label + path)
128
140