bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
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 errno |
|
20 |
import os |
|
21 |
||
22 |
import bzrlib.errors as errors |
|
23 |
||
24 |
from errors import (AlreadyBranchError, BranchExistsWithoutWorkingTree, |
|
25 |
NonExistingParent, NonExistingRevision, NonExistingSource, |
|
26 |
RevisionValueError, TargetAlreadyExists) |
|
27 |
||
28 |
def init(location): |
|
29 |
from bzrlib.builtins import get_format_type |
|
30 |
import bzrlib.bzrdir as bzrdir |
|
31 |
||
32 |
format = get_format_type('default') |
|
33 |
||
34 |
if not os.path.exists(location): |
|
35 |
os.mkdir(location) |
|
36 |
||
37 |
try: |
|
38 |
existing_bzrdir = bzrdir.BzrDir.open(location) |
|
39 |
except errors.NotBranchError: |
|
40 |
bzrdir.BzrDir.create_branch_convenience(location, format=format) |
|
41 |
else: |
|
42 |
if existing_bzrdir.has_branch(): |
|
43 |
if existing_bzrdir.has_workingtree(): |
|
44 |
raise AlreadyBranchError(location) |
|
45 |
else: |
|
46 |
raise BranchExistsWithoutWorkingTree(location) |
|
47 |
else: |
|
48 |
existing_bzrdir.create_branch() |
|
49 |
existing_bzrdir.create_workingtree() |
|
50 |
||
51 |
def branch(from_location, to_location, revision=None): |
|
52 |
from bzrlib.branch import Branch |
|
53 |
from bzrlib.transport import get_transport |
|
54 |
||
55 |
if revision is None: |
|
56 |
revision = [None] |
|
57 |
elif len(revision) > 1: |
|
58 |
raise RevisionValueError('bzr branch --revision takes exactly 1 revision value') |
|
59 |
||
60 |
try: |
|
61 |
br_from = Branch.open(from_location) |
|
62 |
except OSError, e: |
|
63 |
if e.errno == errno.ENOENT: |
|
64 |
raise NonExistingSource(from_location) |
|
65 |
else: |
|
66 |
raise
|
|
67 |
||
68 |
br_from.lock_read() |
|
69 |
||
70 |
try: |
|
71 |
basis_dir = None |
|
72 |
if len(revision) == 1 and revision[0] is not None: |
|
73 |
revision_id = revision[0].in_history(br_from)[1] |
|
74 |
else: |
|
75 |
revision_id = br_from.last_revision() |
|
76 |
||
77 |
to_location = to_location + '/' + os.path.basename(from_location.rstrip("/\\")) |
|
78 |
name = None |
|
79 |
to_transport = get_transport(to_location) |
|
80 |
||
81 |
try: |
|
82 |
to_transport.mkdir('.') |
|
83 |
except errors.FileExists: |
|
84 |
raise TargetAlreadyExists(to_location) |
|
85 |
except errors.NoSuchFile: |
|
86 |
raise NonExistingParent(to_location) |
|
87 |
||
88 |
try: |
|
89 |
dir = br_from.bzrdir.sprout(to_transport.base, revision_id, basis_dir) |
|
90 |
branch = dir.open_branch() |
|
91 |
except errors.NoSuchRevision: |
|
92 |
to_transport.delete_tree('.') |
|
93 |
raise NonExistingRevision(from_location, revision[0]) |
|
94 |
||
95 |
if name: |
|
96 |
branch.control_files.put_utf8('branch-name', name) |
|
97 |
finally: |
|
98 |
br_from.unlock() |
|
99 |
||
100 |
return branch.revno() |
|
101 |
||
102 |
def checkout(): |
|
103 |
""" FIXME - will be implemented later """ |