/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
4
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
import codecs
20
21
import bzrlib
22
import bzrlib.errors as errors
23
24
from errors import (EmptyMessageError, NoMessageNoFileError,
25
                    NoChangesToCommitError, ConflictsInTreeError,
26
                    StrictCommitError, BoundBranchOutOfDate,
27
                    LocalRequiresBoundBranch, NotBranchError)
28
29
def commit(selected_list, message=None, file=None, unchanged=False,
30
           strict=False, local=False):
31
    """ Command to commit changes into the branch.
32
    
33
    :param selected_list: list of files you want to commit (at least the top working directory has to specified)
34
    
35
    :param message: commit message
36
    
37
    :param file: the file which contains the commit message
38
    
39
    :param unchanged: force commit if nothing has changed since the last commit
40
    
41
    :param strict: refuse to commit if there are unknown files in the working tree
42
    
43
    :param local: perform a local only commit in a bound branch
44
    """
45
    from bzrlib.builtins import tree_files
46
    from bzrlib.commit import NullCommitReporter
47
48
    try:
49
        tree, selected_list = tree_files(selected_list)
50
    except errors.NotBranchError:
51
        raise NotBranchError
52
    
53
    if local and not tree.branch.get_bound_location():
54
        raise LocalRequiresBoundBranch()
55
    if message is None and not file:
56
        if message is None:
57
            raise NoMessageNoFileError
58
    elif message and file:
59
        raise NoMessageNoFileError
60
61
    if file:
62
        message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
63
64
    if message == "":
65
        raise EmptyMessageError
66
67
    reporter = NullCommitReporter()
68
69
    try:
70
        tree.commit(message, specific_files=selected_list,
71
                    allow_pointless=unchanged, strict=strict, local=local,
72
                    reporter=reporter)
73
    except errors.PointlessCommit:
74
        raise NoChangesToCommitError
75
    except errors.ConflictsInTree:
76
        raise ConflictsInTreeError
77
    except errors.StrictCommitFailed:
78
        raise StrictCommitError
79
    except errors.BoundBranchOutOfDate, e:
80
        raise BoundBranchOutOfDate(str(e))
81