~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-02-22 07:59:56 UTC
  • mfrom: (1553.5.33 bzr.mbp.locks)
  • Revision ID: pqm@pqm.ubuntu.com-20060222075956-fb281c427e571da6
add LockDir and related fixes

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
# TODO: Some kind of command-line display of revision properties: 
 
18
# perhaps show them in log -v and allow them as options to the commit command.
17
19
 
18
20
import bzrlib.errors
19
21
from bzrlib.graph import node_distances, select_farthest, all_descendants
20
22
from bzrlib.osutils import contains_whitespace
 
23
from bzrlib.progress import DummyProgress
21
24
 
22
25
NULL_REVISION="null:"
23
26
 
43
46
        self.revision_id = revision_id
44
47
        self.properties = properties or {}
45
48
        self._check_properties()
46
 
        self.__dict__.update(args)
47
49
        self.parent_ids = []
48
50
        self.parent_sha1s = []
 
51
        self.__dict__.update(args)
49
52
 
50
53
    def __repr__(self):
51
54
        return "<Revision id %s>" % self.revision_id
76
79
                raise ValueError("invalid property value %r for %r" % 
77
80
                                 (name, value))
78
81
 
 
82
    def get_history(self, repository):
 
83
        """Return the canonical line-of-history for this revision.
 
84
 
 
85
        If ghosts are present this may differ in result from a ghost-free
 
86
        repository.
 
87
        """
 
88
        current_revision = self
 
89
        reversed_result = []
 
90
        while current_revision is not None:
 
91
            reversed_result.append(current_revision.revision_id)
 
92
            if not len (current_revision.parent_ids):
 
93
                reversed_result.append(None)
 
94
                current_revision = None
 
95
            else:
 
96
                next_revision_id = current_revision.parent_ids[0]
 
97
                current_revision = repository.get_revision(next_revision_id)
 
98
        reversed_result.reverse()
 
99
        return reversed_result
 
100
 
79
101
 
80
102
def is_ancestor(revision_id, candidate_id, branch):
81
103
    """Return true if candidate_id is an ancestor of revision_id.
86
108
    revisions_source is an object supporting a get_revision operation that
87
109
    behaves like Branch's.
88
110
    """
89
 
    return candidate_id in branch.get_ancestry(revision_id)
 
111
    return candidate_id in branch.repository.get_ancestry(revision_id)
90
112
 
91
113
 
92
114
def iter_ancestors(revision_id, revision_source, only_present=False):
149
171
        if b_ancestors.has_key(revision):
150
172
            a_intersection.append((a_distance, a_order, revision))
151
173
            b_intersection.append((b_ancestors[revision][1], a_order, revision))
152
 
    mutter("a intersection: %r" % a_intersection)
153
 
    mutter("b intersection: %r" % b_intersection)
 
174
    mutter("a intersection: %r", a_intersection)
 
175
    mutter("b intersection: %r", b_intersection)
154
176
 
155
177
    a_closest = __get_closest(a_intersection)
156
178
    if len(a_closest) == 0:
157
179
        return None
158
180
    b_closest = __get_closest(b_intersection)
159
181
    assert len(b_closest) != 0
160
 
    mutter ("a_closest %r" % a_closest)
161
 
    mutter ("b_closest %r" % b_closest)
 
182
    mutter ("a_closest %r", a_closest)
 
183
    mutter ("b_closest %r", b_closest)
162
184
    if a_closest[0] in b_closest:
163
185
        return a_closest[0]
164
186
    elif b_closest[0] in a_closest:
174
196
    TODO: Produce graphs with the NULL revision as root, so that we can find
175
197
    a common even when trees are not branches don't represent a single line
176
198
    of descent.
 
199
    RBC: 20051024: note that when we have two partial histories, this may not
 
200
         be possible. But if we are willing to pretend :)... sure.
177
201
    """
178
202
    ancestors = {}
179
203
    descendants = {}
206
230
            if parents is not None:
207
231
                ancestors[line] = set(parents)
208
232
        lines = new_lines
 
233
    if root is None:
 
234
        # The history for revision becomes inaccessible without
 
235
        # actually hitting a no-parents revision. This then
 
236
        # makes these asserts below trigger. So, if root is None
 
237
        # determine the actual root by walking the accessible tree
 
238
        # and then stash NULL_REVISION at the end.
 
239
        root = NULL_REVISION
 
240
        descendants[root] = {}
 
241
        # for every revision, check we can access at least
 
242
        # one parent, if we cant, add NULL_REVISION and
 
243
        # a link
 
244
        for rev in ancestors:
 
245
            if len(ancestors[rev]) == 0:
 
246
                raise RuntimeError('unreachable code ?!')
 
247
            ok = False
 
248
            for parent in ancestors[rev]:
 
249
                if parent in ancestors:
 
250
                    ok = True
 
251
            if ok:
 
252
                continue
 
253
            descendants[root][rev] = 1
 
254
            ancestors[rev].add(root)
 
255
        ancestors[root] = set()
209
256
    assert root not in descendants[root]
210
257
    assert root not in ancestors[root]
211
258
    return root, ancestors, descendants
233
280
    return root, ancestors, descendants, common
234
281
 
235
282
 
236
 
def common_ancestor(revision_a, revision_b, revision_source):
 
283
def common_ancestor(revision_a, revision_b, revision_source, 
 
284
                    pb=DummyProgress()):
237
285
    try:
238
 
        root, ancestors, descendants, common = \
239
 
            combined_graph(revision_a, revision_b, revision_source)
240
 
    except bzrlib.errors.NoCommonRoot:
241
 
        raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
242
 
        
243
 
    distances = node_distances (descendants, ancestors, root)
244
 
    farthest = select_farthest(distances, common)
245
 
    if farthest is None or farthest == NULL_REVISION:
246
 
        raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
 
286
        try:
 
287
            pb.update('Picking ancestor', 1, 3)
 
288
            root, ancestors, descendants, common = \
 
289
                combined_graph(revision_a, revision_b, revision_source)
 
290
        except bzrlib.errors.NoCommonRoot:
 
291
            raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
 
292
            
 
293
        pb.update('Picking ancestor', 2, 3)
 
294
        distances = node_distances (descendants, ancestors, root)
 
295
        pb.update('Picking ancestor', 3, 2)
 
296
        farthest = select_farthest(distances, common)
 
297
        if farthest is None or farthest == NULL_REVISION:
 
298
            raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
 
299
    finally:
 
300
        pb.clear()
247
301
    return farthest
248
302
 
249
303