Comments
Patch
@@ -8,34 +8,39 @@
Indices are data structures in the form of key-value mappings used
by the server to speed up computations.
-Each index has a corresponding maker function that takes as parameter
-an iterable with change contexs from which the index is to be created
-and returns the index in a form of a dict.
+Each index has a corresponding updater function that:
+ * Takes as parameters a current index and an iterable with new
+ change contexs.
+ * Computes the entries that have to be updated/inserted to reflect
+ the changes in the new chagesets.
+ * Returns a list of (key, value) pairs of such entries.
"""
-def makeuserchgs(ctxs):
- """Return the `userchgs` index.
+def userchgsentries(index, ctxs):
+ """Return new entries for the `userchgs` index.
`userchgs` is keyed by username, with each value being a list
of changes commited by that user.
"""
newentries = {}
for ctx in ctxs:
- newentries.setdefault(ctx.user(), []).append(ctx.node())
- return newentries
+ user = ctx.user()
+ if user not in newentries:
+ newentries[user] = index.get(user, [])
+ newentries[user].append(ctx.node())
+ return list(newentries.iteritems())
-def makechgdate(ctxs):
- """Return the `chgdate` index.
+def chgdateentries(index, ctxs):
+ """Return new entries for the `chgdate` index.
`chgdate` is keyed by change id, with each value being a commit date
of that change.
"""
- return dict([(ctx.node(), ctx.date()[0]) for ctx in ctxs])
+ return [(ctx.node(), ctx.date()[0]) for ctx in ctxs]
-
-def makefilechgs(ctxs):
- """Return the `filechgs` index.
+def filechgsentries(index, ctxs):
+ """Return new entries for the `filechgs` index.
`filechgs` is keyed by paths (files or directories), with each value
being a list of commits touching this path (for direcories it is
@@ -51,15 +56,17 @@
for i in range(len(dirs)):
paths.add('/'.join(dirs[0:i+1]))
for path in paths:
- filechgs.setdefault(path, []).append(ctx.node())
- return filechgs
+ if path not in filechgs:
+ filechgs[path] = index.get(path, [])
+ filechgs[path].append(ctx.node())
+ return list(filechgs.iteritems())
-def makefiles(ctxs):
- """Return the `files` index.
+def filesentries(index, ctxs):
+ """Return new entries for the `files` index.
`files` is keyed by file name, with each value being an empty string
"""
files = set()
for ctx in ctxs:
files.update(ctx.files())
- return dict([(fn, '') for fn in files])
+ return [(fn, '') for fn in files]
@@ -122,16 +122,16 @@
return self._literalpath(matchingfiles)
indicecfg = {
- 'userchgs': index.makeuserchgs,
- 'chgdate': index.makechgdate,
- 'filechgs': index.makefilechgs,
- 'files': index.makefiles,
+ 'userchgs': index.userchgsentries,
+ 'chgdate': index.chgdateentries,
+ 'filechgs': index.filechgsentries,
+ 'files': index.filesentries,
}
def makeserver(repo):
"""Return an initialized metaserver instance."""
ctxs = [repo[r] for r in xrange(0, len(repo))]
- indices = dict([(name, create(ctxs)) for name, create in
+ indices = dict([(name, dict(newentries({}, ctxs))) for name, newentries in
indicecfg.iteritems()])
return metaserver(repo, indices)