bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.9
by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
1 |
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
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, |
|
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
27 |
LocalRequiresBoundBranch, NotBranchError, NonExistingParent, |
0.8.7
by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
28 |
PathPrefixNotCreated, NoLocationKnown, |
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
29 |
DivergedBranchesError) |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
30 |
|
31 |
def commit(selected_list, message=None, file=None, unchanged=False, |
|
32 |
strict=False, local=False): |
|
33 |
""" Command to commit changes into the branch. |
|
34 |
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
35 |
:param selected_list: list of files you want to commit (at least the top working directory has to be specified)
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
36 |
|
37 |
:param message: commit message
|
|
38 |
|
|
39 |
:param file: the file which contains the commit message
|
|
40 |
|
|
41 |
:param unchanged: force commit if nothing has changed since the last commit
|
|
42 |
|
|
43 |
:param strict: refuse to commit if there are unknown files in the working tree
|
|
44 |
|
|
45 |
:param local: perform a local only commit in a bound branch
|
|
46 |
"""
|
|
47 |
from bzrlib.builtins import tree_files |
|
48 |
from bzrlib.commit import NullCommitReporter |
|
49 |
||
50 |
try: |
|
51 |
tree, selected_list = tree_files(selected_list) |
|
52 |
except errors.NotBranchError: |
|
53 |
raise NotBranchError |
|
54 |
||
55 |
if local and not tree.branch.get_bound_location(): |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
56 |
raise LocalRequiresBoundBranch |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
57 |
if message is None and not file: |
58 |
if message is None: |
|
59 |
raise NoMessageNoFileError |
|
60 |
elif message and file: |
|
61 |
raise NoMessageNoFileError |
|
62 |
||
63 |
if file: |
|
64 |
message = codecs.open(file, 'rt', bzrlib.user_encoding).read() |
|
65 |
||
66 |
if message == "": |
|
67 |
raise EmptyMessageError |
|
68 |
||
69 |
reporter = NullCommitReporter() |
|
70 |
||
71 |
try: |
|
72 |
tree.commit(message, specific_files=selected_list, |
|
73 |
allow_pointless=unchanged, strict=strict, local=local, |
|
74 |
reporter=reporter) |
|
75 |
except errors.PointlessCommit: |
|
76 |
raise NoChangesToCommitError |
|
77 |
except errors.ConflictsInTree: |
|
78 |
raise ConflictsInTreeError |
|
79 |
except errors.StrictCommitFailed: |
|
80 |
raise StrictCommitError |
|
81 |
except errors.BoundBranchOutOfDate, e: |
|
82 |
raise BoundBranchOutOfDate(str(e)) |
|
83 |
||
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
84 |
def push(branch, location=None, remember=False, overwrite=False, |
85 |
create_prefix=False): |
|
86 |
""" Update a mirror of a branch. |
|
87 |
|
|
88 |
:param branch: the source branch
|
|
89 |
|
|
90 |
:param location: the location of the branch that you'd like to update
|
|
91 |
|
|
92 |
:param remember: if set, the location will be stored
|
|
93 |
|
|
94 |
:param overwrite: overwrite target location if it diverged
|
|
95 |
|
|
96 |
:param create_prefix: create the path leading up to the branch if it doesn't exist
|
|
97 |
|
|
98 |
:return: number of revisions pushed
|
|
99 |
"""
|
|
100 |
from bzrlib.branch import Branch |
|
101 |
from bzrlib.transport import get_transport |
|
102 |
||
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
103 |
try: |
104 |
br_from = Branch.open_containing(branch)[0] |
|
105 |
except errors.NotBranchError: |
|
106 |
raise NotBranchError(branch) |
|
107 |
except: |
|
108 |
raise
|
|
109 |
||
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
110 |
stored_loc = br_from.get_push_location() |
111 |
if location is None: |
|
112 |
if stored_loc is None: |
|
0.8.7
by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
113 |
raise NoLocationKnown |
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
114 |
else: |
115 |
location = stored_loc |
|
116 |
||
117 |
transport = get_transport(location) |
|
118 |
location_url = transport.base |
|
119 |
||
120 |
if br_from.get_push_location() is None or remember: |
|
121 |
br_from.set_push_location(location_url) |
|
122 |
||
123 |
old_rh = [] |
|
124 |
||
125 |
try: |
|
126 |
dir_to = bzrlib.bzrdir.BzrDir.open(location_url) |
|
127 |
br_to = dir_to.open_branch() |
|
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
128 |
except errors.NotBranchError: |
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
129 |
# create a branch.
|
130 |
transport = transport.clone('..') |
|
131 |
if not create_prefix: |
|
132 |
try: |
|
133 |
relurl = transport.relpath(location_url) |
|
134 |
transport.mkdir(relurl) |
|
135 |
except errors.NoSuchFile: |
|
136 |
raise NonExistingParent(location) |
|
137 |
else: |
|
138 |
current = transport.base |
|
139 |
needed = [(transport, transport.relpath(location_url))] |
|
140 |
while needed: |
|
141 |
try: |
|
142 |
transport, relpath = needed[-1] |
|
143 |
transport.mkdir(relpath) |
|
144 |
needed.pop() |
|
145 |
except errors.NoSuchFile: |
|
146 |
new_transport = transport.clone('..') |
|
147 |
needed.append((new_transport, |
|
148 |
new_transport.relpath(transport.base))) |
|
149 |
if new_transport.base == transport.base: |
|
150 |
raise PathPrefixNotCreated |
|
151 |
dir_to = br_from.bzrdir.clone(location_url, |
|
152 |
revision_id=br_from.last_revision()) |
|
153 |
br_to = dir_to.open_branch() |
|
154 |
count = len(br_to.revision_history()) |
|
155 |
else: |
|
156 |
old_rh = br_to.revision_history() |
|
157 |
try: |
|
158 |
try: |
|
159 |
tree_to = dir_to.open_workingtree() |
|
160 |
except errors.NotLocalUrl: |
|
161 |
# FIXME - what to do here? how should we warn the user?
|
|
162 |
#warning('This transport does not update the working '
|
|
163 |
# 'tree of: %s' % (br_to.base,))
|
|
164 |
count = br_to.pull(br_from, overwrite) |
|
165 |
except errors.NoWorkingTree: |
|
166 |
count = br_to.pull(br_from, overwrite) |
|
167 |
else: |
|
168 |
count = tree_to.pull(br_from, overwrite) |
|
169 |
except errors.DivergedBranches: |
|
170 |
raise DivergedBranchesError |
|
171 |
||
172 |
return count |