/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to backend/info.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-07-08 17:36:59 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060708173659-8ab442681dadd8ea
2006-07-08  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * backend/errors.py: added some exceptions related to diff() and log()
    * backend/info.py: implemented log()
    * backend/info.py: diff() works well with revnos
    * added e-mail address to copyright header

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
2
# Some parts of the code are:
3
3
# Copyright (C) 2005, 2006 by Canonical Ltd
4
4
 
21
21
 
22
22
from bzrlib.branch import Branch
23
23
 
24
 
from errors import (NotBranchError)
 
24
from errors import (DifferentBranchesError, NotBranchError, PrefixFormatError,
 
25
                    RevisionValueError)
25
26
 
26
27
def diff(revision=None, file_list=None, diff_options=None, prefix=None):
27
28
    """ Save the diff into a temporary file.
28
29
    
29
 
    :param revision: a list of revisions (one or two elements)
 
30
    :param revision: a list of revision numbers (one or two elements)
30
31
    
31
32
    :param file_list: list of files you want to diff
32
33
    
34
35
    
35
36
    :param prefix: 0 - p0, 1 - p1, or specify prefixes in the form of old/:new/
36
37
    
37
 
    :return: path to the temporary file which contains the diff output
 
38
    :return: path to the temporary file which contains the diff output (the frontend has to remove it!)
38
39
    """
39
40
    from tempfile import mkstemp
40
41
    
41
42
    from bzrlib.builtins import internal_tree_files
42
43
    from bzrlib.diff import show_diff_trees
 
44
    from bzrlib.revisionspec import RevisionSpec_int
43
45
    from bzrlib.workingtree import WorkingTree
44
46
    
45
47
    from info_helper import diff_helper
53
55
        new_label = 'new/'
54
56
    else:
55
57
        if not ':' in prefix:
56
 
            raise errors.BzrError("--diff-prefix expects two values separated by a colon")
 
58
            raise PrefixFormatError
57
59
        old_label, new_label = prefix.split(":")
58
60
    
59
61
    try:
63
65
        b2 = None
64
66
    except errors.FileInWrongBranch:
65
67
        if len(file_list) != 2:
66
 
            raise errors.BzrCommandError("Files are in different branches")
 
68
            raise DifferentBranchesError
67
69
 
68
70
        tree1, file1 = WorkingTree.open_containing(file_list[0])
69
71
        tree2, file2 = WorkingTree.open_containing(file_list[1])
70
72
    
71
73
        if file1 != "" or file2 != "":
72
 
            # FIXME diff those two files. rbc 20051123
73
 
            raise errors.BzrCommandError("Files are in different branches")
 
74
            raise DifferentBranchesError
74
75
    
75
76
        file_list = None
76
77
    
79
80
    
80
81
    if revision is not None:
81
82
        if tree2 is not None:
82
 
            raise errors.BzrCommandError("Can't specify -r with two branches")
 
83
            raise RevisionValueError
83
84
    
 
85
        if len(revision) >= 1:
 
86
            revision[0] = RevisionSpec_int(revision[0])
 
87
        if len(revision) == 2:
 
88
            revision[1] = RevisionSpec_int(revision[1])
 
89
        
84
90
        if (len(revision) == 1) or (revision[1].spec is None):
85
91
            ret = diff_helper(tree1, file_list, diff_options,
86
 
                                   revision[0], 
87
 
                                   old_label=old_label, new_label=new_label,
88
 
                                   output=tmpfp)
 
92
                              revision[0], 
 
93
                              old_label=old_label, new_label=new_label,
 
94
                              output=tmpfp)
89
95
        elif len(revision) == 2:
90
96
            ret = diff_helper(tree1, file_list, diff_options,
91
 
                                   revision[0], revision[1],
92
 
                                   old_label=old_label, new_label=new_label,
93
 
                                   output=tmpfp)
 
97
                              revision[0], revision[1],
 
98
                              old_label=old_label, new_label=new_label,
 
99
                              output=tmpfp)
94
100
        else:
95
 
            raise errors.BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
 
101
            raise RevisionValueError
96
102
    else:
97
103
        if tree2 is not None:
98
104
            ret = show_diff_trees(tree1, tree2, tmpfp, 
99
 
                                   specific_files=file_list,
100
 
                                   external_diff_options=diff_options,
101
 
                                   old_label=old_label, new_label=new_label)
 
105
                                  specific_files=file_list,
 
106
                                  external_diff_options=diff_options,
 
107
                                  old_label=old_label, new_label=new_label)
102
108
        else:
103
109
            ret = diff_helper(tree1, file_list, diff_options,
104
 
                                   old_label=old_label, new_label=new_label,
105
 
                                   output=tmpfp)
 
110
                              old_label=old_label, new_label=new_label,
 
111
                              output=tmpfp)
106
112
    
107
113
    tmpfp.close()
108
114
    
216
222
    except errors.NoRepositoryPresent:
217
223
        pass
218
224
 
 
225
def log(location, timezone='original', verbose=False, show_ids=False,
 
226
        forward=False, revision=None, log_format=None, message=None,
 
227
        long=False, short=False, line=False):
 
228
    """ Print log into a temporary file.
 
229
    
 
230
    :param location: location of local/remote branch or file
 
231
    
 
232
    :param timzone: requested timezone
 
233
    
 
234
    :param verbose: verbose output
 
235
    
 
236
    :param show_ids:
 
237
    
 
238
    :param forward: if True, start from the earliest entry
 
239
    
 
240
    :param revision: revision range as a list ([from, to])
 
241
    
 
242
    :param log_format: line, short, long
 
243
    
 
244
    :param message: show revisions whose message matches this regexp
 
245
    
 
246
    :param long: long log format
 
247
    
 
248
    :param short: short log format
 
249
    
 
250
    :param line: line log format
 
251
    
 
252
    :return: full path to the temporary file containing the log (the frontend has to remove it!)
 
253
    """
 
254
    from tempfile import mkstemp
 
255
    
 
256
    from bzrlib import bzrdir    
 
257
    from bzrlib.builtins import get_log_format
 
258
    from bzrlib.log import log_formatter, show_log
 
259
    from bzrlib.revisionspec import RevisionSpec_int
 
260
    
 
261
    assert message is None or isinstance(message, basestring), \
 
262
        "invalid message argument %r" % message
 
263
    direction = (forward and 'forward') or 'reverse'
 
264
        
 
265
    # log everything
 
266
    file_id = None
 
267
    
 
268
    # find the file id to log:
 
269
    dir, fp = bzrdir.BzrDir.open_containing(location)
 
270
    b = dir.open_branch()
 
271
    if fp != '':
 
272
        try:
 
273
            # might be a tree:
 
274
            inv = dir.open_workingtree().inventory
 
275
        except (errors.NotBranchError, errors.NotLocalUrl):
 
276
            # either no tree, or is remote.
 
277
            inv = b.basis_tree().inventory
 
278
        file_id = inv.path2id(fp)
 
279
 
 
280
    if revision is not None:
 
281
        if len(revision) >= 1:
 
282
            revision[0] = RevisionSpec_int(revision[0])
 
283
        if len(revision) == 2:
 
284
            revision[1] = RevisionSpec_int(revision[1])
 
285
    
 
286
    if revision is None:
 
287
        rev1 = None
 
288
        rev2 = None
 
289
    elif len(revision) == 1:
 
290
        rev1 = rev2 = revision[0].in_history(b).revno
 
291
    elif len(revision) == 2:
 
292
        if revision[0].spec is None:
 
293
            # missing begin-range means first revision
 
294
            rev1 = 1
 
295
        else:
 
296
            rev1 = revision[0].in_history(b).revno
 
297
 
 
298
        if revision[1].spec is None:
 
299
            # missing end-range means last known revision
 
300
            rev2 = b.revno()
 
301
        else:
 
302
            rev2 = revision[1].in_history(b).revno
 
303
    else:
 
304
        raise RevisionValueError
 
305
 
 
306
    # By this point, the revision numbers are converted to the +ve
 
307
    # form if they were supplied in the -ve form, so we can do
 
308
    # this comparison in relative safety
 
309
    if rev1 > rev2:
 
310
        (rev2, rev1) = (rev1, rev2)
 
311
 
 
312
    if (log_format == None):
 
313
        default = b.get_config().log_format()
 
314
        log_format = get_log_format(long=long, short=short, line=line, 
 
315
                                    default=default)
 
316
    
 
317
    tmpfile = mkstemp(prefix='olive_')
 
318
    tmpfp = open(tmpfile[1], 'w')
 
319
    
 
320
    lf = log_formatter(log_format,
 
321
                       show_ids=show_ids,
 
322
                       to_file=tmpfp,
 
323
                       show_timezone=timezone)
 
324
 
 
325
    show_log(b,
 
326
             lf,
 
327
             file_id,
 
328
             verbose=verbose,
 
329
             direction=direction,
 
330
             start_revision=rev1,
 
331
             end_revision=rev2,
 
332
             search=message)
 
333
    
 
334
    tmpfp.close()
 
335
    return tmpfile[1]
 
336
 
219
337
def nick(branch, nickname=None):
220
338
    """ Get or set nickname.
221
339