~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-25 23:07:24 UTC
  • mfrom: (3441.5.33 smart-push-gpm)
  • Revision ID: pqm@pqm.ubuntu.com-20080625230724-lyux37pu8nx8tq34
Add Branch.set_last_revision_ex HPSS verb to accelerate push. (Andrew
        Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
        return SuccessfulSmartServerResponse(('ok',))
129
129
 
130
130
 
 
131
class SmartServerBranchRequestSetLastRevisionEx(SmartServerLockedBranchRequest):
 
132
    
 
133
    def do_with_locked_branch(self, branch, new_last_revision_id,
 
134
            allow_divergence, allow_overwrite_descendant):
 
135
        """Set the last revision of the branch.
 
136
 
 
137
        New in 1.6.
 
138
        
 
139
        :param new_last_revision_id: the revision ID to set as the last
 
140
            revision of the branch.
 
141
        :param allow_divergence: A flag.  If non-zero, change the revision ID
 
142
            even if the new_last_revision_id's ancestry has diverged from the
 
143
            current last revision.  If zero, a 'Diverged' error will be
 
144
            returned if new_last_revision_id is not a descendant of the current
 
145
            last revision.
 
146
        :param allow_overwrite_descendant:  A flag.  If zero and
 
147
            new_last_revision_id is not a descendant of the current last
 
148
            revision, then the last revision will not be changed.  If non-zero
 
149
            and there is no divergence, then the last revision is always
 
150
            changed.
 
151
 
 
152
        :returns: on success, a tuple of ('ok', revno, revision_id), where
 
153
            revno and revision_id are the new values of the current last
 
154
            revision info.  The revision_id might be different to the
 
155
            new_last_revision_id if allow_overwrite_descendant was not set.
 
156
        """
 
157
        do_not_overwrite_descendant = not allow_overwrite_descendant
 
158
        try:
 
159
            last_revno, last_rev = branch.last_revision_info()
 
160
            graph = branch.repository.get_graph()
 
161
            if not allow_divergence or do_not_overwrite_descendant:
 
162
                relation = branch._revision_relations(
 
163
                    last_rev, new_last_revision_id, graph)
 
164
                if relation == 'diverged' and not allow_divergence:
 
165
                    return FailedSmartServerResponse(('Diverged',))
 
166
                if relation == 'a_descends_from_b' and do_not_overwrite_descendant:
 
167
                    return SuccessfulSmartServerResponse(
 
168
                        ('ok', last_revno, last_rev))
 
169
            new_revno = graph.find_distance_to_null(
 
170
                new_last_revision_id, [(last_rev, last_revno)])
 
171
            branch.set_last_revision_info(new_revno, new_last_revision_id)
 
172
        except errors.GhostRevisionsHaveNoRevno:
 
173
            return FailedSmartServerResponse(
 
174
                ('NoSuchRevision', new_last_revision_id))
 
175
        return SuccessfulSmartServerResponse(
 
176
            ('ok', new_revno, new_last_revision_id))
 
177
 
 
178
 
131
179
class SmartServerBranchRequestSetLastRevisionInfo(
132
180
    SmartServerLockedBranchRequest):
133
181
    """Branch.set_last_revision_info.  Sets the revno and the revision ID of