📄 vc-svn.el
字号:
;; respect to the latest version on the
;; current branch, and not locked.
;;
;; This is also returned for files which do not
;; exist, as will be the case when finding a
;; new file in a svn-controlled directory. That
;; case is handled in vc-svn-parse-status.
((looking-at " ") 'up-to-date)
;; 'needs-merge The file has been edited by the user,
;; and there is also a more recent version
;; on the current branch stored in the
;; master file. This state can only occur
;; if locking is not used for the file.
((looking-at "\\S-+\\s-+\\*") 'needs-merge)
;; 'edited The working file has been edited by the
;; user. If locking is used for the file,
;; this state means that the current
;; version is locked by the calling user.
(t 'edited)))
;;; Is it really safe not to check for updates? I haven't seen any
;;; cases where failing to check causes a problem that is not caught
;;; in some other way. However, there *are* cases where checking
;;; needlessly causes network delay, such as C-x v v. The common case
;;; is for the commit to be OK; we can handle errors if they occur. -- mbp
(defun vc-svn-state (file)
"Return the current version control state of FILE.
For a list of possible return values, see `vc-state'.
This function should do a full and reliable state computation; it is
usually called immediately after `C-x v v'. `vc-svn-state-heuristic'
provides a faster heuristic when visiting a file.
For svn this does *not* check for updates in the repository, because
that needlessly slows down vc when the repository is remote. Instead,
we rely on Subversion to trap situations such as needing a merge
before commit."
(car (vc-svn-run-status file)))
(defun vc-svn-state-heuristic (file)
"Estimate the version control state of FILE at visiting time.
For a list of possible values, see the doc string of `vc-state'.
This is supposed to be considerably faster than `vc-svn-state'. It
just runs `svn status -v', without the `-u' flag, so it's a strictly
local operation."
(car (vc-svn-run-status file)))
(defun vc-svn-workfile-version (file)
"Return the current workfile version of FILE."
(cadr (vc-svn-run-status file)))
(defun vc-svn-checkout-model (file)
'implicit)
(defun vc-svn-register (file &optional rev comment)
"Register FILE with Subversion.
REV is an initial revision; Subversion ignores it.
COMMENT is an initial description of the file; currently this is ignored."
(vc-svn-with-output-buffer
(let ((status (call-process vc-svn-program-name nil t nil "add" file)))
(or (equal 0 status) ; not zerop; status can be a string
(vc-svn-pop-up-error "Error running Subversion to add `%s'"
(file-name-nondirectory file))))))
(defun vc-svn-checkin (file rev comment)
(apply 'vc-do-command nil 0 vc-svn-program-name file
"commit" (if comment (list "-m" comment) '())))
(defun vc-svn-checkout (file &optional editable rev destfile)
"Check out revision REV of FILE into the working area.
The EDITABLE argument must be non-nil, since Subversion doesn't
support locking.
If REV is non-nil, that is the revision to check out (default is
current workfile version). If REV is the empty string, that means to
check out the head of the trunk. For Subversion, that's equivalent to
passing nil.
If optional arg DESTFILE is given, it is an alternate filename to
write the contents to; we raise an error."
(unless editable
(error "VC asked Subversion to check out a read-only copy of file"))
(when destfile
(error "VC asked Subversion to check out a file under another name"))
(when (equal rev "")
(setq rev nil))
(apply 'vc-do-command nil 0 vc-svn-program-name file
"update" (if rev (list "-r" rev) '()))
(vc-file-setprop file 'vc-workfile-version nil))
(defun vc-svn-revert (file &optional contents-done)
"Revert FILE back to the current workfile version.
If optional arg CONTENTS-DONE is non-nil, then the contents of FILE
have already been reverted from a version backup, and this function
only needs to update the status of FILE within the backend. This
function ignores the CONTENTS-DONE argument."
(vc-do-command nil 0 vc-svn-program-name file "revert"))
(defun vc-svn-merge-news (file)
"Merge recent changes into FILE.
This calls `svn update'. In the case of conflicts, Subversion puts
conflict markers into the file and leaves additional temporary files
containing the `ancestor', `mine', and `other' files.
You may need to run `svn resolved' by hand once these conflicts have
been resolved.
Returns a vc status, which is used to determine whether conflicts need
to be merged."
(prog1
(vc-do-command nil 0 vc-svn-program-name file "update")
;; This file may not have changed in the revisions which were
;; merged, which means that its mtime on disk will not have been
;; updated. However, the workfile version may still have been
;; updated, and we want that to be shown correctly in the
;; modeline.
;; vc-cvs does something like this
(vc-file-setprop file 'vc-checkout-time 0)
(vc-file-setprop file 'vc-workfile-version
(vc-svn-workfile-version file))))
(defun vc-svn-print-log (file)
"Insert the revision log of FILE into the *vc* buffer."
(vc-do-command nil 'async vc-svn-program-name file "log"))
(defun vc-svn-show-log-entry (version)
"Search the log entry for VERSION in the current buffer.
Make sure it is displayed in the buffer's window."
(when (re-search-forward (concat "^-+\n\\(rev\\) "
(regexp-quote version)
":[^|]+|[^|]+| [0-9]+ lines?"))
(goto-char (match-beginning 1))
(recenter 1)))
(defun vc-svn-diff (file &optional rev1 rev2)
"Insert the diff for FILE into the *vc-diff* buffer.
If REV1 and REV2 are non-nil, report differences from REV1 to REV2.
If REV1 is nil, use the current workfile version (as found in the
repository) as the older version; if REV2 is nil, use the current
workfile contents as the newer version.
This function returns a status of either 0 (no differences found), or
1 (either non-empty diff or the diff is run asynchronously)."
(let* ((diff-switches-list
;; In Emacs 21.3.50 or so, the `vc-diff-switches-list' macro
;; started requiring its symbol argument to be quoted.
(condition-case nil
(vc-diff-switches-list svn)
(void-variable (vc-diff-switches-list 'SVN))))
(status (vc-svn-run-status file))
(local (elt status 1))
(changed (elt status 2))
;; If rev1 is the default (the base revision) set it to nil.
;; This is nice because it lets us recognize when the diff
;; will run locally, and thus when we shouldn't bother to run
;; it asynchronously. But it's also necessary, since a diff
;; for vc-default-workfile-unchanged-p *must* run
;; synchronously, or else you'll end up with two diffs in the
;; *vc-diff* buffer. `vc-diff-workfile-unchanged-p' passes
;; the base revision explicitly, but this kludge lets us
;; recognize that we can run the diff synchronously anyway.
;; Fragile, no?
(rev1 (if (and rev1 (not (equal rev1 local))) rev1))
(rev-switches-list
(cond
;; Given base rev against given rev.
((and rev1 rev2) (list "-r" (format "%s:%s" rev1 rev2)))
;; Given base rev against working copy.
(rev1 (list "-r" rev1))
;; Working copy base against given rev.
(rev2 (list "-r" (format "%s:%s" local rev2)))
;; Working copy base against working copy.
(t '())))
;; Run diff asynchronously if we're going to have to go
;; across the network.
(async (or rev1 rev2)))
(let ((status (apply 'vc-do-command "*vc-diff*" (if async 'async 0)
vc-svn-program-name file
(append '("diff") rev-switches-list))))
(if (or async (> (buffer-size (get-buffer "*vc-diff*")) 0))
1 0))))
(defun vc-svn-find-version (file rev buffer)
(vc-do-command buffer 0 vc-svn-program-name file
"cat" "-r" rev))
(provide 'vc-svn)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -