~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2007-02-04 12:35:51 UTC
  • mfrom: (2258.1.2 hpss.api.changes)
  • mto: This revision was merged to the branch mainline in revision 2261.
  • Revision ID: robertc@robertcollins.net-20070204123551-yw876d2dmdhyb3nw
(robertc) Move info stats gathering into Repository.gather_stats allowing server optimisation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
243
243
        return self.control_files.get_physical_lock_status()
244
244
 
245
245
    @needs_read_lock
 
246
    def gather_stats(self, revid=None, committers=None):
 
247
        """Gather statistics from a revision id.
 
248
 
 
249
        :param revid: The revision id to gather statistics from, if None, then
 
250
            no revision specific statistics are gathered.
 
251
        :param committers: Optional parameter controlling whether to grab
 
252
            a count of committers from the revision specific statistics.
 
253
        :return: A dictionary of statistics. Currently this contains:
 
254
            committers: The number of committers if requested.
 
255
            firstrev: A tuple with timestamp, timezone for the penultimate left
 
256
                most ancestor of revid, if revid is not the NULL_REVISION.
 
257
            latestrev: A tuple with timestamp, timezone for revid, if revid is
 
258
                not the NULL_REVISION.
 
259
            revisions: The total revision count in the repository.
 
260
            size: An estimate disk size of the repository in bytes.
 
261
        """
 
262
        result = {}
 
263
        if revid and committers:
 
264
            result['committers'] = 0
 
265
        if revid and revid != _mod_revision.NULL_REVISION:
 
266
            if committers:
 
267
                all_committers = set()
 
268
            revisions = self.get_ancestry(revid)
 
269
            # pop the leading None
 
270
            revisions.pop(0)
 
271
            first_revision = None
 
272
            if not committers:
 
273
                # ignore the revisions in the middle - just grab first and last
 
274
                revisions = revisions[0], revisions[-1]
 
275
            for revision in self.get_revisions(revisions):
 
276
                if not first_revision:
 
277
                    first_revision = revision
 
278
                if committers:
 
279
                    all_committers.add(revision.committer)
 
280
            last_revision = revision
 
281
            if committers:
 
282
                result['committers'] = len(all_committers)
 
283
            result['firstrev'] = (first_revision.timestamp,
 
284
                first_revision.timezone)
 
285
            result['latestrev'] = (last_revision.timestamp,
 
286
                last_revision.timezone)
 
287
 
 
288
        # now gather global repository information
 
289
        if self.bzrdir.root_transport.listable():
 
290
            c, t = self._revision_store.total_size(self.get_transaction())
 
291
            result['revisions'] = c
 
292
            result['size'] = t
 
293
        return result
 
294
 
 
295
    @needs_read_lock
246
296
    def missing_revision_ids(self, other, revision_id=None):
247
297
        """Return the revision ids that other has that this does not.
248
298