bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
1 |
# Copyright (C) 2006 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Server-side branch related request implmentations."""
|
|
18 |
||
19 |
||
20 |
from bzrlib import errors |
|
21 |
from bzrlib.bzrdir import BzrDir |
|
|
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
22 |
from bzrlib.revision import NULL_REVISION |
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
23 |
from bzrlib.smart.request import SmartServerRequest, SmartServerResponse |
24 |
||
25 |
||
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
26 |
class SmartServerBranchRequest(SmartServerRequest): |
27 |
"""Base class for handling common branch request logic.""" |
|
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
28 |
|
29 |
def do(self, path): |
|
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
30 |
"""Execute a request for a branch at path. |
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
31 |
|
32 |
If the branch is a branch reference, NotBranchError is raised.
|
|
33 |
"""
|
|
34 |
transport = self._backing_transport.clone(path) |
|
35 |
bzrdir = BzrDir.open_from_transport(transport) |
|
36 |
if bzrdir.get_branch_reference() is not None: |
|
37 |
raise errors.NotBranchError(transport.base) |
|
38 |
branch = bzrdir.open_branch() |
|
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
39 |
return self.do_with_branch(branch) |
40 |
||
41 |
||
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
42 |
class SmartServerBranchGetConfigFile(SmartServerBranchRequest): |
43 |
||
44 |
def do_with_branch(self, branch): |
|
45 |
"""Return the content of branch.control_files.get('branch.conf'). |
|
46 |
|
|
47 |
The body is not utf8 decoded - its the literal bytestream from disk.
|
|
48 |
"""
|
|
49 |
try: |
|
50 |
content = branch.control_files.get('branch.conf').read() |
|
51 |
except errors.NoSuchFile: |
|
52 |
content = '' |
|
53 |
return SmartServerResponse( ('ok', ), content) |
|
54 |
||
55 |
||
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
56 |
class SmartServerRequestRevisionHistory(SmartServerBranchRequest): |
57 |
||
58 |
def do_with_branch(self, branch): |
|
59 |
"""Get the revision history for the branch. |
|
60 |
||
61 |
The revision list is returned as the body content,
|
|
62 |
with each revision utf8 encoded and \x00 joined.
|
|
63 |
"""
|
|
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
64 |
return SmartServerResponse(('ok', ), |
65 |
('\x00'.join(branch.revision_history())).encode('utf8')) |
|
|
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
66 |
|
67 |
||
68 |
class SmartServerBranchRequestLastRevisionInfo(SmartServerBranchRequest): |
|
69 |
||
70 |
def do_with_branch(self, branch): |
|
71 |
"""Return branch.last_revision_info(). |
|
72 |
|
|
73 |
The revno is encoded in decimal, the revision_id is encoded as utf8.
|
|
74 |
"""
|
|
75 |
revno, last_revision = branch.last_revision_info() |
|
76 |
if last_revision == NULL_REVISION: |
|
77 |
last_revision = '' |
|
78 |
return SmartServerResponse( |
|
79 |
('ok', str(revno), last_revision.encode('utf8'))) |
|
80 |
||
81 |