/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 revspec.py

Properly ignore directories when creating bundles, deal with new files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    InvalidRevisionId,
23
23
    InvalidRevisionSpec,
24
24
    )
25
 
from bzrlib.revision import (
26
 
    NULL_REVISION,
27
 
)
28
25
from bzrlib.revisionspec import (
29
26
    RevisionInfo,
30
27
    RevisionSpec,
32
29
 
33
30
 
34
31
def valid_git_sha1(hex):
35
 
    """Check if `hex` is a validly formatted Git SHA1.
36
 
    
37
 
    :param hex: Hex string to validate
38
 
    :return: Boolean
39
 
    """
40
32
    import binascii
41
33
    try:
42
34
        binascii.unhexlify(hex)
74
66
        raise InvalidRevisionSpec(self.user_spec, branch)
75
67
 
76
68
    def _history(self, branch, revid):
77
 
        branch.lock_read()
78
 
        try:
79
 
            history = list(branch.repository.iter_reverse_revision_history(
80
 
                revid))
81
 
        finally:
82
 
            branch.unlock()
 
69
        history = list(branch.repository.iter_reverse_revision_history(revid))
83
70
        history.reverse()
84
71
        return history
85
72
 
86
73
    def __nonzero__(self):
 
74
        from bzrlib.revision import (
 
75
            NULL_REVISION,
 
76
            )
87
77
        # The default implementation uses branch.repository.has_revision()
88
78
        if self.rev_id is None:
89
79
            return False
93
83
 
94
84
    def _find_short_git_sha1(self, branch, sha1):
95
85
        from bzrlib.plugins.git.mapping import (
96
 
            ForeignGit,
97
86
            mapping_registry,
98
87
            )
99
88
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
102
91
        try:
103
92
            graph = branch.repository.get_graph()
104
93
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
105
 
                if revid == NULL_REVISION:
106
 
                    continue
107
94
                try:
108
95
                    foreign_revid, mapping = parse_revid(revid)
109
96
                except InvalidRevisionId:
110
97
                    continue
111
 
                if not isinstance(mapping.vcs, ForeignGit):
112
 
                    continue
113
98
                if foreign_revid.startswith(sha1):
114
99
                    history = self._history(branch, revid)
115
100
                    return RevisionInfo.from_revision_id(branch, revid, history)