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.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
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 errno |
|
20 |
import os |
|
21 |
||
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
22 |
import bzrlib |
23 |
import bzrlib.bzrdir as bzrdir |
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
24 |
import bzrlib.errors as errors |
25 |
||
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
26 |
from bzrlib.branch import Branch |
27 |
||
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
28 |
from errors import (AlreadyBranchError, BranchExistsWithoutWorkingTree, |
0.8.7
by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
29 |
NonExistingParent, NonExistingRevision, |
30 |
NonExistingSource, TargetAlreadyExists) |
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
31 |
|
32 |
def init(location): |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
33 |
""" Initialize a directory. |
34 |
|
|
35 |
:param location: full path to the directory you want to be versioned
|
|
36 |
"""
|
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
37 |
from bzrlib.builtins import get_format_type |
38 |
||
39 |
format = get_format_type('default') |
|
40 |
||
41 |
if not os.path.exists(location): |
|
42 |
os.mkdir(location) |
|
43 |
||
44 |
try: |
|
45 |
existing_bzrdir = bzrdir.BzrDir.open(location) |
|
46 |
except errors.NotBranchError: |
|
47 |
bzrdir.BzrDir.create_branch_convenience(location, format=format) |
|
48 |
else: |
|
49 |
if existing_bzrdir.has_branch(): |
|
50 |
if existing_bzrdir.has_workingtree(): |
|
51 |
raise AlreadyBranchError(location) |
|
52 |
else: |
|
53 |
raise BranchExistsWithoutWorkingTree(location) |
|
54 |
else: |
|
55 |
existing_bzrdir.create_branch() |
|
56 |
existing_bzrdir.create_workingtree() |
|
57 |
||
58 |
def branch(from_location, to_location, revision=None): |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
59 |
""" Create a branch from a local/remote location. |
60 |
|
|
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
61 |
:param from_location: the original location of the branch
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
62 |
|
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
63 |
:param to_location: the directory where the branch should be created
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
64 |
|
65 |
:param revision: if specified, the given revision will be branched
|
|
66 |
|
|
67 |
:return: number of revisions branched
|
|
68 |
"""
|
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
69 |
from bzrlib.transport import get_transport |
70 |
||
71 |
try: |
|
72 |
br_from = Branch.open(from_location) |
|
73 |
except OSError, e: |
|
74 |
if e.errno == errno.ENOENT: |
|
75 |
raise NonExistingSource(from_location) |
|
76 |
else: |
|
77 |
raise
|
|
78 |
||
79 |
br_from.lock_read() |
|
80 |
||
81 |
try: |
|
82 |
basis_dir = None |
|
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
83 |
if revision is not None: |
84 |
revision_id = br_from.get_rev_id(revision) |
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
85 |
else: |
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
86 |
revision_id = None |
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
87 |
|
88 |
to_location = to_location + '/' + os.path.basename(from_location.rstrip("/\\")) |
|
89 |
name = None |
|
90 |
to_transport = get_transport(to_location) |
|
91 |
||
92 |
try: |
|
93 |
to_transport.mkdir('.') |
|
94 |
except errors.FileExists: |
|
95 |
raise TargetAlreadyExists(to_location) |
|
96 |
except errors.NoSuchFile: |
|
97 |
raise NonExistingParent(to_location) |
|
98 |
||
99 |
try: |
|
100 |
dir = br_from.bzrdir.sprout(to_transport.base, revision_id, basis_dir) |
|
101 |
branch = dir.open_branch() |
|
102 |
except errors.NoSuchRevision: |
|
103 |
to_transport.delete_tree('.') |
|
104 |
raise NonExistingRevision(from_location, revision[0]) |
|
105 |
||
106 |
if name: |
|
107 |
branch.control_files.put_utf8('branch-name', name) |
|
108 |
finally: |
|
109 |
br_from.unlock() |
|
110 |
||
111 |
return branch.revno() |
|
112 |
||
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
113 |
def checkout(branch_location, to_location, revision=None, lightweight=False): |
114 |
""" Create a new checkout of an existing branch. |
|
115 |
|
|
116 |
:param branch_location: the location of the branch you'd like to checkout
|
|
117 |
|
|
118 |
:param to_location: the directory where the checkout should be created
|
|
119 |
|
|
120 |
:param revision: the given revision will be checkout'ed (be aware!)
|
|
121 |
|
|
122 |
:param lightweight: perform a lightweight checkout (be aware!)
|
|
123 |
"""
|
|
124 |
source = Branch.open(branch_location) |
|
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
125 |
|
126 |
if revision is not None: |
|
127 |
revision_id = source.get_rev_id(revision) |
|
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
128 |
else: |
129 |
revision_id = None |
|
130 |
||
131 |
# if the source and to_location are the same,
|
|
132 |
# and there is no working tree,
|
|
133 |
# then reconstitute a branch
|
|
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
134 |
if (bzrlib.osutils.abspath(to_location) == |
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
135 |
bzrlib.osutils.abspath(branch_location)): |
136 |
try: |
|
137 |
source.bzrdir.open_workingtree() |
|
138 |
except errors.NoWorkingTree: |
|
139 |
source.bzrdir.create_workingtree() |
|
140 |
return
|
|
141 |
||
142 |
try: |
|
143 |
os.mkdir(to_location) |
|
144 |
except OSError, e: |
|
145 |
if e.errno == errno.EEXIST: |
|
146 |
raise TargetAlreadyExists(to_location) |
|
147 |
if e.errno == errno.ENOENT: |
|
148 |
raise NonExistingParent(to_location) |
|
149 |
else: |
|
150 |
raise
|
|
151 |
||
152 |
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format() |
|
153 |
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1()) |
|
154 |
||
155 |
try: |
|
156 |
if lightweight: |
|
157 |
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location) |
|
158 |
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source) |
|
159 |
else: |
|
160 |
checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience( |
|
161 |
to_location, force_new_tree=False) |
|
162 |
checkout = checkout_branch.bzrdir |
|
163 |
checkout_branch.bind(source) |
|
164 |
if revision_id is not None: |
|
165 |
rh = checkout_branch.revision_history() |
|
166 |
checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1]) |
|
0.8.4
by Szilveszter Farkas (Phanatic)
* backend/commit.py: minor tweaks to push() |
167 |
|
0.8.3
by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet |
168 |
checkout.create_workingtree(revision_id) |
169 |
finally: |
|
170 |
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format) |