pcvs.el 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459
  1. ;;; pcvs.el --- a front-end to CVS -*- lexical-binding:t -*-
  2. ;; Copyright (C) 1991-2015 Free Software Foundation, Inc.
  3. ;; Author: (The PCL-CVS Trust) pcl-cvs@cyclic.com
  4. ;; (Per Cederqvist) ceder@lysator.liu.se
  5. ;; (Greg A. Woods) woods@weird.com
  6. ;; (Jim Blandy) jimb@cyclic.com
  7. ;; (Karl Fogel) kfogel@floss.red-bean.com
  8. ;; (Jim Kingdon) kingdon@cyclic.com
  9. ;; (Stefan Monnier) monnier@cs.yale.edu
  10. ;; (Greg Klanderman) greg@alphatech.com
  11. ;; (Jari Aalto+mail.emacs) jari.aalto@poboxes.com
  12. ;; Maintainer: (Stefan Monnier) monnier@gnu.org
  13. ;; Keywords: CVS, vc, release management
  14. ;; This file is part of GNU Emacs.
  15. ;; GNU Emacs is free software: you can redistribute it and/or modify
  16. ;; it under the terms of the GNU General Public License as published by
  17. ;; the Free Software Foundation, either version 3 of the License, or
  18. ;; (at your option) any later version.
  19. ;; GNU Emacs is distributed in the hope that it will be useful,
  20. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. ;; GNU General Public License for more details.
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  25. ;;; Commentary:
  26. ;; PCL-CVS is a front-end to the CVS version control system.
  27. ;; It presents the status of all the files in your working area and
  28. ;; allows you to commit/update several of them at a time.
  29. ;; Compare with the general Emacs utility vc-dir, which tries
  30. ;; to be VCS-agnostic. You may find PCL-CVS better/faster for CVS.
  31. ;; PCL-CVS was originally written by Per Cederqvist many years ago. This
  32. ;; version derives from the XEmacs-21 version, itself based on the 2.0b2
  33. ;; version (last release from Per). It is a thorough rework.
  34. ;; PCL-CVS is not a replacement for VC, but adds extra functionality.
  35. ;; As such, I've tried to make PCL-CVS and VC interoperate seamlessly
  36. ;; (I also use VC).
  37. ;; To use PCL-CVS just use `M-x cvs-examine RET <dir> RET'.
  38. ;; There is a TeXinfo manual, which can be helpful to get started.
  39. ;;; Bugs:
  40. ;; - Extracting an old version seems not to recognize encoding correctly.
  41. ;; That's probably because it's done via a process rather than a file.
  42. ;;; Todo:
  43. ;; ******** FIX THE DOCUMENTATION *********
  44. ;;
  45. ;; - rework the displaying of error messages.
  46. ;; - allow to flush messages only
  47. ;; - allow to protect files like ChangeLog from flushing
  48. ;; - query the user for cvs-get-marked (for some cmds or if nothing's selected)
  49. ;; - don't return the first (resp last) FI if the cursor is before
  50. ;; (resp after) it.
  51. ;; - allow cvs-confirm-removals to force always confirmation.
  52. ;; - cvs-checkout should ask for a revision (with completion).
  53. ;; - removal confirmation should allow specifying another file name.
  54. ;;
  55. ;; - hide fileinfos without getting rid of them (will require ewok work).
  56. ;; - add toolbar entries
  57. ;; - marking
  58. ;; marking directories should jump to just after the dir.
  59. ;; allow (un)marking directories at a time with the mouse.
  60. ;; allow cvs-cmd-do to either clear the marks or not.
  61. ;; add a "marks active" notion, like transient-mark-mode does.
  62. ;; - liveness indicator
  63. ;; - indicate in docstring if the cmd understands the `b' prefix(es).
  64. ;; - call smerge-mode when opening CONFLICT files.
  65. ;; - have vc-checkin delegate to cvs-mode-commit when applicable
  66. ;; - higher-level CVS operations
  67. ;; cvs-mode-rename
  68. ;; cvs-mode-branch
  69. ;; - module-level commands
  70. ;; add support for parsing 'modules' file ("cvs co -c")
  71. ;; cvs-mode-rcs2log
  72. ;; cvs-rdiff
  73. ;; cvs-release
  74. ;; cvs-import
  75. ;; C-u M-x cvs-checkout should ask for a cvsroot
  76. ;; cvs-mode-handle-new-vendor-version
  77. ;; - checks out module, or alternately does update join
  78. ;; - does "cvs -n tag LAST_VENDOR" to find old files into *cvs*
  79. ;; cvs-export
  80. ;; (with completion on tag names and hooks to help generate full releases)
  81. ;; - display stickiness information. And current CVS/Tag as well.
  82. ;; - write 'cvs-mode-admin' to do arbitrary 'cvs admin' commands
  83. ;; Most interesting would be version removal and log message replacement.
  84. ;; The last one would be neat when called from log-view-mode.
  85. ;; - cvs-mode-incorporate
  86. ;; It would merge in the status from one *cvs* buffer into another.
  87. ;; This would be used to populate such a buffer that had been created with
  88. ;; a `cvs {update,status,checkout} -l'.
  89. ;; - cvs-mode-(i)diff-other-{file,buffer,cvs-buffer}
  90. ;; - offer the choice to kill the process when the user kills the cvs buffer.
  91. ;; right now, it's killed without further ado.
  92. ;; - make `cvs-mode-ignore' allow manually entering a pattern.
  93. ;; to which dir should it apply ?
  94. ;; - cvs-mode-ignore should try to remove duplicate entries.
  95. ;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ?
  96. ;; - some kind of `cvs annotate' support ?
  97. ;; but vc-annotate can be used instead.
  98. ;; - proper `g' that passes safe args and uses either cvs-status or cvs-examine
  99. ;; maybe also use cvs-update depending on I-don't-know-what.
  100. ;; - add message-levels so that we can hide some levels of messages
  101. ;;; Code:
  102. (eval-when-compile (require 'cl-lib))
  103. (require 'ewoc) ;Ewoc was once cookie
  104. (require 'pcvs-defs)
  105. (require 'pcvs-util)
  106. (require 'pcvs-parse)
  107. (require 'pcvs-info)
  108. (require 'vc-cvs)
  109. ;;;;
  110. ;;;; global vars
  111. ;;;;
  112. (defvar cvs-cookies) ;;nil
  113. ;;"Handle for the cookie structure that is displayed in the *cvs* buffer.")
  114. ;;(make-variable-buffer-local 'cvs-cookies)
  115. ;;;;
  116. ;;;; Dynamically scoped variables
  117. ;;;;
  118. (defvar cvs-from-vc nil "Bound to t inside VC advice.")
  119. ;;;;
  120. ;;;; flags variables
  121. ;;;;
  122. (defun cvs-defaults (&rest defs)
  123. (let ((defs (cvs-first defs cvs-shared-start)))
  124. (append defs
  125. (make-list (- cvs-shared-start (length defs)) (car defs))
  126. cvs-shared-flags)))
  127. ;; For cvs flags, we need to add "-f" to override the cvsrc settings
  128. ;; we also want to evict the annoying -q and -Q options that hide useful
  129. ;; information from pcl-cvs.
  130. (cvs-flags-define cvs-cvs-flags '(("-f")))
  131. (cvs-flags-define cvs-checkout-flags (cvs-defaults '("-P")))
  132. (cvs-flags-define cvs-status-flags (cvs-defaults '("-v") nil))
  133. (cvs-flags-define cvs-log-flags (cvs-defaults nil))
  134. (cvs-flags-define cvs-diff-flags (cvs-defaults '("-u" "-N") '("-c" "-N") '("-u" "-b")))
  135. (cvs-flags-define cvs-tag-flags (cvs-defaults nil))
  136. (cvs-flags-define cvs-add-flags (cvs-defaults nil))
  137. (cvs-flags-define cvs-commit-flags (cvs-defaults nil))
  138. (cvs-flags-define cvs-remove-flags (cvs-defaults nil))
  139. ;;(cvs-flags-define cvs-undo-flags (cvs-defaults nil))
  140. (cvs-flags-define cvs-update-flags (cvs-defaults '("-d" "-P")))
  141. (defun cvs-reread-cvsrc ()
  142. "Reset the default arguments to those in the `cvs-cvsrc-file'."
  143. (interactive)
  144. (condition-case nil
  145. (with-temp-buffer
  146. (insert-file-contents cvs-cvsrc-file)
  147. ;; fetch the values
  148. (dolist (cmd '("cvs" "checkout" "status" "log" "diff" "tag"
  149. "add" "commit" "remove" "update"))
  150. (goto-char (point-min))
  151. (when (re-search-forward
  152. (concat "^" cmd "\\(\\s-+\\(.*\\)\\)?$") nil t)
  153. (let* ((sym (intern (concat "cvs-" cmd "-flags")))
  154. (val (split-string-and-unquote (or (match-string 2) ""))))
  155. (cvs-flags-set sym 0 val))))
  156. ;; ensure that cvs doesn't have -q or -Q
  157. (cvs-flags-set 'cvs-cvs-flags 0
  158. (cons "-f"
  159. (cdr (cvs-partition
  160. (lambda (x) (member x '("-q" "-Q" "-f")))
  161. (cvs-flags-query 'cvs-cvs-flags
  162. nil 'noquery))))))
  163. (file-error nil)))
  164. ;; initialize to cvsrc's default values
  165. (cvs-reread-cvsrc)
  166. ;;;;
  167. ;;;; Mouse bindings and mode motion
  168. ;;;;
  169. (defvar cvs-minor-current-files)
  170. (defun cvs-menu (e)
  171. "Popup the CVS menu."
  172. (interactive "e")
  173. (let ((cvs-minor-current-files
  174. (list (ewoc-data (ewoc-locate
  175. cvs-cookies (posn-point (event-end e)))))))
  176. (popup-menu cvs-menu e)))
  177. (defvar cvs-mode-line-process nil
  178. "Mode-line control for displaying info on cvs process status.")
  179. ;;;;
  180. ;;;; Query-Type-Descriptor for Tags
  181. ;;;;
  182. (autoload 'cvs-status-get-tags "cvs-status")
  183. (defun cvs-tags-list ()
  184. "Return a list of acceptable tags, ready for completions."
  185. (cl-assert (cvs-buffer-p))
  186. (let ((marked (cvs-get-marked)))
  187. `(("BASE") ("HEAD")
  188. ,@(when marked
  189. (with-temp-buffer
  190. (process-file cvs-program
  191. nil ;no input
  192. t ;output to current-buffer
  193. nil ;don't update display while running
  194. "status"
  195. "-v"
  196. (cvs-fileinfo->full-name (car marked)))
  197. (goto-char (point-min))
  198. (let ((tags (cvs-status-get-tags)))
  199. (when (listp tags) tags)))))))
  200. (defvar cvs-tag-history nil)
  201. (defconst cvs-qtypedesc-tag
  202. (cvs-qtypedesc-create 'identity 'identity 'cvs-tags-list 'cvs-tag-history))
  203. ;;;;
  204. (defun cvs-mode! (&optional -cvs-mode!-fun)
  205. "Switch to the *cvs* buffer.
  206. If -CVS-MODE!-FUN is provided, it is executed *cvs* being the current buffer
  207. and with its window selected. Else, the *cvs* buffer is simply selected.
  208. -CVS-MODE!-FUN is called interactively if applicable and else with no argument."
  209. (let* ((-cvs-mode!-buf (current-buffer))
  210. (cvsbuf (cond ((cvs-buffer-p) (current-buffer))
  211. ((and cvs-buffer (cvs-buffer-p cvs-buffer)) cvs-buffer)
  212. (t (error "can't find the *cvs* buffer"))))
  213. (-cvs-mode!-wrapper cvs-minor-wrap-function)
  214. (-cvs-mode!-cont (lambda ()
  215. (save-current-buffer
  216. (if (commandp -cvs-mode!-fun)
  217. (call-interactively -cvs-mode!-fun)
  218. (funcall -cvs-mode!-fun))))))
  219. (if (not -cvs-mode!-fun) (set-buffer cvsbuf)
  220. (let ((cvs-mode!-buf (current-buffer))
  221. (cvs-mode!-owin (selected-window))
  222. (cvs-mode!-nwin (get-buffer-window cvsbuf 'visible)))
  223. (unwind-protect
  224. (progn
  225. (set-buffer cvsbuf)
  226. (when cvs-mode!-nwin (select-window cvs-mode!-nwin))
  227. (if -cvs-mode!-wrapper
  228. (funcall -cvs-mode!-wrapper -cvs-mode!-buf -cvs-mode!-cont)
  229. (funcall -cvs-mode!-cont)))
  230. (set-buffer cvs-mode!-buf)
  231. (when (and cvs-mode!-nwin (eq cvs-mode!-nwin (selected-window)))
  232. ;; the selected window has not been changed by FUN
  233. (select-window cvs-mode!-owin)))))))
  234. ;;;;
  235. ;;;; Prefixes
  236. ;;;;
  237. (defvar cvs-branches (list cvs-vendor-branch "HEAD" "HEAD"))
  238. (cvs-prefix-define cvs-branch-prefix
  239. "Current selected branch."
  240. "version"
  241. (cons cvs-vendor-branch cvs-branches)
  242. cvs-qtypedesc-tag)
  243. (defun cvs-set-branch-prefix (arg)
  244. "Set the branch prefix to take action at the next command.
  245. See `cvs-prefix-set' for a further the description of the behavior.
  246. \\[universal-argument] 1 selects the vendor branch
  247. and \\[universal-argument] 2 selects the HEAD."
  248. (interactive "P")
  249. (cvs-mode!)
  250. (cvs-prefix-set 'cvs-branch-prefix arg))
  251. (defun cvs-add-branch-prefix (flags &optional arg)
  252. "Add branch selection argument if the branch prefix was set.
  253. The argument is added (or not) to the list of FLAGS and is constructed
  254. by appending the branch to ARG which defaults to \"-r\"."
  255. (let ((branch (cvs-prefix-get 'cvs-branch-prefix)))
  256. ;; deactivate the secondary prefix, even if not used.
  257. (cvs-prefix-get 'cvs-secondary-branch-prefix)
  258. (if branch (cons (concat (or arg "-r") branch) flags) flags)))
  259. (cvs-prefix-define cvs-secondary-branch-prefix
  260. "Current secondary selected branch."
  261. "version"
  262. (cons cvs-vendor-branch cvs-branches)
  263. cvs-qtypedesc-tag)
  264. (defun cvs-set-secondary-branch-prefix (arg)
  265. "Set the branch prefix to take action at the next command.
  266. See `cvs-prefix-set' for a further the description of the behavior.
  267. \\[universal-argument] 1 selects the vendor branch
  268. and \\[universal-argument] 2 selects the HEAD."
  269. (interactive "P")
  270. (cvs-mode!)
  271. (cvs-prefix-set 'cvs-secondary-branch-prefix arg))
  272. (defun cvs-add-secondary-branch-prefix (flags &optional arg)
  273. "Add branch selection argument if the secondary branch prefix was set.
  274. The argument is added (or not) to the list of FLAGS and is constructed
  275. by appending the branch to ARG which defaults to \"-r\".
  276. Since the `cvs-secondary-branch-prefix' is only active if the primary
  277. prefix is active, it is important to read the secondary prefix before
  278. the primary since reading the primary can deactivate it."
  279. (let ((branch (and (cvs-prefix-get 'cvs-branch-prefix 'read-only)
  280. (cvs-prefix-get 'cvs-secondary-branch-prefix))))
  281. (if branch (cons (concat (or arg "-r") branch) flags) flags)))
  282. ;;;;
  283. (define-minor-mode cvs-minor-mode
  284. "This mode is used for buffers related to a main *cvs* buffer.
  285. All the `cvs-mode' buffer operations are simply rebound under
  286. the \\[cvs-mode-map] prefix."
  287. nil " CVS"
  288. :group 'pcl-cvs)
  289. (put 'cvs-minor-mode 'permanent-local t)
  290. (defvar cvs-temp-buffers nil)
  291. (defun cvs-temp-buffer (&optional cmd normal nosetup)
  292. "Create a temporary buffer to run CMD in.
  293. If CMD is a string, use it to lookup `cvs-buffer-name-alist' to find
  294. the buffer name to be used and its major mode.
  295. The selected window will not be changed. The new buffer will not maintain undo
  296. information and will be read-only unless NORMAL is non-nil. It will be emptied
  297. \(unless NOSETUP is non-nil) and its `default-directory' will be inherited
  298. from the current buffer."
  299. (let* ((cvs-buf (current-buffer))
  300. (info (cdr (assoc cmd cvs-buffer-name-alist)))
  301. (name (eval (nth 0 info) `((cmd . ,cmd))))
  302. (mode (nth 1 info))
  303. (dir default-directory)
  304. (buf (cond
  305. (name (cvs-get-buffer-create name))
  306. ((and (bufferp cvs-temp-buffer) (buffer-live-p cvs-temp-buffer))
  307. cvs-temp-buffer)
  308. (t
  309. (set (make-local-variable 'cvs-temp-buffer)
  310. (cvs-get-buffer-create
  311. (eval cvs-temp-buffer-name `((dir . ,dir)))
  312. 'noreuse))))))
  313. ;; Handle the potential pre-existing process.
  314. (let ((proc (get-buffer-process buf)))
  315. (when (and (not normal) (processp proc)
  316. (memq (process-status proc) '(run stop)))
  317. (if cmd
  318. ;; When CMD is specified, the buffer is normally shown to the
  319. ;; user, so interrupting the process is not harmful.
  320. ;; Use `delete-process' rather than `kill-process' otherwise
  321. ;; the pending output of the process will still get inserted
  322. ;; after we erase the buffer.
  323. (delete-process proc)
  324. (error "Can not run two cvs processes simultaneously"))))
  325. (if (not name) (kill-local-variable 'other-window-scroll-buffer)
  326. ;; Strangely, if no window is created, `display-buffer' ends up
  327. ;; doing a `switch-to-buffer' which does a `set-buffer', hence
  328. ;; the need for `save-excursion'.
  329. (unless nosetup (save-excursion (display-buffer buf)))
  330. ;; FIXME: this doesn't do the right thing if the user later on
  331. ;; does a `find-file-other-window' and `scroll-other-window'
  332. (set (make-local-variable 'other-window-scroll-buffer) buf))
  333. (add-to-list 'cvs-temp-buffers buf)
  334. (with-current-buffer buf
  335. (setq buffer-read-only nil)
  336. (setq default-directory dir)
  337. (unless nosetup
  338. ;; Disable undo before calling erase-buffer since it may generate
  339. ;; a very large and unwanted undo record.
  340. (buffer-disable-undo)
  341. (erase-buffer))
  342. (set (make-local-variable 'cvs-buffer) cvs-buf)
  343. ;;(cvs-minor-mode 1)
  344. (let ((lbd list-buffers-directory))
  345. (if (fboundp mode) (funcall mode) (fundamental-mode))
  346. (when lbd (setq list-buffers-directory lbd)))
  347. (cvs-minor-mode 1)
  348. ;;(set (make-local-variable 'cvs-buffer) cvs-buf)
  349. (if normal
  350. (buffer-enable-undo)
  351. (setq buffer-read-only t)
  352. (buffer-disable-undo))
  353. buf)))
  354. (defun cvs-mode-kill-buffers ()
  355. "Kill all the \"temporary\" buffers created by the *cvs* buffer."
  356. (interactive)
  357. (dolist (buf cvs-temp-buffers) (ignore-errors (kill-buffer buf))))
  358. (defun cvs-make-cvs-buffer (dir &optional new)
  359. "Create the *cvs* buffer for directory DIR.
  360. If non-nil, NEW means to create a new buffer no matter what."
  361. ;; the real cvs-buffer creation
  362. (setq dir (cvs-expand-dir-name dir))
  363. (let* ((buffer-name (eval cvs-buffer-name `((dir . ,dir))))
  364. (buffer
  365. (or (and (not new)
  366. (eq cvs-reuse-cvs-buffer 'current)
  367. (cvs-buffer-p) ;reuse the current buffer if possible
  368. (current-buffer))
  369. ;; look for another cvs buffer visiting the same directory
  370. (save-excursion
  371. (unless new
  372. (cl-dolist (buffer (cons (current-buffer) (buffer-list)))
  373. (set-buffer buffer)
  374. (and (cvs-buffer-p)
  375. (pcase cvs-reuse-cvs-buffer
  376. (`always t)
  377. (`subdir
  378. (or (string-prefix-p default-directory dir)
  379. (string-prefix-p dir default-directory)))
  380. (`samedir (string= default-directory dir)))
  381. (cl-return buffer)))))
  382. ;; we really have to create a new buffer:
  383. ;; we temporarily bind cwd to "" to prevent
  384. ;; create-file-buffer from using directory info
  385. ;; unless it is explicitly in the cvs-buffer-name.
  386. (cvs-get-buffer-create buffer-name new))))
  387. (with-current-buffer buffer
  388. (or
  389. (and (string= dir default-directory) (cvs-buffer-p)
  390. ;; just a refresh
  391. (ignore-errors
  392. (cvs-cleanup-collection cvs-cookies nil nil t)
  393. (current-buffer)))
  394. ;; setup from scratch
  395. (progn
  396. (setq default-directory dir)
  397. (setq buffer-read-only nil)
  398. (erase-buffer)
  399. (insert "Repository : " (directory-file-name (cvs-get-cvsroot))
  400. "\nModule : " (cvs-get-module)
  401. "\nWorking dir: " (abbreviate-file-name dir)
  402. (if (not (file-readable-p "CVS/Tag")) "\n"
  403. (let ((tag (cvs-file-to-string "CVS/Tag")))
  404. (cond
  405. ((string-match "\\`T" tag)
  406. (concat "\nTag : " (substring tag 1)))
  407. ((string-match "\\`D" tag)
  408. (concat "\nDate : " (substring tag 1)))
  409. ("\n"))))
  410. "\n")
  411. (setq buffer-read-only t)
  412. (cvs-mode)
  413. (set (make-local-variable 'list-buffers-directory) buffer-name)
  414. ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
  415. (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n\n" "\n" t)))
  416. (set (make-local-variable 'cvs-cookies) cookies)
  417. (add-hook 'kill-buffer-hook
  418. (lambda ()
  419. (ignore-errors (kill-buffer cvs-temp-buffer)))
  420. nil t)
  421. ;;(set-buffer buf)
  422. buffer))))))
  423. (cl-defun cvs-cmd-do (cmd dir flags fis new
  424. &key cvsargs noexist dont-change-disc noshow)
  425. (let* ((dir (file-name-as-directory
  426. (abbreviate-file-name (expand-file-name dir))))
  427. (cvsbuf (cvs-make-cvs-buffer dir new)))
  428. ;; Check that dir is under CVS control.
  429. (unless (file-directory-p dir)
  430. (error "%s is not a directory" dir))
  431. (unless (or noexist (file-directory-p (expand-file-name "CVS" dir))
  432. (file-expand-wildcards (expand-file-name "*/CVS" dir)))
  433. (error "%s does not contain CVS controlled files" dir))
  434. (set-buffer cvsbuf)
  435. (cvs-mode-run cmd flags fis
  436. :cvsargs cvsargs :dont-change-disc dont-change-disc)
  437. (if noshow cvsbuf
  438. (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
  439. ;; (funcall (if (and (boundp 'pop-up-frames) pop-up-frames)
  440. ;; 'pop-to-buffer 'switch-to-buffer)
  441. ;; cvsbuf))))
  442. (defun cvs-run-process (args fis postprocess &optional single-dir)
  443. (cl-assert (cvs-buffer-p cvs-buffer))
  444. (save-current-buffer
  445. (let ((procbuf (current-buffer))
  446. (cvsbuf cvs-buffer)
  447. (single-dir (or single-dir (eq cvs-execute-single-dir t))))
  448. (set-buffer procbuf)
  449. (goto-char (point-max))
  450. (unless (bolp) (let ((inhibit-read-only t)) (insert "\n")))
  451. ;; find the set of files we'll process in this round
  452. (let* ((dir+files+rest
  453. (if (or (null fis) (not single-dir))
  454. ;; not single-dir mode: just process the whole thing
  455. (list "" (mapcar 'cvs-fileinfo->full-name fis) nil)
  456. ;; single-dir mode: extract the same-dir-elements
  457. (let ((dir (cvs-fileinfo->dir (car fis))))
  458. ;; output the concerned dir so the parser can translate paths
  459. (let ((inhibit-read-only t))
  460. (insert "pcl-cvs: descending directory " dir "\n"))
  461. ;; loop to find the same-dir-elems
  462. (cl-do* ((files () (cons (cvs-fileinfo->file fi) files))
  463. (fis fis (cdr fis))
  464. (fi (car fis) (car fis)))
  465. ((not (and fis (string= dir (cvs-fileinfo->dir fi))))
  466. (list dir files fis))))))
  467. (dir (nth 0 dir+files+rest))
  468. (files (nth 1 dir+files+rest))
  469. (rest (nth 2 dir+files+rest)))
  470. (add-hook 'kill-buffer-hook
  471. (lambda ()
  472. (let ((proc (get-buffer-process (current-buffer))))
  473. (when (processp proc)
  474. (set-process-filter proc nil)
  475. ;; Abort postprocessing but leave the sentinel so it
  476. ;; will update the list of running procs.
  477. (process-put proc 'cvs-postprocess nil)
  478. (interrupt-process proc))))
  479. nil t)
  480. ;; create the new process and setup the procbuffer correspondingly
  481. (let* ((msg (cvs-header-msg args fis))
  482. (args (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
  483. (if cvs-cvsroot (list "-d" cvs-cvsroot))
  484. args
  485. files))
  486. ;; If process-connection-type is nil and the repository
  487. ;; is accessed via SSH, a bad interaction between libc,
  488. ;; CVS and SSH can lead to garbled output.
  489. ;; It might be a glibc-specific problem (but it can also happens
  490. ;; under Mac OS X, it seems).
  491. ;; It seems that using a pty can help circumvent the problem,
  492. ;; but at the cost of screwing up when the process thinks it
  493. ;; can ask for user input (such as password or host-key
  494. ;; confirmation). A better workaround is to set CVS_RSH to
  495. ;; an appropriate script, or to use a later version of CVS.
  496. (process-connection-type nil) ; Use a pipe, not a pty.
  497. (process
  498. ;; the process will be run in the selected dir
  499. (let ((default-directory (cvs-expand-dir-name dir)))
  500. (apply 'start-file-process "cvs" procbuf cvs-program args))))
  501. ;; setup the process.
  502. (process-put process 'cvs-buffer cvs-buffer)
  503. (with-current-buffer cvs-buffer (cvs-update-header msg 'add))
  504. (process-put process 'cvs-header msg)
  505. (process-put
  506. process 'cvs-postprocess
  507. (if (null rest)
  508. ;; this is the last invocation
  509. postprocess
  510. ;; else, we have to register ourselves to be rerun on the rest
  511. (lambda () (cvs-run-process args rest postprocess single-dir))))
  512. (set-process-sentinel process 'cvs-sentinel)
  513. (set-process-filter process 'cvs-update-filter)
  514. (set-marker (process-mark process) (point-max))
  515. (ignore-errors (process-send-eof process)) ;close its stdin to avoid hangs
  516. ;; now finish setting up the cvs-buffer
  517. (set-buffer cvsbuf)
  518. (setq cvs-mode-line-process (symbol-name (process-status process)))
  519. (force-mode-line-update)))))
  520. ;; The following line is said to improve display updates on some
  521. ;; emacsen. It shouldn't be needed, but it does no harm.
  522. (sit-for 0))
  523. (defun cvs-header-msg (args fis)
  524. (let* ((lastarg nil)
  525. (args (mapcar (lambda (arg)
  526. (cond
  527. ;; filter out the largish commit message
  528. ((and (eq lastarg nil) (string= arg "commit"))
  529. (setq lastarg 'commit) arg)
  530. ((and (eq lastarg 'commit) (string= arg "-m"))
  531. (setq lastarg '-m) arg)
  532. ((eq lastarg '-m)
  533. (setq lastarg 'done) "<log message>")
  534. ;; filter out the largish `admin -mrev:msg' message
  535. ((and (eq lastarg nil) (string= arg "admin"))
  536. (setq lastarg 'admin) arg)
  537. ((and (eq lastarg 'admin)
  538. (string-match "\\`-m[^:]*:" arg))
  539. (setq lastarg 'done)
  540. (concat (match-string 0 arg) "<log message>"))
  541. ;; Keep the rest as is.
  542. (t arg)))
  543. args)))
  544. (concat cvs-program " "
  545. (combine-and-quote-strings
  546. (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
  547. (if cvs-cvsroot (list "-d" cvs-cvsroot))
  548. args
  549. (mapcar 'cvs-fileinfo->full-name fis))))))
  550. (defun cvs-update-header (cmd add)
  551. (let* ((hf (ewoc-get-hf cvs-cookies))
  552. (str (car hf))
  553. (done "")
  554. (tin (ewoc-nth cvs-cookies 0)))
  555. ;; look for the first *real* fileinfo (to determine emptiness)
  556. (while
  557. (and tin
  558. (memq (cvs-fileinfo->type (ewoc-data tin))
  559. '(MESSAGE DIRCHANGE)))
  560. (setq tin (ewoc-next cvs-cookies tin)))
  561. (if add
  562. (progn
  563. ;; Remove the default empty line, if applicable.
  564. (if (not (string-match "." str)) (setq str "\n"))
  565. (setq str (concat "-- Running " cmd " ...\n" str)))
  566. (if (not (string-match
  567. ;; FIXME: If `cmd' is large, this will bump into the
  568. ;; compiled-regexp size limit. We could drop the "^" anchor
  569. ;; and use search-forward to circumvent the problem.
  570. (concat "^-- Running " (regexp-quote cmd) " \\.\\.\\.\n") str))
  571. (error "Internal PCL-CVS error while removing message")
  572. (setq str (replace-match "" t t str))
  573. ;; Re-add the default empty line, if applicable.
  574. (if (not (string-match "." str)) (setq str "\n\n"))
  575. (setq done (concat "-- last cmd: " cmd " --\n"))))
  576. ;; set the new header and footer
  577. (ewoc-set-hf cvs-cookies
  578. str (concat "\n--------------------- "
  579. (if tin "End" "Empty")
  580. " ---------------------\n"
  581. done))))
  582. (defun cvs-sentinel (proc _msg)
  583. "Sentinel for the cvs update process.
  584. This is responsible for parsing the output from the cvs update when
  585. it is finished."
  586. (when (memq (process-status proc) '(signal exit))
  587. (let ((cvs-postproc (process-get proc 'cvs-postprocess))
  588. (cvs-buf (process-get proc 'cvs-buffer))
  589. (procbuf (process-buffer proc)))
  590. (unless (buffer-live-p cvs-buf) (setq cvs-buf nil))
  591. (unless (buffer-live-p procbuf) (setq procbuf nil))
  592. ;; Since the buffer and mode line will show that the
  593. ;; process is dead, we can delete it now. Otherwise it
  594. ;; will stay around until M-x list-processes.
  595. (process-put proc 'postprocess nil)
  596. (delete-process proc)
  597. ;; Don't do anything if the main buffer doesn't exist any more.
  598. (when cvs-buf
  599. (with-current-buffer cvs-buf
  600. (cvs-update-header (process-get proc 'cvs-header) nil)
  601. (setq cvs-mode-line-process (symbol-name (process-status proc)))
  602. (force-mode-line-update)
  603. (when cvs-postproc
  604. (if (null procbuf)
  605. ;;(set-process-buffer proc nil)
  606. (error "cvs' process buffer was killed")
  607. (with-current-buffer procbuf
  608. ;; Do the postprocessing like parsing and such.
  609. (save-excursion
  610. (funcall cvs-postproc)))))))
  611. ;; Check whether something is left.
  612. (when (and procbuf (not (get-buffer-process procbuf)))
  613. (with-current-buffer procbuf
  614. ;; IIRC, we enable undo again once the process is finished
  615. ;; for cases where the output was inserted in *vc-diff* or
  616. ;; in a file-like buffer. --Stef
  617. (buffer-enable-undo)
  618. (with-current-buffer (or cvs-buf (current-buffer))
  619. (message "CVS process has completed in %s"
  620. (buffer-name))))))))
  621. (defun cvs-parse-process (dcd &optional subdir old-fis)
  622. "Parse the output of a cvs process.
  623. DCD is the `dont-change-disc' flag to use when parsing that output.
  624. SUBDIR is the subdirectory (if any) where this command was run.
  625. OLD-FIS is the list of fileinfos on which the cvs command was applied and
  626. which should be considered up-to-date if they are missing from the output."
  627. (when (eq system-type 'darwin)
  628. ;; Fixup the ^D^H^H inserted at beginning of buffer sometimes on MacOSX
  629. ;; because of the call to `process-send-eof'.
  630. (save-excursion
  631. (goto-char (point-min))
  632. (while (re-search-forward "^\\^D+" nil t)
  633. (let ((inhibit-read-only t))
  634. (delete-region (match-beginning 0) (match-end 0))))))
  635. (let* ((fileinfos (cvs-parse-buffer 'cvs-parse-table dcd subdir))
  636. last)
  637. (with-current-buffer cvs-buffer
  638. ;; Expand OLD-FIS to actual files.
  639. (let ((fis nil))
  640. (dolist (fi old-fis)
  641. (setq fis (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
  642. (nconc (ewoc-collect cvs-cookies 'cvs-dir-member-p
  643. (cvs-fileinfo->dir fi))
  644. fis)
  645. (cons fi fis))))
  646. (setq old-fis fis))
  647. ;; Drop OLD-FIS which were already up-to-date.
  648. (let ((fis nil))
  649. (dolist (fi old-fis)
  650. (unless (eq (cvs-fileinfo->type fi) 'UP-TO-DATE) (push fi fis)))
  651. (setq old-fis fis))
  652. ;; Add the new fileinfos to the ewoc.
  653. (dolist (fi fileinfos)
  654. (setq last (cvs-addto-collection cvs-cookies fi last))
  655. ;; This FI was in the output, so remove it from OLD-FIS.
  656. (setq old-fis (delq (ewoc-data last) old-fis)))
  657. ;; Process the "silent output" (i.e. absence means up-to-date).
  658. (dolist (fi old-fis)
  659. (setf (cvs-fileinfo->type fi) 'UP-TO-DATE)
  660. (setq last (cvs-addto-collection cvs-cookies fi last)))
  661. (setq fileinfos (nconc old-fis fileinfos))
  662. ;; Clean up the ewoc as requested by the user.
  663. (cvs-cleanup-collection cvs-cookies
  664. (eq cvs-auto-remove-handled t)
  665. cvs-auto-remove-directories
  666. nil)
  667. ;; Revert buffers if necessary.
  668. (when (and cvs-auto-revert (not dcd) (not cvs-from-vc))
  669. (cvs-revert-if-needed fileinfos)))))
  670. (defmacro defun-cvs-mode (fun args docstring interact &rest body)
  671. "Define a function to be used in a *cvs* buffer.
  672. This will look for a *cvs* buffer and execute BODY in it.
  673. Since the interactive arguments might need to be queried after
  674. switching to the *cvs* buffer, the generic code is rather ugly,
  675. but luckily we can often use simpler alternatives.
  676. FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE).
  677. ARGS and DOCSTRING are the normal argument list.
  678. INTERACT is the interactive specification or nil for non-commands.
  679. STYLE can be either `SIMPLE', `NOARGS' or `DOUBLE'. It's an error for it
  680. to have any other value, unless other details of the function make it
  681. clear what alternative to use.
  682. - `SIMPLE' will get all the interactive arguments from the original buffer.
  683. - `NOARGS' will get all the arguments from the *cvs* buffer and will
  684. always behave as if called interactively.
  685. - `DOUBLE' is the generic case."
  686. (declare (debug (&define sexp lambda-list stringp
  687. ("interactive" interactive) def-body))
  688. (doc-string 3))
  689. (let ((style (cvs-cdr fun))
  690. (fun (cvs-car fun)))
  691. (cond
  692. ;; a trivial interaction, no need to move it
  693. ((or (eq style 'SIMPLE)
  694. (null (nth 1 interact))
  695. (stringp (nth 1 interact)))
  696. `(defun ,fun ,args ,docstring ,interact
  697. (cvs-mode! (lambda () ,@body))))
  698. ;; fun is only called interactively: move all the args to the inner fun
  699. ((eq style 'NOARGS)
  700. `(defun ,fun () ,docstring (interactive)
  701. (cvs-mode! (lambda ,args ,interact ,@body))))
  702. ;; bad case
  703. ((eq style 'DOUBLE)
  704. (string-match ".*" docstring)
  705. (let ((line1 (match-string 0 docstring))
  706. (fun-1 (intern (concat (symbol-name fun) "-1"))))
  707. `(progn
  708. (defun ,fun-1 ,args
  709. ,(concat docstring "\nThis function only works within a *cvs* buffer.
  710. For interactive use, use `" (symbol-name fun) "' instead.")
  711. ,interact
  712. ,@body)
  713. (put ',fun-1 'definition-name ',fun)
  714. (defun ,fun ()
  715. ,(concat line1 "\nWrapper function that switches to a *cvs* buffer
  716. before calling the real function `" (symbol-name fun-1) "'.\n")
  717. (interactive)
  718. (cvs-mode! ',fun-1)))))
  719. (t (error "Unknown style %s in `defun-cvs-mode'" style)))))
  720. (defun-cvs-mode cvs-mode-kill-process ()
  721. "Kill the temporary buffer and associated process."
  722. (interactive)
  723. (when (and (bufferp cvs-temp-buffer) (buffer-live-p cvs-temp-buffer))
  724. (let ((proc (get-buffer-process cvs-temp-buffer)))
  725. (when proc (delete-process proc)))))
  726. ;;
  727. ;; Maintaining the collection in the face of updates
  728. ;;
  729. (defun cvs-addto-collection (c fi &optional tin)
  730. "Add FI to C and return FI's corresponding tin.
  731. FI is inserted in its proper place or maybe even merged with a preexisting
  732. fileinfo if applicable.
  733. TIN specifies an optional starting point."
  734. (unless tin (setq tin (ewoc-nth c 0)))
  735. (while (and tin (cvs-fileinfo< fi (ewoc-data tin)))
  736. (setq tin (ewoc-prev c tin)))
  737. (if (null tin) (ewoc-enter-first c fi) ;empty collection
  738. (cl-assert (not (cvs-fileinfo< fi (ewoc-data tin))))
  739. (let ((next-tin (ewoc-next c tin)))
  740. (while (not (or (null next-tin)
  741. (cvs-fileinfo< fi (ewoc-data next-tin))))
  742. (setq tin next-tin next-tin (ewoc-next c next-tin)))
  743. (if (or (cvs-fileinfo< (ewoc-data tin) fi)
  744. (eq (cvs-fileinfo->type fi) 'MESSAGE))
  745. ;; tin < fi < next-tin
  746. (ewoc-enter-after c tin fi)
  747. ;; fi == tin
  748. (cvs-fileinfo-update (ewoc-data tin) fi)
  749. (ewoc-invalidate c tin)
  750. ;; Move cursor back to where it belongs.
  751. (when (bolp) (cvs-move-to-goal-column))
  752. tin))))
  753. (defcustom cvs-cleanup-functions nil
  754. "Functions to tweak the cleanup process.
  755. The functions are called with a single argument (a FILEINFO) and should
  756. return a non-nil value if that fileinfo should be removed."
  757. :group 'pcl-cvs
  758. :type '(hook :options (cvs-cleanup-removed)))
  759. (defun cvs-cleanup-removed (fi)
  760. "Non-nil if FI has been cvs-removed but still exists.
  761. This is intended for use on `cvs-cleanup-functions' when you have cvs-removed
  762. automatically generated files (which should hence not be under CVS control)
  763. but can't commit the removal because the repository's owner doesn't understand
  764. the problem."
  765. (and (or (eq (cvs-fileinfo->type fi) 'REMOVED)
  766. (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
  767. (eq (cvs-fileinfo->subtype fi) 'REMOVED)))
  768. (file-exists-p (cvs-fileinfo->full-name fi))))
  769. ;; called at the following times:
  770. ;; - postparse ((eq cvs-auto-remove-handled t) cvs-auto-remove-directories nil)
  771. ;; - pre-run ((eq cvs-auto-remove-handled 'delayed) nil t)
  772. ;; - remove-handled (t (or cvs-auto-remove-directories 'handled) t)
  773. ;; - cvs-cmd-do (nil nil t)
  774. ;; - post-ignore (nil nil nil)
  775. ;; - acknowledge (nil nil nil)
  776. ;; - remove (nil nil nil)
  777. (defun cvs-cleanup-collection (c rm-handled rm-dirs rm-msgs)
  778. "Remove undesired entries.
  779. C is the collection
  780. RM-HANDLED if non-nil means remove handled entries (if file is currently
  781. visited, only remove if value is `all').
  782. RM-DIRS behaves like `cvs-auto-remove-directories'.
  783. RM-MSGS if non-nil means remove messages."
  784. (let (last-fi first-dir (rerun t))
  785. (while rerun
  786. (setq rerun nil)
  787. (setq first-dir t)
  788. (setq last-fi (cvs-create-fileinfo 'DEAD "../" "" "")) ;place-holder
  789. (ewoc-filter
  790. c (lambda (fi)
  791. (let* ((type (cvs-fileinfo->type fi))
  792. (subtype (cvs-fileinfo->subtype fi))
  793. (keep
  794. (pcase type
  795. ;; Remove temp messages and keep the others.
  796. (`MESSAGE (not (or rm-msgs (eq subtype 'TEMP))))
  797. ;; Remove dead entries.
  798. (`DEAD nil)
  799. ;; Handled also?
  800. (`UP-TO-DATE
  801. (not
  802. (if (find-buffer-visiting (cvs-fileinfo->full-name fi))
  803. (eq rm-handled 'all)
  804. rm-handled)))
  805. ;; Keep the rest.
  806. (_ (not (run-hook-with-args-until-success
  807. 'cvs-cleanup-functions fi))))))
  808. ;; mark dirs for removal
  809. (when (and keep rm-dirs
  810. (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE)
  811. (not (when first-dir (setq first-dir nil) t))
  812. (or (eq rm-dirs 'all)
  813. (not (string-prefix-p
  814. (cvs-fileinfo->dir last-fi)
  815. (cvs-fileinfo->dir fi)))
  816. (and (eq type 'DIRCHANGE) (eq rm-dirs 'empty))
  817. (eq subtype 'FOOTER)))
  818. (setf (cvs-fileinfo->type last-fi) 'DEAD)
  819. (setq rerun t))
  820. (when keep (setq last-fi fi)))))
  821. ;; remove empty last dir
  822. (when (and rm-dirs
  823. (not first-dir)
  824. (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE))
  825. (setf (cvs-fileinfo->type last-fi) 'DEAD)
  826. (setq rerun t)))))
  827. (defun cvs-get-cvsroot ()
  828. "Get the CVSROOT for DIR."
  829. (let ((cvs-cvsroot-file (expand-file-name "Root" "CVS")))
  830. (or (cvs-file-to-string cvs-cvsroot-file t)
  831. cvs-cvsroot
  832. (getenv "CVSROOT")
  833. "?????")))
  834. (defun cvs-get-module ()
  835. "Return the current CVS module.
  836. This usually doesn't really work but is a handy initval in a prompt."
  837. (let* ((repfile (expand-file-name "Repository" "CVS"))
  838. (rep (cvs-file-to-string repfile t)))
  839. (cond
  840. ((null rep) "")
  841. ((not (file-name-absolute-p rep)) rep)
  842. (t
  843. (let* ((root (cvs-get-cvsroot))
  844. (str (concat (file-name-as-directory (or root "/")) " || " rep)))
  845. (if (and root (string-match "\\(.*\\) || \\1\\(.*\\)\\'" str))
  846. (match-string 2 str)
  847. (file-name-nondirectory rep)))))))
  848. ;;;;
  849. ;;;; running a "cvs checkout".
  850. ;;;;
  851. ;;;###autoload
  852. (defun cvs-checkout (modules dir flags &optional root)
  853. "Run a `cvs checkout MODULES' in DIR.
  854. Feed the output to a *cvs* buffer, display it in the current window,
  855. and run `cvs-mode' on it.
  856. With a prefix argument, prompt for cvs FLAGS to use."
  857. (interactive
  858. (let ((root (cvs-get-cvsroot)))
  859. (if (or (null root) current-prefix-arg)
  860. (setq root (read-string "CVS Root: ")))
  861. (list (split-string-and-unquote
  862. (read-string "Module(s): " (cvs-get-module)))
  863. (read-directory-name "CVS Checkout Directory: "
  864. nil default-directory nil)
  865. (cvs-add-branch-prefix
  866. (cvs-flags-query 'cvs-checkout-flags "cvs checkout flags"))
  867. root)))
  868. (when (eq flags t)
  869. (setf flags (cvs-flags-query 'cvs-checkout-flags nil 'noquery)))
  870. (let ((cvs-cvsroot root))
  871. (cvs-cmd-do "checkout" (or dir default-directory)
  872. (append flags modules) nil 'new
  873. :noexist t)))
  874. (defun-cvs-mode (cvs-mode-checkout . NOARGS) (dir)
  875. "Run `cvs checkout' against the current branch.
  876. The files are stored to DIR."
  877. (interactive
  878. (let* ((branch (cvs-prefix-get 'cvs-branch-prefix))
  879. (prompt (format-message "CVS Checkout Directory for `%s%s': "
  880. (cvs-get-module)
  881. (if branch (format " (branch: %s)" branch)
  882. ""))))
  883. (list (read-directory-name prompt nil default-directory nil))))
  884. (let ((modules (split-string-and-unquote (cvs-get-module)))
  885. (flags (cvs-add-branch-prefix
  886. (cvs-flags-query 'cvs-checkout-flags "cvs checkout flags")))
  887. (cvs-cvsroot (cvs-get-cvsroot)))
  888. (cvs-checkout modules dir flags)))
  889. ;;;;
  890. ;;;; The code for running a "cvs update" and friends in various ways.
  891. ;;;;
  892. (defun-cvs-mode (cvs-mode-revert-buffer . SIMPLE)
  893. (&optional _ignore-auto _noconfirm)
  894. "Rerun `cvs-examine' on the current directory with the default flags."
  895. (interactive)
  896. (cvs-examine default-directory t))
  897. (defun cvs-query-directory (prompt)
  898. "Read directory name, prompting with PROMPT.
  899. If in a *cvs* buffer, don't prompt unless a prefix argument is given."
  900. (if (and (cvs-buffer-p)
  901. (not current-prefix-arg))
  902. default-directory
  903. (read-directory-name prompt nil default-directory nil)))
  904. ;;;###autoload
  905. (defun cvs-quickdir (dir &optional _flags noshow)
  906. "Open a *cvs* buffer on DIR without running cvs.
  907. With a prefix argument, prompt for a directory to use.
  908. A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
  909. prevents reuse of an existing *cvs* buffer.
  910. Optional argument NOSHOW if non-nil means not to display the buffer.
  911. FLAGS is ignored."
  912. (interactive (list (cvs-query-directory "CVS quickdir (directory): ")))
  913. ;; FIXME: code duplication with cvs-cmd-do and cvs-parse-process
  914. (let* ((dir (file-name-as-directory
  915. (abbreviate-file-name (expand-file-name dir))))
  916. (new (> (prefix-numeric-value current-prefix-arg) 8))
  917. (cvsbuf (cvs-make-cvs-buffer dir new))
  918. last)
  919. ;; Check that dir is under CVS control.
  920. (unless (file-directory-p dir)
  921. (error "%s is not a directory" dir))
  922. (unless (file-directory-p (expand-file-name "CVS" dir))
  923. (error "%s does not contain CVS controlled files" dir))
  924. (set-buffer cvsbuf)
  925. (dolist (fi (cvs-fileinfo-from-entries ""))
  926. (setq last (cvs-addto-collection cvs-cookies fi last)))
  927. (cvs-cleanup-collection cvs-cookies
  928. (eq cvs-auto-remove-handled t)
  929. cvs-auto-remove-directories
  930. nil)
  931. (if noshow cvsbuf
  932. (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
  933. ;;;###autoload
  934. (defun cvs-examine (directory flags &optional noshow)
  935. "Run a `cvs -n update' in the specified DIRECTORY.
  936. That is, check what needs to be done, but don't change the disc.
  937. Feed the output to a *cvs* buffer and run `cvs-mode' on it.
  938. With a prefix argument, prompt for a directory and cvs FLAGS to use.
  939. A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
  940. prevents reuse of an existing *cvs* buffer.
  941. Optional argument NOSHOW if non-nil means not to display the buffer."
  942. (interactive (list (cvs-query-directory "CVS Examine (directory): ")
  943. (cvs-flags-query 'cvs-update-flags "cvs -n update flags")))
  944. (when (eq flags t)
  945. (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
  946. (when find-file-visit-truename (setq directory (file-truename directory)))
  947. (cvs-cmd-do "update" directory flags nil
  948. (> (prefix-numeric-value current-prefix-arg) 8)
  949. :cvsargs '("-n")
  950. :noshow noshow
  951. :dont-change-disc t))
  952. ;;;###autoload
  953. (defun cvs-update (directory flags)
  954. "Run a `cvs update' in the current working DIRECTORY.
  955. Feed the output to a *cvs* buffer and run `cvs-mode' on it.
  956. With a \\[universal-argument] prefix argument, prompt for a directory to use.
  957. A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
  958. prevents reuse of an existing *cvs* buffer.
  959. The prefix is also passed to `cvs-flags-query' to select the FLAGS
  960. passed to cvs."
  961. (interactive (list (cvs-query-directory "CVS Update (directory): ")
  962. (cvs-flags-query 'cvs-update-flags "cvs update flags")))
  963. (when (eq flags t)
  964. (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
  965. (cvs-cmd-do "update" directory flags nil
  966. (> (prefix-numeric-value current-prefix-arg) 8)))
  967. ;;;###autoload
  968. (defun cvs-status (directory flags &optional noshow)
  969. "Run a `cvs status' in the current working DIRECTORY.
  970. Feed the output to a *cvs* buffer and run `cvs-mode' on it.
  971. With a prefix argument, prompt for a directory and cvs FLAGS to use.
  972. A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
  973. prevents reuse of an existing *cvs* buffer.
  974. Optional argument NOSHOW if non-nil means not to display the buffer."
  975. (interactive (list (cvs-query-directory "CVS Status (directory): ")
  976. (cvs-flags-query 'cvs-status-flags "cvs status flags")))
  977. (when (eq flags t)
  978. (setf flags (cvs-flags-query 'cvs-status-flags nil 'noquery)))
  979. (cvs-cmd-do "status" directory flags nil
  980. (> (prefix-numeric-value current-prefix-arg) 8)
  981. :noshow noshow :dont-change-disc t))
  982. (defun cvs-update-filter (proc string)
  983. "Filter function for PCL-CVS.
  984. This function gets the output that CVS sends to stdout. It inserts
  985. the STRING into (process-buffer PROC) but it also checks if CVS is waiting
  986. for a lock file. If so, it inserts a message cookie in the *cvs* buffer."
  987. (save-match-data
  988. (with-current-buffer (process-buffer proc)
  989. (let ((inhibit-read-only t))
  990. (save-excursion
  991. ;; Insert the text, moving the process-marker.
  992. (goto-char (process-mark proc))
  993. (insert string)
  994. (set-marker (process-mark proc) (point))
  995. ;; FIXME: Delete any old lock message
  996. ;;(if (tin-nth cookies 1)
  997. ;; (tin-delete cookies
  998. ;; (tin-nth cookies 1)))
  999. ;; Check if CVS is waiting for a lock.
  1000. (beginning-of-line 0) ;Move to beginning of last complete line.
  1001. (when (looking-at "^[ a-z]+: \\(.*waiting for .*lock in \\(.*\\)\\)$")
  1002. (let ((msg (match-string 1))
  1003. (lock (match-string 2)))
  1004. (with-current-buffer cvs-buffer
  1005. (set (make-local-variable 'cvs-lock-file) lock)
  1006. ;; display the lock situation in the *cvs* buffer:
  1007. (ewoc-enter-last
  1008. cvs-cookies
  1009. (cvs-create-fileinfo
  1010. 'MESSAGE "" " "
  1011. (concat msg
  1012. (when (file-exists-p lock)
  1013. (substitute-command-keys
  1014. "\n\t(type \\[cvs-mode-delete-lock] to delete it)")))
  1015. :subtype 'TEMP))
  1016. (pop-to-buffer (current-buffer))
  1017. (goto-char (point-max))
  1018. (beep)))))))))
  1019. ;;;;
  1020. ;;;; The cvs-mode and its associated commands.
  1021. ;;;;
  1022. (cvs-prefix-define cvs-force-command "" "" '("/F") cvs-qtypedesc-string1)
  1023. (defun-cvs-mode cvs-mode-force-command (arg)
  1024. "Force the next cvs command to operate on all the selected files.
  1025. By default, cvs commands only operate on files on which the command
  1026. \"makes sense\". This overrides the safety feature on the next cvs command.
  1027. It actually behaves as a toggle. If prefixed by \\[universal-argument] \\[universal-argument],
  1028. the override will persist until the next toggle."
  1029. (interactive "P")
  1030. (cvs-prefix-set 'cvs-force-command arg))
  1031. (put 'cvs-mode 'mode-class 'special)
  1032. (define-derived-mode cvs-mode nil "CVS"
  1033. "Mode used for PCL-CVS, a frontend to CVS.
  1034. Full documentation is in the Texinfo file."
  1035. (setq mode-line-process
  1036. '("" cvs-force-command cvs-ignore-marks-modif
  1037. ":" (cvs-branch-prefix
  1038. ("" cvs-branch-prefix (cvs-secondary-branch-prefix
  1039. ("->" cvs-secondary-branch-prefix))))
  1040. " " cvs-mode-line-process))
  1041. (if buffer-file-name
  1042. (error "Use M-x cvs-quickdir to get a *cvs* buffer"))
  1043. (buffer-disable-undo)
  1044. ;;(set (make-local-variable 'goal-column) cvs-cursor-column)
  1045. (set (make-local-variable 'revert-buffer-function) 'cvs-mode-revert-buffer)
  1046. (setq truncate-lines t)
  1047. (cvs-prefix-make-local 'cvs-branch-prefix)
  1048. (cvs-prefix-make-local 'cvs-secondary-branch-prefix)
  1049. (cvs-prefix-make-local 'cvs-force-command)
  1050. (cvs-prefix-make-local 'cvs-ignore-marks-modif)
  1051. (make-local-variable 'cvs-mode-line-process)
  1052. (make-local-variable 'cvs-temp-buffers))
  1053. (defun cvs-buffer-p (&optional buffer)
  1054. "Return whether the (by default current) BUFFER is a `cvs-mode' buffer."
  1055. (save-excursion
  1056. (if buffer (set-buffer buffer))
  1057. (and (eq major-mode 'cvs-mode))))
  1058. (defun cvs-buffer-check ()
  1059. "Check that the current buffer follows cvs-buffer's conventions."
  1060. (let ((buf (current-buffer))
  1061. (check 'none))
  1062. (or (and (setq check 'collection)
  1063. (eq (ewoc-buffer cvs-cookies) buf)
  1064. (setq check 'cvs-temp-buffer)
  1065. (or (null cvs-temp-buffer)
  1066. (null (buffer-live-p cvs-temp-buffer))
  1067. (and (eq (with-current-buffer cvs-temp-buffer cvs-buffer) buf)
  1068. (equal (with-current-buffer cvs-temp-buffer
  1069. default-directory)
  1070. default-directory)))
  1071. t)
  1072. (error "Inconsistent %s in buffer %s" check (buffer-name buf)))))
  1073. (defun cvs-mode-quit ()
  1074. "Quit PCL-CVS, killing the *cvs* buffer."
  1075. (interactive)
  1076. (and (y-or-n-p "Quit pcl-cvs? ") (kill-buffer (current-buffer))))
  1077. ;; Give help....
  1078. (defun cvs-help ()
  1079. "Display help for various PCL-CVS commands."
  1080. (interactive)
  1081. (if (eq last-command 'cvs-help)
  1082. (describe-function 'cvs-mode) ; would need minor-mode for log-edit-mode
  1083. (message "%s"
  1084. (substitute-command-keys
  1085. "`\\[cvs-help]':help `\\[cvs-mode-add]':add `\\[cvs-mode-commit]':commit \
  1086. `\\[cvs-mode-diff-map]':diff* `\\[cvs-mode-log]':log \
  1087. `\\[cvs-mode-remove]':remove `\\[cvs-mode-status]':status \
  1088. `\\[cvs-mode-undo]':undo"))))
  1089. ;; Move around in the buffer
  1090. (defun cvs-move-to-goal-column ()
  1091. (let* ((eol (line-end-position))
  1092. (fpos (next-single-property-change (point) 'cvs-goal-column nil eol)))
  1093. (when (< fpos eol)
  1094. (goto-char fpos))))
  1095. (defun-cvs-mode cvs-mode-previous-line (arg)
  1096. "Go to the previous line.
  1097. If a prefix argument is given, move by that many lines."
  1098. (interactive "p")
  1099. (ewoc-goto-prev cvs-cookies arg)
  1100. (cvs-move-to-goal-column))
  1101. (defun-cvs-mode cvs-mode-next-line (arg)
  1102. "Go to the next line.
  1103. If a prefix argument is given, move by that many lines."
  1104. (interactive "p")
  1105. (ewoc-goto-next cvs-cookies arg)
  1106. (cvs-move-to-goal-column))
  1107. ;;;;
  1108. ;;;; Mark handling
  1109. ;;;;
  1110. (defun-cvs-mode cvs-mode-mark (&optional arg)
  1111. "Mark the fileinfo on the current line.
  1112. If the fileinfo is a directory, all the contents of that directory are
  1113. marked instead. A directory can never be marked."
  1114. (interactive)
  1115. (let* ((tin (ewoc-locate cvs-cookies))
  1116. (fi (ewoc-data tin)))
  1117. (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
  1118. ;; it's a directory: let's mark all files inside
  1119. (ewoc-map
  1120. (lambda (f dir)
  1121. (when (cvs-dir-member-p f dir)
  1122. (setf (cvs-fileinfo->marked f)
  1123. (not (if (eq arg 'toggle) (cvs-fileinfo->marked f) arg)))
  1124. t)) ;Tell cookie to redisplay this cookie.
  1125. cvs-cookies
  1126. (cvs-fileinfo->dir fi))
  1127. ;; not a directory: just do the obvious
  1128. (setf (cvs-fileinfo->marked fi)
  1129. (not (if (eq arg 'toggle) (cvs-fileinfo->marked fi) arg)))
  1130. (ewoc-invalidate cvs-cookies tin)
  1131. (cvs-mode-next-line 1))))
  1132. (defalias 'cvs-mouse-toggle-mark 'cvs-mode-toggle-mark)
  1133. (defun cvs-mode-toggle-mark (e)
  1134. "Toggle the mark of the entry at point."
  1135. (interactive (list last-input-event))
  1136. (save-excursion
  1137. (posn-set-point (event-end e))
  1138. (cvs-mode-mark 'toggle)))
  1139. (defun-cvs-mode cvs-mode-unmark ()
  1140. "Unmark the fileinfo on the current line."
  1141. (interactive)
  1142. (cvs-mode-mark t))
  1143. (defun-cvs-mode cvs-mode-mark-all-files ()
  1144. "Mark all files."
  1145. (interactive)
  1146. (ewoc-map (lambda (cookie)
  1147. (unless (eq (cvs-fileinfo->type cookie) 'DIRCHANGE)
  1148. (setf (cvs-fileinfo->marked cookie) t)))
  1149. cvs-cookies))
  1150. (defun-cvs-mode (cvs-mode-mark-on-state . SIMPLE) (state)
  1151. "Mark all files in state STATE."
  1152. (interactive
  1153. (list
  1154. (let ((default
  1155. (condition-case nil
  1156. (downcase
  1157. (symbol-name
  1158. (cvs-fileinfo->type
  1159. (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
  1160. (error nil))))
  1161. (intern
  1162. (upcase
  1163. (completing-read
  1164. (concat
  1165. "Mark files in state" (if default (concat " [" default "]")) ": ")
  1166. (mapcar (lambda (x)
  1167. (list (downcase (symbol-name (car x)))))
  1168. cvs-states)
  1169. nil t nil nil default))))))
  1170. (ewoc-map (lambda (fi)
  1171. (when (eq (cvs-fileinfo->type fi) state)
  1172. (setf (cvs-fileinfo->marked fi) t)))
  1173. cvs-cookies))
  1174. (defun-cvs-mode cvs-mode-mark-matching-files (regex)
  1175. "Mark all files matching REGEX."
  1176. (interactive "sMark files matching: ")
  1177. (ewoc-map (lambda (cookie)
  1178. (when (and (not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
  1179. (string-match regex (cvs-fileinfo->file cookie)))
  1180. (setf (cvs-fileinfo->marked cookie) t)))
  1181. cvs-cookies))
  1182. (defun-cvs-mode cvs-mode-unmark-all-files ()
  1183. "Unmark all files.
  1184. Directories are also unmarked, but that doesn't matter, since
  1185. they should always be unmarked."
  1186. (interactive)
  1187. (ewoc-map (lambda (cookie)
  1188. (setf (cvs-fileinfo->marked cookie) nil)
  1189. t)
  1190. cvs-cookies))
  1191. (defun-cvs-mode cvs-mode-unmark-up ()
  1192. "Unmark the file on the previous line."
  1193. (interactive)
  1194. (let ((tin (ewoc-goto-prev cvs-cookies 1)))
  1195. (when tin
  1196. (setf (cvs-fileinfo->marked (ewoc-data tin)) nil)
  1197. (ewoc-invalidate cvs-cookies tin)))
  1198. (cvs-move-to-goal-column))
  1199. (defconst cvs-ignore-marks-alternatives
  1200. '(("toggle-marks" . "/TM")
  1201. ("force-marks" . "/FM")
  1202. ("ignore-marks" . "/IM")))
  1203. (cvs-prefix-define cvs-ignore-marks-modif
  1204. "Prefix to decide whether to ignore marks or not."
  1205. "active"
  1206. (mapcar 'cdr cvs-ignore-marks-alternatives)
  1207. (cvs-qtypedesc-create
  1208. (lambda (str) (cdr (assoc str cvs-ignore-marks-alternatives)))
  1209. (lambda (obj) (car (rassoc obj cvs-ignore-marks-alternatives)))
  1210. (lambda () cvs-ignore-marks-alternatives)
  1211. nil t))
  1212. (defun-cvs-mode cvs-mode-toggle-marks (arg)
  1213. "Toggle whether the next CVS command uses marks.
  1214. See `cvs-prefix-set' for further description of the behavior.
  1215. \\[universal-argument] 1 selects `force-marks',
  1216. \\[universal-argument] 2 selects `ignore-marks',
  1217. \\[universal-argument] 3 selects `toggle-marks'."
  1218. (interactive "P")
  1219. (cvs-prefix-set 'cvs-ignore-marks-modif arg))
  1220. (defun cvs-ignore-marks-p (cmd &optional read-only)
  1221. (let ((default (if (member cmd cvs-invert-ignore-marks)
  1222. (not cvs-default-ignore-marks)
  1223. cvs-default-ignore-marks))
  1224. (modif (cvs-prefix-get 'cvs-ignore-marks-modif read-only)))
  1225. (cond
  1226. ((equal modif "/IM") t)
  1227. ((equal modif "/TM") (not default))
  1228. ((equal modif "/FM") nil)
  1229. (t default))))
  1230. (defun cvs-mode-mark-get-modif (cmd)
  1231. (if (cvs-ignore-marks-p cmd 'read-only) "/IM" "/FM"))
  1232. (defun cvs-get-marked (&optional ignore-marks ignore-contents)
  1233. "Return a list of all selected fileinfos.
  1234. If there are any marked tins, and IGNORE-MARKS is nil, return them.
  1235. Otherwise, if the cursor selects a directory, and IGNORE-CONTENTS is
  1236. nil, return all files in it, else return just the directory.
  1237. Otherwise return (a list containing) the file the cursor points to, or
  1238. an empty list if it doesn't point to a file at all."
  1239. (let ((fis nil))
  1240. (dolist (fi (if (and (boundp 'cvs-minor-current-files)
  1241. (consp cvs-minor-current-files))
  1242. (mapcar
  1243. (lambda (f)
  1244. (if (cvs-fileinfo-p f) f
  1245. (let ((f (file-relative-name f)))
  1246. (if (file-directory-p f)
  1247. (cvs-create-fileinfo
  1248. 'DIRCHANGE (file-name-as-directory f) "." "")
  1249. (let ((dir (file-name-directory f))
  1250. (file (file-name-nondirectory f)))
  1251. (cvs-create-fileinfo
  1252. 'UNKNOWN (or dir "") file ""))))))
  1253. cvs-minor-current-files)
  1254. (or (and (not ignore-marks)
  1255. (ewoc-collect cvs-cookies 'cvs-fileinfo->marked))
  1256. (list (ewoc-data (ewoc-locate cvs-cookies))))))
  1257. (if (or ignore-contents (not (eq (cvs-fileinfo->type fi) 'DIRCHANGE)))
  1258. (push fi fis)
  1259. ;; If a directory is selected, return members, if any.
  1260. (setq fis
  1261. (append (ewoc-collect
  1262. cvs-cookies 'cvs-dir-member-p (cvs-fileinfo->dir fi))
  1263. fis))))
  1264. (nreverse fis)))
  1265. (cl-defun cvs-mode-marked (filter &optional cmd
  1266. &key read-only one file noquery)
  1267. "Get the list of marked FIS.
  1268. CMD is used to determine whether to use the marks or not.
  1269. Only files for which FILTER is applicable are returned.
  1270. If READ-ONLY is non-nil, the current toggling is left intact.
  1271. If ONE is non-nil, marks are ignored and a single FI is returned.
  1272. If FILE is non-nil, directory entries won't be selected."
  1273. (unless cmd (setq cmd (symbol-name filter)))
  1274. (let* ((fis (cvs-get-marked (or one (cvs-ignore-marks-p cmd read-only))
  1275. (and (not file)
  1276. (cvs-applicable-p 'DIRCHANGE filter))))
  1277. (force (cvs-prefix-get 'cvs-force-command))
  1278. (fis (car (cvs-partition
  1279. (lambda (fi) (cvs-applicable-p fi (and (not force) filter)))
  1280. fis))))
  1281. (when (and (or (null fis) (and one (cdr fis))) (not noquery))
  1282. (message (if (null fis)
  1283. "`%s' is not applicable to any of the selected files."
  1284. "`%s' is only applicable to a single file.") cmd)
  1285. (sit-for 1)
  1286. (setq fis (list (cvs-insert-file
  1287. (read-file-name (format "File to %s: " cmd))))))
  1288. (if one (car fis) fis)))
  1289. (defun cvs-enabledp (filter)
  1290. "Determine whether FILTER applies to at least one of the selected files."
  1291. (ignore-errors (cvs-mode-marked filter nil :read-only t :noquery t)))
  1292. (defun cvs-mode-files (&rest -cvs-mode-files-args)
  1293. (cvs-mode!
  1294. (lambda ()
  1295. (mapcar 'cvs-fileinfo->full-name
  1296. (apply 'cvs-mode-marked -cvs-mode-files-args)))))
  1297. ;;
  1298. ;; Interface between Log-Edit and PCL-CVS
  1299. ;;
  1300. (defun cvs-mode-commit-setup ()
  1301. "Run `cvs-mode-commit' with setup."
  1302. (interactive)
  1303. (cvs-mode-commit 'force))
  1304. (defcustom cvs-mode-commit-hook nil
  1305. "Hook run after setting up the commit buffer."
  1306. :type 'hook
  1307. :options '(cvs-mode-diff)
  1308. :group 'pcl-cvs)
  1309. (defun cvs-mode-commit (setup)
  1310. "Check in all marked files, or the current file.
  1311. The user will be asked for a log message in a buffer.
  1312. The buffer's mode and name is determined by the \"message\" setting
  1313. of `cvs-buffer-name-alist'.
  1314. The POSTPROC specified there (typically `log-edit') is then called,
  1315. passing it the SETUP argument."
  1316. (interactive "P")
  1317. ;; It seems that the save-excursion that happens if I use the better
  1318. ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
  1319. ;; end up being rather annoying (like log-edit-mode's message being
  1320. ;; displayed in the wrong minibuffer).
  1321. (cvs-mode!)
  1322. (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
  1323. (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
  1324. 'log-edit)))
  1325. (funcall setupfun 'cvs-do-commit setup
  1326. '((log-edit-listfun . cvs-commit-filelist)
  1327. (log-edit-diff-function . cvs-mode-diff)) buf)
  1328. (set (make-local-variable 'cvs-minor-wrap-function) 'cvs-commit-minor-wrap)
  1329. (run-hooks 'cvs-mode-commit-hook)))
  1330. (defun cvs-commit-minor-wrap (_buf f)
  1331. (let ((cvs-ignore-marks-modif (cvs-mode-mark-get-modif "commit")))
  1332. (funcall f)))
  1333. (defun cvs-commit-filelist ()
  1334. (cvs-mode-files 'commit nil :read-only t :file t :noquery t))
  1335. (defun cvs-do-commit (flags)
  1336. "Do the actual commit, using the current buffer as the log message."
  1337. (interactive (list (cvs-flags-query 'cvs-commit-flags "cvs commit flags")))
  1338. (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
  1339. (cvs-mode!)
  1340. ;;(pop-to-buffer cvs-buffer)
  1341. (cvs-mode-do "commit" `("-m" ,msg ,@flags) 'commit)))
  1342. ;;;; Editing existing commit log messages.
  1343. (defun cvs-edit-log-text-at-point ()
  1344. (save-excursion
  1345. (end-of-line)
  1346. (when (re-search-backward "^revision " nil t)
  1347. (forward-line 1)
  1348. (if (looking-at "date:") (forward-line 1))
  1349. (if (looking-at "branches:") (forward-line 1))
  1350. (buffer-substring
  1351. (point)
  1352. (if (re-search-forward
  1353. "^\\(-\\{28\\}\\|=\\{77\\}\\|revision [.0-9]+\\)$"
  1354. nil t)
  1355. (match-beginning 0)
  1356. (point))))))
  1357. (defvar cvs-edit-log-revision)
  1358. (defvar cvs-edit-log-files) (put 'cvs-edit-log-files 'permanent-local t)
  1359. (defun cvs-mode-edit-log (file rev &optional text)
  1360. "Edit the log message at point.
  1361. This is best called from a `log-view-mode' buffer."
  1362. (interactive
  1363. (list
  1364. (or (cvs-mode! (lambda ()
  1365. (car (cvs-mode-files nil nil
  1366. :read-only t :file t :noquery t))))
  1367. (read-string "File name: "))
  1368. (or (cvs-mode! (lambda () (cvs-prefix-get 'cvs-branch-prefix)))
  1369. (read-string "Revision to edit: "))
  1370. (cvs-edit-log-text-at-point)))
  1371. ;; It seems that the save-excursion that happens if I use the better
  1372. ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
  1373. ;; end up being rather annoying (like log-edit-mode's message being
  1374. ;; displayed in the wrong minibuffer).
  1375. (cvs-mode!)
  1376. (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
  1377. (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
  1378. 'log-edit)))
  1379. (with-current-buffer buf
  1380. ;; Set the filename before, so log-edit can correctly setup its
  1381. ;; log-edit-initial-files variable.
  1382. (set (make-local-variable 'cvs-edit-log-files) (list file)))
  1383. (funcall setupfun 'cvs-do-edit-log nil
  1384. '((log-edit-listfun . cvs-edit-log-filelist)
  1385. (log-edit-diff-function . cvs-mode-diff))
  1386. buf)
  1387. (when text (erase-buffer) (insert text))
  1388. (set (make-local-variable 'cvs-edit-log-revision) rev)
  1389. (set (make-local-variable 'cvs-minor-wrap-function)
  1390. 'cvs-edit-log-minor-wrap)
  1391. ;; (run-hooks 'cvs-mode-commit-hook)
  1392. ))
  1393. (defun cvs-edit-log-minor-wrap (buf f)
  1394. (let ((cvs-branch-prefix (with-current-buffer buf cvs-edit-log-revision))
  1395. (cvs-minor-current-files
  1396. (with-current-buffer buf cvs-edit-log-files))
  1397. ;; FIXME: I need to force because the fileinfos are UNKNOWN
  1398. (cvs-force-command "/F"))
  1399. (funcall f)))
  1400. (defun cvs-edit-log-filelist ()
  1401. (if cvs-minor-wrap-function
  1402. (cvs-mode-files nil nil :read-only t :file t :noquery t)
  1403. cvs-edit-log-files))
  1404. (defun cvs-do-edit-log (rev)
  1405. "Do the actual commit, using the current buffer as the log message."
  1406. (interactive (list cvs-edit-log-revision))
  1407. (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
  1408. (cvs-mode!
  1409. (lambda ()
  1410. (cvs-mode-do "admin" (list (concat "-m" rev ":" msg)) nil)))))
  1411. ;;;;
  1412. ;;;; CVS Mode commands
  1413. ;;;;
  1414. (defun-cvs-mode (cvs-mode-insert . NOARGS) (file)
  1415. "Insert an entry for a specific file into the current listing.
  1416. This is typically used if the file is up-to-date (or has been added
  1417. outside of PCL-CVS) and one wants to do some operation on it."
  1418. (interactive
  1419. (list (read-file-name
  1420. "File to insert: "
  1421. ;; Can't use ignore-errors here because interactive
  1422. ;; specs aren't byte-compiled.
  1423. (condition-case nil
  1424. (file-name-as-directory
  1425. (expand-file-name
  1426. (cvs-fileinfo->dir
  1427. (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
  1428. (error nil)))))
  1429. (cvs-insert-file file))
  1430. (defun cvs-insert-file (file)
  1431. "Insert FILE (and its contents if it's a dir) and return its FI."
  1432. (let ((file (file-relative-name (directory-file-name file))) last)
  1433. (dolist (fi (cvs-fileinfo-from-entries file))
  1434. (setq last (cvs-addto-collection cvs-cookies fi last)))
  1435. ;; There should have been at least one entry.
  1436. (goto-char (ewoc-location last))
  1437. (ewoc-data last)))
  1438. (defun cvs-mark-fis-dead (fis)
  1439. ;; Helper function, introduced because of the need for macro-expansion.
  1440. (dolist (fi fis)
  1441. (setf (cvs-fileinfo->type fi) 'DEAD)))
  1442. (defun-cvs-mode (cvs-mode-add . SIMPLE) (flags)
  1443. "Add marked files to the cvs repository.
  1444. With prefix argument, prompt for cvs flags."
  1445. (interactive (list (cvs-flags-query 'cvs-add-flags "cvs add flags")))
  1446. (let ((fis (cvs-mode-marked 'add))
  1447. (needdesc nil) (dirs nil))
  1448. ;; Find directories and look for fis needing a description.
  1449. (dolist (fi fis)
  1450. (cond
  1451. ((file-directory-p (cvs-fileinfo->full-name fi)) (push fi dirs))
  1452. ((eq (cvs-fileinfo->type fi) 'UNKNOWN) (setq needdesc t))))
  1453. ;; Prompt for description if necessary.
  1454. (let* ((msg (if (and needdesc
  1455. (or current-prefix-arg (not cvs-add-default-message)))
  1456. (read-from-minibuffer "Enter description: ")
  1457. (or cvs-add-default-message "")))
  1458. (flags `("-m" ,msg ,@flags))
  1459. (postproc
  1460. ;; Setup postprocessing for the directory entries.
  1461. (when dirs
  1462. (lambda ()
  1463. (cvs-run-process (list "-n" "update")
  1464. dirs
  1465. (lambda () (cvs-parse-process t)))
  1466. (cvs-mark-fis-dead dirs)))))
  1467. (cvs-mode-run "add" flags fis :postproc postproc))))
  1468. (defun-cvs-mode (cvs-mode-diff . DOUBLE) (flags)
  1469. "Diff the selected files against the repository.
  1470. This command compares the files in your working area against the
  1471. revision which they are based upon.
  1472. See also `cvs-diff-ignore-marks'."
  1473. (interactive
  1474. (list (cvs-add-branch-prefix
  1475. (cvs-add-secondary-branch-prefix
  1476. (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))))
  1477. (cvs-mode-do "diff" flags 'diff
  1478. :show t)) ;; :ignore-exit t
  1479. (defun-cvs-mode (cvs-mode-diff-head . SIMPLE) (flags)
  1480. "Diff the selected files against the head of the current branch.
  1481. See `cvs-mode-diff' for more info."
  1482. (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
  1483. (cvs-mode-diff-1 (cons "-rHEAD" flags)))
  1484. (defun-cvs-mode (cvs-mode-diff-repository . SIMPLE) (flags)
  1485. "Diff the files for changes in the repository since last co/update/commit.
  1486. See `cvs-mode-diff' for more info."
  1487. (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
  1488. (cvs-mode-diff-1 (cons "-rBASE" (cons "-rHEAD" flags))))
  1489. (defun-cvs-mode (cvs-mode-diff-yesterday . SIMPLE) (flags)
  1490. "Diff the selected files against yesterday's head of the current branch.
  1491. See `cvs-mode-diff' for more info."
  1492. (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
  1493. (cvs-mode-diff-1 (cons "-Dyesterday" flags)))
  1494. (defun-cvs-mode (cvs-mode-diff-vendor . SIMPLE) (flags)
  1495. "Diff the selected files against the head of the vendor branch.
  1496. See `cvs-mode-diff' for more info."
  1497. (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
  1498. (cvs-mode-diff-1 (cons (concat "-r" cvs-vendor-branch) flags)))
  1499. ;; sadly, this is not provided by cvs, so we have to roll our own
  1500. (defun-cvs-mode (cvs-mode-diff-backup . SIMPLE) (flags)
  1501. "Diff the files against the backup file.
  1502. This command can be used on files that are marked with \"Merged\"
  1503. or \"Conflict\" in the *cvs* buffer."
  1504. (interactive (list (cvs-flags-query 'cvs-diff-flags "diff flags")))
  1505. (unless (listp flags) (error "flags should be a list of strings"))
  1506. (save-some-buffers)
  1507. (let* ((marked (cvs-get-marked (cvs-ignore-marks-p "diff")))
  1508. (fis (car (cvs-partition 'cvs-fileinfo->backup-file marked))))
  1509. (unless (consp fis)
  1510. (error "No files with a backup file selected!"))
  1511. (set-buffer (cvs-temp-buffer "diff"))
  1512. (message "cvs diff backup...")
  1513. (cvs-execute-single-file-list fis 'cvs-diff-backup-extractor
  1514. cvs-diff-program flags))
  1515. (message "cvs diff backup... Done."))
  1516. (defun cvs-diff-backup-extractor (fileinfo)
  1517. "Return the filename and the name of the backup file as a list.
  1518. Signal an error if there is no backup file."
  1519. (let ((backup-file (cvs-fileinfo->backup-file fileinfo)))
  1520. (unless backup-file
  1521. (error "%s has no backup file" (cvs-fileinfo->full-name fileinfo)))
  1522. (list backup-file (cvs-fileinfo->full-name fileinfo))))
  1523. ;;
  1524. ;; Emerge support
  1525. ;;
  1526. (defun cvs-emerge-diff (b1 b2) (emerge-buffers b1 b2 b1))
  1527. (defun cvs-emerge-merge (b1 b2 base out)
  1528. (emerge-buffers-with-ancestor b1 b2 base (find-file-noselect out)))
  1529. ;;
  1530. ;; Ediff support
  1531. ;;
  1532. (defvar ediff-after-quit-destination-buffer)
  1533. (defvar ediff-after-quit-hook-internal)
  1534. (defvar cvs-transient-buffers)
  1535. (defun cvs-ediff-startup-hook ()
  1536. (add-hook 'ediff-after-quit-hook-internal
  1537. `(lambda ()
  1538. (cvs-ediff-exit-hook
  1539. ',ediff-after-quit-destination-buffer ',cvs-transient-buffers))
  1540. nil 'local))
  1541. (defun cvs-ediff-exit-hook (cvs-buf tmp-bufs)
  1542. ;; kill the temp buffers (and their associated windows)
  1543. (dolist (tb tmp-bufs)
  1544. (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
  1545. (let ((win (get-buffer-window tb t)))
  1546. (kill-buffer tb)
  1547. (when (window-live-p win) (ignore-errors (delete-window win))))))
  1548. ;; switch back to the *cvs* buffer
  1549. (when (and cvs-buf (buffer-live-p cvs-buf)
  1550. (not (get-buffer-window cvs-buf t)))
  1551. (ignore-errors (switch-to-buffer cvs-buf))))
  1552. (defun cvs-ediff-diff (b1 b2)
  1553. (let ((ediff-after-quit-destination-buffer (current-buffer))
  1554. (startup-hook '(cvs-ediff-startup-hook)))
  1555. (ediff-buffers b1 b2 startup-hook 'ediff-revision)))
  1556. (defun cvs-ediff-merge (b1 b2 base out)
  1557. (let ((ediff-after-quit-destination-buffer (current-buffer))
  1558. (startup-hook '(cvs-ediff-startup-hook)))
  1559. (ediff-merge-buffers-with-ancestor
  1560. b1 b2 base startup-hook
  1561. 'ediff-merge-revisions-with-ancestor
  1562. out)))
  1563. ;;
  1564. ;; Interactive merge/diff support.
  1565. ;;
  1566. (defun cvs-retrieve-revision (fileinfo rev)
  1567. "Retrieve the given REVision of the file in FILEINFO into a new buffer."
  1568. (let* ((file (cvs-fileinfo->full-name fileinfo))
  1569. (buffile (concat file "." rev)))
  1570. (or (find-buffer-visiting buffile)
  1571. (with-current-buffer (create-file-buffer buffile)
  1572. (message "Retrieving revision %s..." rev)
  1573. ;; Discard stderr output to work around the CVS+SSH+libc
  1574. ;; problem when stdout and stderr are the same.
  1575. (let ((res
  1576. (let ((coding-system-for-read 'binary))
  1577. (apply 'process-file cvs-program nil '(t nil) nil
  1578. "-q" "update" "-p"
  1579. ;; If `rev' is HEAD, don't pass it at all:
  1580. ;; the default behavior is to get the head
  1581. ;; of the current branch whereas "-r HEAD"
  1582. ;; stupidly gives you the head of the trunk.
  1583. (append (unless (equal rev "HEAD") (list "-r" rev))
  1584. (list file))))))
  1585. (when (and res (not (and (equal 0 res))))
  1586. (error "Something went wrong retrieving revision %s: %s" rev res))
  1587. ;; Figure out the encoding used and decode the byte-sequence
  1588. ;; into a sequence of chars.
  1589. (decode-coding-inserted-region
  1590. (point-min) (point-max) file t nil nil t)
  1591. ;; Set buffer-file-coding-system.
  1592. (after-insert-file-set-coding (buffer-size) t)
  1593. (set-buffer-modified-p nil)
  1594. (let ((buffer-file-name (expand-file-name file)))
  1595. (after-find-file))
  1596. (setq buffer-read-only t)
  1597. (message "Retrieving revision %s... Done" rev)
  1598. (current-buffer))))))
  1599. ;; FIXME: The user should be able to specify ancestor/head/backup and we should
  1600. ;; provide sensible defaults when merge info is unavailable (rather than rely
  1601. ;; on smerge-ediff). Also provide sane defaults for need-merge files.
  1602. (defun-cvs-mode cvs-mode-imerge ()
  1603. "Merge interactively appropriate revisions of the selected file."
  1604. (interactive)
  1605. (let ((fi (cvs-mode-marked 'merge nil :one t :file t)))
  1606. (let ((merge (cvs-fileinfo->merge fi))
  1607. (file (cvs-fileinfo->full-name fi))
  1608. (backup-file (cvs-fileinfo->backup-file fi)))
  1609. (if (not (and merge backup-file))
  1610. (let ((buf (find-file-noselect file)))
  1611. (message "Missing merge info or backup file, using VC.")
  1612. (with-current-buffer buf
  1613. (smerge-ediff)))
  1614. (let* ((ancestor-buf (cvs-retrieve-revision fi (car merge)))
  1615. (head-buf (cvs-retrieve-revision fi (cdr merge)))
  1616. (backup-buf (let ((auto-mode-alist nil))
  1617. (find-file-noselect backup-file)))
  1618. ;; this binding is used by cvs-ediff-startup-hook
  1619. (cvs-transient-buffers (list ancestor-buf backup-buf head-buf)))
  1620. (with-current-buffer backup-buf
  1621. (let ((buffer-file-name (expand-file-name file)))
  1622. (after-find-file)))
  1623. (funcall (cdr cvs-idiff-imerge-handlers)
  1624. backup-buf head-buf ancestor-buf file))))))
  1625. (cvs-flags-define cvs-idiff-version
  1626. (list "BASE" cvs-vendor-branch cvs-vendor-branch "BASE" "BASE")
  1627. "version: " cvs-qtypedesc-tag)
  1628. (defun-cvs-mode (cvs-mode-idiff . NOARGS) (&optional rev1 rev2)
  1629. "Diff interactively current file to revisions."
  1630. (interactive
  1631. (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
  1632. (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
  1633. (list (or rev1 (cvs-flags-query 'cvs-idiff-version))
  1634. rev2)))
  1635. (let ((fi (cvs-mode-marked 'diff "idiff" :one t :file t)))
  1636. (let* ((file (cvs-fileinfo->full-name fi))
  1637. (rev1-buf (cvs-retrieve-revision fi (or rev1 "BASE")))
  1638. (rev2-buf (if rev2 (cvs-retrieve-revision fi rev2)))
  1639. ;; this binding is used by cvs-ediff-startup-hook
  1640. (cvs-transient-buffers (list rev1-buf rev2-buf)))
  1641. (funcall (car cvs-idiff-imerge-handlers)
  1642. rev1-buf (or rev2-buf (find-file-noselect file))))))
  1643. (defun-cvs-mode (cvs-mode-idiff-other . NOARGS) ()
  1644. "Diff interactively current file to revisions."
  1645. (interactive)
  1646. (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
  1647. (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix)))
  1648. (fis (cvs-mode-marked 'diff "idiff" :file t)))
  1649. (when (> (length fis) 2)
  1650. (error "idiff-other cannot be applied to more than 2 files at a time"))
  1651. (let* ((fi1 (car fis))
  1652. (rev1-buf (if rev1 (cvs-retrieve-revision fi1 rev1)
  1653. (find-file-noselect (cvs-fileinfo->full-name fi1))))
  1654. rev2-buf)
  1655. (if (cdr fis)
  1656. (let ((fi2 (nth 1 fis)))
  1657. (setq rev2-buf
  1658. (if rev2 (cvs-retrieve-revision fi2 rev2)
  1659. (find-file-noselect (cvs-fileinfo->full-name fi2)))))
  1660. (error "idiff-other doesn't know what other file/buffer to use"))
  1661. (let* (;; this binding is used by cvs-ediff-startup-hook
  1662. (cvs-transient-buffers (list rev1-buf rev2-buf)))
  1663. (funcall (car cvs-idiff-imerge-handlers)
  1664. rev1-buf rev2-buf)))))
  1665. (defun cvs-is-within-p (fis dir)
  1666. "Non-nil if buffer is inside one of FIS (in DIR)."
  1667. (when (stringp buffer-file-name)
  1668. (setq buffer-file-name (expand-file-name buffer-file-name))
  1669. (let (ret)
  1670. (dolist (fi (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))
  1671. (when (string-prefix-p
  1672. (expand-file-name (cvs-fileinfo->full-name fi) dir)
  1673. buffer-file-name)
  1674. (setq ret t)))
  1675. ret)))
  1676. (cl-defun cvs-mode-run (cmd flags fis
  1677. &key (buf (cvs-temp-buffer))
  1678. dont-change-disc cvsargs postproc)
  1679. "Generic cvs-mode-<foo> function.
  1680. Executes `cvs CVSARGS CMD FLAGS FIS'.
  1681. BUF is the buffer to be used for cvs' output.
  1682. DONT-CHANGE-DISC non-nil indicates that the command will not change the
  1683. contents of files. This is only used by the parser.
  1684. POSTPROC is a function of no argument to be evaluated at the very end (after
  1685. parsing if applicable)."
  1686. (unless postproc (setq postproc #'ignore))
  1687. (let ((def-dir default-directory))
  1688. ;; Save the relevant buffers
  1689. (save-some-buffers nil (lambda () (cvs-is-within-p fis def-dir))))
  1690. (unless (listp flags) (error "flags should be a list of strings"))
  1691. ;; Some w32 versions of CVS don't like an explicit . too much.
  1692. (when (and (car fis) (null (cdr fis))
  1693. (eq (cvs-fileinfo->type (car fis)) 'DIRCHANGE)
  1694. ;; (equal (cvs-fileinfo->file (car fis)) ".")
  1695. (equal (cvs-fileinfo->dir (car fis)) ""))
  1696. (setq fis nil))
  1697. (let* ((single-dir (or (not (listp cvs-execute-single-dir))
  1698. (member cmd cvs-execute-single-dir)))
  1699. (parse (member cmd cvs-parse-known-commands))
  1700. (args (append cvsargs (list cmd) flags))
  1701. (after-mode (nth 2 (cdr (assoc cmd cvs-buffer-name-alist)))))
  1702. (cvs-cleanup-collection cvs-cookies ;cleanup remaining messages
  1703. (eq cvs-auto-remove-handled 'delayed) nil t)
  1704. (when (fboundp after-mode)
  1705. (setq postproc (let ((pp postproc))
  1706. (lambda () (funcall pp) (funcall after-mode)))))
  1707. (when parse
  1708. (let ((old-fis
  1709. (when (member cmd '("status" "update")) ;FIXME: Yuck!!
  1710. ;; absence of `cvs update' output has a specific meaning.
  1711. (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." "")))))
  1712. (pp postproc))
  1713. (setq postproc (lambda ()
  1714. (cvs-parse-process dont-change-disc nil old-fis)
  1715. (funcall pp)))))
  1716. (with-current-buffer buf
  1717. (let ((inhibit-read-only t)) (erase-buffer))
  1718. (message "Running cvs %s ..." cmd)
  1719. (cvs-run-process args fis postproc single-dir))))
  1720. (cl-defun cvs-mode-do (cmd flags filter
  1721. &key show dont-change-disc cvsargs postproc)
  1722. "Generic cvs-mode-<foo> function.
  1723. Executes `cvs CVSARGS CMD FLAGS' on the selected files.
  1724. FILTER is passed to `cvs-applicable-p' to only apply the command to
  1725. files for which it makes sense.
  1726. SHOW indicates that CMD should be not be run in the default temp buffer and
  1727. should be shown to the user. The buffer and mode to be used are determined
  1728. by `cvs-buffer-name-alist'.
  1729. DONT-CHANGE-DISC non-nil indicates that the command will not change the
  1730. contents of files. This is only used by the parser."
  1731. (cvs-mode-run cmd flags (cvs-mode-marked filter cmd)
  1732. :buf (cvs-temp-buffer (when show cmd))
  1733. :dont-change-disc dont-change-disc
  1734. :cvsargs cvsargs
  1735. :postproc postproc))
  1736. (defun-cvs-mode (cvs-mode-status . SIMPLE) (flags)
  1737. "Show cvs status for all marked files.
  1738. With prefix argument, prompt for cvs flags."
  1739. (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
  1740. (cvs-mode-do "status" flags nil :dont-change-disc t :show t
  1741. :postproc (when (eq cvs-auto-remove-handled 'status)
  1742. (let ((buf (current-buffer)))
  1743. (lambda () (with-current-buffer buf
  1744. (cvs-mode-remove-handled)))))))
  1745. (autoload 'cvs-status-cvstrees "cvs-status")
  1746. (defun-cvs-mode (cvs-mode-tree . SIMPLE) (flags)
  1747. "Call cvstree using the file under the point as a keyfile."
  1748. (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
  1749. (cvs-mode-run "status" (cons "-v" flags) (cvs-mode-marked nil "status")
  1750. :buf (cvs-temp-buffer "tree")
  1751. :dont-change-disc t
  1752. :postproc #'cvs-status-cvstrees))
  1753. ;; cvs log
  1754. (defun-cvs-mode (cvs-mode-log . NOARGS) (flags)
  1755. "Display the cvs log of all selected files.
  1756. With prefix argument, prompt for cvs flags."
  1757. (interactive (list (cvs-add-branch-prefix
  1758. (cvs-flags-query 'cvs-log-flags "cvs log flags"))))
  1759. (cvs-mode-do "log" flags nil :show t))
  1760. (defun-cvs-mode (cvs-mode-update . NOARGS) (flags)
  1761. "Update all marked files.
  1762. With a prefix argument, prompt for cvs flags."
  1763. (interactive
  1764. (list (cvs-add-branch-prefix
  1765. (cvs-add-secondary-branch-prefix
  1766. (cvs-flags-query 'cvs-update-flags "cvs update flags")
  1767. "-j") "-j")))
  1768. (cvs-mode-do "update" flags 'update))
  1769. (defun-cvs-mode (cvs-mode-examine . NOARGS) (flags)
  1770. "Re-examine all marked files.
  1771. With a prefix argument, prompt for cvs flags."
  1772. (interactive
  1773. (list (cvs-add-branch-prefix
  1774. (cvs-add-secondary-branch-prefix
  1775. (cvs-flags-query 'cvs-update-flags "cvs -n update flags")
  1776. "-j") "-j")))
  1777. (cvs-mode-do "update" flags nil :cvsargs '("-n") :dont-change-disc t))
  1778. (defun-cvs-mode cvs-mode-ignore ()
  1779. "Arrange so that CVS ignores the selected files.
  1780. This command ignores files that are not flagged as `Unknown'."
  1781. (interactive)
  1782. (dolist (fi (cvs-mode-marked 'ignore))
  1783. (vc-cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi)
  1784. (eq (cvs-fileinfo->subtype fi) 'NEW-DIR))
  1785. (setf (cvs-fileinfo->type fi) 'DEAD))
  1786. (cvs-cleanup-collection cvs-cookies nil nil nil))
  1787. (define-obsolete-function-alias 'cvs-append-to-ignore 'vc-cvs-append-to-ignore
  1788. "24.4")
  1789. (defun cvs-mode-find-file-other-window (e)
  1790. "Select a buffer containing the file in another window."
  1791. (interactive (list last-input-event))
  1792. (cvs-mode-find-file e t))
  1793. (defun cvs-mode-display-file (e)
  1794. "Show a buffer containing the file in another window."
  1795. (interactive (list last-input-event))
  1796. (cvs-mode-find-file e 'dont-select))
  1797. (defun cvs-mode-view-file (e)
  1798. "View the file."
  1799. (interactive (list last-input-event))
  1800. (cvs-mode-find-file e nil t))
  1801. (defun cvs-mode-view-file-other-window (e)
  1802. "View the file in another window."
  1803. (interactive (list last-input-event))
  1804. (cvs-mode-find-file e t t))
  1805. (defun cvs-find-modif (fi)
  1806. (with-temp-buffer
  1807. (process-file cvs-program nil (current-buffer) nil
  1808. "-f" "diff" (cvs-fileinfo->file fi))
  1809. (goto-char (point-min))
  1810. (if (re-search-forward "^\\([0-9]+\\)" nil t)
  1811. (string-to-number (match-string 1))
  1812. 1)))
  1813. (defun cvs-mode-find-file (e &optional other view)
  1814. "Select a buffer containing the file.
  1815. With a prefix, opens the buffer in an OTHER window."
  1816. (interactive (list last-input-event current-prefix-arg))
  1817. ;; If the event moves point, check that it moves it to a valid location.
  1818. (when (and (/= (point) (progn (posn-set-point (event-end e)) (point)))
  1819. (not (memq (get-text-property (1- (line-end-position))
  1820. 'font-lock-face)
  1821. '(cvs-header cvs-filename))))
  1822. (error "Not a file name"))
  1823. (cvs-mode!
  1824. (lambda (&optional rev)
  1825. (interactive (list (cvs-prefix-get 'cvs-branch-prefix)))
  1826. (let* ((cvs-buf (current-buffer))
  1827. (fi (cvs-mode-marked nil nil :one t)))
  1828. (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
  1829. (let ((odir default-directory))
  1830. (setq default-directory
  1831. (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
  1832. (cond ((eq other 'dont-select)
  1833. (display-buffer (find-file-noselect default-directory)))
  1834. (other (dired-other-window default-directory))
  1835. (t (dired default-directory)))
  1836. (set-buffer cvs-buf)
  1837. (setq default-directory odir))
  1838. (let ((buf (if rev (cvs-retrieve-revision fi rev)
  1839. (find-file-noselect (cvs-fileinfo->full-name fi)))))
  1840. (funcall (cond ((eq other 'dont-select) 'display-buffer)
  1841. (other
  1842. (if view 'view-buffer-other-window
  1843. 'switch-to-buffer-other-window))
  1844. (t (if view 'view-buffer 'switch-to-buffer)))
  1845. buf)
  1846. (when (and cvs-find-file-and-jump (cvs-applicable-p fi 'diff-base))
  1847. (save-restriction
  1848. (widen)
  1849. (goto-char (point-min))
  1850. (forward-line (1- (cvs-find-modif fi)))))
  1851. buf))))))
  1852. (defun-cvs-mode (cvs-mode-undo . SIMPLE) (flags)
  1853. "Undo local changes to all marked files.
  1854. The file is removed and `cvs update FILE' is run."
  1855. ;;"With prefix argument, prompt for cvs FLAGS."
  1856. (interactive (list nil));; (cvs-flags-query 'cvs-undo-flags "undo flags")
  1857. (if current-prefix-arg (call-interactively 'cvs-mode-revert-to-rev)
  1858. (let* ((fis (cvs-do-removal 'undo "update" 'all))
  1859. (removedp (lambda (fi)
  1860. (or (eq (cvs-fileinfo->type fi) 'REMOVED)
  1861. (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
  1862. (eq (cvs-fileinfo->subtype fi) 'REMOVED)))))
  1863. (fis-split (cvs-partition removedp fis))
  1864. (fis-removed (car fis-split))
  1865. (fis-other (cdr fis-split)))
  1866. (if (null fis-other)
  1867. (when fis-removed (cvs-mode-run "add" nil fis-removed))
  1868. (cvs-mode-run "update" flags fis-other
  1869. :postproc
  1870. (when fis-removed
  1871. (let ((buf (current-buffer)))
  1872. (lambda ()
  1873. (with-current-buffer buf
  1874. (cvs-mode-run "add" nil fis-removed))))))))))
  1875. (defun-cvs-mode (cvs-mode-revert-to-rev . NOARGS) (rev)
  1876. "Revert the selected files to an old revision."
  1877. (interactive
  1878. (list (or (cvs-prefix-get 'cvs-branch-prefix)
  1879. (let ((current-prefix-arg '(4)))
  1880. (cvs-flags-query 'cvs-idiff-version)))))
  1881. (let* ((fis (cvs-mode-marked 'revert "revert" :file t))
  1882. (tag (concat "tmp_pcl_tag_" (make-temp-name "")))
  1883. (buf (current-buffer))
  1884. (untag (lambda ()
  1885. (with-current-buffer buf
  1886. (cvs-mode-run "tag" (list "-d" tag) fis))))
  1887. (update (lambda ()
  1888. (with-current-buffer buf
  1889. (cvs-mode-run "update" (list "-j" tag "-j" rev) fis
  1890. :postproc untag)))))
  1891. (cvs-mode-run "tag" (list tag) fis :postproc update)))
  1892. (defun-cvs-mode cvs-mode-delete-lock ()
  1893. "Delete the lock file that CVS is waiting for.
  1894. Note that this can be dangerous. You should only do this
  1895. if you are convinced that the process that created the lock is dead."
  1896. (interactive)
  1897. (let* ((default-directory (cvs-expand-dir-name cvs-lock-file))
  1898. (locks (directory-files default-directory nil cvs-lock-file-regexp)))
  1899. (cond
  1900. ((not locks) (error "No lock files found"))
  1901. ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
  1902. (dolist (lock locks)
  1903. (cond ((file-directory-p lock) (delete-directory lock))
  1904. ((file-exists-p lock) (delete-file lock))))))))
  1905. (defun-cvs-mode cvs-mode-remove-handled ()
  1906. "Remove all lines that are handled.
  1907. Empty directories are removed."
  1908. (interactive)
  1909. (cvs-cleanup-collection cvs-cookies
  1910. 'all (or cvs-auto-remove-directories 'handled) t))
  1911. (defun-cvs-mode cvs-mode-acknowledge ()
  1912. "Remove all marked files from the buffer."
  1913. (interactive)
  1914. (dolist (fi (cvs-get-marked (cvs-ignore-marks-p "acknowledge") t))
  1915. (setf (cvs-fileinfo->type fi) 'DEAD))
  1916. (cvs-cleanup-collection cvs-cookies nil nil nil))
  1917. (defun cvs-do-removal (filter &optional cmd all)
  1918. "Remove files.
  1919. Returns a list of FIS that should be `cvs remove'd."
  1920. (let* ((files (cvs-mode-marked filter cmd :file t :read-only t))
  1921. (fis (cdr (cvs-partition (lambda (fi)
  1922. (eq (cvs-fileinfo->type fi) 'UNKNOWN))
  1923. (cvs-mode-marked filter cmd))))
  1924. (silent (or (not cvs-confirm-removals)
  1925. (cvs-every (lambda (fi)
  1926. (or (not (file-exists-p
  1927. (cvs-fileinfo->full-name fi)))
  1928. (cvs-applicable-p fi 'safe-rm)))
  1929. files)))
  1930. (tmpbuf (cvs-temp-buffer)))
  1931. (when (and (not silent) (equal cvs-confirm-removals 'list))
  1932. (with-current-buffer tmpbuf
  1933. (let ((inhibit-read-only t))
  1934. (cvs-insert-strings (mapcar 'cvs-fileinfo->full-name fis))
  1935. (cvs-pop-to-buffer-same-frame (current-buffer))
  1936. (shrink-window-if-larger-than-buffer))))
  1937. (if (not (or silent
  1938. (unwind-protect
  1939. (yes-or-no-p
  1940. (let ((nfiles (length files))
  1941. (verb (if (eq filter 'undo) "Undo" "Delete")))
  1942. (if (= 1 nfiles)
  1943. (format "%s file: \"%s\" ? "
  1944. verb
  1945. (cvs-fileinfo->file (car files)))
  1946. (format "%s %d files? "
  1947. verb
  1948. nfiles))))
  1949. (cvs-bury-buffer tmpbuf cvs-buffer))))
  1950. (progn (message "Aborting") nil)
  1951. (dolist (fi files)
  1952. (let* ((type (cvs-fileinfo->type fi))
  1953. (file (cvs-fileinfo->full-name fi)))
  1954. (when (or all (eq type 'UNKNOWN))
  1955. (when (file-exists-p file) (delete-file file))
  1956. (unless all (setf (cvs-fileinfo->type fi) 'DEAD) t))))
  1957. fis)))
  1958. (defun-cvs-mode (cvs-mode-remove . SIMPLE) (flags)
  1959. "Remove all marked files.
  1960. With prefix argument, prompt for cvs flags."
  1961. (interactive (list (cvs-flags-query 'cvs-remove-flags "cvs remove flags")))
  1962. (let ((fis (cvs-do-removal 'remove)))
  1963. (if fis (cvs-mode-run "remove" (cons "-f" flags) fis)
  1964. (cvs-cleanup-collection cvs-cookies nil nil nil))))
  1965. (defvar cvs-tag-name "")
  1966. (defun-cvs-mode (cvs-mode-tag . SIMPLE) (tag &optional flags)
  1967. "Run `cvs tag TAG' on all selected files.
  1968. With prefix argument, prompt for cvs flags.
  1969. By default this can only be used on directories.
  1970. Use \\[cvs-mode-force-command] or change `cvs-force-dir-tag' if you need
  1971. to use it on individual files."
  1972. (interactive
  1973. (list (setq cvs-tag-name
  1974. (cvs-query-read cvs-tag-name "Tag name: " cvs-qtypedesc-tag))
  1975. (cvs-flags-query 'cvs-tag-flags "tag flags")))
  1976. (cvs-mode-do "tag" (append flags (list tag))
  1977. (when cvs-force-dir-tag 'tag)))
  1978. (defun-cvs-mode (cvs-mode-untag . SIMPLE) (tag &optional flags)
  1979. "Run `cvs tag -d TAG' on all selected files.
  1980. With prefix argument, prompt for cvs flags."
  1981. (interactive
  1982. (list (setq cvs-tag-name
  1983. (cvs-query-read cvs-tag-name "Tag to delete: "
  1984. cvs-qtypedesc-tag))
  1985. (cvs-flags-query 'cvs-tag-flags "tag flags")))
  1986. (cvs-mode-do "tag" (append '("-d") flags (list tag))
  1987. (when cvs-force-dir-tag 'tag)))
  1988. ;; Byte compile files.
  1989. (defun-cvs-mode cvs-mode-byte-compile-files ()
  1990. "Run byte-compile-file on all selected files with '.el' extension."
  1991. (interactive)
  1992. (let ((marked (cvs-get-marked (cvs-ignore-marks-p "byte-compile"))))
  1993. (dolist (fi marked)
  1994. (let ((filename (cvs-fileinfo->full-name fi)))
  1995. (when (string-match "\\.el\\'" filename)
  1996. (byte-compile-file filename))))))
  1997. ;; ChangeLog support.
  1998. (defvar add-log-buffer-file-name-function)
  1999. (defun-cvs-mode cvs-mode-add-change-log-entry-other-window ()
  2000. "Add a ChangeLog entry in the ChangeLog of the current directory."
  2001. (interactive)
  2002. ;; Require `add-log' explicitly, because if it gets autoloaded when we call
  2003. ;; add-change-log-entry-other-window below, the
  2004. ;; add-log-buffer-file-name-function ends up unbound when we leave the `let'.
  2005. (require 'add-log)
  2006. (dolist (fi (cvs-mode-marked nil nil))
  2007. (let* ((default-directory (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
  2008. (add-log-buffer-file-name-function
  2009. (lambda ()
  2010. (let ((file (expand-file-name (cvs-fileinfo->file fi))))
  2011. (if (file-directory-p file)
  2012. ;; Be careful to use a directory name, otherwise add-log
  2013. ;; starts looking for a ChangeLog file in the
  2014. ;; parent dir.
  2015. (file-name-as-directory file)
  2016. file)))))
  2017. (kill-local-variable 'change-log-default-name)
  2018. (save-excursion (add-change-log-entry-other-window)))))
  2019. ;; interactive commands to set optional flags
  2020. (defun cvs-mode-set-flags (flag)
  2021. "Ask for new setting of cvs-FLAG-flags."
  2022. (interactive
  2023. (list (completing-read
  2024. "Which flag: "
  2025. '("cvs" "diff" "update" "status" "log" "tag" ;"rtag"
  2026. "commit" "remove" "undo" "checkout")
  2027. nil t)))
  2028. (let* ((sym (intern (concat "cvs-" flag "-flags"))))
  2029. (let ((current-prefix-arg '(16)))
  2030. (cvs-flags-query sym (concat flag " flags")))))
  2031. ;;;;
  2032. ;;;; Utilities for the *cvs* buffer
  2033. ;;;;
  2034. (defun cvs-dir-member-p (fileinfo dir)
  2035. "Return true if FILEINFO represents a file in directory DIR."
  2036. (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
  2037. (string-prefix-p dir (cvs-fileinfo->dir fileinfo))))
  2038. (defun cvs-execute-single-file (fi extractor program constant-args)
  2039. "Internal function for `cvs-execute-single-file-list'."
  2040. (let* ((arg-list (funcall extractor fi))
  2041. (inhibit-read-only t))
  2042. ;; Execute the command unless extractor returned t.
  2043. (when (listp arg-list)
  2044. (let* ((args (append constant-args arg-list)))
  2045. (insert (format "=== %s %s\n\n"
  2046. program (split-string-and-unquote args)))
  2047. ;; FIXME: return the exit status?
  2048. (apply 'process-file program nil t t args)
  2049. (goto-char (point-max))))))
  2050. ;; FIXME: make this run in the background ala cvs-run-process...
  2051. (defun cvs-execute-single-file-list (fis extractor program constant-args)
  2052. "Run PROGRAM on all elements on FIS.
  2053. CONSTANT-ARGS is a list of strings to pass as arguments to PROGRAM.
  2054. The arguments given to the program will be CONSTANT-ARGS followed by
  2055. the list that EXTRACTOR returns.
  2056. EXTRACTOR will be called once for each file on FIS. It is given
  2057. one argument, the cvs-fileinfo. It can return t, which means ignore
  2058. this file, or a list of arguments to send to the program."
  2059. (dolist (fi fis)
  2060. (cvs-execute-single-file fi extractor program constant-args)))
  2061. (defun cvs-revert-if-needed (fis)
  2062. (dolist (fileinfo fis)
  2063. (let* ((file (cvs-fileinfo->full-name fileinfo))
  2064. (buffer (find-buffer-visiting file)))
  2065. ;; For a revert to happen the user must be editing the file...
  2066. (unless (or (null buffer)
  2067. (memq (cvs-fileinfo->type fileinfo) '(MESSAGE UNKNOWN))
  2068. ;; FIXME: check whether revert is really needed.
  2069. ;; `(verify-visited-file-modtime buffer)' doesn't cut it
  2070. ;; because it only looks at the time stamp (it ignores
  2071. ;; read-write changes) which is not changed by `commit'.
  2072. (buffer-modified-p buffer))
  2073. (with-current-buffer buffer
  2074. (ignore-errors
  2075. (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
  2076. ;; `preserve-modes' avoids changing the (minor) modes. But we
  2077. ;; do want to reset the mode for VC, so we do it explicitly.
  2078. (vc-refresh-state)
  2079. (when (eq (cvs-fileinfo->type fileinfo) 'CONFLICT)
  2080. (smerge-start-session))))))))
  2081. (defun cvs-change-cvsroot (newroot)
  2082. "Change the CVSROOT."
  2083. (interactive "DNew repository: ")
  2084. (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
  2085. (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
  2086. " Change cvs-cvsroot anyhow? ")))
  2087. (setq cvs-cvsroot newroot)))
  2088. ;;;;
  2089. ;;;; useful global settings
  2090. ;;;;
  2091. ;;
  2092. ;; Hook to allow calling PCL-CVS by visiting the /CVS subdirectory
  2093. ;;
  2094. ;;;###autoload
  2095. (defcustom cvs-dired-action 'cvs-quickdir
  2096. "The action to be performed when opening a CVS directory.
  2097. Sensible values are `cvs-examine', `cvs-status' and `cvs-quickdir'."
  2098. :group 'pcl-cvs
  2099. :type '(choice (const cvs-examine) (const cvs-status) (const cvs-quickdir)))
  2100. ;;;###autoload
  2101. (defcustom cvs-dired-use-hook '(4)
  2102. "Whether or not opening a CVS directory should run PCL-CVS.
  2103. A value of nil means never do it.
  2104. `always' means to always do it unless a prefix argument is given to the
  2105. command that prompted the opening of the directory.
  2106. Anything else means to do it only if the prefix arg is equal to this value."
  2107. :group 'pcl-cvs
  2108. :type '(choice (const :tag "Never" nil)
  2109. (const :tag "Always" always)
  2110. (const :tag "Prefix" (4))))
  2111. ;;;###autoload
  2112. (progn (defun cvs-dired-noselect (dir)
  2113. "Run `cvs-examine' if DIR is a CVS administrative directory.
  2114. The exact behavior is determined also by `cvs-dired-use-hook'."
  2115. (when (stringp dir)
  2116. (setq dir (directory-file-name dir))
  2117. (when (and (string= "CVS" (file-name-nondirectory dir))
  2118. (file-readable-p (expand-file-name "Entries" dir))
  2119. cvs-dired-use-hook
  2120. (if (eq cvs-dired-use-hook 'always)
  2121. (not current-prefix-arg)
  2122. (equal current-prefix-arg cvs-dired-use-hook)))
  2123. (save-excursion
  2124. (funcall cvs-dired-action (file-name-directory dir) t t))))))
  2125. ;;
  2126. ;; hook into VC
  2127. ;;
  2128. (add-hook 'vc-post-command-functions 'cvs-vc-command-advice)
  2129. (defun cvs-vc-command-advice (command files flags)
  2130. (when (and (equal command "cvs")
  2131. (progn
  2132. (while (and (stringp (car flags))
  2133. (string-match "\\`-" (car flags)))
  2134. (pop flags))
  2135. ;; don't parse output we don't understand.
  2136. (member (car flags) cvs-parse-known-commands))
  2137. ;; Don't parse "update -p" output.
  2138. (not (and (member (car flags) '("update" "checkout"))
  2139. (let ((found-p nil))
  2140. (dolist (flag flags found-p)
  2141. (if (equal flag "-p") (setq found-p t)))))))
  2142. (save-current-buffer
  2143. (let ((buffer (current-buffer))
  2144. (dir default-directory)
  2145. (cvs-from-vc t))
  2146. (dolist (cvs-buf (buffer-list))
  2147. (set-buffer cvs-buf)
  2148. ;; look for a corresponding pcl-cvs buffer
  2149. (when (and (eq major-mode 'cvs-mode)
  2150. (string-prefix-p default-directory dir))
  2151. (let ((subdir (substring dir (length default-directory))))
  2152. (set-buffer buffer)
  2153. (set (make-local-variable 'cvs-buffer) cvs-buf)
  2154. ;; `cvs -q add file' produces no useful output :-(
  2155. (when (and (equal (car flags) "add")
  2156. (goto-char (point-min))
  2157. (looking-at ".*to add this file permanently\n\\'"))
  2158. (dolist (file (if (listp files) files (list files)))
  2159. (insert (format-message
  2160. "cvs add: scheduling file `%s' for addition\n"
  2161. (file-name-nondirectory file)))))
  2162. ;; VC never (?) does `cvs -n update' so dcd=nil
  2163. ;; should probably always be the right choice.
  2164. (cvs-parse-process nil subdir))))))))
  2165. ;;
  2166. ;; Hook into write-buffer
  2167. ;;
  2168. (defun cvs-mark-buffer-changed ()
  2169. (let* ((file (expand-file-name buffer-file-name))
  2170. (version (and (fboundp 'vc-backend)
  2171. (eq (vc-backend file) 'CVS)
  2172. (vc-working-revision file))))
  2173. (when version
  2174. (save-excursion
  2175. (dolist (cvs-buf (buffer-list))
  2176. (set-buffer cvs-buf)
  2177. ;; look for a corresponding pcl-cvs buffer
  2178. (when (and (eq major-mode 'cvs-mode)
  2179. (string-prefix-p default-directory file))
  2180. (let* ((file (substring file (length default-directory)))
  2181. (fi (cvs-create-fileinfo
  2182. (if (string= "0" version)
  2183. 'ADDED 'MODIFIED)
  2184. (or (file-name-directory file) "")
  2185. (file-name-nondirectory file)
  2186. "cvs-mark-buffer-changed")))
  2187. (cvs-addto-collection cvs-cookies fi))))))))
  2188. (add-hook 'after-save-hook 'cvs-mark-buffer-changed)
  2189. (defun cvs-insert-visited-file ()
  2190. (let* ((file (expand-file-name buffer-file-name))
  2191. (version (and (fboundp 'vc-backend)
  2192. (eq (vc-backend file) 'CVS)
  2193. (vc-working-revision file))))
  2194. (when version
  2195. (save-current-buffer
  2196. (dolist (cvs-buf (buffer-list))
  2197. (set-buffer cvs-buf)
  2198. ;; look for a corresponding pcl-cvs buffer
  2199. (when (and (eq major-mode 'cvs-mode)
  2200. (string-prefix-p default-directory file))
  2201. (cvs-insert-file file)))))))
  2202. (add-hook 'find-file-hook 'cvs-insert-visited-file 'append)
  2203. (provide 'pcvs)
  2204. ;;; pcvs.el ends here