12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843 |
- (require 'vc-hooks)
- (require 'vc-dispatcher)
- (require 'ediff)
- (eval-when-compile
- (require 'cl)
- (require 'dired))
- (unless (assoc 'vc-parent-buffer minor-mode-alist)
- (setq minor-mode-alist
- (cons '(vc-parent-buffer vc-parent-buffer-name)
- minor-mode-alist)))
- (defgroup vc nil
- "Version-control system in Emacs."
- :group 'tools)
- (defcustom vc-initial-comment nil
- "If non-nil, prompt for initial comment when a file is registered."
- :type 'boolean
- :group 'vc)
- (make-obsolete-variable 'vc-initial-comment "it has no effect." "23.2")
- (defcustom vc-default-init-revision "1.1"
- "A string used as the default revision number when a new file is registered.
- This can be overridden by giving a prefix argument to \\[vc-register]. This
- can also be overridden by a particular VC backend."
- :type 'string
- :group 'vc
- :version "20.3")
- (defcustom vc-checkin-switches nil
- "A string or list of strings specifying extra switches for checkin.
- These are passed to the checkin program by \\[vc-checkin]."
- :type '(choice (const :tag "None" nil)
- (string :tag "Argument String")
- (repeat :tag "Argument List"
- :value ("")
- string))
- :group 'vc)
- (defcustom vc-checkout-switches nil
- "A string or list of strings specifying extra switches for checkout.
- These are passed to the checkout program by \\[vc-checkout]."
- :type '(choice (const :tag "None" nil)
- (string :tag "Argument String")
- (repeat :tag "Argument List"
- :value ("")
- string))
- :group 'vc)
- (defcustom vc-register-switches nil
- "A string or list of strings; extra switches for registering a file.
- These are passed to the checkin program by \\[vc-register]."
- :type '(choice (const :tag "None" nil)
- (string :tag "Argument String")
- (repeat :tag "Argument List"
- :value ("")
- string))
- :group 'vc)
- (defcustom vc-diff-switches nil
- "A string or list of strings specifying switches for diff under VC.
- When running diff under a given BACKEND, VC uses the first
- non-nil value of `vc-BACKEND-diff-switches', `vc-diff-switches',
- and `diff-switches', in that order. Since nil means to check the
- next variable in the sequence, either of the first two may use
- the value t to mean no switches at all. `vc-diff-switches'
- should contain switches that are specific to version control, but
- not specific to any particular backend."
- :type '(choice (const :tag "Unspecified" nil)
- (const :tag "None" t)
- (string :tag "Argument String")
- (repeat :tag "Argument List" :value ("") string))
- :group 'vc
- :version "21.1")
- (defcustom vc-diff-knows-L nil
- "Indicates whether diff understands the -L option.
- The value is either `yes', `no', or nil. If it is nil, VC tries
- to use -L and sets this variable to remember whether it worked."
- :type '(choice (const :tag "Work out" nil) (const yes) (const no))
- :group 'vc)
- (defcustom vc-log-show-limit 2000
- "Limit the number of items shown by the VC log commands.
- Zero means unlimited.
- Not all VC backends are able to support this feature."
- :type 'integer
- :group 'vc)
- (defcustom vc-allow-async-revert nil
- "Specifies whether the diff during \\[vc-revert] may be asynchronous.
- Enabling this option means that you can confirm a revert operation even
- if the local changes in the file have not been found and displayed yet."
- :type '(choice (const :tag "No" nil)
- (const :tag "Yes" t))
- :group 'vc
- :version "22.1")
- (defcustom vc-checkout-hook nil
- "Normal hook (list of functions) run after checking out a file.
- See `run-hooks'."
- :type 'hook
- :group 'vc
- :version "21.1")
- (defcustom vc-checkin-hook nil
- "Normal hook (list of functions) run after commit or file checkin.
- See also `log-edit-done-hook'."
- :type 'hook
- :options '(log-edit-comment-to-change-log)
- :group 'vc)
- (defcustom vc-before-checkin-hook nil
- "Normal hook (list of functions) run before a commit or a file checkin.
- See `run-hooks'."
- :type 'hook
- :group 'vc)
- (defcustom vc-revert-show-diff t
- "If non-nil, `vc-revert' shows a `vc-diff' buffer before querying."
- :type 'boolean
- :group 'vc
- :version "24.1")
- (defcustom vc-static-header-alist
- '(("\\.c\\'" .
- "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
- "Associate static header string templates with file types.
- A \%s in the template is replaced with the first string associated with
- the file's version control type in `vc-BACKEND-header'."
- :type '(repeat (cons :format "%v"
- (regexp :tag "File Type")
- (string :tag "Header String")))
- :group 'vc)
- (defcustom vc-comment-alist
- '((nroff-mode ".\\\"" ""))
- "Special comment delimiters for generating VC headers.
- Add an entry in this list if you need to override the normal `comment-start'
- and `comment-end' variables. This will only be necessary if the mode language
- is sensitive to blank lines."
- :type '(repeat (list :format "%v"
- (symbol :tag "Mode")
- (string :tag "Comment Start")
- (string :tag "Comment End")))
- :group 'vc)
- (defcustom vc-checkout-carefully (= (user-uid) 0)
- "Non-nil means be extra-careful in checkout.
- Verify that the file really is not locked
- and that its contents match what the repository version says."
- :type 'boolean
- :group 'vc)
- (make-obsolete-variable 'vc-checkout-carefully
- "the corresponding checks are always done now."
- "21.1")
- (defvar vc-disable-async-diff nil
- "VC sets this to t locally to disable some async diff operations.
- Backends that offer asynchronous diffs should respect this variable
- in their implementation of vc-BACKEND-diff.")
- (defun vc-clear-context ()
- "Clear all cached file properties."
- (interactive)
- (fillarray vc-file-prop-obarray 0))
- (defmacro with-vc-properties (files form settings)
- "Execute FORM, then maybe set per-file properties for FILES.
- If any of FILES is actually a directory, then do the same for all
- buffers for files in that directory.
- SETTINGS is an association list of property/value pairs. After
- executing FORM, set those properties from SETTINGS that have not yet
- been updated to their corresponding values."
- (declare (debug t))
- `(let ((vc-touched-properties (list t))
- (flist nil))
- (dolist (file ,files)
- (if (file-directory-p file)
- (dolist (buffer (buffer-list))
- (let ((fname (buffer-file-name buffer)))
- (when (and fname (vc-string-prefix-p file fname))
- (push fname flist))))
- (push file flist)))
- ,form
- (dolist (file flist)
- (dolist (setting ,settings)
- (let ((property (car setting)))
- (unless (memq property vc-touched-properties)
- (put (intern file vc-file-prop-obarray)
- property (cdr setting))))))))
- (defun vc-backend-for-registration (file)
- "Return a backend that can be used for registering FILE.
- If no backend declares itself responsible for FILE, then FILE
- must not be in a version controlled directory, so try to create a
- repository, prompting for the directory and the VC backend to
- use."
- (catch 'found
-
-
- (dolist (backend vc-handled-backends)
- (and (not (vc-call-backend backend 'registered file))
- (vc-call-backend backend 'responsible-p file)
- (throw 'found backend)))
-
- (let* ((possible-backends
- (let (pos)
- (dolist (crt vc-handled-backends)
- (when (vc-find-backend-function crt 'create-repo)
- (push crt pos)))
- pos))
- (bk
- (intern
-
-
-
- (completing-read
- (format "%s is not in a version controlled directory.\nUse VC backend: " file)
- (mapcar 'symbol-name possible-backends) nil t)))
- (repo-dir
- (let ((def-dir (file-name-directory file)))
-
-
-
- (read-file-name
- (format "create %s repository in: " bk)
- default-directory def-dir t nil
- (lambda (arg)
- (message "arg %s" arg)
- (and (file-directory-p arg)
- (vc-string-prefix-p (expand-file-name arg) def-dir)))))))
- (let ((default-directory repo-dir))
- (vc-call-backend bk 'create-repo))
- (throw 'found bk))))
- (defun vc-responsible-backend (file)
- "Return the name of a backend system that is responsible for FILE.
- If FILE is already registered, return the
- backend of FILE. If FILE is not registered, then the
- first backend in `vc-handled-backends' that declares itself
- responsible for FILE is returned."
- (or (and (not (file-directory-p file)) (vc-backend file))
- (catch 'found
-
-
- (dolist (backend vc-handled-backends)
- (and (vc-call-backend backend 'responsible-p file)
- (throw 'found backend))))
- (error "No VC backend is responsible for %s" file)))
- (defun vc-expand-dirs (file-or-dir-list)
- "Expands directories in a file list specification.
- Within directories, only files already under version control are noticed."
- (let ((flattened '()))
- (dolist (node file-or-dir-list)
- (when (file-directory-p node)
- (vc-file-tree-walk
- node (lambda (f) (when (vc-backend f) (push f flattened)))))
- (unless (file-directory-p node) (push node flattened)))
- (nreverse flattened)))
- (defvar vc-dir-backend)
- (defvar log-view-vc-backend)
- (defvar diff-vc-backend)
- (defun vc-deduce-backend ()
- (cond ((derived-mode-p 'vc-dir-mode) vc-dir-backend)
- ((derived-mode-p 'log-view-mode) log-view-vc-backend)
- ((derived-mode-p 'diff-mode) diff-vc-backend)
-
- ((derived-mode-p 'dired-mode 'shell-mode 'compilation-mode)
- (vc-responsible-backend default-directory))
- (vc-mode (vc-backend buffer-file-name))))
- (declare-function vc-dir-current-file "vc-dir" ())
- (declare-function vc-dir-deduce-fileset "vc-dir" (&optional state-model-only-files))
- (defun vc-deduce-fileset (&optional observer allow-unregistered
- state-model-only-files)
- "Deduce a set of files and a backend to which to apply an operation.
- Return (BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL).
- If we're in VC-dir mode, FILESET is the list of marked files.
- Otherwise, if in a buffer visiting a version-controlled file,
- FILESET is a single-file fileset containing that file.
- Otherwise, if ALLOW-UNREGISTERED is non-nil and the visited file
- is unregistered, FILESET is a single-file fileset containing it.
- Otherwise, throw an error.
- STATE-MODEL-ONLY-FILES if non-nil, means that the caller needs
- the FILESET-ONLY-FILES STATE and MODEL info. Otherwise, that
- part may be skipped.
- BEWARE: this function may change the
- current buffer."
-
-
- (let (backend)
- (cond
- ((derived-mode-p 'vc-dir-mode)
- (vc-dir-deduce-fileset state-model-only-files))
- ((derived-mode-p 'dired-mode)
- (if observer
- (vc-dired-deduce-fileset)
- (error "State changing VC operations not supported in `dired-mode'")))
- ((setq backend (vc-backend buffer-file-name))
- (if state-model-only-files
- (list backend (list buffer-file-name)
- (list buffer-file-name)
- (vc-state buffer-file-name)
- (vc-checkout-model backend buffer-file-name))
- (list backend (list buffer-file-name))))
- ((and (buffer-live-p vc-parent-buffer)
-
- (or (buffer-file-name vc-parent-buffer)
- (with-current-buffer vc-parent-buffer
- (derived-mode-p 'vc-dir-mode))))
- (progn
- (set-buffer vc-parent-buffer)
- (vc-deduce-fileset observer allow-unregistered state-model-only-files)))
- ((not buffer-file-name)
- (error "Buffer %s is not associated with a file" (buffer-name)))
- ((and allow-unregistered (not (vc-registered buffer-file-name)))
- (if state-model-only-files
- (list (vc-backend-for-registration (buffer-file-name))
- (list buffer-file-name)
- (list buffer-file-name)
- (when state-model-only-files 'unregistered)
- nil)
- (list (vc-backend-for-registration (buffer-file-name))
- (list buffer-file-name))))
- (t (error "No fileset is available here")))))
- (defun vc-dired-deduce-fileset ()
- (let ((backend (vc-responsible-backend default-directory)))
- (unless backend (error "Directory not under VC"))
- (list backend
- (dired-map-over-marks (dired-get-filename nil t) nil))))
- (defun vc-ensure-vc-buffer ()
- "Make sure that the current buffer visits a version-controlled file."
- (cond
- ((derived-mode-p 'vc-dir-mode)
- (set-buffer (find-file-noselect (vc-dir-current-file))))
- (t
- (while (and vc-parent-buffer
- (buffer-live-p vc-parent-buffer)
-
-
- (not (eq vc-parent-buffer (current-buffer))))
- (set-buffer vc-parent-buffer))
- (if (not buffer-file-name)
- (error "Buffer %s is not associated with a file" (buffer-name))
- (unless (vc-backend buffer-file-name)
- (error "File %s is not under version control" buffer-file-name))))))
- (defsubst vc-editable-p (file)
- "Return non-nil if FILE can be edited."
- (let ((backend (vc-backend file)))
- (and backend
- (or (eq (vc-checkout-model backend (list file)) 'implicit)
- (memq (vc-state file) '(edited needs-merge conflict))))))
- (defun vc-compatible-state (p q)
- "Controls which states can be in the same commit."
- (or
- (eq p q)
- (and (member p '(edited added removed)) (member q '(edited added removed)))))
- (defun vc-next-action (verbose)
- "Do the next logical version control operation on the current fileset.
- This requires that all files in the current VC fileset be in the
- same state. If not, signal an error.
- For merging-based version control systems:
- If every file in the VC fileset is not registered for version
- control, register the fileset (but don't commit).
- If every work file in the VC fileset is added or changed, pop
- up a *vc-log* buffer to commit the fileset.
- For a centralized version control system, if any work file in
- the VC fileset is out of date, offer to update the fileset.
- For old-style locking-based version control systems, like RCS:
- If every file is not registered, register the file(s).
- If every file is registered and unlocked, check out (lock)
- the file(s) for editing.
- If every file is locked by you and has changes, pop up a
- *vc-log* buffer to check in the changes. If the variable
- `vc-keep-workfiles' is non-nil (the default), leave a
- read-only copy of each changed file after checking in.
- If every file is locked by you and unchanged, unlock them.
- If every file is locked by someone else, offer to steal the lock."
- (interactive "P")
- (let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files))
- (backend (car vc-fileset))
- (files (nth 1 vc-fileset))
- (fileset-only-files (nth 2 vc-fileset))
-
- (state (nth 3 vc-fileset))
-
-
- (model (nth 4 vc-fileset)))
-
- (cond
- ((eq state 'missing)
- (error "Fileset files are missing, so cannot be operated on"))
- ((eq state 'ignored)
- (error "Fileset files are ignored by the version-control system"))
- ((or (null state) (eq state 'unregistered))
- (vc-register nil vc-fileset))
-
- ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update)))
- (cond
- (verbose
-
- (let* ((revision
- (read-string "Branch, revision, or backend to move to: "))
- (revision-downcase (downcase revision)))
- (if (member
- revision-downcase
- (mapcar (lambda (arg) (downcase (symbol-name arg)))
- vc-handled-backends))
- (let ((vsym (intern-soft revision-downcase)))
- (dolist (file files) (vc-transfer-file file vsym)))
- (dolist (file files)
- (vc-checkout file (eq model 'implicit) revision)))))
- ((not (eq model 'implicit))
-
- (dolist (file files) (vc-checkout file t)))
- (t
-
- (message "Fileset is up-to-date"))))
-
- ((vc-compatible-state state 'edited)
- (let ((ready-for-commit files))
-
- (dolist (file files)
-
-
-
-
- (when (and (file-exists-p file) (not (file-writable-p file)))
-
- (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue? " file))
- (error "Aborted"))
-
- (condition-case nil
- (set-file-modes file (logior (file-modes file) 128))
- (error (error "Unable to make file writable")))
- (let ((visited (get-file-buffer file)))
- (when visited
- (with-current-buffer visited
- (toggle-read-only -1))))))
-
- (save-excursion
- (dolist (file files)
- (let ((visited (get-file-buffer file)))
-
-
- (when (and (not (eq model 'implicit))
- (vc-workfile-unchanged-p file)
-
-
-
-
- (not (and visited (buffer-modified-p))))
- (vc-revert-file file)
- (setq ready-for-commit (delete file ready-for-commit))))))
-
- (if (not ready-for-commit)
- (message "No files remain to be committed")
- (if (not verbose)
- (vc-checkin ready-for-commit backend)
- (let* ((revision (read-string "New revision or backend: "))
- (revision-downcase (downcase revision)))
- (if (member
- revision-downcase
- (mapcar (lambda (arg) (downcase (symbol-name arg)))
- vc-handled-backends))
- (let ((vsym (intern revision-downcase)))
- (dolist (file files) (vc-transfer-file file vsym)))
- (vc-checkin ready-for-commit backend revision)))))))
-
- ((stringp state)
-
-
-
-
-
-
-
-
-
-
-
-
- (dolist (file files)
- (vc-steal-lock
- file (if verbose
- (read-string (format "%s revision to steal: " file))
- (vc-working-revision file))
- state)))
-
- ((eq state 'conflict)
-
-
-
-
-
- (vc-mark-resolved backend files))
-
- ((eq state 'needs-update)
- (dolist (file files)
- (if (yes-or-no-p (format
- "%s is not up-to-date. Get latest revision? "
- (file-name-nondirectory file)))
- (vc-checkout file (eq model 'implicit) t)
- (when (and (not (eq model 'implicit))
- (yes-or-no-p "Lock this revision? "))
- (vc-checkout file t)))))
-
- ((eq state 'needs-merge)
- (dolist (file files)
- (when (yes-or-no-p (format
- "%s is not up-to-date. Merge in changes now? "
- (file-name-nondirectory file)))
- (vc-maybe-resolve-conflicts
- file (vc-call-backend backend 'merge-news file)))))
-
- ((eq state 'unlocked-changes)
- (dolist (file files)
- (when (not (equal buffer-file-name file))
- (find-file-other-window file))
- (if (save-window-excursion
- (vc-diff-internal nil
- (cons (car vc-fileset) (cons (cadr vc-fileset) (list file)))
- (vc-working-revision file) nil)
- (goto-char (point-min))
- (let ((inhibit-read-only t))
- (insert
- (format "Changes to %s since last lock:\n\n" file)))
- (not (beep))
- (yes-or-no-p (concat "File has unlocked changes. "
- "Claim lock retaining changes? ")))
- (progn (vc-call-backend backend 'steal-lock file)
- (clear-visited-file-modtime)
-
-
- (vc-clear-headers file)
- (write-file buffer-file-name)
- (vc-mode-line file backend))
- (if (not (yes-or-no-p
- "Revert to checked-in revision, instead? "))
- (error "Checkout aborted")
- (vc-revert-buffer-internal t t)
- (vc-checkout file t)))))
-
- (t
- (error "Fileset is in an unknown state %s" state)))))
- (defun vc-create-repo (backend)
- "Create an empty repository in the current directory."
- (interactive
- (list
- (intern
- (upcase
- (completing-read
- "Create repository for: "
- (mapcar (lambda (b) (list (downcase (symbol-name b)))) vc-handled-backends)
- nil t)))))
- (vc-call-backend backend 'create-repo))
- (declare-function vc-dir-move-to-goal-column "vc-dir" ())
- (defun vc-register (&optional set-revision vc-fileset comment)
- "Register into a version control system.
- If VC-FILESET is given, register the files in that fileset.
- Otherwise register the current file.
- With prefix argument SET-REVISION, allow user to specify initial revision
- level. If COMMENT is present, use that as an initial comment.
- The version control system to use is found by cycling through the list
- `vc-handled-backends'. The first backend in that list which declares
- itself responsible for the file (usually because other files in that
- directory are already registered under that backend) will be used to
- register the file. If no backend declares itself responsible, the
- first backend that could register the file is used."
- (interactive "P")
- (let* ((fileset-arg (or vc-fileset (vc-deduce-fileset nil t)))
- (backend (car fileset-arg))
- (files (nth 1 fileset-arg)))
-
-
-
- (dolist (fname files)
- (let ((bname (get-file-buffer fname)))
- (unless fname (setq fname buffer-file-name))
- (when (vc-backend fname)
- (if (vc-registered fname)
- (error "This file is already registered")
- (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
- (error "Aborted"))))
-
-
- (when bname
- (with-current-buffer bname
- (when (and (not (buffer-modified-p))
- (zerop (buffer-size))
- (not (file-exists-p buffer-file-name)))
- (set-buffer-modified-p t))
- (vc-buffer-sync)))))
- (message "Registering %s... " files)
- (mapc 'vc-file-clearprops files)
- (vc-call-backend backend 'register files
- (if set-revision
- (read-string (format "Initial revision level for %s: " files))
- (vc-call-backend backend 'init-revision))
- comment)
- (mapc
- (lambda (file)
- (vc-file-setprop file 'vc-backend backend)
-
-
-
-
-
-
- (vc-resynch-buffer file vc-keep-workfiles t))
- files)
- (when (derived-mode-p 'vc-dir-mode)
- (vc-dir-move-to-goal-column))
- (message "Registering %s... done" files)))
- (defun vc-register-with (backend)
- "Register the current file with a specified back end."
- (interactive "SBackend: ")
- (when (not (member backend vc-handled-backends))
- (error "Unknown back end"))
- (let ((vc-handled-backends (list backend)))
- (call-interactively 'vc-register)))
- (defun vc-checkout (file &optional writable rev)
- "Retrieve a copy of the revision REV of FILE.
- If WRITABLE is non-nil, make sure the retrieved file is writable.
- REV defaults to the latest revision.
- After check-out, runs the normal hook `vc-checkout-hook'."
- (and writable
- (not rev)
- (vc-call make-version-backups-p file)
- (vc-up-to-date-p file)
- (vc-make-version-backup file))
- (let ((backend (vc-backend file)))
- (with-vc-properties (list file)
- (condition-case err
- (vc-call-backend backend 'checkout file writable rev)
- (file-error
-
- (when writable
- (let ((buf (get-file-buffer file)))
- (when buf (with-current-buffer buf (toggle-read-only -1)))))
- (signal (car err) (cdr err))))
- `((vc-state . ,(if (or (eq (vc-checkout-model backend (list file)) 'implicit)
- (not writable))
- (if (vc-call-backend backend 'latest-on-branch-p file)
- 'up-to-date
- 'needs-update)
- 'edited))
- (vc-checkout-time . ,(nth 5 (file-attributes file))))))
- (vc-resynch-buffer file t t)
- (run-hooks 'vc-checkout-hook))
- (defun vc-mark-resolved (backend files)
- (prog1 (with-vc-properties
- files
- (vc-call-backend backend 'mark-resolved files)
-
- `((vc-state . edited)))
- (message
- (substitute-command-keys
- "Conflicts have been resolved in %s. \
- Type \\[vc-next-action] to check in changes.")
- (if (> (length files) 1)
- (format "%d files" (length files))
- "this file"))))
- (defun vc-steal-lock (file rev owner)
- "Steal the lock on FILE."
- (let (file-description)
- (if rev
- (setq file-description (format "%s:%s" file rev))
- (setq file-description file))
- (when (not (yes-or-no-p (format "Steal the lock on %s from %s? "
- file-description owner)))
- (error "Steal canceled"))
- (message "Stealing lock on %s..." file)
- (with-vc-properties
- (list file)
- (vc-call steal-lock file rev)
- `((vc-state . edited)))
- (vc-resynch-buffer file t t)
- (message "Stealing lock on %s...done" file)
-
-
- (compose-mail owner (format "Stolen lock on %s" file-description))
- (setq default-directory (expand-file-name "~/"))
- (goto-char (point-max))
- (insert
- (format "I stole the lock on %s, " file-description)
- (current-time-string)
- ".\n")
- (message "Please explain why you stole the lock. Type C-c C-c when done.")))
- (defun vc-checkin (files backend &optional rev comment initial-contents)
- "Check in FILES.
- The optional argument REV may be a string specifying the new revision
- level (strongly deprecated). COMMENT is a comment
- string; if omitted, a buffer is popped up to accept a comment. If
- INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
- of the log entry buffer.
- If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
- that the version control system supports this mode of operation.
- Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
- (when vc-before-checkin-hook
- (run-hooks 'vc-before-checkin-hook))
- (lexical-let
- ((backend backend))
- (vc-start-logentry
- files comment initial-contents
- "Enter a change comment."
- "*vc-log*"
- (lambda ()
- (vc-call-backend backend 'log-edit-mode))
- (lexical-let ((rev rev))
- (lambda (files comment)
- (message "Checking in %s..." (vc-delistify files))
-
-
- (or (and comment (string-match "[^\t\n ]" comment))
- (setq comment "*** empty log message ***"))
- (with-vc-properties
- files
-
-
-
- (progn
- (vc-call-backend backend 'checkin files rev comment)
- (mapc 'vc-delete-automatic-version-backups files))
- `((vc-state . up-to-date)
- (vc-checkout-time . ,(nth 5 (file-attributes file)))
- (vc-working-revision . nil)))
- (message "Checking in %s...done" (vc-delistify files))))
- 'vc-checkin-hook)))
- (defvar vc-coding-system-inherit-eol t
- "When non-nil, inherit the EOL format for reading Diff output from the file.
- Used in `vc-coding-system-for-diff' to determine the EOL format to use
- for reading Diff output for a file. If non-nil, the EOL format is
- inherited from the file itself.
- Set this variable to nil if your Diff tool might use a different
- EOL. Then Emacs will auto-detect the EOL format in Diff output, which
- gives better results.")
- (defun vc-coding-system-for-diff (file)
- "Return the coding system for reading diff output for FILE."
- (or coding-system-for-read
-
-
- (let ((buf (find-buffer-visiting file)))
- (when buf (with-current-buffer buf
- (if vc-coding-system-inherit-eol
- buffer-file-coding-system
-
-
-
- (coding-system-base buffer-file-coding-system)))))
-
- (car (find-operation-coding-system 'insert-file-contents file))
-
- 'undecided))
- (defun vc-switches (backend op)
- "Return a list of vc-BACKEND switches for operation OP.
- BACKEND is a symbol such as `CVS', which will be downcased.
- OP is a symbol such as `diff'.
- In decreasing order of preference, return the value of:
- vc-BACKEND-OP-switches (e.g. `vc-cvs-diff-switches');
- vc-OP-switches (e.g. `vc-diff-switches'); or, in the case of
- diff only, `diff-switches'.
- If the chosen value is not a string or a list, return nil.
- This is so that you may set, e.g. `vc-svn-diff-switches' to t in order
- to override the value of `vc-diff-switches' and `diff-switches'."
- (let ((switches
- (or (when backend
- (let ((sym (vc-make-backend-sym
- backend (intern (concat (symbol-name op)
- "-switches")))))
- (when (boundp sym) (symbol-value sym))))
- (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
- (when (boundp sym) (symbol-value sym)))
- (cond
- ((eq op 'diff) diff-switches)))))
- (if (stringp switches) (list switches)
-
-
-
- (when (listp switches) switches))))
- (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
- (make-obsolete 'vc-diff-switches-list 'vc-switches "22.1")
- (defun vc-diff-finish (buffer messages)
-
-
- (when (buffer-live-p buffer)
- (let ((window (get-buffer-window buffer t))
- (emptyp (zerop (buffer-size buffer))))
- (with-current-buffer buffer
- (and messages emptyp
- (let ((inhibit-read-only t))
- (insert (cdr messages) ".\n")
- (message "%s" (cdr messages))))
- (goto-char (point-min))
- (when window
- (shrink-window-if-larger-than-buffer window)))
- (when (and messages (not emptyp))
- (message "%sdone" (car messages))))))
- (defvar vc-diff-added-files nil
- "If non-nil, diff added files by comparing them to /dev/null.")
- (defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose buffer)
- "Report diffs between two revisions of a fileset.
- Output goes to the buffer BUFFER, which defaults to *vc-diff*.
- BUFFER, if non-nil, should be a buffer or a buffer name.
- Return t if the buffer had changes, nil otherwise."
- (unless buffer
- (setq buffer "*vc-diff*"))
- (let* ((files (cadr vc-fileset))
- (messages (cons (format "Finding changes in %s..."
- (vc-delistify files))
- (format "No changes between %s and %s"
- (or rev1 "working revision")
- (or rev2 "workfile"))))
-
-
-
- (coding-system-for-read
- (if files (vc-coding-system-for-diff (car files)) 'undecided)))
- (vc-setup-buffer buffer)
- (message "%s" (car messages))
-
-
-
-
-
-
-
-
-
-
- (when vc-diff-added-files
- (let ((filtered '())
- process-file-side-effects)
- (dolist (file files)
- (if (or (file-directory-p file)
- (not (string= (vc-working-revision file) "0")))
- (push file filtered)
-
-
- (if (or rev1 rev2)
- (error "No revisions of %s exist" file)
-
-
- (apply 'vc-do-command buffer
- 1 "diff" file
- (append (vc-switches nil 'diff) '("/dev/null"))))))
- (setq files (nreverse filtered))))
- (let ((vc-disable-async-diff (not async)))
- (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer))
- (set-buffer buffer)
- (if (and (zerop (buffer-size))
- (not (get-buffer-process (current-buffer))))
-
- (progn
- (message "%s" (cdr messages))
- nil)
- (diff-mode)
- (set (make-local-variable 'diff-vc-backend) (car vc-fileset))
- (set (make-local-variable 'revert-buffer-function)
- `(lambda (ignore-auto noconfirm)
- (vc-diff-internal ,async ',vc-fileset ,rev1 ,rev2 ,verbose)))
-
-
-
- (setq buffer-read-only t)
-
- (pop-to-buffer (current-buffer))
-
-
-
- (vc-exec-after `(vc-diff-finish ,(current-buffer)
- ',(when verbose messages)))
-
-
- t)))
- (defun vc-read-revision (prompt &optional files backend default initial-input)
- (cond
- ((null files)
- (let ((vc-fileset (vc-deduce-fileset t)))
- (setq files (cadr vc-fileset))
- (setq backend (car vc-fileset))))
- ((null backend) (setq backend (vc-backend (car files)))))
- (let ((completion-table
- (vc-call-backend backend 'revision-completion-table files)))
- (if completion-table
- (completing-read prompt completion-table
- nil nil initial-input nil default)
- (read-string prompt initial-input nil default))))
- (defun vc-diff-build-argument-list-internal ()
- "Build argument list for calling internal diff functions."
- (let* ((vc-fileset (vc-deduce-fileset t))
- (files (cadr vc-fileset))
- (backend (car vc-fileset))
- (first (car files))
- (rev1-default nil)
- (rev2-default nil))
- (cond
-
-
- ((/= (length files) 1)
- nil)
-
- ((file-directory-p first)
- nil)
-
- ((not (vc-up-to-date-p first))
- (setq rev1-default (vc-working-revision first)))
-
- (t
- (setq rev1-default (vc-call-backend backend 'previous-revision first
- (vc-working-revision first)))
- (when (string= rev1-default "") (setq rev1-default nil))
- (setq rev2-default (vc-working-revision first))))
-
- (let* ((rev1-prompt (if rev1-default
- (concat "Older revision (default "
- rev1-default "): ")
- "Older revision: "))
- (rev2-prompt (concat "Newer revision (default "
- (or rev2-default "current source") "): "))
- (rev1 (vc-read-revision rev1-prompt files backend rev1-default))
- (rev2 (vc-read-revision rev2-prompt files backend rev2-default)))
- (when (string= rev1 "") (setq rev1 nil))
- (when (string= rev2 "") (setq rev2 nil))
- (list files rev1 rev2))))
- (defun vc-version-diff (files rev1 rev2)
- "Report diffs between revisions of the fileset in the repository history."
- (interactive (vc-diff-build-argument-list-internal))
-
- (when (and (not rev1) rev2)
- (error "Not a valid revision range"))
-
-
- (vc-diff-internal t (vc-deduce-fileset t) rev1 rev2
- (called-interactively-p 'interactive)))
- (defun vc-diff (historic &optional not-urgent)
- "Display diffs between file revisions.
- Normally this compares the currently selected fileset with their
- working revisions. With a prefix argument HISTORIC, it reads two revision
- designators specifying which revisions to compare.
- The optional argument NOT-URGENT non-nil means it is ok to say no to
- saving the buffer."
- (interactive (list current-prefix-arg t))
- (if historic
- (call-interactively 'vc-version-diff)
- (when buffer-file-name (vc-buffer-sync not-urgent))
- (vc-diff-internal t (vc-deduce-fileset t) nil nil
- (called-interactively-p 'interactive))))
- (declare-function ediff-vc-internal (rev1 rev2 &optional startup-hooks))
- (defun vc-version-ediff (files rev1 rev2)
- "Show differences between revisions of the fileset in the
- repository history using ediff."
- (interactive (vc-diff-build-argument-list-internal))
-
- (when (and (not rev1) rev2)
- (error "Not a valid revision range"))
- (message "%s" (format "Finding changes in %s..." (vc-delistify files)))
-
- (when (null rev1) (setq rev1 ""))
- (when (null rev2) (setq rev2 ""))
- (cond
-
-
- ((= (length files) 1)
- (ediff-load-version-control)
- (find-file (car files))
- (ediff-vc-internal rev1 rev2 nil))
- (t
- (error "More than one file is not supported"))))
- (defun vc-ediff (historic &optional not-urgent)
- "Display diffs between file revisions using ediff.
- Normally this compares the currently selected fileset with their
- working revisions. With a prefix argument HISTORIC, it reads two revision
- designators specifying which revisions to compare.
- The optional argument NOT-URGENT non-nil means it is ok to say no to
- saving the buffer."
- (interactive (list current-prefix-arg t))
- (if historic
- (call-interactively 'vc-version-ediff)
- (when buffer-file-name (vc-buffer-sync not-urgent))
- (vc-version-ediff (cadr (vc-deduce-fileset t)) nil nil)))
- (defun vc-root-diff (historic &optional not-urgent)
- "Display diffs between VC-controlled whole tree revisions.
- Normally, this compares the tree corresponding to the current
- fileset with the working revision.
- With a prefix argument HISTORIC, prompt for two revision
- designators specifying which revisions to compare.
- The optional argument NOT-URGENT non-nil means it is ok to say no to
- saving the buffer."
- (interactive (list current-prefix-arg t))
- (if historic
-
-
-
- (call-interactively 'vc-version-diff)
- (when buffer-file-name (vc-buffer-sync not-urgent))
- (let ((backend (vc-deduce-backend))
- rootdir working-revision)
- (unless backend
- (error "Buffer is not version controlled"))
- (setq rootdir (vc-call-backend backend 'root default-directory))
- (setq working-revision (vc-working-revision rootdir))
-
-
-
-
- (let ((default-directory rootdir))
- (vc-diff-internal
- t (list backend (list rootdir) working-revision) nil nil
- (called-interactively-p 'interactive))))))
- (defun vc-revision-other-window (rev)
- "Visit revision REV of the current file in another window.
- If the current file is named `F', the revision is named `F.~REV~'.
- If `F.~REV~' already exists, use it instead of checking it out again."
- (interactive
- (save-current-buffer
- (vc-ensure-vc-buffer)
- (list
- (vc-read-revision "Revision to visit (default is working revision): "
- (list buffer-file-name)))))
- (vc-ensure-vc-buffer)
- (let* ((file buffer-file-name)
- (revision (if (string-equal rev "")
- (vc-working-revision file)
- rev)))
- (switch-to-buffer-other-window (vc-find-revision file revision))))
- (defun vc-find-revision (file revision &optional backend)
- "Read REVISION of FILE into a buffer and return the buffer.
- Use BACKEND as the VC backend if specified."
- (let ((automatic-backup (vc-version-backup-file-name file revision))
- (filebuf (or (get-file-buffer file) (current-buffer)))
- (filename (vc-version-backup-file-name file revision 'manual)))
- (unless (file-exists-p filename)
- (if (file-exists-p automatic-backup)
- (rename-file automatic-backup filename nil)
- (message "Checking out %s..." filename)
- (with-current-buffer filebuf
- (let ((failed t))
- (unwind-protect
- (let ((coding-system-for-read 'no-conversion)
- (coding-system-for-write 'no-conversion))
- (with-temp-file filename
- (let ((outbuf (current-buffer)))
-
-
- (with-current-buffer filebuf
- (if backend
- (vc-call-backend backend 'find-revision file revision outbuf)
- (vc-call find-revision file revision outbuf)))))
- (setq failed nil))
- (when (and failed (file-exists-p filename))
- (delete-file filename))))
- (vc-mode-line file))
- (message "Checking out %s...done" filename)))
- (let ((result-buf (find-file-noselect filename)))
- (with-current-buffer result-buf
-
-
- (set (make-local-variable 'vc-parent-buffer) filebuf))
- result-buf)))
- (defun vc-insert-headers ()
- "Insert headers into a file for use with a version control system.
- Headers desired are inserted at point, and are pulled from
- the variable `vc-BACKEND-header'."
- (interactive)
- (vc-ensure-vc-buffer)
- (save-excursion
- (save-restriction
- (widen)
- (when (or (not (vc-check-headers))
- (y-or-n-p "Version headers already exist. Insert another set? "))
- (let* ((delims (cdr (assq major-mode vc-comment-alist)))
- (-start-vc (or (car delims) comment-start "#"))
- (-end-vc (or (car (cdr delims)) comment-end ""))
- (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
- 'header))
- (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
- (dolist (s hdstrings)
- (insert comment-start-vc "\t" s "\t"
- comment-end-vc "\n"))
- (when vc-static-header-alist
- (dolist (f vc-static-header-alist)
- (when (string-match (car f) buffer-file-name)
- (insert (format (cdr f) (car hdstrings)))))))))))
- (defun vc-clear-headers (&optional file)
- "Clear all version headers in the current buffer (or FILE).
- The headers are reset to their non-expanded form."
- (let* ((filename (or file buffer-file-name))
- (visited (find-buffer-visiting filename))
- (backend (vc-backend filename)))
- (when (vc-find-backend-function backend 'clear-headers)
- (if visited
- (let ((context (vc-buffer-context)))
-
-
-
- (save-excursion
- (vc-call-backend backend 'clear-headers))
- (vc-restore-buffer-context context))
- (set-buffer (find-file-noselect filename))
- (vc-call-backend backend 'clear-headers)
- (kill-buffer filename)))))
- (defun vc-modify-change-comment (files rev oldcomment)
- "Edit the comment associated with the given files and revision."
-
-
-
- (let ((backend (vc-responsible-backend (car files))))
- (vc-start-logentry
- files oldcomment t
- "Enter a replacement change comment."
- "*vc-log*"
- (lambda () (vc-call-backend backend 'log-edit-mode))
- (lexical-let ((rev rev)
- (backend backend))
- (lambda (files comment)
- (vc-call-backend backend
- 'modify-change-comment files rev comment))))))
- (defun vc-merge ()
- "Perform a version control merge operation.
- You must be visiting a version controlled file, or in a `vc-dir' buffer.
- On a distributed version control system, this runs a \"merge\"
- operation to incorporate changes from another branch onto the
- current branch, prompting for an argument list.
- On a non-distributed version control system, this merges changes
- between two revisions into the current fileset. This asks for
- two revisions to merge from in the minibuffer. If the first
- revision is a branch number, then merge all changes from that
- branch. If the first revision is empty, merge the most recent
- changes from the current branch."
- (interactive)
- (let* ((vc-fileset (vc-deduce-fileset t))
- (backend (car vc-fileset))
- (files (cadr vc-fileset)))
- (cond
-
- ((vc-find-backend-function backend 'merge-branch)
- (vc-call-backend backend 'merge-branch))
-
- ((vc-find-backend-function backend 'merge)
- (vc-buffer-sync)
- (dolist (file files)
- (let* ((state (vc-state file))
- first-revision second-revision status)
- (cond
- ((stringp state)
- (error "File %s is locked by %s" file state))
- ((not (vc-editable-p file))
- (vc-checkout file t)))
- (setq first-revision
- (vc-read-revision
- (concat "Merge " file
- " from branch or revision "
- "(default news on current branch): ")
- (list file)
- backend))
- (cond
- ((string= first-revision "")
- (setq status (vc-call-backend backend 'merge-news file)))
- (t
- (if (not (vc-branch-p first-revision))
- (setq second-revision
- (vc-read-revision
- "Second revision: "
- (list file) backend nil
-
- (concat (vc-branch-part first-revision) ".")))
-
-
- (setq second-revision first-revision)
-
- (setq first-revision (vc-branch-part first-revision)))
- (setq status (vc-call-backend backend 'merge file
- first-revision second-revision))))
- (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE"))))
- (t
- (error "Sorry, merging is not implemented for %s" backend)))))
- (defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
- (vc-resynch-buffer file t (not (buffer-modified-p)))
- (if (zerop status) (message "Merge successful")
- (smerge-mode 1)
- (message "File contains conflicts.")))
- (defalias 'vc-resolve-conflicts 'smerge-ediff)
- (defun vc-find-conflicted-file ()
- "Visit the next conflicted file in the current project."
- (interactive)
- (let* ((backend (or (if buffer-file-name (vc-backend buffer-file-name))
- (vc-responsible-backend default-directory)
- (error "No VC backend")))
- (files (vc-call-backend backend
- 'conflicted-files default-directory)))
-
- (if (equal (car files) buffer-file-name) (pop files))
- (if (null files)
- (message "No more conflicted files")
- (find-file (pop files))
- (message "%s more conflicted files after this one"
- (if files (length files) "No")))))
- (defun vc-tag-precondition (dir)
- "Scan the tree below DIR, looking for files not up-to-date.
- If any file is not up-to-date, return the name of the first such file.
- \(This means, neither tag creation nor retrieval is allowed.\)
- If one or more of the files are currently visited, return `visited'.
- Otherwise, return nil."
- (let ((status nil))
- (catch 'vc-locked-example
- (vc-file-tree-walk
- dir
- (lambda (f)
- (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
- (when (get-file-buffer f) (setq status 'visited)))))
- status)))
- (defun vc-create-tag (dir name branchp)
- "Descending recursively from DIR, make a tag called NAME.
- For each registered file, the working revision becomes part of
- the named configuration. If the prefix argument BRANCHP is
- given, the tag is made as a new branch and the files are
- checked out in that new branch."
- (interactive
- (let ((granularity
- (vc-call-backend (vc-responsible-backend default-directory)
- 'revision-granularity)))
- (list
- (if (eq granularity 'repository)
-
-
- default-directory
- (read-directory-name "Directory: " default-directory default-directory t))
- (read-string (if current-prefix-arg "New branch name: " "New tag name: "))
- current-prefix-arg)))
- (message "Making %s... " (if branchp "branch" "tag"))
- (when (file-directory-p dir) (setq dir (file-name-as-directory dir)))
- (vc-call-backend (vc-responsible-backend dir)
- 'create-tag dir name branchp)
- (vc-resynch-buffer dir t t t)
- (message "Making %s... done" (if branchp "branch" "tag")))
- (defun vc-retrieve-tag (dir name)
- "Descending recursively from DIR, retrieve the tag called NAME.
- If NAME is empty, it refers to the latest revisions.
- If locking is used for the files in DIR, then there must not be any
- locked files at or below DIR (but if NAME is empty, locked files are
- allowed and simply skipped)."
- (interactive
- (let ((granularity
- (vc-call-backend (vc-responsible-backend default-directory)
- 'revision-granularity)))
- (list
- (if (eq granularity 'repository)
-
-
- default-directory
- (read-directory-name "Directory: " default-directory default-directory t))
- (read-string "Tag name to retrieve (default latest revisions): "))))
- (let ((update (yes-or-no-p "Update any affected buffers? "))
- (msg (if (or (not name) (string= name ""))
- (format "Updating %s... " (abbreviate-file-name dir))
- (format "Retrieving tag into %s... "
- (abbreviate-file-name dir)))))
- (message "%s" msg)
- (vc-call-backend (vc-responsible-backend dir)
- 'retrieve-tag dir name update)
- (vc-resynch-buffer dir t t t)
- (message "%s" (concat msg "done"))))
- (defvar vc-log-short-style '(directory)
- "Whether or not to show a short log.
- If it contains `directory' then if the fileset contains a directory show a short log.
- If it contains `file' then show short logs for files.
- Not all VC backends support short logs!")
- (defvar log-view-vc-fileset)
- (defun vc-print-log-setup-buttons (working-revision is-start-revision limit pl-return)
- (when (and limit (not (eq 'limit-unsupported pl-return))
- (not is-start-revision))
- (goto-char (point-max))
- (lexical-let ((working-revision working-revision)
- (limit limit))
- (insert "\n")
- (insert-text-button "Show 2X entries"
- 'action (lambda (&rest ignore)
- (vc-print-log-internal
- log-view-vc-backend log-view-vc-fileset
- working-revision nil (* 2 limit)))
- 'help-echo "Show the log again, and double the number of log entries shown")
- (insert " ")
- (insert-text-button "Show unlimited entries"
- 'action (lambda (&rest ignore)
- (vc-print-log-internal
- log-view-vc-backend log-view-vc-fileset
- working-revision nil nil))
- 'help-echo "Show the log again, including all entries"))))
- (defun vc-print-log-internal (backend files working-revision
- &optional is-start-revision limit)
-
-
-
- (let ((dir-present nil)
- (vc-short-log nil)
- (buffer-name "*vc-change-log*")
- type
- pl-return)
- (dolist (file files)
- (when (file-directory-p file)
- (setq dir-present t)))
- (setq vc-short-log
- (not (null (if dir-present
- (memq 'directory vc-log-short-style)
- (memq 'file vc-log-short-style)))))
- (setq type (if vc-short-log 'short 'long))
- (lexical-let
- ((working-revision working-revision)
- (backend backend)
- (limit limit)
- (shortlog vc-short-log)
- (files files)
- (is-start-revision is-start-revision))
- (vc-log-internal-common
- backend buffer-name files type
- (lambda (bk buf type-arg files-arg)
- (vc-call-backend bk 'print-log files-arg buf
- shortlog (when is-start-revision working-revision) limit))
- (lambda (bk files-arg ret)
- (vc-print-log-setup-buttons working-revision
- is-start-revision limit ret))
- (lambda (bk)
- (vc-call-backend bk 'show-log-entry working-revision))
- (lambda (ignore-auto noconfirm)
- (vc-print-log-internal backend files working-revision is-start-revision limit))))))
- (defvar vc-log-view-type nil
- "Set this to differentiate the different types of logs.")
- (put 'vc-log-view-type 'permanent-local t)
- (defun vc-log-internal-common (backend
- buffer-name
- files
- type
- backend-func
- setup-buttons-func
- goto-location-func
- rev-buff-func)
- (let (retval)
- (with-current-buffer (get-buffer-create buffer-name)
- (set (make-local-variable 'vc-log-view-type) type))
- (setq retval (funcall backend-func backend buffer-name type files))
- (pop-to-buffer buffer-name)
- (let ((inhibit-read-only t))
-
-
- (vc-call-backend backend 'log-view-mode)
- (set (make-local-variable 'log-view-vc-backend) backend)
- (set (make-local-variable 'log-view-vc-fileset) files)
- (set (make-local-variable 'revert-buffer-function)
- rev-buff-func))
- (vc-exec-after
- `(let ((inhibit-read-only t))
- (funcall ',setup-buttons-func ',backend ',files ',retval)
- (shrink-window-if-larger-than-buffer)
- (funcall ',goto-location-func ',backend)
- (setq vc-sentinel-movepoint (point))
- (set-buffer-modified-p nil)))))
- (defun vc-incoming-outgoing-internal (backend remote-location buffer-name type)
- (vc-log-internal-common
- backend buffer-name nil type
- (lexical-let
- ((remote-location remote-location))
- (lambda (bk buf type-arg files)
- (vc-call-backend bk type-arg buf remote-location)))
- (lambda (bk files-arg ret))
- (lambda (bk)
- (goto-char (point-min)))
- (lexical-let
- ((backend backend)
- (remote-location remote-location)
- (buffer-name buffer-name)
- (type type))
- (lambda (ignore-auto noconfirm)
- (vc-incoming-outgoing-internal backend remote-location buffer-name type)))))
- (defun vc-print-log (&optional working-revision limit)
- "List the change log of the current fileset in a window.
- If WORKING-REVISION is non-nil, leave point at that revision.
- If LIMIT is non-nil, it should be a number specifying the maximum
- number of revisions to show; the default is `vc-log-show-limit'.
- When called interactively with a prefix argument, prompt for
- WORKING-REVISION and LIMIT."
- (interactive
- (cond
- (current-prefix-arg
- (let ((rev (read-from-minibuffer "Log from revision (default: last revision): " nil
- nil nil nil))
- (lim (string-to-number
- (read-from-minibuffer
- "Limit display (unlimited: 0): "
- (format "%s" vc-log-show-limit)
- nil nil nil))))
- (when (string= rev "") (setq rev nil))
- (when (<= lim 0) (setq lim nil))
- (list rev lim)))
- (t
- (list nil (when (> vc-log-show-limit 0) vc-log-show-limit)))))
- (let* ((vc-fileset (vc-deduce-fileset t))
- (backend (car vc-fileset))
- (files (cadr vc-fileset))
- (working-revision (or working-revision (vc-working-revision (car files)))))
- (vc-print-log-internal backend files working-revision nil limit)))
- (defun vc-print-root-log (&optional limit)
- "List the change log for the current VC controlled tree in a window.
- If LIMIT is non-nil, it should be a number specifying the maximum
- number of revisions to show; the default is `vc-log-show-limit'.
- When called interactively with a prefix argument, prompt for LIMIT."
- (interactive
- (cond
- (current-prefix-arg
- (let ((lim (string-to-number
- (read-from-minibuffer
- "Limit display (unlimited: 0): "
- (format "%s" vc-log-show-limit)
- nil nil nil))))
- (when (<= lim 0) (setq lim nil))
- (list lim)))
- (t
- (list (when (> vc-log-show-limit 0) vc-log-show-limit)))))
- (let ((backend (vc-deduce-backend))
- rootdir working-revision)
- (unless backend
- (error "Buffer is not version controlled"))
- (setq rootdir (vc-call-backend backend 'root default-directory))
- (setq working-revision (vc-working-revision rootdir))
- (vc-print-log-internal backend (list rootdir) working-revision nil limit)))
- (defun vc-log-incoming (&optional remote-location)
- "Show a log of changes that will be received with a pull operation from REMOTE-LOCATION.
- When called interactively with a prefix argument, prompt for REMOTE-LOCATION.."
- (interactive
- (when current-prefix-arg
- (list (read-string "Remote location (empty for default): "))))
- (let ((backend (vc-deduce-backend))
- rootdir working-revision)
- (unless backend
- (error "Buffer is not version controlled"))
- (vc-incoming-outgoing-internal backend remote-location "*vc-incoming*" 'log-incoming)))
- (defun vc-log-outgoing (&optional remote-location)
- "Show a log of changes that will be sent with a push operation to REMOTE-LOCATION.
- When called interactively with a prefix argument, prompt for REMOTE-LOCATION."
- (interactive
- (when current-prefix-arg
- (list (read-string "Remote location (empty for default): "))))
- (let ((backend (vc-deduce-backend))
- rootdir working-revision)
- (unless backend
- (error "Buffer is not version controlled"))
- (vc-incoming-outgoing-internal backend remote-location "*vc-outgoing*" 'log-outgoing)))
- (defun vc-revert ()
- "Revert working copies of the selected fileset to their repository contents.
- This asks for confirmation if the buffer contents are not identical
- to the working revision (except for keyword expansion)."
- (interactive)
- (let* ((vc-fileset (vc-deduce-fileset))
- (files (cadr vc-fileset))
- (queried nil)
- diff-buffer)
-
-
-
- (when (or (not files) (memq (buffer-file-name) files))
- (vc-buffer-sync nil))
- (dolist (file files)
- (let ((buf (get-file-buffer file)))
- (when (and buf (buffer-modified-p buf))
- (error "Please kill or save all modified buffers before reverting")))
- (when (vc-up-to-date-p file)
- (if (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
- (setq queried t)
- (error "Revert canceled"))))
- (unwind-protect
- (when (if vc-revert-show-diff
- (progn
- (setq diff-buffer (generate-new-buffer-name "*vc-diff*"))
- (vc-diff-internal vc-allow-async-revert vc-fileset
- nil nil nil diff-buffer))
-
- (null queried))
- (unless (yes-or-no-p
- (format "Discard changes in %s? "
- (let ((str (vc-delistify files))
- (nfiles (length files)))
- (if (< (length str) 50)
- str
- (format "%d file%s" nfiles
- (if (= nfiles 1) "" "s"))))))
- (error "Revert canceled")))
- (when diff-buffer
- (quit-windows-on diff-buffer t)))
- (dolist (file files)
- (message "Reverting %s..." (vc-delistify files))
- (vc-revert-file file)
- (message "Reverting %s...done" (vc-delistify files)))))
- (defun vc-rollback ()
- "Roll back (remove) the most recent changeset committed to the repository.
- This may be either a file-level or a repository-level operation,
- depending on the underlying version-control system."
- (interactive)
- (let* ((vc-fileset (vc-deduce-fileset))
- (backend (car vc-fileset))
- (files (cadr vc-fileset))
- (granularity (vc-call-backend backend 'revision-granularity)))
- (unless (vc-find-backend-function backend 'rollback)
- (error "Rollback is not supported in %s" backend))
- (when (and (not (eq granularity 'repository)) (/= (length files) 1))
- (error "Rollback requires a singleton fileset or repository versioning"))
-
- (when (not (vc-call-backend backend 'latest-on-branch-p (car files)))
- (error "Rollback is only possible at the tip revision"))
-
-
-
-
- (when (or (not files) (memq (buffer-file-name) files))
- (vc-buffer-sync nil))
- (dolist (file files)
- (when (buffer-modified-p (get-file-buffer file))
- (error "Please kill or save all modified buffers before rollback"))
- (when (not (vc-up-to-date-p file))
- (error "Please revert all modified workfiles before rollback")))
-
- (vc-setup-buffer "*vc-diff*")
- (not-modified)
- (message "Finding changes...")
- (let* ((tip (vc-working-revision (car files)))
-
- (previous (vc-call-backend backend 'previous-revision
- (car files) tip)))
- (vc-diff-internal nil vc-fileset previous tip))
-
- (unless (yes-or-no-p "Discard these revisions? ")
- (error "Rollback canceled"))
- (quit-windows-on "*vc-diff*" t)
-
- (message "Rolling back %s..." (vc-delistify files))
- (with-vc-properties
- files
- (vc-call-backend backend 'rollback files)
- `((vc-state . ,'up-to-date)
- (vc-checkout-time . , (nth 5 (file-attributes file)))
- (vc-working-revision . nil)))
- (dolist (f files) (vc-resynch-buffer f t t))
- (message "Rolling back %s...done" (vc-delistify files))))
- (define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
- (defun vc-pull (&optional arg)
- "Update the current fileset or branch.
- You must be visiting a version controlled file, or in a `vc-dir' buffer.
- On a distributed version control system, this runs a \"pull\"
- operation to update the current branch, prompting for an argument
- list if required. Optional prefix ARG forces a prompt.
- On a non-distributed version control system, update the current
- fileset to the tip revisions. For each unchanged and unlocked
- file, this simply replaces the work file with the latest revision
- on its branch. If the file contains changes, any changes in the
- tip revision are merged into the working file."
- (interactive "P")
- (let* ((vc-fileset (vc-deduce-fileset t))
- (backend (car vc-fileset))
- (files (cadr vc-fileset)))
- (cond
-
- ((vc-find-backend-function backend 'pull)
- (vc-call-backend backend 'pull arg))
-
- ((vc-find-backend-function backend 'merge-news)
- (save-some-buffers
- nil (lambda ()
- (and (buffer-modified-p)
- (let ((file (buffer-file-name)))
- (and file (member file files))))))
- (dolist (file files)
- (if (vc-up-to-date-p file)
- (vc-checkout file nil t)
- (vc-maybe-resolve-conflicts
- file (vc-call-backend backend 'merge-news file)))))
-
- ((eq (vc-checkout-model backend files) 'locking)
- (dolist (file files)
- (if (vc-up-to-date-p file)
- (vc-checkout file nil t))))
- (t
- (error "VC update is unsupported for `%s'" backend)))))
- (defalias 'vc-update 'vc-pull)
- (defun vc-version-backup-file (file &optional rev)
- "Return name of backup file for revision REV of FILE.
- If version backups should be used for FILE, and there exists
- such a backup for REV or the working revision of file, return
- its name; otherwise return nil."
- (when (vc-call make-version-backups-p file)
- (let ((backup-file (vc-version-backup-file-name file rev)))
- (if (file-exists-p backup-file)
- backup-file
-
- (setq backup-file (vc-version-backup-file-name file rev 'manual))
- (when (file-exists-p backup-file)
- backup-file)))))
- (defun vc-revert-file (file)
- "Revert FILE back to the repository working revision it was based on."
- (with-vc-properties
- (list file)
- (let ((backup-file (vc-version-backup-file file)))
- (when backup-file
- (copy-file backup-file file 'ok-if-already-exists)
- (vc-delete-automatic-version-backups file))
- (vc-call revert file backup-file))
- `((vc-state . up-to-date)
- (vc-checkout-time . ,(nth 5 (file-attributes file)))))
- (vc-resynch-buffer file t t))
- (defun vc-switch-backend (file backend)
- "Make BACKEND the current version control system for FILE.
- FILE must already be registered in BACKEND. The change is not
- permanent, only for the current session. This function only changes
- VC's perspective on FILE, it does not register or unregister it.
- By default, this command cycles through the registered backends.
- To get a prompt, use a prefix argument."
- (interactive
- (list
- (or buffer-file-name
- (error "There is no version-controlled file in this buffer"))
- (let ((crt-bk (vc-backend buffer-file-name))
- (backends nil))
- (unless crt-bk
- (error "File %s is not under version control" buffer-file-name))
-
- (dolist (crt vc-handled-backends)
- (when (and (vc-call-backend crt 'registered buffer-file-name)
- (not (eq crt-bk crt)))
- (push crt backends)))
-
- (let ((def (car backends))
- (others backends))
- (cond
- ((null others) (error "No other backend to switch to"))
- (current-prefix-arg
- (intern
- (upcase
- (completing-read
- (format "Switch to backend [%s]: " def)
- (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
- nil t nil nil (downcase (symbol-name def))))))
- (t def))))))
- (unless (eq backend (vc-backend file))
- (vc-file-clearprops file)
- (vc-file-setprop file 'vc-backend backend)
-
- (unless (vc-call-backend backend 'registered file)
- (vc-file-clearprops file)
- (error "%s is not registered in %s" file backend))
- (vc-mode-line file)))
- (defun vc-transfer-file (file new-backend)
- "Transfer FILE to another version control system NEW-BACKEND.
- If NEW-BACKEND has a higher precedence than FILE's current backend
- \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
- NEW-BACKEND, using the revision number from the current backend as the
- base level. If NEW-BACKEND has a lower precedence than the current
- backend, then commit all changes that were made under the current
- backend to NEW-BACKEND, and unregister FILE from the current backend.
- \(If FILE is not yet registered under NEW-BACKEND, register it.)"
- (let* ((old-backend (vc-backend file))
- (edited (memq (vc-state file) '(edited needs-merge)))
- (registered (vc-call-backend new-backend 'registered file))
- (move
- (and registered
-
- (or (memq new-backend (memq old-backend vc-handled-backends))
- (y-or-n-p "Final transfer? "))))
- ( nil))
- (when (eq old-backend new-backend)
- (error "%s is the current backend of %s" new-backend file))
- (if registered
- (set-file-modes file (logior (file-modes file) 128))
-
- (vc-switch-backend file old-backend)
- (let* ((rev (vc-working-revision file))
- (modified-file (and edited (make-temp-file file)))
- (unmodified-file (and modified-file (vc-version-backup-file file))))
-
- (unwind-protect
- (progn
- (when modified-file
- (copy-file file modified-file 'ok-if-already-exists)
-
-
-
- (if unmodified-file
- (copy-file unmodified-file file
- 'ok-if-already-exists 'keep-date)
- (when (y-or-n-p "Get base revision from repository? ")
- (vc-revert-file file))))
- (vc-call-backend new-backend 'receive-file file rev))
- (when modified-file
- (vc-switch-backend file new-backend)
- (unless (eq (vc-checkout-model new-backend (list file)) 'implicit)
- (vc-checkout file t nil))
- (rename-file modified-file file 'ok-if-already-exists)
- (vc-file-setprop file 'vc-checkout-time nil)))))
- (when move
- (vc-switch-backend file old-backend)
- (setq comment (vc-call-backend old-backend 'comment-history file))
- (vc-call-backend old-backend 'unregister file))
- (vc-switch-backend file new-backend)
- (when (or move edited)
- (vc-file-setprop file 'vc-state 'edited)
- (vc-mode-line file new-backend)
- (vc-checkin file new-backend nil comment (stringp comment)))))
- (defun vc-rename-master (oldmaster newfile templates)
- "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
- (let* ((dir (file-name-directory (expand-file-name oldmaster)))
- (newdir (or (file-name-directory newfile) ""))
- (newbase (file-name-nondirectory newfile))
- (masters
-
- (mapcar
- (lambda (s) (vc-possible-master s newdir newbase))
- templates)))
- (when (or (file-symlink-p oldmaster)
- (file-symlink-p (file-name-directory oldmaster)))
- (error "This is unsafe in the presence of symbolic links"))
- (rename-file
- oldmaster
- (catch 'found
-
- (dolist (f masters)
- (when (and f (string= (file-name-directory (expand-file-name f)) dir))
- (throw 'found f)))
-
- (dolist (f masters)
- (and f (or (not (setq dir (file-name-directory f)))
- (file-directory-p dir))
- (throw 'found f)))
- (error "New file lacks a version control directory")))))
- (defun vc-delete-file (file)
- "Delete file and mark it as such in the version control system."
- (interactive "fVC delete file: ")
- (setq file (expand-file-name file))
- (let ((buf (get-file-buffer file))
- (backend (vc-backend file)))
- (unless backend
- (error "File %s is not under version control"
- (file-name-nondirectory file)))
- (unless (vc-find-backend-function backend 'delete-file)
- (error "Deleting files under %s is not supported in VC" backend))
- (when (and buf (buffer-modified-p buf))
- (error "Please save or undo your changes before deleting %s" file))
- (let ((state (vc-state file)))
- (when (eq state 'edited)
- (error "Please commit or undo your changes before deleting %s" file))
- (when (eq state 'conflict)
- (error "Please resolve the conflicts before deleting %s" file)))
- (unless (y-or-n-p (format "Really want to delete %s? "
- (file-name-nondirectory file)))
- (error "Abort!"))
- (unless (or (file-directory-p file) (null make-backup-files)
- (not (file-exists-p file)))
- (with-current-buffer (or buf (find-file-noselect file))
- (let ((backup-inhibited nil))
- (backup-buffer))))
-
-
- (let ((default-directory (file-name-directory file)))
- (vc-call-backend backend 'delete-file file))
-
- (when (file-exists-p file) (delete-file file))
-
- (vc-file-clearprops file)
-
-
- (vc-resynch-buffer file nil t)))
- (defun vc-rename-file (old new)
- "Rename file OLD to NEW in both work area and repository."
- (interactive "fVC rename file: \nFRename to: ")
-
- (let ((old-base (file-name-nondirectory old)))
- (when (and (not (string= "" old-base))
- (string= "" (file-name-nondirectory new)))
- (setq new (concat new old-base))))
- (let ((oldbuf (get-file-buffer old)))
- (when (and oldbuf (buffer-modified-p oldbuf))
- (error "Please save files before moving them"))
- (when (get-file-buffer new)
- (error "Already editing new file name"))
- (when (file-exists-p new)
- (error "New file already exists"))
- (let ((state (vc-state old)))
- (unless (memq state '(up-to-date edited))
- (error "Please %s files before moving them"
- (if (stringp state) "check in" "update"))))
- (vc-call rename-file old new)
- (vc-file-clearprops old)
-
- (when (file-exists-p old) (rename-file old new))
-
-
-
- (when oldbuf
- (with-current-buffer oldbuf
- (let ((buffer-read-only buffer-read-only))
- (set-visited-file-name new))
- (vc-mode-line new (vc-backend new))
- (set-buffer-modified-p nil)))))
- (defun vc-update-change-log (&rest args)
- "Find change log file and add entries from recent version control logs.
- Normally, find log entries for all registered files in the default
- directory.
- With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
- With any numeric prefix arg, find log entries for all currently visited
- files that are under version control. This puts all the entries in the
- log for the default directory, which may not be appropriate.
- From a program, any ARGS are assumed to be filenames for which
- log entries should be gathered."
- (interactive
- (cond ((consp current-prefix-arg)
- (list buffer-file-name))
- (current-prefix-arg
- (let ((files nil)
- (buffers (buffer-list))
- file)
- (while buffers
- (setq file (buffer-file-name (car buffers)))
- (and file (vc-backend file)
- (setq files (cons file files)))
- (setq buffers (cdr buffers)))
- files))
- (t
-
-
-
- nil)))
- (vc-call-backend (vc-responsible-backend default-directory)
- 'update-changelog args))
- (defun vc-branch-p (rev)
- "Return t if REV is a branch revision."
- (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
- (defun vc-branch-part (rev)
- "Return the branch part of a revision number REV."
- (let ((index (string-match "\\.[0-9]+\\'" rev)))
- (when index
- (substring rev 0 index))))
- (defun vc-default-responsible-p (backend file)
- "Indicate whether BACKEND is responsible for FILE.
- The default is to return nil always."
- nil)
- (defun vc-default-could-register (backend file)
- "Return non-nil if BACKEND could be used to register FILE.
- The default implementation returns t for all files."
- t)
- (defun vc-default-latest-on-branch-p (backend file)
- "Return non-nil if FILE is the latest on its branch.
- This default implementation always returns non-nil, which means that
- editing non-current revisions is not supported by default."
- t)
- (defun vc-default-init-revision (backend) vc-default-init-revision)
- (defun vc-default-find-revision (backend file rev buffer)
- "Provide the new `find-revision' op based on the old `checkout' op.
- This is only for compatibility with old backends. They should be updated
- to provide the `find-revision' operation instead."
- (let ((tmpfile (make-temp-file (expand-file-name file))))
- (unwind-protect
- (progn
- (vc-call-backend backend 'checkout file nil rev tmpfile)
- (with-current-buffer buffer
- (insert-file-contents-literally tmpfile)))
- (delete-file tmpfile))))
- (defun vc-default-rename-file (backend old new)
- (condition-case nil
- (add-name-to-file old new)
- (error (rename-file old new)))
- (vc-delete-file old)
- (with-current-buffer (find-file-noselect new)
- (vc-register)))
- (defalias 'vc-default-check-headers 'ignore)
- (declare-function log-edit-mode "log-edit" ())
- (defun vc-default-log-edit-mode (backend) (log-edit-mode))
- (defun vc-default-log-view-mode (backend) (log-view-mode))
- (defun vc-default-show-log-entry (backend rev)
- (with-no-warnings
- (log-view-goto-rev rev)))
- (defun vc-default-comment-history (backend file)
- "Return a string with all log entries stored in BACKEND for FILE."
- (when (vc-find-backend-function backend 'print-log)
- (with-current-buffer "*vc*"
- (vc-call-backend backend 'print-log (list file))
- (buffer-string))))
- (defun vc-default-receive-file (backend file rev)
- "Let BACKEND receive FILE from another version control system."
- (vc-call-backend backend 'register (list file) rev ""))
- (defun vc-default-retrieve-tag (backend dir name update)
- (if (string= name "")
- (progn
- (vc-file-tree-walk
- dir
- (lambda (f) (and
- (vc-up-to-date-p f)
- (vc-error-occurred
- (vc-call-backend backend 'checkout f nil "")
- (when update (vc-resynch-buffer f t t)))))))
- (let ((result (vc-tag-precondition dir)))
- (if (stringp result)
- (error "File %s is locked" result)
- (setq update (and (eq result 'visited) update))
- (vc-file-tree-walk
- dir
- (lambda (f) (vc-error-occurred
- (vc-call-backend backend 'checkout f nil name)
- (when update (vc-resynch-buffer f t t)))))))))
- (defun vc-default-revert (backend file contents-done)
- (unless contents-done
- (let ((rev (vc-working-revision file))
- (file-buffer (or (get-file-buffer file) (current-buffer))))
- (message "Checking out %s..." file)
- (let ((failed t)
- (backup-name (car (find-backup-file-name file))))
- (when backup-name
- (copy-file file backup-name 'ok-if-already-exists 'keep-date)
- (unless (file-writable-p file)
- (set-file-modes file (logior (file-modes file) 128))))
- (unwind-protect
- (let ((coding-system-for-read 'no-conversion)
- (coding-system-for-write 'no-conversion))
- (with-temp-file file
- (let ((outbuf (current-buffer)))
-
- (with-current-buffer file-buffer
- (let ((default-directory (file-name-directory file)))
- (vc-call-backend backend 'find-revision
- file rev outbuf)))))
- (setq failed nil))
- (when backup-name
- (if failed
- (rename-file backup-name file 'ok-if-already-exists)
- (and (not vc-make-backup-files) (delete-file backup-name))))))
- (message "Checking out %s...done" file))))
- (defalias 'vc-default-revision-completion-table 'ignore)
- (defalias 'vc-default-mark-resolved 'ignore)
- (defun vc-default-dir-status-files (backend dir files default-state update-function)
- (funcall update-function
- (mapcar (lambda (file) (list file default-state)) files)))
- (defun vc-check-headers ()
- "Check if the current file has any headers in it."
- (interactive)
- (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
- (defun vc-string-prefix-p (prefix string)
- (let ((lpref (length prefix)))
- (and (>= (length string) lpref)
- (eq t (compare-strings prefix nil nil string nil lpref)))))
- (defun vc-file-tree-walk (dirname func &rest args)
- "Walk recursively through DIRNAME.
- Invoke FUNC f ARGS on each VC-managed file f underneath it."
- (vc-file-tree-walk-internal (expand-file-name dirname) func args)
- (message "Traversing directory %s...done" dirname))
- (defun vc-file-tree-walk-internal (file func args)
- (if (not (file-directory-p file))
- (when (vc-backend file) (apply func file args))
- (message "Traversing directory %s..." (abbreviate-file-name file))
- (let ((dir (file-name-as-directory file)))
- (mapcar
- (lambda (f) (or
- (string-equal f ".")
- (string-equal f "..")
- (member f vc-directory-exclusion-list)
- (let ((dirf (expand-file-name f dir)))
- (or
- (file-symlink-p dirf)
- (vc-file-tree-walk-internal dirf func args)))))
- (directory-files dir)))))
- (provide 'vc)
|