/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to remote.py

Add tests for revspec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import bzrlib
18
17
from bzrlib import (
19
18
    config,
 
19
    debug,
20
20
    tag,
21
21
    trace,
22
22
    ui,
29
29
    NoSuchRevision,
30
30
    NotLocalUrl,
31
31
    )
32
 
from bzrlib.trace import (
33
 
    info,
34
 
    )
35
32
from bzrlib.transport import (
36
33
    Transport,
37
34
    )
71
68
import tempfile
72
69
import urllib
73
70
import urlparse
 
71
urlparse.uses_netloc.extend(['git', 'git+ssh'])
74
72
 
75
73
from dulwich.pack import load_pack_index
76
74
 
81
79
    return []
82
80
 
83
81
 
 
82
def split_git_url(url):
 
83
    """Split a Git URL.
 
84
 
 
85
    :param url: Git URL
 
86
    :return: Tuple with host, port, username, path.
 
87
    """
 
88
    (scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
 
89
    path = urllib.unquote(loc)
 
90
    if path.startswith("/~"):
 
91
        path = path[1:]
 
92
    (username, hostport) = urllib.splituser(netloc)
 
93
    (host, port) = urllib.splitnport(hostport, None)
 
94
    return (host, port, username, path)
 
95
 
 
96
 
84
97
class GitSmartTransport(Transport):
85
98
 
86
99
    def __init__(self, url, _client=None):
87
100
        Transport.__init__(self, url)
88
 
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
89
 
        hostport, escaped_path = urllib.splithost(loc)
90
 
        self._path = urllib.unquote(escaped_path)
91
 
        (self._username, hostport) = urllib.splituser(hostport)
92
 
        (self._host, self._port) = urllib.splitnport(hostport, None)
 
101
        (self._host, self._port, self._username, self._path) = \
 
102
            split_git_url(url)
 
103
        if 'transport' in debug.debug_flags:
 
104
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
 
105
                         self._host, self._username, self._port, self._path)
93
106
        self._client = _client
94
107
 
95
108
    def external_url(self):
107
120
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
108
121
        if progress is None:
109
122
            def progress(text):
110
 
                info("git: %s" % text)
 
123
                trace.info("git: %s" % text)
111
124
        client = self._get_client(thin_packs=False)
112
125
        try:
113
126
            return client.fetch_pack(self._get_path(), determine_wants,
182
195
    def open_repository(self):
183
196
        return RemoteGitRepository(self, self._lockfiles)
184
197
 
185
 
    def open_branch(self, ignore_fallbacks=False):
 
198
    def _open_branch(self, name=None, ignore_fallbacks=False, 
 
199
                    unsupported=False):
186
200
        repo = self.open_repository()
187
 
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
188
 
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
 
201
        refname = self._branch_name_to_ref(name)
 
202
        return RemoteGitBranch(self, repo, refname, self._lockfiles)
189
203
 
190
204
    def open_workingtree(self, recommend_upgrade=False):
191
205
        raise NotLocalUrl(self.transport.base)
327
341
        if self._ref is not None:
328
342
            return self._ref
329
343
        heads = self.repository.get_refs()
330
 
        if not self.name in heads:
 
344
        if self.name in heads:
 
345
            self._ref = heads[self.name]
 
346
        elif ("refs/heads/" + self.name) in heads:
 
347
            self._ref = heads["refs/heads/" + self.name]
 
348
        else:
331
349
            raise NoSuchRef(self.name)
332
 
        self._ref = heads[self.name]
333
350
        return self._ref
334
351
 
335
352
    def _synchronize_history(self, destination, revision_id):