Commits

Radomir Dopieralski  committed 261e1c4

Made Mercurial handle the log too

  • Participants
  • Parent commits 06db1c5

Comments (0)

Files changed (1)

File w/plugin/hgstore.py

 import mercurial.hgweb.request
 import datetime
 
-class MercurialStorage(object):
+class MercurialStorageAndLog(object):
     def __init__(self, path="pages"):
         self.path = os.path.abspath(path)
         if not os.path.exists(self.path):
             return u""
 
     def save(self, page, text):
-        newly_created = not self.exists(page)
+        created = not self.exists(page)
         tmpfd, tmpname = tempfile.mkstemp(
             prefix=self._filename(page), 
             dir=self.path)
         f = os.fdopen(tmpfd, "wb")
         f.write(text.encode("utf-8"))
         os.rename(tmpname, self._filepath(page))
-        if newly_created:
-            self.repo.add(self._filename(page))
-        self.repo.commit(text="saved")
+        if created:
+            self.repo.add([self._filename(page)])
+    
+    def edited(self, page, author="", comment=""):
+        self.repo.commit(text=comment.encode("utf-8") or "saved", user=author)
 
     def changes(self):
         for node in reversed(self.repo.changelog.nodesbetween()[0]):
 def plugin(wiki, config):
     repo_path = (config["repository"] or 
         os.path.join(wiki.config["data_dir"], "pages"))
-    wiki.storage = MercurialStorage(os.path.abspath(repo_path))
+    wiki.storage = MercurialStorageAndLog(os.path.abspath(repo_path))
+    wiki.log = wiki.storage
     wrapper = HgwebWrapper(wiki.storage.repo, wiki)
     wrapper.wsgi_orig = wiki.wsgi
     wiki.wsgi = wrapper.wiki_wsgi