HPSS: new server commands

Aaron Bentley aaron.bentley at utoronto.ca
Mon Apr 16 13:05:24 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
> +class SmartServerBranchRequestLastRevisionInfo(SmartServerBranchRequest):
> +    
> +    def do_with_branch(self, branch):
> +        """Return branch.last_revision_info().
> +        
> +        The revno is encoded in decimal, the revision_id is encoded as utf8.
> +        """
> +        revno, last_revision = branch.last_revision_info()
> +        if last_revision == NULL_REVISION:
> +            last_revision = ''
> +        return SmartServerResponse(('ok', str(revno), last_revision))
> +
> +
> +class SmartServerBranchRequestSetLastRevision(SmartServerLockedBranchRequest):
> +    
> +    def do_with_locked_branch(self, branch, new_last_revision_id):
> +        if new_last_revision_id == '':
> +            branch.set_revision_history([])
> +        else:
> +            if not branch.repository.has_revision(new_last_revision_id):
> +                return SmartServerResponse(
> +                    ('NoSuchRevision', new_last_revision_id))
> +            branch.generate_revision_history(new_last_revision_id)
> +        return SmartServerResponse(('ok',))

I think it makes more sense to implement SetLastRevisionInfo.  This maps
directly to Branch.set_last_revision_info, and runs in O(1) time on a
Branch6 branch.  (Whereas any implementation of SetLastRevision will
always run in O(n) time, on either branch type)


> +class SmartServerRequestHasRevision(SmartServerRepositoryRequest):
> +
> +    def do_repository_request(self, repository, revision_id):
> +        """Return ok if a specific revision is in the repository at path.
> +
> +        :param repository: The repository to query in.
> +        :param revision_id: The utf8 encoded revision_id to lookup.
> +        :return: A smart server response of ('ok', ) if the revision is
> +            present.
> +        """
> +        if repository.has_revision(revision_id):
> +            return SmartServerResponse(('ok', ))
> +        else:
> +            return SmartServerResponse(('no', ))

Does this make sense?  To me, 'ok' means the request was valid, and was
successfully processed.  So I'd expect something more like:

result = repository.has_revision(revision_id)
result_str = {True:'yes', False: 'no'}[result]
return SmartServerResponse(('ok', result_str))


Or at least it should be consistent with SmartServerRepositoryIsShared:

> +class SmartServerRepositoryIsShared(SmartServerRepositoryRequest):
> +
> +    def do_repository_request(self, repository):
> +        """Return the result of repository.is_shared().
> +
> +        :param repository: The repository to query in.
> +        :return: A smart server response of ('yes', ) if the repository is
> +            shared, and ('no', ) if it is not.
> +        """
> +        if repository.is_shared():
> +            return SmartServerResponse(('yes', ))
> +        else:
> +            return SmartServerResponse(('no', ))

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGI2aD0F+nu1YWqI0RAkVlAJ9kWtMISb4cKKHmzvCcyQ6zd8LNSwCgiaZH
tStlhg7t7ySSLY05p73dtcM=
=MfFH
-----END PGP SIGNATURE-----



More information about the bazaar mailing list