/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/commit.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-06-11 19:06:06 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-20060611190606-313cd4690a10cd78
* backend/commit.py: commit() implemented
* backend/fileops.py: remove() implemented
* backend/errors.py: more exceptions added
* more detailed comments for the different functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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