~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Martin Pool
  • Date: 2005-07-18 18:53:46 UTC
  • Revision ID: mbp@sourcefrog.net-20050718185346-6226a1be01b942e1
- new 'weave stats' command

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
             verbose=False,
90
90
             direction='reverse',
91
91
             start_revision=None,
92
 
             end_revision=None):
 
92
             end_revision=None,
 
93
             search=None):
93
94
    """Write out human-readable log of commits to this branch.
94
95
 
95
96
    lf
124
125
    if specific_fileid:
125
126
        mutter('get log for file_id %r' % specific_fileid)
126
127
 
 
128
    if search is not None:
 
129
        import re
 
130
        searchRE = re.compile(search, re.IGNORECASE)
 
131
    else:
 
132
        searchRE = None
 
133
 
127
134
    which_revs = branch.enum_history(direction)
 
135
    which_revs = [x for x in which_revs if (
 
136
            (start_revision is None or x[0] >= start_revision)
 
137
            and (end_revision is None or x[0] <= end_revision))]
128
138
 
129
139
    if not (verbose or specific_fileid):
130
140
        # no need to know what changed between revisions
132
142
    elif direction == 'reverse':
133
143
        with_deltas = deltas_for_log_reverse(branch, which_revs)
134
144
    else:        
135
 
        raise NotImplementedError("sorry, verbose forward logs not done yet")
 
145
        with_deltas = deltas_for_log_forward(branch, which_revs)
136
146
 
137
147
    for revno, rev, delta in with_deltas:
138
148
        if specific_fileid:
139
149
            if not delta.touches_file_id(specific_fileid):
140
150
                continue
141
151
 
142
 
        if start_revision is not None and revno < start_revision:
143
 
            continue
144
 
 
145
 
        if end_revision is not None and revno > end_revision:
146
 
            continue
147
 
        
148
152
        if not verbose:
149
153
            # although we calculated it, throw it away without display
150
154
            delta = None
151
155
 
152
 
        lf.show(revno, rev, delta)
 
156
        if searchRE is None or searchRE.search(rev.message):
 
157
            lf.show(revno, rev, delta)
153
158
 
154
159
 
155
160
 
179
184
        if last_revno:
180
185
            yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
181
186
 
 
187
        this_tree = EmptyTree(branch.get_root_id())
 
188
 
182
189
        last_revno = revno
183
190
        last_revision = this_revision
184
191
        last_tree = this_tree
185
192
 
186
193
    if last_revno:
187
 
        this_tree = EmptyTree()
 
194
        if last_revno == 1:
 
195
            this_tree = EmptyTree(branch.get_root_id())
 
196
        else:
 
197
            this_revno = last_revno - 1
 
198
            this_revision_id = branch.revision_history()[this_revno]
 
199
            this_tree = branch.revision_tree(this_revision_id)
188
200
        yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
189
201
 
190
202
 
 
203
def deltas_for_log_forward(branch, which_revs):
 
204
    """Compute deltas for display in forward log.
 
205
 
 
206
    Given a sequence of (revno, revision_id) pairs, return
 
207
    (revno, rev, delta).
 
208
 
 
209
    The delta is from the given revision to the next one in the
 
210
    sequence, which makes sense if the log is being displayed from
 
211
    newest to oldest.
 
212
    """
 
213
    from tree import EmptyTree
 
214
    from diff import compare_trees
 
215
 
 
216
    last_revno = last_revision_id = last_tree = None
 
217
    prev_tree = EmptyTree(branch.get_root_id())
 
218
 
 
219
    for revno, revision_id in which_revs:
 
220
        this_tree = branch.revision_tree(revision_id)
 
221
        this_revision = branch.get_revision(revision_id)
 
222
 
 
223
        if not last_revno:
 
224
            if revno == 1:
 
225
                last_tree = EmptyTree(branch.get_root_id())
 
226
            else:
 
227
                last_revno = revno - 1
 
228
                last_revision_id = branch.revision_history()[last_revno]
 
229
                last_tree = branch.revision_tree(last_revision_id)
 
230
 
 
231
        yield revno, this_revision, compare_trees(last_tree, this_tree, False)
 
232
 
 
233
        last_revno = revno
 
234
        last_revision = this_revision
 
235
        last_tree = this_tree
191
236
 
192
237
 
193
238
class LogFormatter(object):