pcvs.el 91 KB

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