/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 breezy/git/workingtree.py

Merge tree reference fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from dulwich.ignore import (
26
26
    IgnoreFilterManager,
27
27
    )
 
28
from dulwich.config import ConfigFile as GitConfigFile
28
29
from dulwich.file import GitFile, FileLocked
29
30
from dulwich.index import (
30
31
    Index,
49
50
import sys
50
51
 
51
52
from .. import (
 
53
    branch as _mod_branch,
52
54
    conflicts as _mod_conflicts,
53
55
    errors,
54
56
    controldir as _mod_controldir,
61
63
    trace,
62
64
    transport as _mod_transport,
63
65
    tree,
 
66
    urlutils,
64
67
    workingtree,
65
68
    )
66
69
from ..decorators import (
1240
1243
    def _read_submodule_head(self, path):
1241
1244
        return read_submodule_head(self.abspath(path))
1242
1245
 
1243
 
    def get_reference_revision(self, path):
 
1246
    def get_reference_revision(self, path, branch=None):
1244
1247
        hexsha = self._read_submodule_head(path)
1245
1248
        if hexsha is None:
1246
1249
            return _mod_revision.NULL_REVISION
1325
1328
                    new_parents = [revision_id]
1326
1329
                tree.set_parent_ids(new_parents)
1327
1330
 
 
1331
    def reference_parent(self, path, possible_transports=None):
 
1332
        remote_url = self.get_reference_info(path)
 
1333
        if remote_url is None:
 
1334
            trace.warning("Unable to find submodule info for %s", path)
 
1335
            return None
 
1336
        return _mod_branch.Branch.open(remote_url, possible_transports=possible_transports)
 
1337
 
 
1338
    def get_reference_info(self, path):
 
1339
        submodule_info = self._submodule_info()
 
1340
        info = submodule_info.get(path.encode('utf-8'))
 
1341
        if info is None:
 
1342
            return None
 
1343
        return info[0].decode('utf-8')
 
1344
 
 
1345
    def set_reference_info(self, tree_path, branch_location):
 
1346
        path = self.abspath('.gitmodules')
 
1347
        try:
 
1348
            config = GitConfigFile.from_path(path)
 
1349
        except EnvironmentError as e:
 
1350
            if e.errno == errno.ENOENT:
 
1351
                config = GitConfigFile()
 
1352
            else:
 
1353
                raise
 
1354
        section = (b'submodule', tree_path.encode('utf-8'))
 
1355
        if branch_location is None:
 
1356
            try:
 
1357
                del config[section]
 
1358
            except KeyError:
 
1359
                pass
 
1360
        else:
 
1361
            branch_location = urlutils.join(
 
1362
                urlutils.strip_segment_parameters(self.branch.user_url),
 
1363
                branch_location)
 
1364
            config.set(
 
1365
                section,
 
1366
                b'path', tree_path.encode('utf-8'))
 
1367
            config.set(
 
1368
                section,
 
1369
                b'url', branch_location.encode('utf-8'))
 
1370
        config.write_to_path(path)
 
1371
        self.add('.gitmodules')
 
1372
 
1328
1373
 
1329
1374
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):
1330
1375