/b-gtk/fix-viz

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