22
22
from bzrlib.branch import Branch
24
from errors import (NotBranchError)
24
from errors import (DifferentBranchesError, NotBranchError, PrefixFormatError,
26
27
def diff(revision=None, file_list=None, diff_options=None, prefix=None):
27
28
""" Save the diff into a temporary file.
29
:param revision: a list of revisions (one or two elements)
30
:param revision: a list of revision numbers (one or two elements)
31
32
:param file_list: list of files you want to diff
35
36
:param prefix: 0 - p0, 1 - p1, or specify prefixes in the form of old/:new/
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!)
39
40
from tempfile import mkstemp
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
45
47
from info_helper import diff_helper
64
66
except errors.FileInWrongBranch:
65
67
if len(file_list) != 2:
66
raise errors.BzrCommandError("Files are in different branches")
68
raise DifferentBranchesError
68
70
tree1, file1 = WorkingTree.open_containing(file_list[0])
69
71
tree2, file2 = WorkingTree.open_containing(file_list[1])
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
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
85
if len(revision) >= 1:
86
revision[0] = RevisionSpec_int(revision[0])
87
if len(revision) == 2:
88
revision[1] = RevisionSpec_int(revision[1])
84
90
if (len(revision) == 1) or (revision[1].spec is None):
85
91
ret = diff_helper(tree1, file_list, diff_options,
87
old_label=old_label, new_label=new_label,
93
old_label=old_label, new_label=new_label,
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,
97
revision[0], revision[1],
98
old_label=old_label, new_label=new_label,
95
raise errors.BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
101
raise RevisionValueError
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)
103
109
ret = diff_helper(tree1, file_list, diff_options,
104
old_label=old_label, new_label=new_label,
110
old_label=old_label, new_label=new_label,
216
222
except errors.NoRepositoryPresent:
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.
230
:param location: location of local/remote branch or file
232
:param timzone: requested timezone
234
:param verbose: verbose output
238
:param forward: if True, start from the earliest entry
240
:param revision: revision range as a list ([from, to])
242
:param log_format: line, short, long
244
:param message: show revisions whose message matches this regexp
246
:param long: long log format
248
:param short: short log format
250
:param line: line log format
252
:return: full path to the temporary file containing the log (the frontend has to remove it!)
254
from tempfile import mkstemp
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
261
assert message is None or isinstance(message, basestring), \
262
"invalid message argument %r" % message
263
direction = (forward and 'forward') or 'reverse'
268
# find the file id to log:
269
dir, fp = bzrdir.BzrDir.open_containing(location)
270
b = dir.open_branch()
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)
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])
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
296
rev1 = revision[0].in_history(b).revno
298
if revision[1].spec is None:
299
# missing end-range means last known revision
302
rev2 = revision[1].in_history(b).revno
304
raise RevisionValueError
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
310
(rev2, rev1) = (rev1, rev2)
312
if (log_format == None):
313
default = b.get_config().log_format()
314
log_format = get_log_format(long=long, short=short, line=line,
317
tmpfile = mkstemp(prefix='olive_')
318
tmpfp = open(tmpfile[1], 'w')
320
lf = log_formatter(log_format,
323
show_timezone=timezone)
219
337
def nick(branch, nickname=None):
220
338
""" Get or set nickname.