24
24
from errors import (NotBranchError)
26
def nick(branch, nickname=None):
27
""" Get or set nickname.
29
:param branch: path to the branch
31
:param nickname: if specified, the nickname will be set
36
branch = Branch.open_containing(branch)[0]
37
except errors.NotBranchError:
40
if nickname is not None:
41
branch.nick = nickname
46
""" Get current revision number for specified branch
48
:param branch: path to the branch
50
:return: revision number
53
revno = Branch.open_containing(branch)[0].revno()
54
except errors.NotBranchError:
60
""" Get version information from bzr
62
:return: bzrlib version
64
return bzrlib.__version__
66
def whoami(branch=None, email=False):
67
""" Get user's data (name and email address)
69
:param branch: if specified, the user's data will be looked up in the branch's config
71
:param email: if True, only the email address will be returned
73
:return: user info (only email address if email is True)
26
def diff(revision=None, file_list=None, diff_options=None, prefix=None):
27
""" Save the diff into a temporary file.
29
:param revision: a list of revisions (one or two elements)
31
:param file_list: list of files you want to diff
33
:param diff_options: external diff options
35
: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
39
from tempfile import mkstemp
41
from bzrlib.builtins import internal_tree_files
42
from bzrlib.diff import show_diff_trees
75
43
from bzrlib.workingtree import WorkingTree
77
if branch is not None:
79
b = WorkingTree.open_containing(u'.')[0].branch
80
config = bzrlib.config.BranchConfig(b)
81
except NotBranchError:
82
config = bzrlib.config.GlobalConfig()
84
config = bzrlib.config.GlobalConfig()
87
return config.user_email()
89
return config.username()
45
from info_helper import diff_helper
47
if (prefix is None) or (prefix == '0'):
56
raise errors.BzrError("--diff-prefix expects two values separated by a colon")
57
old_label, new_label = prefix.split(":")
60
tree1, file_list = internal_tree_files(file_list)
64
except errors.FileInWrongBranch:
65
if len(file_list) != 2:
66
raise errors.BzrCommandError("Files are in different branches")
68
tree1, file1 = WorkingTree.open_containing(file_list[0])
69
tree2, file2 = WorkingTree.open_containing(file_list[1])
71
if file1 != "" or file2 != "":
72
# FIXME diff those two files. rbc 20051123
73
raise errors.BzrCommandError("Files are in different branches")
77
tmpfile = mkstemp(prefix='olive_')
78
tmpfp = open(tmpfile[1], 'w')
80
if revision is not None:
82
raise errors.BzrCommandError("Can't specify -r with two branches")
84
if (len(revision) == 1) or (revision[1].spec is None):
85
ret = diff_helper(tree1, file_list, diff_options,
87
old_label=old_label, new_label=new_label,
89
elif len(revision) == 2:
90
ret = diff_helper(tree1, file_list, diff_options,
91
revision[0], revision[1],
92
old_label=old_label, new_label=new_label,
95
raise errors.BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
98
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)
103
ret = diff_helper(tree1, file_list, diff_options,
104
old_label=old_label, new_label=new_label,
91
114
def info(location):
92
115
""" Get info about branch, working tree, and repository
193
216
except errors.NoRepositoryPresent:
219
def nick(branch, nickname=None):
220
""" Get or set nickname.
222
:param branch: path to the branch
224
:param nickname: if specified, the nickname will be set
229
branch = Branch.open_containing(branch)[0]
230
except errors.NotBranchError:
233
if nickname is not None:
234
branch.nick = nickname
239
""" Get current revision number for specified branch
241
:param branch: path to the branch
243
:return: revision number
246
revno = Branch.open_containing(branch)[0].revno()
247
except errors.NotBranchError:
253
""" Get version information from bzr
255
:return: bzrlib version
257
return bzrlib.__version__
259
def whoami(branch=None, email=False):
260
""" Get user's data (name and email address)
262
:param branch: if specified, the user's data will be looked up in the branch's config
264
:param email: if True, only the email address will be returned
266
:return: user info (only email address if email is True)
268
from bzrlib.workingtree import WorkingTree
270
if branch is not None:
272
b = WorkingTree.open_containing(u'.')[0].branch
273
config = bzrlib.config.BranchConfig(b)
274
except NotBranchError:
275
config = bzrlib.config.GlobalConfig()
277
config = bzrlib.config.GlobalConfig()
280
return config.user_email()
282
return config.username()