vc-oddmuse.el 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ;;; vc-oddmuse.el -- add VC support to oddmuse-curl
  2. ;;
  3. ;; Copyright (C) 2014 Alex Schroeder <alex@gnu.org>
  4. ;;
  5. ;; Latest version:
  6. ;; http://git.savannah.gnu.org/cgit/oddmuse.git/plain/contrib/vc-oddmuse.el
  7. ;; Discussion, feedback:
  8. ;; http://www.emacswiki.org/cgi-bin/wiki/OddmuseCurl
  9. ;;
  10. ;; This program is free software: you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by the Free
  12. ;; Software Foundation, either version 3 of the License, or (at your option)
  13. ;; any later version.
  14. ;;
  15. ;; This program is distributed in the hope that it will be useful, but WITHOUT
  16. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  18. ;; more details.
  19. ;;
  20. ;; You should have received a copy of the GNU General Public License along
  21. ;; with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;;; Commentary:
  23. ;;
  24. ;; Add the following to your init file:
  25. ;;
  26. ;; (add-to-list 'vc-handled-backends 'oddmuse)
  27. (add-to-list 'vc-handled-backends 'oddmuse)
  28. (require 'oddmuse-curl)
  29. (require 'diff)
  30. (defun vc-oddmuse-revision-granularity () 'file)
  31. (defun vc-oddmuse-registered (file)
  32. "Handle files in `oddmuse-directory'."
  33. (string-match (concat "^" (expand-file-name oddmuse-directory))
  34. (file-name-directory file)))
  35. (defun vc-oddmuse-state (file)
  36. "Return the current version control state of FILE.
  37. For a list of possible values, see `vc-state'."
  38. ;; Avoid downloading the current version from the wiki and comparing
  39. ;; the text: Too much traffic!
  40. 'edited)
  41. (defun vc-oddmuse-working-revision (file)
  42. "The current revision based on `oddmuse-revisions'."
  43. (with-oddmuse-file
  44. (oddmuse-get-latest-revision wiki pagename)))
  45. (defun vc-oddmuse-checkout-model (files)
  46. "No locking."
  47. 'implicit)
  48. (defun vc-oddmuse-create-repo (file)
  49. (error "You cannot create Oddmuse wikis using Emacs."))
  50. (defun vc-oddmuse-register (files &optional rev comment)
  51. "This always works.")
  52. (defvar vc-oddmuse-log-command
  53. (concat "curl --silent %w"
  54. " --form action=rc"
  55. " --form showedit=1"
  56. " --form all=1"
  57. " --form from=1"
  58. " --form raw=1"
  59. " --form match='%r'")
  60. "Command to use for publishing index pages.
  61. It must print the page to stdout.
  62. See `oddmuse-format-command' for the formatting options.")
  63. (defun vc-oddmuse-print-log (files buffer &optional shortlog start-revision limit)
  64. "Load complete recent changes for the files."
  65. ;; Derive `oddmuse-wiki' from the first file
  66. (with-oddmuse-file (car files)
  67. ;; The wiki expects a Perl regular expression!
  68. (let ((regexp (concat "^(" (mapconcat 'file-name-nondirectory files "|") ")$")))
  69. (oddmuse-run "Getting recent changes" vc-oddmuse-log-command nil nil buffer)))
  70. (with-current-buffer buffer
  71. (oddmuse-render-rss3))
  72. 'limit-unsupported)
  73. (defun vc-oddmuse-log-outgoing ()
  74. (error "This is not supported."))
  75. (defun vc-oddmuse-log-incoming ()
  76. (error "This is not supported."))
  77. (defvar vc-oddmuse-get-revision-command
  78. (concat "curl --silent"
  79. " --form action=browse"
  80. " --form id=%t"
  81. " --form revision=%v"
  82. " --form raw=1"
  83. " '%w'")
  84. "Command to use to get older revisions of a page.
  85. It must print the page to stdout.
  86. %? '?' character
  87. %w URL of the wiki as provided by `oddmuse-wikis'
  88. %t Page title as provided by `oddmuse-page-name'
  89. %v Revision to retrieve as provided by `oddmuse-revision'")
  90. (defun oddmuse-revision-filename (rev)
  91. "Return filename for revision REV.
  92. This uses `oddmuse-directory', `wiki' and `pagename' as bound by
  93. `with-oddmuse-file'."
  94. (concat oddmuse-directory
  95. "/" wiki
  96. "/" pagename
  97. ".~" rev "~"))
  98. (defun vc-oddmuse-diff (files &optional rev1 rev2 buffer)
  99. "Report the differences for FILES."
  100. (setq buffer (or buffer (get-buffer-create "*vc-diff*")))
  101. (dolist (file files)
  102. (with-oddmuse-file file
  103. (setq rev1 (or rev1 (oddmuse-get-latest-revision wiki pagename)))
  104. (dolist (rev (list rev1 rev2))
  105. (when (and rev (not (file-readable-p (oddmuse-revision-filename rev))))
  106. (let* ((oddmuse-revision rev)
  107. (command vc-oddmuse-get-revision-command)
  108. (filename (oddmuse-revision-filename rev)))
  109. (with-temp-buffer
  110. (oddmuse-run
  111. (concat "Downloading revision " rev)
  112. command wiki pagename)
  113. (write-file filename)))))
  114. (diff-no-select
  115. (if rev1 (oddmuse-revision-filename rev1) file)
  116. (if rev2 (oddmuse-revision-filename rev2) file)
  117. nil
  118. (vc-switches 'oddmuse 'diff)
  119. buffer))))
  120. (defun vc-oddmuse-revert (file &optional contents-done)
  121. "Revert FILE back to the wiki revision.
  122. If optional arg CONTENTS-DONE is non-nil, then nothing needs to
  123. be done, as the contents of FILE have already been reverted from
  124. a version backup."
  125. (unless contents-done
  126. (with-oddmuse-file file
  127. (let ((command (oddmuse-format-command vc-oddmuse-get-revision-command)))
  128. (with-temp-buffer
  129. (oddmuse-run "Loading" command wiki pagename)
  130. (write-file file))))))
  131. (defun vc-oddmuse-checkin (files rev comment)
  132. "Commit changes in FILES to this backend.
  133. REV is a historical artifact and should be ignored. COMMENT is
  134. used as a check-in comment."
  135. (dolist (file files)
  136. (with-oddmuse-file file
  137. (let* ((summary comment)
  138. (command (oddmuse-format-command oddmuse-post-command))
  139. (buf (get-buffer-create " *oddmuse-response*")))
  140. (with-temp-buffer
  141. (insert-file-contents file)
  142. (oddmuse-run "Posting" command wiki pagename buf t 302))))))
  143. (provide 'vc-oddmuse)