123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473 |
- (eval-when-compile
- (require 'cl)
- (require 'vc))
- (defgroup vc-rcs nil
- "VC RCS backend."
- :version "24.1"
- :group 'vc)
- (defcustom vc-rcs-release nil
- "The release number of your RCS installation, as a string.
- If nil, VC itself computes this value when it is first needed."
- :type '(choice (const :tag "Auto" nil)
- (string :tag "Specified")
- (const :tag "Unknown" unknown))
- :group 'vc-rcs)
- (defcustom vc-rcs-register-switches nil
- "Switches for registering a file in RCS.
- A string or list of strings passed to the checkin program by
- \\[vc-register]. If nil, use the value of `vc-register-switches'.
- If t, use no switches."
- :type '(choice (const :tag "Unspecified" nil)
- (const :tag "None" t)
- (string :tag "Argument String")
- (repeat :tag "Argument List" :value ("") string))
- :version "21.1"
- :group 'vc-rcs)
- (defcustom vc-rcs-diff-switches nil
- "String or list of strings specifying switches for RCS diff under VC.
- If nil, use the value of `vc-diff-switches'. If t, use no switches."
- :type '(choice (const :tag "Unspecified" nil)
- (const :tag "None" t)
- (string :tag "Argument String")
- (repeat :tag "Argument List" :value ("") string))
- :version "21.1"
- :group 'vc-rcs)
- (defcustom vc-rcs-header '("\$Id\$")
- "Header keywords to be inserted by `vc-insert-headers'."
- :type '(repeat string)
- :version "24.1"
- :group 'vc-rcs)
- (defcustom vc-rcsdiff-knows-brief nil
- "Indicates whether rcsdiff understands the --brief option.
- The value is either `yes', `no', or nil. If it is nil, VC tries
- to use --brief and sets this variable to remember whether it worked."
- :type '(choice (const :tag "Work out" nil) (const yes) (const no))
- :group 'vc-rcs)
- (defcustom vc-rcs-master-templates
- (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
- "Where to look for RCS master files.
- For a description of possible values, see `vc-check-master-templates'."
- :type '(choice (const :tag "Use standard RCS file names"
- '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
- (repeat :tag "User-specified"
- (choice string
- function)))
- :version "21.1"
- :group 'vc-rcs)
- (defun vc-rcs-revision-granularity () 'file)
- (defun vc-rcs-checkout-model (files)
- "RCS-specific version of `vc-checkout-model'."
- (let ((file (if (consp files) (car files) files))
- result)
- (when vc-consult-headers
- (vc-file-setprop file 'vc-checkout-model nil)
- (vc-rcs-consult-headers file)
- (setq result (vc-file-getprop file 'vc-checkout-model)))
- (or result
- (progn (vc-rcs-fetch-master-state file)
- (vc-file-getprop file 'vc-checkout-model)))))
- (progn
- (defun vc-rcs-registered (f) (vc-default-registered 'RCS f)))
- (defun vc-rcs-state (file)
- "Implementation of `vc-state' for RCS."
- (if (not (vc-rcs-registered file))
- 'unregistered
- (or (boundp 'vc-rcs-headers-result)
- (and vc-consult-headers
- (vc-rcs-consult-headers file)))
- (let ((state
-
-
-
- (vc-rcs-fetch-master-state file
- (vc-file-getprop file
- 'vc-working-revision))))
- (if (not (eq state 'up-to-date))
- state
- (if (vc-workfile-unchanged-p file)
- 'up-to-date
- (if (eq (vc-rcs-checkout-model (list file)) 'locking)
- 'unlocked-changes
- 'edited))))))
- (defun vc-rcs-state-heuristic (file)
- "State heuristic for RCS."
- (let (vc-rcs-headers-result)
- (if (and vc-consult-headers
- (setq vc-rcs-headers-result
- (vc-rcs-consult-headers file))
- (eq vc-rcs-headers-result 'rev-and-lock))
- (let ((state (vc-file-getprop file 'vc-state)))
-
-
-
- (if (and (eq state 'up-to-date)
- (not (vc-mistrust-permissions file))
- (file-exists-p file))
- (cond
- ((string-match ".rw..-..-." (nth 8 (file-attributes file)))
- (vc-file-setprop file 'vc-checkout-model 'implicit)
- (setq state
- (if (vc-rcs-workfile-is-newer file)
- 'edited
- 'up-to-date)))
- ((string-match ".r-..-..-." (nth 8 (file-attributes file)))
- (vc-file-setprop file 'vc-checkout-model 'locking))))
- state)
- (if (not (vc-mistrust-permissions file))
- (let* ((attributes (file-attributes file 'string))
- (owner-name (nth 2 attributes))
- (permissions (nth 8 attributes)))
- (cond ((and permissions (string-match ".r-..-..-." permissions))
- (vc-file-setprop file 'vc-checkout-model 'locking)
- 'up-to-date)
- ((and permissions (string-match ".rw..-..-." permissions))
- (if (eq (vc-rcs-checkout-model file) 'locking)
- (if (file-ownership-preserved-p file)
- 'edited
- owner-name)
- (if (vc-rcs-workfile-is-newer file)
- 'edited
- 'up-to-date)))
- (t
-
-
- (vc-rcs-state file))))
- (vc-rcs-state file)))))
- (defun vc-rcs-dir-status (dir update-function)
-
-
-
-
-
-
- (let ((flist (vc-expand-dirs (list dir)))
- (result nil))
- (dolist (file flist)
- (let ((state (vc-state file))
- (frel (file-relative-name file)))
- (when (and (eq (vc-backend file) 'RCS)
- (not (eq state 'up-to-date)))
- (push (list frel state) result))))
- (funcall update-function result)))
- (defun vc-rcs-working-revision (file)
- "RCS-specific version of `vc-working-revision'."
- (or (and vc-consult-headers
- (vc-rcs-consult-headers file)
- (vc-file-getprop file 'vc-working-revision))
- (progn
- (vc-rcs-fetch-master-state file)
- (vc-file-getprop file 'vc-working-revision))))
- (defun vc-rcs-latest-on-branch-p (file &optional version)
- "Return non-nil if workfile version of FILE is the latest on its branch.
- When VERSION is given, perform check for that version."
- (unless version (setq version (vc-working-revision file)))
- (with-temp-buffer
- (string= version
- (if (vc-rcs-trunk-p version)
- (progn
-
- (vc-insert-file (vc-name file) "^[0-9]")
- (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
-
-
- (vc-insert-file (vc-name file) "^desc")
- (vc-rcs-find-most-recent-rev (vc-branch-part version))))))
- (defun vc-rcs-workfile-unchanged-p (file)
- "RCS-specific implementation of `vc-workfile-unchanged-p'."
-
-
- (let* ((version (concat "-r" (vc-working-revision file)))
- (status (if (eq vc-rcsdiff-knows-brief 'no)
- (vc-do-command "*vc*" 1 "rcsdiff" file version)
- (vc-do-command "*vc*" 2 "rcsdiff" file "--brief" version))))
- (if (eq status 2)
- (if (not vc-rcsdiff-knows-brief)
- (setq vc-rcsdiff-knows-brief 'no
- status (vc-do-command "*vc*" 1 "rcsdiff" file version))
- (error "rcsdiff failed"))
- (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
-
- (zerop status)))
- (defun vc-rcs-create-repo ()
- "Create a new RCS repository."
-
- (make-directory "RCS"))
- (defun vc-rcs-register (files &optional rev comment)
- "Register FILES into the RCS version-control system.
- REV is the optional revision number for the files. COMMENT can be used
- to provide an initial description for each FILES.
- Passes either `vc-rcs-register-switches' or `vc-register-switches'
- to the RCS command.
- Automatically retrieve a read-only version of the file with keywords
- expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
- (let (subdir name)
-
- (when rev (unless comment (setq comment "")))
- (dolist (file files)
- (and (not (file-exists-p
- (setq subdir (expand-file-name "RCS"
- (file-name-directory file)))))
- (not (directory-files (file-name-directory file)
- nil ".*,v$" t))
- (yes-or-no-p "Create RCS subdirectory? ")
- (make-directory subdir))
- (apply 'vc-do-command "*vc*" 0 "ci" file
-
- (and (vc-rcs-release-p "5.6.4") "-i")
- (concat (if vc-keep-workfiles "-u" "-r") rev)
- (and comment (concat "-t-" comment))
- (vc-switches 'RCS 'register))
-
- (with-current-buffer "*vc*"
- (goto-char (point-min))
- (if (not (setq name
- (if (looking-at (concat "^\\(.*\\) <-- "
- (file-name-nondirectory file)))
- (match-string 1))))
-
-
-
- (vc-rcs-registered file)
- (vc-file-setprop file 'vc-name
- (if (file-name-absolute-p name)
- name
- (expand-file-name
- name
- (file-name-directory file))))))
- (vc-file-setprop file 'vc-working-revision
- (if (re-search-forward
- "^initial revision: \\([0-9.]+\\).*\n"
- nil t)
- (match-string 1))))))
- (defun vc-rcs-responsible-p (file)
- "Return non-nil if RCS thinks it would be responsible for registering FILE."
-
- (file-directory-p (expand-file-name "RCS"
- (if (file-directory-p file)
- file
- (file-name-directory file)))))
- (defun vc-rcs-receive-file (file rev)
- "Implementation of receive-file for RCS."
- (let ((checkout-model (vc-rcs-checkout-model (list file))))
- (vc-rcs-register file rev "")
- (when (eq checkout-model 'implicit)
- (vc-rcs-set-non-strict-locking file))
- (vc-rcs-set-default-branch file (concat rev ".1"))))
- (defun vc-rcs-unregister (file)
- "Unregister FILE from RCS.
- If this leaves the RCS subdirectory empty, ask the user
- whether to remove it."
- (let* ((master (vc-name file))
- (dir (file-name-directory master))
- (backup-info (find-backup-file-name master)))
- (if (not backup-info)
- (delete-file master)
- (rename-file master (car backup-info) 'ok-if-already-exists)
- (dolist (f (cdr backup-info)) (ignore-errors (delete-file f))))
- (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
-
-
- (not (directory-files dir nil
- "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
- (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
- (delete-directory dir))))
- (defun vc-rcs-checkin (files rev comment)
- "RCS-specific version of `vc-backend-checkin'."
- (let ((switches (vc-switches 'RCS 'checkin)))
-
- (dolist (file (vc-expand-dirs files))
- (let ((old-version (vc-working-revision file)) new-version
- (default-branch (vc-file-getprop file 'vc-rcs-default-branch)))
-
-
- (and (not rev)
- default-branch
- (string-match (concat "^" (regexp-quote old-version) "\\.")
- default-branch)
- (setq rev default-branch)
- (setq switches (cons "-f" switches)))
- (if (and (not rev) old-version)
- (setq rev (vc-branch-part old-version)))
- (apply 'vc-do-command "*vc*" 0 "ci" (vc-name file)
-
- (and (vc-rcs-release-p "5.6.4") "-j")
- (concat (if vc-keep-workfiles "-u" "-r") rev)
- (concat "-m" comment)
- switches)
- (vc-file-setprop file 'vc-working-revision nil)
-
- (set-buffer "*vc*")
- (goto-char (point-min))
- (when (or (re-search-forward
- "new revision: \\([0-9.]+\\);" nil t)
- (re-search-forward
- "reverting to previous revision \\([0-9.]+\\)" nil t))
- (setq new-version (match-string 1))
- (vc-file-setprop file 'vc-working-revision new-version))
-
-
- (cond
- ((and old-version new-version
- (not (string= (vc-branch-part old-version)
- (vc-branch-part new-version))))
- (vc-rcs-set-default-branch file
- (if (vc-rcs-trunk-p new-version) nil
- (vc-branch-part new-version)))
-
-
- (if (not (vc-rcs-release-p "5.6.2"))
-
-
- (vc-do-command "*vc*" 1 "rcs" (vc-name file)
- (concat "-u" old-version)))))))))
- (defun vc-rcs-find-revision (file rev buffer)
- (apply 'vc-do-command
- (or buffer "*vc*") 0 "co" (vc-name file)
- "-q"
- (concat "-p" rev)
- (vc-switches 'RCS 'checkout)))
- (defun vc-rcs-checkout (file &optional editable rev)
- "Retrieve a copy of a saved version of FILE. If FILE is a directory,
- attempt the checkout for all registered files beneath it."
- (if (file-directory-p file)
- (mapc 'vc-rcs-checkout (vc-expand-dirs (list file)))
- (let ((file-buffer (get-file-buffer file))
- switches)
- (message "Checking out %s..." file)
- (save-excursion
-
- (if file-buffer (set-buffer file-buffer))
- (setq switches (vc-switches 'RCS 'checkout))
-
-
-
- (let ((default-directory default-directory))
- (save-excursion
-
-
- (setq default-directory (file-name-directory file))
- (let (new-version)
-
-
- (and rev (string= rev "")
- (vc-rcs-set-default-branch file nil))
-
- (apply 'vc-do-command
- "*vc*" 0 "co" (vc-name file)
-
-
- (if (eq (vc-rcs-checkout-model (list file)) 'implicit) "-f")
- (if editable "-l")
- (if (stringp rev)
-
- (concat "-r" rev)
- (let ((workrev (vc-working-revision file)))
- (if workrev
- (concat "-r"
- (if (not rev)
-
-
- workrev
-
- (if (not (vc-rcs-trunk-p workrev))
-
- (vc-branch-part workrev)
-
- (vc-rcs-set-default-branch file
- nil)
- ""))))))
- switches)
-
- (with-current-buffer "*vc*"
- (setq new-version
- (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
- (vc-file-setprop file 'vc-working-revision new-version)
-
- (and rev (not (string= rev ""))
- (vc-rcs-set-default-branch
- file
- (if (vc-rcs-latest-on-branch-p file new-version)
- (if (vc-rcs-trunk-p new-version) nil
- (vc-branch-part new-version))
- new-version)))))
- (message "Checking out %s...done" file))))))
- (defun vc-rcs-rollback (files)
- "Roll back, undoing the most recent checkins of FILES. Directories are
- expanded to all registered subfiles in them."
- (if (not files)
- (error "RCS backend doesn't support directory-level rollback"))
- (dolist (file (vc-expand-dirs files))
- (let* ((discard (vc-working-revision file))
- (previous (if (vc-rcs-trunk-p discard) "" (vc-branch-part discard)))
- (config (current-window-configuration))
- (done nil))
- (if (null (yes-or-no-p (format "Remove version %s from %s history? "
- discard file)))
- (error "Aborted"))
- (message "Removing revision %s from %s." discard file)
- (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-o" discard))
-
-
-
-
- (while (not done)
- (condition-case err
- (progn
- (vc-do-command "*vc*" 0 "co" (vc-name file) "-f"
- (concat "-u" previous))
- (setq done t))
- (error (set-buffer "*vc*")
- (goto-char (point-min))
- (if (search-forward "no side branches present for" nil t)
- (progn (setq previous (vc-branch-part previous))
- (vc-rcs-set-default-branch file previous)
-
-
-
- (set-window-configuration config))
-
- (signal (car err) (cdr err)))))))))
- (defun vc-rcs-revert (file &optional contents-done)
- "Revert FILE to the version it was based on. If FILE is a directory,
- revert all registered files beneath it."
- (if (file-directory-p file)
- (mapc 'vc-rcs-revert (vc-expand-dirs (list file)))
- (vc-do-command "*vc*" 0 "co" (vc-name file) "-f"
- (concat (if (eq (vc-state file) 'edited) "-u" "-r")
- (vc-working-revision file)))))
- (defun vc-rcs-merge (file first-version &optional second-version)
- "Merge changes into current working copy of FILE.
- The changes are between FIRST-VERSION and SECOND-VERSION."
- (vc-do-command "*vc*" 1 "rcsmerge" (vc-name file)
- "-kk"
- (concat "-r" first-version)
- (if second-version (concat "-r" second-version))))
- (defun vc-rcs-steal-lock (file &optional rev)
- "Steal the lock on the current workfile for FILE and revision REV.
- If FILE is a directory, steal the lock on all registered files beneath it.
- Needs RCS 5.6.2 or later for -M."
- (if (file-directory-p file)
- (mapc 'vc-rcs-steal-lock (vc-expand-dirs (list file)))
- (vc-do-command "*vc*" 0 "rcs" (vc-name file) "-M" (concat "-u" rev))
-
-
- (vc-do-command "*vc*" 0 "co" (vc-name file) "-f" (concat "-l" rev))))
- (defun vc-rcs-modify-change-comment (files rev comment)
- "Modify the change comments change on FILES on a specified REV. If FILE is a
- directory the operation is applied to all registered files beneath it."
- (dolist (file (vc-expand-dirs files))
- (vc-do-command "*vc*" 0 "rcs" (vc-name file)
- (concat "-m" rev ":" comment))))
- (defun vc-rcs-print-log-cleanup ()
- (let ((inhibit-read-only t))
- (goto-char (point-max))
- (forward-line -1)
- (while (looking-at "=*\n")
- (delete-char (- (match-end 0) (match-beginning 0)))
- (forward-line -1))
- (goto-char (point-min))
- (when (looking-at "[\b\t\n\v\f\r ]+")
- (delete-char (- (match-end 0) (match-beginning 0))))))
- (defun vc-rcs-print-log (files buffer &optional shortlog start-revision-ignored limit)
- "Get change log associated with FILE. If FILE is a
- directory the operation is applied to all registered files beneath it."
- (vc-do-command (or buffer "*vc*") 0 "rlog" (mapcar 'vc-name (vc-expand-dirs files)))
- (with-current-buffer (or buffer "*vc*")
- (vc-rcs-print-log-cleanup))
- (when limit 'limit-unsupported))
- (defun vc-rcs-diff (files &optional oldvers newvers buffer)
- "Get a difference report using RCS between two sets of files."
- (apply 'vc-do-command (or buffer "*vc-diff*")
- 1
- "rcsdiff" (vc-expand-dirs files)
- (append (list "-q"
- (and oldvers (concat "-r" oldvers))
- (and newvers (concat "-r" newvers)))
- (vc-switches 'RCS 'diff))))
- (defun vc-rcs-comment-history (file)
- "Return a string with all log entries stored in BACKEND for FILE."
- (with-current-buffer "*vc*"
-
- (vc-call-backend (vc-backend file) 'print-log (list file))
-
- (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
- "\\(branches: .*;\n\\)?"
- "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
- (goto-char (point-max)) (forward-line -1)
- (while (looking-at "=*\n")
- (delete-char (- (match-end 0) (match-beginning 0)))
- (forward-line -1))
- (goto-char (point-min))
- (if (looking-at "[\b\t\n\v\f\r ]+")
- (delete-char (- (match-end 0) (match-beginning 0))))
- (goto-char (point-min))
- (re-search-forward separator nil t)
- (delete-region (point-min) (point))
- (while (re-search-forward separator nil t)
- (delete-region (match-beginning 0) (match-end 0))))
-
- (buffer-string)))
- (defun vc-rcs-annotate-command (file buffer &optional revision)
- "Annotate FILE, inserting the results in BUFFER.
- Optional arg REVISION is a revision to annotate from."
- (vc-setup-buffer buffer)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (let* ((tree (with-temp-buffer
- (insert-file-contents (vc-rcs-registered file))
- (vc-rcs-parse)))
- (revisions (cdr (assq 'revisions tree)))
-
- (cur (cdr (assq 'head (cdr (assq 'headers tree)))))
-
- (meta (cdr (assoc cur revisions)))
-
- p s
-
-
-
-
-
-
- nbls
-
-
-
-
-
-
- prda
-
-
-
-
- path
-
- pre)
- (unless revision
- (setq revision cur))
- (unless (assoc revision revisions)
- (error "No such revision: %s" revision))
-
- (let ((par revision)
- bpt kids)
- (while (setq bpt (vc-branch-part par)
- par (vc-branch-part bpt))
- (setq kids (cdr (assq 'branches (cdr (assoc par revisions)))))
-
- (while (not (string= bpt (vc-branch-part (car kids))))
- (setq kids (cdr kids)))
- (push (cons par (car kids)) nbls)))
-
- (set-buffer buffer)
- (insert (cdr (assq 'text meta)))
-
-
-
- (flet ((r/d/a () (vector pre
- (cdr (assq 'date meta))
- (cdr (assq 'author meta)))))
- (while (when (setq pre cur cur (cdr (assq 'next meta)))
- (not (string= "" cur)))
- (setq
-
-
-
-
- prda (when (or prda (string= (if nbls (caar nbls) revision) pre))
- (r/d/a))
- meta (cdr (assoc cur revisions)))
-
-
-
-
-
-
-
-
-
- (dolist (insn (cdr (assq :insn meta)))
- (goto-char (point-min))
- (forward-line (1- (pop insn)))
- (setq p (point))
- (case (pop insn)
- (k (setq s (buffer-substring-no-properties
- p (progn (forward-line (car insn))
- (point))))
- (when prda
- (push `(,p . ,(propertize s :vc-rcs-r/d/a prda)) path))
- (delete-region p (point)))
- (i (setq s (car insn))
- (when prda
- (push `(,p . ,(length s)) path))
- (insert s)))))
-
-
-
- (put-text-property (point-min) (point-max) :vc-rcs-r/d/a (r/d/a))
-
- (dolist (insn path)
- (goto-char (pop insn))
- (if (stringp insn)
- (insert insn)
- (delete-char insn)))
-
-
-
- (while nbls
- (setq pre (cdr (pop nbls)))
- (while (progn
- (setq meta (cdr (assoc pre revisions))
- prda nil)
- (dolist (insn (cdr (assq :insn meta)))
- (goto-char (point-min))
- (forward-line (1- (pop insn)))
- (case (pop insn)
- (k (delete-region
- (point) (progn (forward-line (car insn))
- (point))))
- (i (insert (propertize
- (car insn)
- :vc-rcs-r/d/a
- (or prda (setq prda (r/d/a))))))))
- (prog1 (not (string= (if nbls (caar nbls) revision) pre))
- (setq pre (cdr (assq 'next meta)))))))))
-
-
-
-
-
- (let ((ht (make-hash-table :test 'eq))
- (me (user-login-name))
- (maxw 0)
- (all-me t)
- rda w a)
- (goto-char (point-max))
- (while (not (bobp))
- (forward-line -1)
- (setq rda (get-text-property (point) :vc-rcs-r/d/a))
- (unless (gethash rda ht)
- (setq a (aref rda 2)
- all-me (and all-me (string= a me)))
- (puthash rda (setq w (+ (length (aref rda 0))
- (length a)))
- ht)
- (setq maxw (max w maxw))))
- (let ((padding (make-string maxw 32)))
- (flet ((pad (w) (substring-no-properties padding w))
- (render (rda &rest ls)
- (propertize
- (apply 'concat
- (format-time-string "%Y-%m-%d" (aref rda 1))
- " "
- (aref rda 0)
- ls)
- :vc-annotate-prefix t
- :vc-rcs-r/d/a rda)))
- (maphash
- (if all-me
- (lambda (rda w)
- (puthash rda (render rda (pad w) ": ") ht))
- (lambda (rda w)
- (puthash rda (render rda " " (pad w) " " (aref rda 2) ": ") ht)))
- ht)))
- (while (not (eobp))
- (insert (gethash (get-text-property (point) :vc-rcs-r/d/a) ht))
- (forward-line 1))))
- (declare-function vc-annotate-convert-time "vc-annotate" (time))
- (defun vc-rcs-annotate-current-time ()
- "Return the current time, based at midnight of the current day, and
- encoded as fractional days."
- (vc-annotate-convert-time
- (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
- (defun vc-rcs-annotate-time ()
- "Return the time of the next annotation (as fraction of days)
- systime, or nil if there is none. Also, reposition point."
- (unless (eobp)
- (prog1 (vc-annotate-convert-time
- (aref (get-text-property (point) :vc-rcs-r/d/a) 1))
- (goto-char (next-single-property-change (point) :vc-annotate-prefix)))))
- (defun vc-rcs-annotate-extract-revision-at-line ()
- (aref (get-text-property (point) :vc-rcs-r/d/a) 0))
- (defun vc-rcs-create-tag (dir name branchp)
- (when branchp
- (error "RCS backend does not support module branches"))
- (let ((result (vc-tag-precondition dir)))
- (if (stringp result)
- (error "File %s is not up-to-date" result)
- (vc-file-tree-walk
- dir
- (lambda (f)
- (vc-do-command "*vc*" 0 "rcs" (vc-name f) (concat "-n" name ":")))))))
- (defun vc-rcs-trunk-p (rev)
- "Return t if REV is a revision on the trunk."
- (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
- (defun vc-rcs-minor-part (rev)
- "Return the minor revision number of a revision number REV."
- (string-match "[0-9]+\\'" rev)
- (substring rev (match-beginning 0) (match-end 0)))
- (defun vc-rcs-previous-revision (file rev)
- "Return the revision number immediately preceding REV for FILE,
- or nil if there is no previous revision. This default
- implementation works for MAJOR.MINOR-style revision numbers as
- used by RCS and CVS."
- (let ((branch (vc-branch-part rev))
- (minor-num (string-to-number (vc-rcs-minor-part rev))))
- (when branch
- (if (> minor-num 1)
-
- (concat branch "." (number-to-string (1- minor-num)))
- (if (vc-rcs-trunk-p rev)
-
-
- nil
-
-
- (vc-branch-part branch))))))
- (defun vc-rcs-next-revision (file rev)
- "Return the revision number immediately following REV for FILE,
- or nil if there is no next revision. This default implementation
- works for MAJOR.MINOR-style revision numbers as used by RCS
- and CVS."
- (when (not (string= rev (vc-working-revision file)))
- (let ((branch (vc-branch-part rev))
- (minor-num (string-to-number (vc-rcs-minor-part rev))))
- (concat branch "." (number-to-string (1+ minor-num))))))
- (defun vc-rcs-update-changelog (files)
- "Default implementation of update-changelog.
- Uses `rcs2log' which only works for RCS and CVS."
-
- (let ((odefault default-directory)
- (changelog (find-change-log))
-
- (tempfile (make-temp-file
- (expand-file-name "vc"
- (or small-temporary-file-directory
- temporary-file-directory))))
- (login-name (or user-login-name
- (format "uid%d" (number-to-string (user-uid)))))
- (full-name (or add-log-full-name
- (user-full-name)
- (user-login-name)
- (format "uid%d" (number-to-string (user-uid)))))
- (mailing-address (or add-log-mailing-address
- user-mail-address)))
- (find-file-other-window changelog)
- (barf-if-buffer-read-only)
- (vc-buffer-sync)
- (undo-boundary)
- (goto-char (point-min))
- (push-mark)
- (message "Computing change log entries...")
- (message "Computing change log entries... %s"
- (unwind-protect
- (progn
- (setq default-directory odefault)
- (if (eq 0 (apply 'call-process
- (expand-file-name "rcs2log"
- exec-directory)
- nil (list t tempfile) nil
- "-c" changelog
- "-u" (concat login-name
- "\t" full-name
- "\t" mailing-address)
- (mapcar
- (lambda (f)
- (file-relative-name
- (expand-file-name f odefault)))
- files)))
- "done"
- (pop-to-buffer (get-buffer-create "*vc*"))
- (erase-buffer)
- (insert-file-contents tempfile)
- "failed"))
- (setq default-directory (file-name-directory changelog))
- (delete-file tempfile)))))
- (defun vc-rcs-check-headers ()
- "Check if the current file has any headers in it."
- (save-excursion
- (goto-char (point-min))
- (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
- \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
- (defun vc-rcs-clear-headers ()
- "Implementation of vc-clear-headers for RCS."
- (let ((case-fold-search nil))
- (goto-char (point-min))
- (while (re-search-forward
- (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
- "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
- nil t)
- (replace-match "$\\1$"))))
- (defun vc-rcs-rename-file (old new)
-
- (vc-rename-master (vc-name old) new vc-rcs-master-templates))
- (defun vc-rcs-find-file-hook ()
-
-
-
- (and (stringp (vc-state buffer-file-name 'RCS))
- (setq buffer-read-only t)))
- (defun vc-rcs-workfile-is-newer (file)
- "Return non-nil if FILE is newer than its RCS master.
- This likely means that FILE has been changed with respect
- to its master version."
- (let ((file-time (nth 5 (file-attributes file)))
- (master-time (nth 5 (file-attributes (vc-name file)))))
- (or (> (nth 0 file-time) (nth 0 master-time))
- (and (= (nth 0 file-time) (nth 0 master-time))
- (> (nth 1 file-time) (nth 1 master-time))))))
- (defun vc-rcs-find-most-recent-rev (branch)
- "Find most recent revision on BRANCH."
- (goto-char (point-min))
- (let ((latest-rev -1) value)
- (while (re-search-forward (concat "^\\(" (regexp-quote branch)
- "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
- nil t)
- (let ((rev (string-to-number (match-string 2))))
- (when (< latest-rev rev)
- (setq latest-rev rev)
- (setq value (match-string 1)))))
- (or value
- (vc-branch-part branch))))
- (defun vc-rcs-fetch-master-state (file &optional working-revision)
- "Compute the master file's idea of the state of FILE.
- If a WORKING-REVISION is given, compute the state of that version,
- otherwise determine the workfile version based on the master file.
- This function sets the properties `vc-working-revision' and
- `vc-checkout-model' to their correct values, based on the master
- file."
- (with-temp-buffer
- (if (or (not (vc-insert-file (vc-name file) "^[0-9]"))
- (progn (goto-char (point-min))
- (not (looking-at "^head[ \t\n]+[^;]+;$"))))
- (error "File %s is not an RCS master file" (vc-name file)))
- (let ((workfile-is-latest nil)
- (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
- (vc-file-setprop file 'vc-rcs-default-branch default-branch)
- (unless working-revision
-
-
-
-
- (cond
-
- ((or (not default-branch) (string= "" default-branch))
- (setq working-revision
- (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
- (setq workfile-is-latest t))
-
- ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
- default-branch)
- (setq working-revision default-branch))
-
- (t (vc-insert-file (vc-name file) "^desc")
- (setq working-revision
- (vc-rcs-find-most-recent-rev default-branch))
- (setq workfile-is-latest t)))
- (vc-file-setprop file 'vc-working-revision working-revision))
-
- (goto-char (point-min))
- (vc-file-setprop file 'vc-checkout-model
- (if (re-search-forward ";[ \t\n]*strict;" nil t)
- 'locking 'implicit))
-
- (goto-char (point-min))
- (let ((locking-user
- (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
- (regexp-quote working-revision)
- "[^0-9.]")
- 1)))
- (cond
-
- ((not locking-user)
- (if (or workfile-is-latest
- (vc-rcs-latest-on-branch-p file working-revision))
-
- 'up-to-date
-
- 'needs-update))
-
- ((and (stringp locking-user)
- (string= locking-user (vc-user-login-name file)))
-
- (if (or (eq (vc-file-getprop file 'vc-checkout-model) 'locking)
- workfile-is-latest
- (vc-rcs-latest-on-branch-p file working-revision))
- 'edited
-
-
-
-
- 'needs-merge))
-
- ((stringp locking-user)
- locking-user)
- (t
- (error "Error getting state of RCS file")))))))
- (defun vc-rcs-consult-headers (file)
- "Search for RCS headers in FILE, and set properties accordingly.
- Returns: nil if no headers were found
- 'rev if a workfile revision was found
- 'rev-and-lock if revision and lock info was found"
- (cond
- ((not (get-file-buffer file)) nil)
- ((let (status version locking-user)
- (with-current-buffer (get-file-buffer file)
- (save-excursion
- (goto-char (point-min))
- (cond
-
-
-
- ((or (and (search-forward "$Id\ : " nil t)
- (looking-at "[^ ]+ \\([0-9.]+\\) "))
- (and (progn (goto-char (point-min))
- (search-forward "$Header\ : " nil t))
- (looking-at "[^ ]+ \\([0-9.]+\\) ")))
- (goto-char (match-end 0))
-
- (setq version (match-string-no-properties 1))
-
- (cond
- ((looking-at
- (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] "
- "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? "
- "[^ ]+ [^ ]+ "))
- (goto-char (match-end 0))
- (cond
-
- ((looking-at "\\$")
- (setq locking-user 'none)
- (setq status 'rev-and-lock))
-
- ((looking-at "\\([^ ]+\\) \\$")
- (setq locking-user (match-string-no-properties 1))
- (setq status 'rev-and-lock))
-
- (nil)))
-
-
- (nil)))
-
-
- ((re-search-forward (concat "\\$"
- "Revision: \\([0-9.]+\\) \\$")
- nil t)
-
- (setq version (match-string-no-properties 1))
-
- (goto-char (point-min))
- (if (re-search-forward (concat "\\$" "Locker:") nil t)
- (cond ((looking-at " \\([^ ]+\\) \\$")
- (setq locking-user (match-string-no-properties 1))
- (setq status 'rev-and-lock))
- ((looking-at " *\\$")
- (setq locking-user 'none)
- (setq status 'rev-and-lock))
- (t
- (setq locking-user 'none)
- (setq status 'rev-and-lock)))
- (setq status 'rev)))
-
-
- (t nil))))
- (if status (vc-file-setprop file 'vc-working-revision version))
- (and (eq status 'rev-and-lock)
- (vc-file-setprop file 'vc-state
- (cond
- ((eq locking-user 'none) 'up-to-date)
- ((string= locking-user (vc-user-login-name file))
- 'edited)
- (t locking-user)))
-
-
-
-
-
-
-
-
- (not (vc-mistrust-permissions file))
- (vc-up-to-date-p file)
- (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
- (vc-file-setprop file 'vc-checkout-model 'locking)
- (vc-file-setprop file 'vc-checkout-model 'implicit)))
- status))))
- (defun vc-release-greater-or-equal (r1 r2)
- "Compare release numbers, represented as strings.
- Release components are assumed cardinal numbers, not decimal fractions
- \(5.10 is a higher release than 5.9\). Omitted fields are considered
- lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
- of the string is found, or a non-numeric component shows up \(5.6.7 is
- earlier than \"5.6.7 beta\", which is probably not what you want in
- some cases\). This code is suitable for existing RCS release numbers.
- CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
- (let (v1 v2 i1 i2)
- (catch 'done
- (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
- (setq i1 (match-end 0))
- (setq v1 (string-to-number (match-string 1 r1)))
- (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
- (setq i2 (match-end 0))
- (setq v2 (string-to-number (match-string 1 r2)))
- (if (> v1 v2) (throw 'done t)
- (if (< v1 v2) (throw 'done nil)
- (throw 'done
- (vc-release-greater-or-equal
- (substring r1 i1)
- (substring r2 i2)))))))
- (throw 'done t)))
- (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
- (throw 'done nil))
- (throw 'done t)))))
- (defun vc-rcs-release-p (release)
- "Return t if we have RELEASE or better."
- (let ((installation (vc-rcs-system-release)))
- (if (and installation
- (not (eq installation 'unknown)))
- (vc-release-greater-or-equal installation release))))
- (defun vc-rcs-system-release ()
- "Return the RCS release installed on this system, as a string.
- Return symbol `unknown' if the release cannot be deducted. The user can
- override this using variable `vc-rcs-release'.
- If the user has not set variable `vc-rcs-release' and it is nil,
- variable `vc-rcs-release' is set to the returned value."
- (or vc-rcs-release
- (setq vc-rcs-release
- (or (and (zerop (vc-do-command "*vc*" nil "rcs" nil "-V"))
- (with-current-buffer (get-buffer "*vc*")
- (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
- 'unknown))))
- (defun vc-rcs-set-non-strict-locking (file)
- (vc-do-command "*vc*" 0 "rcs" file "-U")
- (vc-file-setprop file 'vc-checkout-model 'implicit)
- (set-file-modes file (logior (file-modes file) 128)))
- (defun vc-rcs-set-default-branch (file branch)
- (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-b" branch))
- (vc-file-setprop file 'vc-rcs-default-branch branch))
- (defun vc-rcs-parse (&optional buffer)
- "Parse current buffer, presumed to be in RCS-style masterfile format.
- Optional arg BUFFER specifies another buffer to parse. Return an alist
- of two elements, w/ keys `headers' and `revisions' and values in turn
- sub-alists. For `headers', the values unless otherwise specified are
- strings and the keys are:
- desc -- description
- head -- latest revision
- branch -- the branch the \"head revision\" lies on;
- absent if the head revision lies on the trunk
- access -- ???
- symbols -- sub-alist of (SYMBOL . REVISION) elements
- locks -- if file is checked out, something like \"ttn:1.7\"
- strict -- t if \"strict locking\" is in effect, otherwise nil
- comment -- may be absent; typically something like \"# \" or \"; \"
- expand -- may be absent; ???
- For `revisions', the car is REVISION (string), the cdr a sub-alist,
- with string values (unless otherwise specified) and keys:
- date -- a time value (like that returned by `encode-time'); as a
- special case, a year value less than 100 is augmented by 1900
- author -- username
- state -- typically \"Exp\" or \"Rel\"
- branches -- list of revisions that begin branches from this revision
- next -- on the trunk: the chronologically-preceding revision, or \"\";
- on a branch: the chronologically-following revision, or \"\"
- log -- change log entry
- text -- for the head revision on the trunk, the body of the file;
- other revisions have `:insn' instead
- :insn -- for non-head revisions, a list of parsed instructions
- in one of two forms, in both cases START meaning \"first
- go to line START\":
- - `(START k COUNT)' -- kill COUNT lines
- - `(START i TEXT)' -- insert TEXT (a string)
- The list is in descending order by START.
- The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
- (setq buffer (get-buffer (or buffer (current-buffer))))
- (set-buffer buffer)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (let ((desc nil) (headers nil) (revs nil)
-
-
-
-
-
-
-
-
-
-
- context
-
- tok
-
-
- b e
-
-
-
-
-
-
-
-
- @-holes)
- (flet ((sw () (skip-chars-forward " \t\n"))
- (at (tag) (save-excursion (eq tag (read buffer))))
- (to-eol () (buffer-substring-no-properties
- (point) (progn (forward-line 1)
- (1- (point)))))
- (to-semi () (setq b (point)
- e (progn (search-forward ";")
- (1- (point)))))
- (to-one@ () (setq @-holes nil
- b (progn (search-forward "@") (point))
- e (progn (while (and (search-forward "@")
- (= ?@ (char-after))
- (progn
- (push (point) @-holes)
- (forward-char 1)
- (push (point) @-holes))))
- (1- (point)))))
- (tok+val (set-b+e name &optional proc)
- (unless (eq name (setq tok (read buffer)))
- (error "Missing `%s' while parsing %s" name context))
- (sw)
- (funcall set-b+e)
- (cons tok (if proc
- (funcall proc)
- (buffer-substring-no-properties b e))))
- (k-semi (name &optional proc) (tok+val 'to-semi name proc))
- (gather () (let ((pairs `(,e ,@@-holes ,b))
- acc)
- (while pairs
- (push (buffer-substring-no-properties
- (cadr pairs) (car pairs))
- acc)
- (setq pairs (cddr pairs)))
- (apply 'concat acc)))
- (k-one@ (name &optional later) (tok+val 'to-one@ name
- (if later
- (lambda () t)
- 'gather))))
- (save-excursion
- (goto-char (point-min))
-
- (setq context 'headers)
- (flet ((hpush (name &optional proc)
- (push (k-semi name proc) headers)))
- (hpush 'head)
- (when (at 'branch)
- (hpush 'branch))
- (hpush 'access)
- (hpush 'symbols
- (lambda ()
- (mapcar (lambda (together)
- (let ((two (split-string together ":")))
- (setcar two (intern (car two)))
- (setcdr two (cadr two))
- two))
- (split-string
- (buffer-substring-no-properties b e)))))
- (hpush 'locks))
- (push `(strict . ,(when (at 'strict)
- (search-forward ";")
- t))
- headers)
- (when (at 'comment)
- (push (k-one@ 'comment) headers)
- (search-forward ";"))
- (when (at 'expand)
- (push (k-one@ 'expand) headers)
- (search-forward ";"))
- (setq headers (nreverse headers))
-
- (sw) (setq context 'rev-headers)
- (while (looking-at "[0-9]")
- (push `(,(to-eol)
- ,(k-semi 'date
- (lambda ()
- (let ((ls (mapcar 'string-to-number
- (split-string
- (buffer-substring-no-properties
- b e)
- "\\."))))
-
-
- (when (< (car ls) 100)
- (setcar ls (+ 1900 (car ls))))
- (apply 'encode-time (nreverse ls)))))
- ,@(mapcar 'k-semi '(author state))
- ,(k-semi 'branches
- (lambda ()
- (split-string
- (buffer-substring-no-properties b e))))
- ,(k-semi 'next))
- revs)
- (sw))
- (setq revs (nreverse revs))
-
- (sw) (setq context 'desc
- desc (k-one@ 'desc))
-
- (let (acc
-
-
- rev
-
-
-
- cmd start act
-
-
- asc
-
-
-
-
-
- sub)
- (flet ((incg (beg end) (let ((b beg) (e end) @-holes)
- (while (and asc (< (car asc) e))
- (push (pop asc) @-holes))
-
-
-
-
- (unless asc
- (setq sub 'buffer-substring-no-properties))
- (gather))))
- (while (and (sw)
- (not (eobp))
- (setq context (to-eol)
- rev (or (assoc context revs)
- (error "Rev `%s' has body but no head"
- context))))
- (push (k-one@ 'log) (cdr rev))
-
- (push (k-one@ 'text t) (cdr rev))
-
-
-
-
-
- (if (string= context (cdr (assq 'head headers)))
- (setcdr (cadr rev) (gather))
- (if @-holes
- (setq asc (nreverse @-holes)
- sub 'incg)
- (setq sub 'buffer-substring-no-properties))
- (goto-char b)
- (setq acc nil)
- (while (< (point) e)
- (forward-char 1)
- (setq cmd (char-before)
- start (read (current-buffer))
- act (read (current-buffer)))
- (forward-char 1)
- (push (case cmd
- (?d
-
-
- `(,start k ,act))
- (?a
-
-
-
-
-
- `(,(1+ start) i
- ,(funcall sub (point) (progn (forward-line act)
- (point)))))
- (t (error "Bad command `%c' in `text' for rev `%s'"
- cmd context)))
- acc))
- (goto-char (1+ e))
- (setcar (cdr rev) (cons :insn acc)))))))
-
- `((headers ,desc ,@headers)
- (revisions ,@revs)))))
- (provide 'vc-rcs)
|