1 ;;; psvn.el --- Subversion interface for emacs
2 ;; Copyright (C) 2002-2008 by Stefan Reichoer
4 ;; Author: Stefan Reichoer <stefan@xsteve.at>
7 ;; psvn.el is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; psvn.el is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
24 ;; psvn.el is tested with GNU Emacs 21.3 on windows, debian linux,
25 ;; freebsd5, red hat el4, ubuntu edgy with svn 1.4.0
27 ;; psvn.el needs at least svn 1.1.0
28 ;; if you upgrade to a higher version, you need to do a fresh checkout
30 ;; psvn.el is an interface for the revision control tool subversion
31 ;; (see http://subversion.tigris.org)
32 ;; psvn.el provides a similar interface for subversion as pcl-cvs for cvs.
33 ;; At the moment the following commands are implemented:
35 ;; M-x svn-status: run 'svn -status -v'
36 ;; M-x svn-examine (like pcl-cvs cvs-examine) is alias for svn-status
38 ;; and show the result in the svn-status-buffer-name buffer (normally: *svn-status*).
39 ;; If svn-status-verbose is set to nil, only "svn status" without "-v"
40 ;; is run. Currently you have to toggle this variable manually.
41 ;; This buffer uses svn-status mode in which the following keys are defined:
42 ;; g - svn-status-update: run 'svn status -v'
43 ;; M-s - svn-status-update: run 'svn status -v'
44 ;; C-u g - svn-status-update: run 'svn status -vu'
45 ;; = - svn-status-show-svn-diff run 'svn diff'
46 ;; l - svn-status-show-svn-log run 'svn log'
47 ;; i - svn-status-info run 'svn info'
48 ;; r - svn-status-revert run 'svn revert'
49 ;; X v - svn-status-resolved run 'svn resolved'
50 ;; U - svn-status-update-cmd run 'svn update'
51 ;; M-u - svn-status-update-cmd run 'svn update'
52 ;; c - svn-status-commit run 'svn commit'
53 ;; a - svn-status-add-file run 'svn add --non-recursive'
54 ;; A - svn-status-add-file-recursively run 'svn add'
55 ;; + - svn-status-make-directory run 'svn mkdir'
56 ;; R - svn-status-mv run 'svn mv'
57 ;; C - svn-status-cp run 'svn cp'
58 ;; D - svn-status-rm run 'svn rm'
59 ;; M-c - svn-status-cleanup run 'svn cleanup'
60 ;; k - svn-status-lock run 'svn lock'
61 ;; K - svn-status-unlock run 'svn unlock'
62 ;; b - svn-status-blame run 'svn blame'
63 ;; X e - svn-status-export run 'svn export'
64 ;; RET - svn-status-find-file-or-examine-directory
65 ;; ^ - svn-status-examine-parent
66 ;; ~ - svn-status-get-specific-revision
67 ;; E - svn-status-ediff-with-revision
68 ;; X X - svn-status-resolve-conflicts
69 ;; s - svn-status-show-process-buffer
70 ;; h - svn-status-pop-to-partner-buffer
71 ;; e - svn-status-toggle-edit-cmd-flag
72 ;; ? - svn-status-toggle-hide-unknown
73 ;; _ - svn-status-toggle-hide-unmodified
74 ;; m - svn-status-set-user-mark
75 ;; u - svn-status-unset-user-mark
76 ;; $ - svn-status-toggle-elide
77 ;; w - svn-status-copy-current-line-info
78 ;; DEL - svn-status-unset-user-mark-backwards
79 ;; * ! - svn-status-unset-all-usermarks
80 ;; * ? - svn-status-mark-unknown
81 ;; * A - svn-status-mark-added
82 ;; * M - svn-status-mark-modified
83 ;; * D - svn-status-mark-deleted
84 ;; * * - svn-status-mark-changed
85 ;; * . - svn-status-mark-by-file-ext
86 ;; * % - svn-status-mark-filename-regexp
87 ;; . - svn-status-goto-root-or-return
88 ;; f - svn-status-find-file
89 ;; o - svn-status-find-file-other-window
90 ;; C-o - svn-status-find-file-other-window-noselect
91 ;; v - svn-status-view-file-other-window
92 ;; I - svn-status-parse-info
93 ;; V - svn-status-svnversion
94 ;; P l - svn-status-property-list
95 ;; P s - svn-status-property-set
96 ;; P d - svn-status-property-delete
97 ;; P e - svn-status-property-edit-one-entry
98 ;; P i - svn-status-property-ignore-file
99 ;; P I - svn-status-property-ignore-file-extension
100 ;; P C-i - svn-status-property-edit-svn-ignore
101 ;; P k - svn-status-property-set-keyword-list
102 ;; P K i - svn-status-property-set-keyword-id
103 ;; P K d - svn-status-property-set-keyword-date
104 ;; P y - svn-status-property-set-eol-style
105 ;; P x - svn-status-property-set-executable
106 ;; P m - svn-status-property-set-mime-type
107 ;; H - svn-status-use-history
108 ;; x - svn-status-update-buffer
109 ;; q - svn-status-bury-buffer
111 ;; C-x C-j - svn-status-dired-jump
113 ;; The output in the buffer contains this header to ease reading
115 ;; FPH BASE CMTD Author em File
119 ;; BASE = local base revision
120 ;; CMTD = last committed revision
121 ;; Author = author of change
122 ;; em = "**" or "(Update Available)" [see `svn-status-short-mod-flag-p']
123 ;; if file can be updated
124 ;; File = path/filename
127 ;; To use psvn.el put the following line in your .emacs:
129 ;; Start the svn interface with M-x svn-status
131 ;; The latest version of psvn.el can be found at:
132 ;; http://www.xsteve.at/prg/emacs/psvn.el
133 ;; Or you can check it out from the subversion repository:
134 ;; svn co http://svn.collab.net/repos/svn/trunk/contrib/client-side/emacs emacs-svn
137 ;; * shortcut for svn propset svn:keywords "Date" psvn.el
138 ;; * docstrings for the functions
139 ;; * perhaps shortcuts for ranges, dates
140 ;; * when editing the command line - offer help from the svn client
141 ;; * finish svn-status-property-set
142 ;; * Add repository browser
143 ;; * Get rid of all byte-compiler warnings
144 ;; * SVK working copy support
145 ;; * multiple independent buffers in svn-status-mode
146 ;; There are "TODO" comments in other parts of this file as well.
148 ;; Overview over the implemented/not (yet) implemented svn sub-commands:
150 ;; * blame implemented
152 ;; * checkout (co) implemented
153 ;; * cleanup implemented
154 ;; * commit (ci) implemented
155 ;; * copy (cp) implemented
156 ;; * delete (del, remove, rm) implemented
157 ;; * diff (di) implemented
158 ;; * export implemented
160 ;; * import used (in svn-admin-create-trunk-directory)
161 ;; * info implemented
162 ;; * list (ls) implemented
163 ;; * lock implemented
166 ;; * mkdir implemented
167 ;; * move (mv, rename, ren) implemented
168 ;; * propdel (pdel) implemented
169 ;; * propedit (pedit, pe) not needed
170 ;; * propget (pget, pg) used (in svn-status-property-edit)
171 ;; * proplist (plist, pl) implemented
172 ;; * propset (pset, ps) used (in svn-prop-edit-do-it)
173 ;; * resolved implemented
174 ;; * revert implemented
175 ;; * status (stat, st) implemented
177 ;; * unlock implemented
178 ;; * update (up) implemented
180 ;; For the not yet implemented commands you should use the command line
181 ;; svn client. If there are user requests for any missing commands I will
182 ;; probably implement them.
184 ;; There is also limited support for the web-based software project management and bug/issue tracking system trac
185 ;; Trac ticket links can be enabled in the *svn-log* buffers when using the following:
186 ;; (setq svn-log-link-handlers '(trac-ticket-short))
188 ;; Comments / suggestions and bug reports are welcome!
193 ;; "svn-" is the package prefix used in psvn.el. There are also longer
194 ;; prefixes which clarify the code and help symbol completion, but they
195 ;; are not intended to prevent name clashes with other packages. All
196 ;; interactive commands meant to be used only in a specific mode should
197 ;; have names beginning with the name of that mode: for example,
198 ;; "svn-status-add-file" in "svn-status-mode". "psvn" should be used
199 ;; only in names of files, customization groups, and features. If SVK
200 ;; support is ever added, it should use "svn-svk-" when no existing
201 ;; prefix is applicable.
203 ;; Many of the variables marked as `risky-local-variable' are probably
204 ;; impossible to abuse, as the commands that read them are used only in
205 ;; buffers that are not visiting any files. Better safe than sorry.
211 (eval-when-compile (require 'dired
))
212 (eval-when-compile (require 'ediff-util
))
213 (eval-when-compile (require 'elp
))
214 (eval-when-compile (require 'pp
))
218 (require 'diff-mode
))
221 (defconst svn-psvn-revision
"$Id$"
222 "The revision number of psvn.")
224 ;;; user setable variables
225 (defcustom svn-status-verbose t
226 "*Add '-v' to svn status call.
227 This can be toggled with \\[svn-status-toggle-svn-verbose-flag]."
230 (defcustom svn-log-edit-file-name
"++svn-log++"
231 "*Name of a saved log file.
232 This can be either absolute, or relative to the default directory
233 of the `svn-log-edit-buffer-name' buffer."
236 (put 'svn-log-edit-file-name
'risky-local-variable t
)
237 (defcustom svn-log-edit-insert-files-to-commit t
238 "*Insert the filelist to commit in the *svn-log* buffer"
241 (defcustom svn-log-edit-show-diff-for-commit nil
242 "*Show the diff being committed when you run `svn-status-commit.'."
245 (defcustom svn-log-edit-use-log-edit-mode
246 (and (condition-case nil
(require 'log-edit
) (error nil
)) t
)
247 "*Use log-edit-mode as base for svn-log-edit-mode
248 This variable takes effect only when psvn.el is being loaded."
251 (defcustom svn-log-edit-paragraph-start
252 "$\\|[ \t]*$\\|##.*$\\|\\*.*:.*$\\|[ \t]+(.+):.*$"
253 "*Value used for `paragraph-start' in `svn-log-edit-buffer-name' buffer."
256 (defcustom svn-log-edit-paragraph-separate
"$\\|##.*$"
257 "*Value used for `paragraph-separate' in `svn-log-edit-buffer-name' buffer."
260 (defcustom svn-status-hide-unknown nil
261 "*Hide unknown files in `svn-status-buffer-name' buffer.
262 This can be toggled with \\[svn-status-toggle-hide-unknown]."
265 (defcustom svn-status-hide-unmodified nil
266 "*Hide unmodified files in `svn-status-buffer-name' buffer.
267 This can be toggled with \\[svn-status-toggle-hide-unmodified]."
270 (defcustom svn-status-sort-status-buffer t
271 "*Whether to sort the `svn-status-buffer-name' buffer.
273 Setting this variable to nil speeds up \\[M-x svn-status], however the
274 listing may then become incorrect.
276 This can be toggled with \\[svn-status-toggle-sort-status-buffer]."
280 (defcustom svn-status-ediff-delete-temporary-files nil
281 "*Whether to delete temporary ediff files. If set to ask, ask the user"
282 :type
'(choice (const t
)
287 (defcustom svn-status-changelog-style
'changelog
288 "*The changelog style that is used for `svn-file-add-to-changelog'.
290 'changelog: use `add-change-log-entry-other-window'
291 'svn-dev: use commit messages that are used by the svn developers
292 a function: This function is called to add a new entry to the changelog file.
294 :type
'(set (const changelog
)
298 (defcustom svn-status-unmark-files-after-list
'(commit revert
)
299 "*List of operations after which all user marks will be removed.
300 Possible values are: commit, revert."
301 :type
'(set (const commit
)
305 (defcustom svn-status-preserve-window-configuration t
306 "*Try to preserve the window configuration."
310 (defcustom svn-status-auto-revert-buffers t
311 "*Auto revert buffers that have changed on disk."
315 (defcustom svn-status-negate-meaning-of-arg-commands
'()
316 "*List of operations that should use a negated meaning of the prefix argument.
317 The supported functions are `svn-status' and `svn-status-set-user-mark'."
318 :type
'(set (function-item svn-status
)
319 (function-item svn-status-set-user-mark
))
322 (defcustom svn-status-svn-executable
"svn"
323 "*The name of the svn executable.
324 This can be either absolute or looked up on `exec-path'."
325 ;; Don't use (file :must-match t). It doesn't know about `exec-path'.
328 (put 'svn-status-svn-executable
'risky-local-variable t
)
330 (defcustom svn-status-default-export-directory
"~/" "*The default directory that is suggested svn export."
334 (defcustom svn-status-svn-environment-var-list
'("LC_MESSAGES=C" "LC_ALL=")
335 "*A list of environment variables that should be set for that svn process.
336 Each element is either a string \"VARIABLE=VALUE\" which will be added to
337 the environment when svn is run, or just \"VARIABLE\" which causes that
338 variable to be entirely removed from the environment.
340 The default setting is '(\"LC_MESSAGES=C\" \"LC_ALL=\"). This ensures that the svn command
341 line client does not output localized strings. psvn.el relies on the english
343 :type
'(repeat string
)
345 (put 'svn-status-svn-environment-var-list
'risky-local-variable t
)
347 (defcustom svn-browse-url-function nil
348 ;; If the user hasn't changed `svn-browse-url-function', then changing
349 ;; `browse-url-browser-function' should affect psvn even after it has
351 "Function to display a Subversion related WWW page in a browser.
352 So far, this is used only for \"trac\" issue tracker integration.
353 By default, this is nil, which means use `browse-url-browser-function'.
354 Any non-nil value overrides that variable, with the same syntax."
355 ;; It would be nice to show the full list of browsers supported by
356 ;; browse-url, but (custom-variable-type 'browse-url-browser-function)
357 ;; returns just `function' if browse-url has not yet been loaded,
358 ;; and there seems to be no easy way to autoload browse-url when
359 ;; the custom-type of svn-browse-url-function is actually needed.
360 ;; So I'll only offer enough choices to cover all supported types.
361 :type
`(choice (const :tag
"Specified by `browse-url-browser-function'" nil
)
362 (function :value browse-url-default-browser
363 ;; In XEmacs 21.4.17, the `function' widget matches
364 ;; all objects. Constrain it here so that alists
365 ;; fall through to the next choice. Accept either
366 ;; a symbol (fbound or not) or a lambda expression.
367 :match
,(lambda (widget value
)
368 (or (symbolp value
) (functionp value
))))
369 (svn-alist :tag
"Regexp/function association list"
370 :key-type regexp
:value-type function
371 :value
(("." . browse-url-default-browser
))))
372 :link
'(emacs-commentary-link "browse-url")
374 ;; (put 'svn-browse-url-function 'risky-local-variable t)
375 ;; already implied by "-function" suffix
377 (defcustom svn-status-window-alist
378 '((diff "*svn-diff*") (log "*svn-log*") (info t
) (blame t
) (proplist t
) (update t
))
379 "An alist to specify which windows should be used for svn command outputs.
380 The following keys are supported: diff, log, info, blame, proplist, update.
381 The following values can be given:
382 nil ... show in `svn-process-buffer-name' buffer
383 t ... show in dedicated *svn-info* buffer
384 invisible ... don't show the buffer (eventually useful for update)
385 a string ... show in a buffer named string"
390 (const :tag
"Show in *svn-process* buffer" nil
)
391 (const :tag
"Show in dedicated *svn-info* buffer" t
)
392 (const :tag
"Don't show the output" invisible
)
393 (string :tag
"Show in a buffer named"))))
394 :options
'(diff log info blame proplist update
)
397 (defcustom svn-status-short-mod-flag-p t
398 "*Whether the mark for out of date files is short or long.
400 If this variable is is t, and a file is out of date (i.e., there is a newer
401 version in the repository than the working copy), then the file will
404 If this variable is nil, and the file is out of date then the longer phrase
405 \"(Update Available)\" is used.
407 In either case the mark gets the face
408 `svn-status-update-available-face', and will only be visible if
409 `\\[svn-status-update]' is run with a prefix argument"
410 :type
'(choice (const :tag
"Short \"**\"" t
)
411 (const :tag
"Long \"(Update Available)\"" nil
))
414 (defvar svn-status-debug-level
0 "The psvn.el debugging verbosity level.
415 The higher the number, the more debug messages are shown.
417 See `svn-status-message' for the meaning of values for that variable.")
419 (defvar svn-bookmark-list nil
"A list of locations for a quick access via `svn-status-via-bookmark'")
420 ;;(setq svn-bookmark-list '(("proj1" . "~/work/proj1")
421 ;; ("doc1" . "~/docs/doc1")))
423 (defvar svn-status-buffer-name
"*svn-status*" "Name for the svn status buffer")
424 (defvar svn-process-buffer-name
" *svn-process*" "Name for the svn process buffer")
425 (defvar svn-log-edit-buffer-name
"*svn-log-edit*" "Name for the svn log-edit buffer")
427 (defcustom svn-status-use-header-line
428 (if (boundp 'header-line-format
) t
'inline
)
429 "*Whether a header line should be used.
430 When t: Use the emacs header line
431 When 'inline: Insert the header line in the `svn-status-buffer-name' buffer
432 Otherwise: Don't display a header line"
433 :type
'(choice (const :tag
"Show column titles as a header line" t
)
434 (const :tag
"Insert column titles as text in the buffer" inline
)
435 (other :tag
"No column titles" nil
))
438 ;;; default arguments to pass to svn commands
439 ;; TODO: When customizing, an option menu or completion might be nice....
440 (defcustom svn-status-default-log-arguments
'("-v")
441 "*List of arguments to pass to svn log.
442 \(used in `svn-status-show-svn-log'; override these by giving prefixes\)."
443 :type
'(repeat string
)
445 (put 'svn-status-default-log-arguments
'risky-local-variable t
)
447 (defcustom svn-status-default-commit-arguments
'()
448 "*List of arguments to pass to svn commit.
449 If you don't like recursive commits, set this value to (\"-N\")
450 or mark the directory before committing it.
451 Do not put an empty string here, except as an argument of an option:
452 Subversion and the operating system may treat that as a file name
453 equivalent to \".\", so you would commit more than you intended."
454 :type
'(repeat string
)
456 (put 'svn-status-default-commit-arguments
'risky-local-variable t
)
458 (defcustom svn-status-default-diff-arguments
'("-x" "--ignore-eol-style")
459 "*A list of arguments that is passed to the svn diff command.
460 When the built in diff command is used,
461 the following options are available: --ignore-eol-style, --ignore-space-change,
462 --ignore-all-space, --ignore-eol-style.
463 The following setting ignores eol style changes and all white space changes:
464 '(\"-x\" \"--ignore-eol-style --ignore-all-space\")
466 If you'd like to suppress whitespace changes using the external diff command
467 use the following value:
468 '(\"--diff-cmd\" \"diff\" \"-x\" \"-wbBu\")
471 :type
'(repeat string
)
473 (put 'svn-status-default-diff-arguments
'risky-local-variable t
)
475 (defcustom svn-status-default-blame-arguments
'("-x" "--ignore-eol-style")
476 "*A list of arguments that is passed to the svn blame command.
477 See `svn-status-default-diff-arguments' for some examples."
478 :type
'(repeat string
)
481 (put 'svn-status-default-blame-arguments
'risky-local-variable t
)
483 (defvar svn-trac-project-root nil
484 "Path for an eventual existing trac issue tracker.
485 This can be set with \\[svn-status-set-trac-project-root].")
487 (defvar svn-status-module-name nil
488 "*A short name for the actual project.
489 This can be set with \\[svn-status-set-module-name].")
491 (defvar svn-status-branch-list nil
492 "*A list of known branches for the actual project
493 This can be set with \\[svn-status-set-branch-list].
495 The list contains full repository paths or shortcuts starting with \#
496 \# at the beginning is replaced by the repository url.
497 \#1\# has the special meaning that all paths below the given directory
498 will be considered for interactive selections.
500 A useful setting might be: '\(\"\#trunk\" \"\#1\#tags\" \"\#1\#branches\")")
502 (defvar svn-status-load-state-before-svn-status t
503 "*Whether to automatically restore state from ++psvn.state file before running svn-status.")
505 (defvar svn-log-link-handlers nil
"A list of link handlers in *svn-log* buffers.
506 These link handlers must be registered via `svn-log-register-link-handler'")
509 (defvar svn-status-mode-hook nil
"Hook run when entering `svn-status-mode'.")
510 (defvar svn-log-edit-mode-hook nil
"Hook run when entering `svn-log-edit-mode'.")
511 (defvar svn-log-edit-done-hook nil
"Hook run after commiting files via svn.")
512 ;; (put 'svn-log-edit-mode-hook 'risky-local-variable t)
513 ;; (put 'svn-log-edit-done-hook 'risky-local-variable t)
514 ;; already implied by "-hook" suffix
516 (defvar svn-post-process-svn-output-hook nil
"Hook that can be used to preprocess the output from svn.
517 The function `svn-status-remove-control-M' can be useful for that hook")
519 (when (eq system-type
'windows-nt
)
520 (add-hook 'svn-post-process-svn-output-hook
'svn-status-remove-control-M
))
522 (defvar svn-status-svn-process-coding-system
(when (boundp 'locale-coding-system
) locale-coding-system
)
523 "The coding system that is used for the svn command line client.
524 It is used in svn-run, if it is not nil.")
526 (defvar svn-status-svn-file-coding-system
'undecided-unix
527 "The coding system that is used to save files that are loaded as
528 parameter or data files via the svn command line client.
529 It is used in the following functions: `svn-prop-edit-do-it', `svn-log-edit-done'.
530 You could set it to 'utf-8")
532 (defcustom svn-status-use-ido-completion
533 (fboundp 'ido-completing-read
)
534 "*Use ido completion functionality."
538 (defvar svn-status-completing-read-function
539 (if svn-status-use-ido-completion
'ido-completing-read
'completing-read
))
541 ;;; experimental features
542 (defvar svn-status-track-user-input nil
"Track user/password queries.
543 This feature is implemented via a process filter.
544 It is an experimental feature.")
546 (defvar svn-status-refresh-info nil
"Whether `svn-status-update-buffer' should call `svn-status-parse-info'.")
550 "Subversion interface for Emacs."
553 (defgroup psvn-faces nil
560 (defconst svn-xemacsp
(featurep 'xemacs
))
563 (require 'overlay nil t
)))
565 (defcustom svn-status-display-full-path nil
566 "Specifies how the filenames look like in the listing.
567 If t, their full path name will be displayed, else only the filename."
571 (defcustom svn-status-prefix-key
[(control x
) (meta s
)]
572 "Prefix key for the psvn commands in the global keymap."
573 :type
'(choice (const [(control x
) ?v ?S
])
576 (const [(control x
) ?v
])
577 (const [(control x
) ?V
])
580 :set
(lambda (var value
)
582 (global-unset-key (symbol-value var
)))
584 (global-set-key (symbol-value var
) 'svn-global-keymap
)))
586 (defcustom svn-admin-default-create-directory
"~/"
587 "*The default directory that is suggested for `svn-admin-create'."
591 (defvar svn-status-custom-hide-function nil
592 "A function that receives a line-info and decides whether to hide that line.
593 See psvn.el for an example function.")
594 ;; (put 'svn-status-custom-hide-function 'risky-local-variable t)
595 ;; already implied by "-function" suffix
598 ;; Use the normally used mode for files ending in .~HEAD~, .~BASE~, ...
599 (add-to-list 'auto-mode-alist
'("\\.~?\\(HEAD\\|BASE\\|PREV\\)~?\\'" ignore t
))
601 ;;; internal variables
602 (defvar svn-status-directory-history nil
"List of visited svn working directories.")
603 (defvar svn-process-cmd nil
)
604 (defvar svn-status-info nil
)
605 (defvar svn-status-filename-to-buffer-position-cache
(make-hash-table :test
'equal
:weakness t
))
606 (defvar svn-status-base-info nil
"The parsed result from the svn info command.")
607 (defvar svn-status-initial-window-configuration nil
)
608 (defvar svn-status-default-column
23)
609 (defvar svn-status-default-revision-width
4)
610 (defvar svn-status-default-author-width
9)
611 (defvar svn-status-line-format
" %c%c%c %4s %4s %-9s")
612 (defvar svn-start-of-file-list-line-number
0)
613 (defvar svn-status-files-to-commit nil
614 "List of files to commit at `svn-log-edit-done'.
615 This is always set together with `svn-status-recursive-commit'.")
616 (defvar svn-status-recursive-commit nil
617 "Non-nil if the next commit should be recursive.
618 This is always set together with `svn-status-files-to-commit'.")
619 (defvar svn-log-edit-update-log-entry nil
620 "Revision number whose log entry is being edited.
621 This is nil if the log entry is for a new commit.")
622 (defvar svn-status-pre-commit-window-configuration nil
)
623 (defvar svn-status-pre-propedit-window-configuration nil
)
624 (defvar svn-status-head-revision nil
)
625 (defvar svn-status-root-return-info nil
)
626 (defvar svn-status-property-edit-must-match-flag nil
)
627 (defvar svn-status-propedit-property-name nil
"The property name for the actual svn propset command")
628 (defvar svn-status-propedit-file-list nil
)
629 (defvar svn-status-mode-line-process
"")
630 (defvar svn-status-mode-line-process-status
"")
631 (defvar svn-status-mode-line-process-edit-flag
"")
632 (defvar svn-status-edit-svn-command nil
)
633 (defvar svn-status-update-previous-process-output nil
)
634 (defvar svn-pre-run-asynch-recent-keys nil
)
635 (defvar svn-pre-run-mode-line-process nil
)
636 (defvar svn-status-temp-dir
639 (when (boundp 'temporary-file-directory
) temporary-file-directory
) ;emacs
640 ;; XEmacs 21.4.17 can return "/tmp/kalle" from (temp-directory).
641 ;; `file-name-as-directory' adds a slash so we can append a file name.
642 (when (fboundp 'temp-directory
) (file-name-as-directory (temp-directory)))
643 "/tmp/")) "The directory that is used to store temporary files for psvn.")
644 ;; Because `temporary-file-directory' is not a risky local variable in
645 ;; GNU Emacs 22.0.51, we don't mark `svn-status-temp-dir' as such either.
646 (defvar svn-temp-suffix
(make-temp-name "."))
647 (put 'svn-temp-suffix
'risky-local-variable t
)
648 (defvar svn-status-temp-file-to-remove nil
)
649 (put 'svn-status-temp-file-to-remove
'risky-local-variable t
)
650 (defvar svn-status-temp-arg-file
(concat svn-status-temp-dir
"svn.arg" svn-temp-suffix
))
651 (put 'svn-status-temp-arg-file
'risky-local-variable t
)
652 (defvar svn-status-options nil
)
653 (defvar svn-status-remote
)
654 (defvar svn-status-commit-rev-number nil
)
655 (defvar svn-status-update-rev-number nil
)
656 (defvar svn-status-operated-on-dot nil
)
657 (defvar svn-status-last-commit-author nil
)
658 (defvar svn-status-elided-list nil
)
659 (defvar svn-status-last-output-buffer-name nil
"The buffer name for the buffer that holds the output from the last executed svn command")
660 (defvar svn-status-pre-run-svn-buffer nil
)
661 (defvar svn-status-update-list nil
)
662 (defvar svn-transient-buffers
)
663 (defvar svn-ediff-windows
)
664 (defvar svn-ediff-result
)
665 (defvar svn-status-last-diff-options nil
)
666 (defvar svn-status-blame-file-name nil
)
667 (defvar svn-admin-last-repository-dir nil
"The last repository url for various operations.")
668 (defvar svn-last-cmd-ring
(make-ring 30) "Ring that holds the last executed svn commands (for debugging purposes)")
669 (defvar svn-status-cached-version-string nil
)
670 (defvar svn-client-version nil
"The version number of the used svn client")
671 (defvar svn-status-get-line-information-for-file nil
)
672 (defvar svn-status-base-dir-cache
(make-hash-table :test
'equal
:weakness nil
))
673 (defvar svn-log-registered-link-handlers
(make-hash-table :test
'eql
:weakness nil
))
675 (defvar svn-status-partner-buffer nil
"The partner buffer for this svn related buffer")
676 (make-variable-buffer-local 'svn-status-partner-buffer
)
678 ;; Emacs 21 defines these in ediff-init.el but it seems more robust
679 ;; to just declare the variables here than try to load that file.
680 ;; It is Ediff's job to declare these as risky-local-variable if needed.
681 (defvar ediff-buffer-A
)
682 (defvar ediff-buffer-B
)
683 (defvar ediff-buffer-C
)
684 (defvar ediff-quit-hook
)
686 ;; Ditto for log-edit.el.
687 (defvar log-edit-initial-files
)
688 (defvar log-edit-callback
)
689 (defvar log-edit-listfun
)
691 ;; Ediff does not use this variable in GNU Emacs 20.7, GNU Emacs 21.4,
692 ;; nor XEmacs 21.4.17. However, pcl-cvs (a.k.a. pcvs) does.
693 ;; TODO: Check if this should be moved into the "svn-" namespace.
694 (defvar ediff-after-quit-destination-buffer
)
696 ;; That is an example for the svn-status-custom-hide-function:
697 ;; Note: For many cases it is a better solution to ignore files or
698 ;; file extensions via the svn-ignore properties (on P i, P I)
699 ;; (setq svn-status-custom-hide-function 'svn-status-hide-pyc-files)
700 ;; (defun svn-status-hide-pyc-files (info)
701 ;; "Hide all pyc files in the `svn-status-buffer-name' buffer."
702 ;; (let* ((fname (svn-status-line-info->filename-nondirectory info))
703 ;; (fname-len (length fname)))
704 ;; (and (> fname-len 4) (string= (substring fname (- fname-len 4)) ".pyc"))))
707 (defface svn-status-marked-face
708 '((((type tty
) (class color
)) (:foreground
"green" :weight light
))
709 (((class color
) (background light
)) (:foreground
"green3"))
710 (((class color
) (background dark
)) (:foreground
"palegreen2"))
712 "Face to highlight the mark for user marked files in svn status buffers."
715 (defface svn-status-marked-popup-face
716 '((((type tty
) (class color
)) (:foreground
"green" :weight light
))
717 (((class color
) (background light
)) (:foreground
"green3"))
718 (((class color
) (background dark
)) (:foreground
"palegreen2"))
720 "Face to highlight the actual file, if a popup menu is activated."
723 (defface svn-status-update-available-face
724 '((((type tty
) (class color
)) (:foreground
"magenta" :weight light
))
725 (((class color
) (background light
)) (:foreground
"magenta"))
726 (((class color
) (background dark
)) (:foreground
"yellow"))
728 "Face used to highlight the 'out of date' mark.
729 \(i.e., the mark used when there is a newer version in the repository
730 than the working copy.\)
732 See also `svn-status-short-mod-flag-p'."
735 ;based on cvs-filename-face
736 (defface svn-status-directory-face
737 '((((type tty
) (class color
)) (:foreground
"lightblue" :weight light
))
738 (((class color
) (background light
)) (:foreground
"blue4"))
739 (((class color
) (background dark
)) (:foreground
"lightskyblue1"))
741 "Face for directories in *svn-status* buffers.
742 See `svn-status--line-info->directory-p' for what counts as a directory."
745 ;based on font-lock-comment-face
746 (defface svn-status-filename-face
747 '((((class color
) (background light
)) (:foreground
"chocolate"))
748 (((class color
) (background dark
)) (:foreground
"beige")))
749 "Face for non-directories in *svn-status* buffers.
750 See `svn-status--line-info->directory-p' for what counts as a directory."
753 ;not based on anything, may be horribly ugly!
754 (defface svn-status-symlink-face
755 '((((class color
) (background light
)) (:foreground
"cornflower blue"))
756 (((class color
) (background dark
)) (:foreground
"cyan")))
757 "Face for symlinks in *svn-status* buffers.
759 This is the face given to the actual link (i.e., the versioned item),
760 the target of the link gets either `svn-status-filename-face' or
761 `svn-status-directory-face'."
764 ;based on font-lock-warning-face
765 (defface svn-status-locked-face
767 (:weight bold
:foreground
"Red")))
768 "Face for the phrase \"[ LOCKED ]\" `svn-status-buffer-name' buffers."
771 ;based on vhdl-font-lock-directive-face
772 (defface svn-status-switched-face
775 (:foreground
"CadetBlue"))
778 (:foreground
"Aquamarine"))
780 (:bold t
:italic t
)))
781 "Face for the phrase \"(switched)\" non-directories in svn status buffers."
785 (defface svn-status-blame-highlight-face
786 '((((type tty
) (class color
)) (:foreground
"green" :weight light
))
787 (((class color
) (background light
)) (:foreground
"green3"))
788 (((class color
) (background dark
)) (:foreground
"palegreen2"))
790 "Default face for highlighting a line in svn status blame mode."
792 (defface svn-status-blame-highlight-face
793 '((t :inherit highlight
))
794 "Default face for highlighting a line in svn status blame mode."
797 (defface svn-status-blame-rev-number-face
798 '((((class color
) (background light
)) (:foreground
"DarkGoldenrod"))
799 (((class color
) (background dark
)) (:foreground
"LightGoldenrod"))
800 (t (:weight bold
:slant italic
)))
801 "Face to highlight revision numbers in the svn-blame mode."
804 (defvar svn-highlight t
)
805 ;; stolen from PCL-CVS
806 (defun svn-add-face (str face
&optional keymap
)
807 "Return string STR decorated with the specified FACE.
808 If `svn-highlight' is nil then just return STR."
810 ;; Do not use `list*'; cl.el might not have been loaded. We could
811 ;; put (require 'cl) at the top but let's try to manage without.
812 (add-text-properties 0 (length str
)
814 mouse-face highlight
)
815 ;; 18.10.2004: the keymap parameter is not used (yet) in psvn.el
817 ;; `(mouse-face highlight
818 ;; local-map ,keymap)))
822 (defun svn-status-maybe-add-face (condition text face
)
823 "If CONDITION then add FACE to TEXT.
824 Else return TEXT unchanged."
826 (svn-add-face text face
)
829 (defun svn-status-choose-face-to-add (condition text face1 face2
)
830 "If CONDITION then add FACE1 to TEXT, else add FACE2 to TEXT."
832 (svn-add-face text face1
)
833 (svn-add-face text face2
)))
835 (defun svn-status-maybe-add-string (condition string face
)
836 "If CONDITION then return STRING decorated with FACE.
837 Otherwise, return \"\"."
839 (svn-add-face string face
)
844 (defalias 'svn-point-at-eol
845 (if (fboundp 'point-at-eol
) 'point-at-eol
'line-end-position
))
846 (defalias 'svn-point-at-bol
847 (if (fboundp 'point-at-bol
) 'point-at-bol
'line-beginning-position
))
848 (defalias 'svn-read-directory-name
849 (if (fboundp 'read-directory-name
) 'read-directory-name
'read-file-name
))
852 (if (not (fboundp 'gethash
))
854 (defalias 'svn-puthash
(if (fboundp 'puthash
) 'puthash
'cl-puthash
))
857 (if (fboundp 'line-number-at-pos
)
858 (defalias 'svn-line-number-at-pos
'line-number-at-pos
)
859 (defun svn-line-number-at-pos (&optional pos
)
860 "Return (narrowed) buffer line number at position POS.
861 If POS is nil, use current buffer location."
862 (let ((opoint (or pos
(point))) start
)
864 (goto-char (point-min))
868 (1+ (count-lines start
(point)))))))
871 ;; Evaluate the defsubst at compile time, so that the byte compiler
872 ;; knows the definition and can inline calls. It cannot detect the
873 ;; defsubst automatically from within the if form.
875 (if (fboundp 'match-string-no-properties
)
876 (defalias 'svn-match-string-no-properties
'match-string-no-properties
)
877 (defsubst svn-match-string-no-properties
(match)
878 (buffer-substring-no-properties (match-beginning match
) (match-end match
)))))
880 ;; XEmacs 21.4.17 does not have an `alist' widget. Define a replacement.
881 ;; To find out whether the `alist' widget exists, we cannot check just
882 ;; (get 'alist 'widget-type), because GNU Emacs 21.4 defines it in
883 ;; "wid-edit.el", which is not preloaded; it will be autoloaded when
884 ;; `widget-create' is called. Instead, we call `widgetp', which is
885 ;; also autoloaded from "wid-edit.el". XEmacs 21.4.17 does not have
886 ;; `widgetp' either, so we check that first.
887 (if (and (fboundp 'widgetp
) (widgetp 'alist
))
888 (define-widget 'svn-alist
'alist
889 "An association list.
890 Use this instead of `alist', for XEmacs 21.4 compatibility.")
891 (define-widget 'svn-alist
'list
892 "An association list.
893 Use this instead of `alist', for XEmacs 21.4 compatibility."
894 :convert-widget
'svn-alist-convert-widget
895 :tag
"Association List"
898 (defun svn-alist-convert-widget (widget)
899 (let* ((value-type (widget-get widget
:value-type
))
900 (option-widgets (loop for option in
(widget-get widget
:options
)
901 collect
`(cons :format
"%v"
902 (const :format
"%t: %v\n"
906 (widget-put widget
:args
907 `(,@(when option-widgets
908 `((set :inline t
:format
"%v"
910 (editable-list :inline t
912 ,(widget-get widget
:key-type
)
916 ;; process launch functions
917 (defvar svn-call-process-function
(if (fboundp 'process-file
) 'process-file
'call-process
))
918 (defvar svn-start-process-function
(if (fboundp 'start-file-process
) 'start-file-process
'start-process
))
923 (defvar svn-global-keymap nil
"Global keymap for psvn.el.
924 To bind this to a different key, customize `svn-status-prefix-key'.")
925 (put 'svn-global-keymap
'risky-local-variable t
)
926 (when (not svn-global-keymap
)
927 (setq svn-global-keymap
(make-sparse-keymap))
928 (define-key svn-global-keymap
(kbd "v") 'svn-status-version
)
929 (define-key svn-global-keymap
(kbd "s") 'svn-status-this-directory
)
930 (define-key svn-global-keymap
(kbd "b") 'svn-status-via-bookmark
)
931 (define-key svn-global-keymap
(kbd "h") 'svn-status-use-history
)
932 (define-key svn-global-keymap
(kbd "u") 'svn-status-update-cmd
)
933 (define-key svn-global-keymap
(kbd "=") 'svn-status-show-svn-diff
)
934 (define-key svn-global-keymap
(kbd "f =") 'svn-file-show-svn-diff
)
935 (define-key svn-global-keymap
(kbd "f e") 'svn-file-show-svn-ediff
)
936 (define-key svn-global-keymap
(kbd "f l") 'svn-status-show-svn-log
)
937 (define-key svn-global-keymap
(kbd "f b") 'svn-status-blame
)
938 (define-key svn-global-keymap
(kbd "f a") 'svn-file-add-to-changelog
)
939 (define-key svn-global-keymap
(kbd "c") 'svn-status-commit
)
940 (define-key svn-global-keymap
(kbd "S") 'svn-status-switch-to-status-buffer
)
941 (define-key svn-global-keymap
(kbd "o") 'svn-status-pop-to-status-buffer
))
943 (defvar svn-status-diff-mode-map
()
944 "Keymap used in `svn-status-diff-mode' for additional commands that are not defined in diff-mode.")
945 (put 'svn-status-diff-mode-map
'risky-local-variable t
) ;for Emacs 20.7
947 (when (not svn-status-diff-mode-map
)
948 (setq svn-status-diff-mode-map
(copy-keymap diff-mode-shared-map
))
949 (define-key svn-status-diff-mode-map
[?g
] 'revert-buffer
)
950 (define-key svn-status-diff-mode-map
[?s
] 'svn-status-pop-to-status-buffer
)
951 (define-key svn-status-diff-mode-map
[?c
] 'svn-status-diff-pop-to-commit-buffer
)
952 (define-key svn-status-diff-mode-map
[?w
] 'svn-status-diff-save-current-defun-as-kill
))
954 (defvar svn-global-trac-map
()
955 "Subkeymap used in `svn-global-keymap' for trac issue tracker commands.")
956 (put 'svn-global-trac-map
'risky-local-variable t
) ;for Emacs 20.7
957 (when (not svn-global-trac-map
)
958 (setq svn-global-trac-map
(make-sparse-keymap))
959 (define-key svn-global-trac-map
(kbd "w") 'svn-trac-browse-wiki
)
960 (define-key svn-global-trac-map
(kbd "t") 'svn-trac-browse-timeline
)
961 (define-key svn-global-trac-map
(kbd "m") 'svn-trac-browse-roadmap
)
962 (define-key svn-global-trac-map
(kbd "s") 'svn-trac-browse-source
)
963 (define-key svn-global-trac-map
(kbd "r") 'svn-trac-browse-report
)
964 (define-key svn-global-trac-map
(kbd "i") 'svn-trac-browse-ticket
)
965 (define-key svn-global-trac-map
(kbd "c") 'svn-trac-browse-changeset
)
966 (define-key svn-global-keymap
(kbd "t") svn-global-trac-map
))
968 ;; The setter of `svn-status-prefix-key' makes a binding in the global
969 ;; map refer to the `svn-global-keymap' symbol, rather than directly
970 ;; to the keymap. Emacs then implicitly uses the symbol-function.
971 ;; This has the advantage that `describe-bindings' (C-h b) can show
972 ;; the name of the keymap and link to its documentation.
973 (defalias 'svn-global-keymap svn-global-keymap
)
974 ;; `defalias' of GNU Emacs 21.4 doesn't allow a docstring argument.
975 (put 'svn-global-keymap
'function-documentation
976 '(documentation-property 'svn-global-keymap
'variable-documentation t
))
979 ;; named after SVN_WC_ADM_DIR_NAME in svn_wc.h
980 (defun svn-wc-adm-dir-name ()
981 "Return the name of the \".svn\" subdirectory or equivalent."
982 (if (and (eq system-type
'windows-nt
)
983 (getenv "SVN_ASP_DOT_NET_HACK"))
987 (defun svn-log-edit-file-name (&optional curdir
)
988 "Get the name of the saved log edit file
989 If curdir, return `svn-log-edit-file-name'
990 Otherwise position svn-log-edit-file-name in the root directory of this working copy"
992 svn-log-edit-file-name
993 (concat (svn-status-base-dir) svn-log-edit-file-name
)))
995 (defun svn-status-message (level &rest args
)
996 "If LEVEL is lower than `svn-status-debug-level' print ARGS using `message'.
998 Guideline for numbers:
999 1 - error messages, 3 - non-serious error messages, 5 - messages for things
1000 that take a long time, 7 - not very important messages on stuff, 9 - messages
1002 (if (<= level svn-status-debug-level
)
1003 (apply 'message args
)))
1005 (defun svn-status-flatten-list (list)
1006 "Flatten any lists within ARGS, so that there are no sublists."
1007 (loop for item in list
1008 if
(listp item
) nconc
(svn-status-flatten-list item
)
1011 (defun svn-status-window-line-position (w)
1012 "Return the window line at point for window W, or nil if W is nil."
1013 (svn-status-message 3 "About to count lines; selected window is %s" (selected-window))
1014 (and w
(count-lines (window-start w
) (point))))
1017 (defun svn-checkout (repos-url path
)
1018 "Run svn checkout REPOS-URL PATH."
1019 (interactive (list (read-string "Checkout from repository Url: ")
1020 (svn-read-directory-name "Checkout to directory: ")))
1021 (svn-run t t
'checkout
"checkout" repos-url
(expand-file-name path
)))
1023 ;;;###autoload (defalias 'svn-examine 'svn-status)
1024 (defalias 'svn-examine
'svn-status
)
1027 (defun svn-status (dir &optional arg
)
1028 "Examine the status of Subversion working copy in directory DIR.
1029 If ARG is -, allow editing of the parameters. One could add -N to
1030 run svn status non recursively to make it faster.
1031 For every other non nil ARG pass the -u argument to `svn status', which
1032 asks svn to connect to the repository and check to see if there are updates
1035 If there is no .svn directory, examine if there is CVS and run
1036 `cvs-examine'. Otherwise ask if to run `dired'."
1037 (interactive (list (svn-read-directory-name "SVN status directory: "
1038 nil default-directory nil
)
1039 current-prefix-arg
))
1040 (let ((svn-dir (format "%s%s"
1041 (file-name-as-directory dir
)
1042 (svn-wc-adm-dir-name)))
1043 (cvs-dir (format "%sCVS" (file-name-as-directory dir
))))
1045 ((file-directory-p svn-dir
)
1046 (setq arg
(svn-status-possibly-negate-meaning-of-arg arg
'svn-status
))
1047 (svn-status-1 dir arg
))
1048 ((and (file-directory-p cvs-dir
)
1049 (fboundp 'cvs-examine
))
1050 (cvs-examine dir nil
))
1056 "is not Subversion controlled (missing %s "
1058 "Run dired instead? ")
1060 (svn-wc-adm-dir-name)))
1063 (defvar svn-status-display-new-status-buffer nil
)
1064 (defun svn-status-1 (dir &optional arg
)
1065 "Examine DIR. See `svn-status' for more information."
1066 (unless (file-directory-p dir
)
1067 (error "%s is not a directory" dir
))
1068 (setq dir
(file-name-as-directory dir
))
1069 (when svn-status-load-state-before-svn-status
1070 (unless (string= dir
(car svn-status-directory-history
))
1071 (let ((default-directory dir
)) ;otherwise svn-status-base-dir looks in the wrong place
1072 (svn-status-load-state t
))))
1073 (setq svn-status-directory-history
(delete dir svn-status-directory-history
))
1074 (add-to-list 'svn-status-directory-history dir
)
1075 (if (string= (buffer-name) svn-status-buffer-name
)
1076 (setq svn-status-display-new-status-buffer nil
)
1077 (setq svn-status-display-new-status-buffer t
)
1078 ;;(message "psvn: Saving initial window configuration")
1079 (setq svn-status-initial-window-configuration
1080 (current-window-configuration)))
1081 (let* ((cur-buf (current-buffer))
1082 (status-buf (get-buffer-create svn-status-buffer-name
))
1083 (proc-buf (get-buffer-create svn-process-buffer-name
))
1084 (want-edit (eq arg
'-
))
1085 (status-option (if want-edit
1086 (if svn-status-verbose
"-v" "")
1087 (if svn-status-verbose
1090 (svn-status-edit-svn-command
1091 (or want-edit svn-status-edit-svn-command
)))
1093 (set-buffer status-buf
)
1094 (setq default-directory dir
)
1095 (set-buffer proc-buf
)
1096 (setq default-directory dir
1097 svn-status-remote
(when arg t
))
1098 (set-buffer cur-buf
)
1099 (svn-run t t
'status
"status" status-option
))))
1101 (defun svn-status-this-directory (arg)
1102 "Run `svn-status' for the `default-directory'"
1104 (svn-status default-directory arg
))
1106 (defun svn-status-use-history ()
1107 "Interactively select a different directory from `svn-status-directory-history'."
1109 (let* ((in-status-buffer (eq major-mode
'svn-status-mode
))
1110 (hist (if in-status-buffer
(cdr svn-status-directory-history
) svn-status-directory-history
))
1111 (dir (funcall svn-status-completing-read-function
"svn-status on directory: " hist
))
1112 (svn-status-buffer (get-buffer svn-status-buffer-name
))
1113 (svn-buffer-available (and svn-status-buffer
1114 (with-current-buffer svn-status-buffer-name
(string= default-directory dir
)))))
1115 (if (file-directory-p dir
)
1116 (if svn-buffer-available
1117 (svn-status-switch-to-status-buffer)
1118 (unless svn-status-refresh-info
1119 (setq svn-status-refresh-info
'once
))
1121 (error "%s is not a directory" dir
))))
1123 (defun svn-had-user-input-since-asynch-run ()
1124 (not (equal (recent-keys) svn-pre-run-asynch-recent-keys
)))
1126 (defun svn-process-environment ()
1127 "Construct the environment for the svn process.
1128 It is a combination of `svn-status-svn-environment-var-list' and
1129 the usual `process-environment'."
1130 ;; If there are duplicate elements in `process-environment', then GNU
1131 ;; Emacs 21.4 guarantees that the first one wins; but GNU Emacs 20.7
1132 ;; and XEmacs 21.4.17 don't document what happens. We'll just remove
1133 ;; any duplicates ourselves, then. This also gives us an opportunity
1134 ;; to handle the "VARIABLE" syntax that none of them supports.
1135 (loop with found
= '()
1136 for elt in
(append svn-status-svn-environment-var-list
1137 process-environment
)
1138 for has-value
= (string-match "=" elt
)
1139 for name
= (substring elt
0 has-value
)
1140 unless
(member name found
)
1141 do
(push name found
)
1145 (defun svn-run (run-asynchron clear-process-buffer cmdtype
&rest arglist
)
1146 "Run svn with arguments ARGLIST.
1148 If RUN-ASYNCHRON is t then run svn asynchronously.
1150 If CLEAR-PROCESS-BUFFER is t then erase the contents of the
1151 `svn-process-buffer-name' buffer before commencing.
1153 CMDTYPE is a symbol such as 'mv, 'revert, or 'add, representing the
1156 ARGLIST is a list of arguments \(which must include the command name,
1157 for example: '(\"revert\" \"file1\"\)
1158 ARGLIST is flattened and any every nil value is discarded.
1160 If the variable `svn-status-edit-svn-command' is non-nil then the user
1161 can edit ARGLIST before running svn.
1163 The hook svn-pre-run-hook allows to monitor/modify the ARGLIST."
1164 (setq arglist
(svn-status-flatten-list arglist
))
1165 (if (eq (process-status "svn") nil
)
1167 (when svn-status-edit-svn-command
1168 (setq arglist
(append
1169 (list (car arglist
))
1171 (read-from-minibuffer
1172 (format "svn %s flags: " (car arglist
))
1173 (mapconcat 'identity
(cdr arglist
) " ")))))
1174 (when (eq svn-status-edit-svn-command t
)
1175 (svn-status-toggle-edit-cmd-flag t
))
1176 (message "svn-run %s: %S" cmdtype arglist
))
1177 (run-hooks 'svn-pre-run-hook
)
1178 (unless (eq mode-line-process
'svn-status-mode-line-process
)
1179 (setq svn-pre-run-mode-line-process mode-line-process
)
1180 (setq mode-line-process
'svn-status-mode-line-process
))
1181 (setq svn-status-pre-run-svn-buffer
(current-buffer))
1182 (let* ((proc-buf (get-buffer-create svn-process-buffer-name
))
1183 (svn-exe svn-status-svn-executable
)
1185 (when (listp (car arglist
))
1186 (setq arglist
(car arglist
)))
1188 (set-buffer proc-buf
)
1189 (unless (file-executable-p default-directory
)
1190 (message "psvn: workaround in %s needed: %s no longer exists" (current-buffer) default-directory
)
1191 (cd (expand-file-name "~")))
1192 (setq buffer-read-only nil
)
1193 (buffer-disable-undo)
1195 (if clear-process-buffer
1196 (delete-region (point-min) (point-max))
1197 (goto-char (point-max)))
1198 (setq svn-process-cmd cmdtype
)
1199 (setq svn-status-last-commit-author nil
)
1200 (setq svn-status-mode-line-process-status
(format " running %s" cmdtype
))
1201 (svn-status-update-mode-line)
1203 (ring-insert svn-last-cmd-ring
(list (current-time-string) arglist default-directory
))
1206 ;;(message "running asynchron: %s %S" svn-exe arglist)
1207 (setq svn-pre-run-asynch-recent-keys
(recent-keys))
1208 (let ((process-environment (svn-process-environment))
1209 (process-connection-type nil
))
1210 ;; Communicate with the subprocess via pipes rather
1211 ;; than via a pseudoterminal, so that if the svn+ssh
1212 ;; scheme is being used, SSH will not ask for a
1213 ;; passphrase via stdio; psvn.el is currently unable
1214 ;; to answer such prompts. Instead, SSH will run
1215 ;; x11-ssh-askpass if possible. If Emacs is being
1216 ;; run on a TTY without $DISPLAY, this will fail; in
1217 ;; such cases, the user should start ssh-agent and
1218 ;; then run ssh-add explicitly.
1219 (setq svn-proc
(apply svn-start-process-function
"svn" proc-buf svn-exe arglist
)))
1220 (when svn-status-svn-process-coding-system
1221 (set-process-coding-system svn-proc svn-status-svn-process-coding-system
1222 svn-status-svn-process-coding-system
))
1223 (set-process-sentinel svn-proc
'svn-process-sentinel
)
1224 (when svn-status-track-user-input
1225 (set-process-filter svn-proc
'svn-process-filter
)))
1226 ;;(message "running synchron: %s %S" svn-exe arglist)
1227 (let ((process-environment (svn-process-environment)))
1228 ;; `call-process' ignores `process-connection-type' and
1229 ;; never opens a pseudoterminal.
1230 (apply svn-call-process-function svn-exe nil proc-buf nil arglist
))
1231 (setq svn-status-last-output-buffer-name svn-process-buffer-name
)
1232 (run-hooks 'svn-post-process-svn-output-hook
)
1233 (setq svn-status-mode-line-process-status
"")
1234 (svn-status-update-mode-line)
1235 (when svn-pre-run-mode-line-process
1236 (setq mode-line-process svn-pre-run-mode-line-process
)
1237 (setq svn-pre-run-mode-line-process nil
))))))
1238 (error "You can only run one svn process at once!")))
1240 (defun svn-process-sentinel-fixup-path-seperators ()
1241 "Convert all path separators to UNIX style.
1242 \(This is a no-op unless `system-type' is windows-nt\)"
1243 (when (eq system-type
'windows-nt
)
1245 (goto-char (point-min))
1246 (while (search-forward "\\" nil t
)
1247 (replace-match "/")))))
1249 (defun svn-process-sentinel (process event
)
1250 ;;(princ (format "Process: %s had the event `%s'" process event)))
1252 (let ((act-buf (current-buffer)))
1253 (when svn-pre-run-mode-line-process
1254 (with-current-buffer svn-status-pre-run-svn-buffer
1255 (setq mode-line-process svn-pre-run-mode-line-process
))
1256 (setq svn-pre-run-mode-line-process nil
))
1257 (set-buffer (process-buffer process
))
1258 (setq svn-status-mode-line-process-status
"")
1259 (svn-status-update-mode-line)
1260 (cond ((string= event
"finished\n")
1261 (run-hooks 'svn-post-process-svn-output-hook
)
1262 (cond ((eq svn-process-cmd
'status
)
1263 ;;(message "svn status finished")
1264 (svn-process-sentinel-fixup-path-seperators)
1265 (svn-parse-status-result)
1266 (svn-status-apply-elide-list)
1267 (when svn-status-update-previous-process-output
1268 (set-buffer (process-buffer process
))
1269 (delete-region (point-min) (point-max))
1270 (insert "Output from svn command:\n")
1271 (insert svn-status-update-previous-process-output
)
1272 (goto-char (point-min))
1273 (setq svn-status-update-previous-process-output nil
))
1274 (when svn-status-update-list
1275 ;; (message "Using svn-status-update-list: %S" svn-status-update-list)
1277 (svn-status-update-with-command-list svn-status-update-list
))
1278 (setq svn-status-update-list nil
))
1279 (when svn-status-display-new-status-buffer
1280 (set-window-configuration svn-status-initial-window-configuration
)
1281 (if (svn-had-user-input-since-asynch-run)
1282 (message "svn status finished")
1283 (switch-to-buffer svn-status-buffer-name
))))
1284 ((eq svn-process-cmd
'log
)
1285 (svn-status-show-process-output 'log t
)
1286 (pop-to-buffer svn-status-last-output-buffer-name
)
1289 (unless (looking-at "Changed paths:")
1291 (font-lock-fontify-buffer)
1292 (message "svn log finished"))
1293 ((eq svn-process-cmd
'info
)
1294 (svn-status-show-process-output 'info t
)
1295 (message "svn info finished"))
1296 ((eq svn-process-cmd
'ls
)
1297 (svn-status-show-process-output 'info t
)
1298 (message "svn ls finished"))
1299 ((eq svn-process-cmd
'diff
)
1300 (svn-status-activate-diff-mode)
1301 (message "svn diff finished"))
1302 ((eq svn-process-cmd
'parse-info
)
1303 (svn-status-parse-info-result))
1304 ((eq svn-process-cmd
'blame
)
1305 (svn-status-show-process-output 'blame t
)
1306 (when svn-status-pre-run-svn-buffer
1307 (with-current-buffer svn-status-pre-run-svn-buffer
1308 (unless (eq major-mode
'svn-status-mode
)
1309 (let ((src-line-number (svn-line-number-at-pos)))
1310 (pop-to-buffer (get-buffer svn-status-last-output-buffer-name
))
1311 (goto-line src-line-number
)))))
1312 (with-current-buffer (get-buffer svn-status-last-output-buffer-name
)
1313 (svn-status-activate-blame-mode))
1314 (message "svn blame finished"))
1315 ((eq svn-process-cmd
'commit
)
1316 (svn-process-sentinel-fixup-path-seperators)
1317 (svn-status-remove-temp-file-maybe)
1318 (when (member 'commit svn-status-unmark-files-after-list
)
1319 (svn-status-unset-all-usermarks))
1320 (svn-status-update-with-command-list (svn-status-parse-commit-output))
1321 (svn-revert-some-buffers)
1322 (run-hooks 'svn-log-edit-done-hook
)
1323 (setq svn-status-files-to-commit nil
1324 svn-status-recursive-commit nil
)
1325 (if (null svn-status-commit-rev-number
)
1326 (message "No revision to commit.")
1327 (message "svn: Committed revision %s." svn-status-commit-rev-number
)))
1328 ((eq svn-process-cmd
'update
)
1329 (svn-status-show-process-output 'update t
)
1330 (setq svn-status-update-list
(svn-status-parse-update-output))
1331 (svn-revert-some-buffers)
1333 (if (car svn-status-update-rev-number
)
1334 (message "svn: Updated to revision %s." (cadr svn-status-update-rev-number
))
1335 (message "svn: At revision %s." (cadr svn-status-update-rev-number
))))
1336 ((eq svn-process-cmd
'add
)
1337 (svn-status-update-with-command-list (svn-status-parse-ar-output))
1338 (message "svn add finished"))
1339 ((eq svn-process-cmd
'lock
)
1341 (message "svn lock finished"))
1342 ((eq svn-process-cmd
'unlock
)
1344 (message "svn unlock finished"))
1345 ((eq svn-process-cmd
'mkdir
)
1347 (message "svn mkdir finished"))
1348 ((eq svn-process-cmd
'revert
)
1349 (when (member 'revert svn-status-unmark-files-after-list
)
1350 (svn-status-unset-all-usermarks))
1352 (message "svn revert finished"))
1353 ((eq svn-process-cmd
'resolved
)
1355 (message "svn resolved finished"))
1356 ((eq svn-process-cmd
'rm
)
1357 (svn-status-update-with-command-list (svn-status-parse-ar-output))
1358 (message "svn rm finished"))
1359 ((eq svn-process-cmd
'cleanup
)
1360 (message "svn cleanup finished"))
1361 ((eq svn-process-cmd
'proplist
)
1362 (svn-status-show-process-output 'proplist t
)
1363 (message "svn proplist finished"))
1364 ((eq svn-process-cmd
'checkout
)
1365 (svn-status default-directory
))
1366 ((eq svn-process-cmd
'proplist-parse
)
1367 (svn-status-property-parse-property-names))
1368 ((eq svn-process-cmd
'propset
)
1369 (svn-status-remove-temp-file-maybe)
1370 (if (member svn-status-propedit-property-name
'("svn:keywords"))
1371 (svn-status-update-with-command-list (svn-status-parse-property-output))
1372 (svn-status-update)))
1373 ((eq svn-process-cmd
'propdel
)
1374 (svn-status-update))))
1375 ((string= event
"killed\n")
1376 (message "svn process killed"))
1377 ((string-match "exited abnormally" event
)
1378 (while (accept-process-output process
0 100))
1379 ;; find last error message and show it.
1380 (goto-char (point-max))
1381 (if (re-search-backward "^svn: \\(.*\\)" nil t
)
1382 (svn-process-handle-error (match-string 1))
1383 (message "svn failed: %s" event
)))
1385 (message "svn process had unknown event: %s" event
))
1386 (svn-status-show-process-output nil t
))))
1388 (defvar svn-process-handle-error-msg nil
)
1389 (defun svn-process-handle-error (error-msg)
1390 (let ((svn-process-handle-error-msg error-msg
))
1391 (electric-helpify 'svn-process-help-with-error-msg
)))
1393 (defun svn-process-help-with-error-msg ()
1395 (let ((help-msg (cadr (assoc svn-process-handle-error-msg
1396 '(("Cannot non-recursively commit a directory deletion"
1397 "Please unmark all files and position point at the directory you would like to remove.\nThen run commit again."))))))
1400 (with-output-to-temp-buffer (help-buffer)
1401 (princ (format "svn failed: %s\n\n%s" svn-process-handle-error-msg help-msg
))))
1402 (message "svn failed: %s" svn-process-handle-error-msg
))))
1405 (defun svn-process-filter (process str
)
1406 "Track the svn process output and ask user questions in the minibuffer when appropriate."
1407 (save-window-excursion
1408 (set-buffer svn-process-buffer-name
)
1409 ;;(message "svn-process-filter: %s" str)
1410 (goto-char (point-max))
1413 (goto-char (svn-point-at-bol))
1414 (when (looking-at "Password for '\\(.+\\)': ")
1415 ;(svn-status-show-process-buffer)
1416 (let ((passwd (read-passwd
1417 (format "Enter svn password for %s: " (match-string 1)))))
1418 (svn-process-send-string-and-newline passwd t
)))
1419 (when (looking-at "Username: ")
1420 (let ((user-name (read-string "Username for svn operation: ")))
1421 (svn-process-send-string-and-newline user-name
)))
1422 (when (looking-at "(R)eject, accept (t)emporarily or accept (p)ermanently")
1423 (svn-status-show-process-buffer)
1424 (let ((answer (read-string "(R)eject, accept (t)emporarily or accept (p)ermanently? ")))
1425 (svn-process-send-string (substring answer
0 1)))))))
1427 (defun svn-revert-some-buffers (&optional tree
)
1428 "Reverts all buffers visiting a file in TREE that aren't modified.
1429 To be run after a commit, an update or a merge."
1431 (let ((tree (or (svn-status-base-dir) tree
)))
1432 (dolist (buffer (buffer-list))
1433 (with-current-buffer buffer
1434 (when (not (buffer-modified-p))
1435 (let ((file (buffer-file-name)))
1437 (let ((root (svn-status-base-dir (file-name-directory file
)))
1438 (point-pos (point)))
1441 ;; buffer is modified and in the tree TREE.
1442 svn-status-auto-revert-buffers
)
1443 ;; (message "svn-revert-some-buffers: %s %s" (buffer-file-name) (verify-visited-file-modtime (current-buffer)))
1444 ;; Keep the buffer if the file doesn't exist
1445 (when (and (file-exists-p file
) (not (verify-visited-file-modtime (current-buffer))))
1447 (goto-char point-pos
)))))))))))
1449 (defun svn-parse-rev-num (str)
1450 (if (and str
(stringp str
)
1451 (save-match-data (string-match "^[0-9]+" str
)))
1452 (string-to-number str
)
1455 (defsubst svn-status-make-ui-status
()
1456 "Make a ui-status structure for a file in a svn working copy.
1457 The initial values in the structure returned by this function
1458 are good for a file or directory that the user hasn't seen before.
1460 The ui-status structure keeps track of how the file or directory
1461 should be displayed in svn-status mode. Updating the svn-status
1462 buffer from the working copy preserves the ui-status if possible.
1463 User commands modify this structure; each file or directory must
1464 thus have its own copy.
1466 Currently, the ui-status is a list (USER-MARK USER-ELIDE).
1467 USER-MARK is non-nil iff the user has marked the file or directory,
1468 typically with `svn-status-set-user-mark'. To read USER-MARK,
1469 call `svn-status-line-info->has-usermark'.
1470 USER-ELIDE is non-nil iff the user has elided the file or directory
1471 from the svn-status buffer, typically with `svn-status-toggle-elide'.
1472 To read USER-ELIDE, call `svn-status-line-info->user-elide'.
1474 Call `svn-status-line-info->ui-status' to access the whole ui-status
1478 (defun svn-status-make-dummy-dirs (dir-list old-ui-information
)
1479 "Calculate additionally necessary directories that were not shown in the output
1481 ;; (message "svn-status-make-dummy-dirs %S" dir-list)
1484 (dolist (dir dir-list
)
1485 (setq base-dir
(file-name-directory dir
))
1487 ;;(message "dir: %S dir-list: %S, base-dir: %S" dir dir-list base-dir)
1488 (setq candidate
(replace-regexp-in-string "/+$" "" base-dir
))
1489 (setq base-dir
(file-name-directory candidate
))
1490 ;; (message "dir: %S, candidate: %S" dir candidate)
1491 (add-to-list 'dir-list candidate
))))
1492 ;; (message "svn-status-make-dummy-dirs %S" dir-list)
1493 (append (mapcar (lambda (dir)
1494 (svn-status-make-line-info
1496 (gethash dir old-ui-information
)))
1500 (defun svn-status-make-line-info (&optional
1504 local-rev last-change-rev
1512 "Create a new line-info from the given arguments
1513 Anything left nil gets a sensible default.
1514 nb: LOCKED-MARK refers to the kind of locks you get after an error,
1515 LOCKED-REPO-MARK is the kind managed with `svn lock'"
1516 (list (or ui
(svn-status-make-ui-status))
1521 (or last-change-rev ?
)
1530 (defvar svn-user-names-including-blanks nil
"A list of svn user names that include blanks.")
1531 ;;(setq svn-user-names-including-blanks '("feng shui" "mister blank"))
1532 ;;(add-hook 'svn-pre-parse-status-hook 'svn-status-parse-fixup-user-names-including-blanks)
1534 (defun svn-status-parse-fixup-user-names-including-blanks ()
1535 "Helper function to allow user names that include blanks.
1536 Add this function to the `svn-pre-parse-status-hook'. The variable
1537 `svn-user-names-including-blanks' must be configured to hold all user names that contain
1538 blanks. This function replaces the blanks with '-' to allow further processing with
1539 the usual parsing functionality in `svn-parse-status-result'."
1540 (when svn-user-names-including-blanks
1541 (goto-char (point-min))
1542 (let ((search-string (concat " \\(" (mapconcat 'concat svn-user-names-including-blanks
"\\|") "\\) ")))
1545 (while (re-search-forward search-string
(point-max) t
)
1546 (replace-match (replace-regexp-in-string " " "-" (match-string 1)) nil nil nil
1)))))))
1548 (defun svn-parse-status-result ()
1549 "Parse the `svn-process-buffer-name' buffer.
1550 The results are used to build the `svn-status-info' variable."
1551 (setq svn-status-head-revision nil
)
1553 (let ((old-ui-information (svn-status-ui-information-hash-table))
1557 (svn-wc-locked-mark)
1558 (svn-repo-locked-mark)
1559 (svn-with-history-mark)
1567 (revision-width svn-status-default-revision-width
)
1568 (author-width svn-status-default-author-width
)
1569 (svn-marks-length (if svn-status-verbose
1570 (if svn-status-remote
1572 (if svn-status-remote
1576 (externals-map (make-hash-table :test
'equal
))
1577 (skip-double-external-dir-entry-name nil
))
1578 (set-buffer svn-process-buffer-name
)
1579 (setq svn-status-info nil
)
1580 (run-hooks 'svn-pre-parse-status-hook
)
1581 (goto-char (point-min))
1582 (while (< (point) (point-max))
1584 ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
1586 ((looking-at "Status against revision:[ ]+\\([0-9]+\\)")
1587 ;; the above message appears for the main listing plus once for each svn:externals entry
1588 (unless svn-status-head-revision
1589 (setq svn-status-head-revision
(match-string 1))))
1590 ((looking-at "Performing status on external item at '\\(.*\\)'")
1591 ;; The *next* line has info about the directory named in svn:externals
1592 ;; [ie the directory in (match-string 1)]
1593 ;; we should parse it, and merge the info with what we have already know
1594 ;; but for now just ignore the line completely
1596 ;; Actually, this seems to not always be the case
1597 ;; I have an example where we are in an svn:external which
1598 ;; is itself inside a svn:external, this need not be true:
1599 ;; the next line is not 'X dir' but just 'dir', so we
1600 ;; actually need to parse that line, or the results will
1602 ;; so we should merge lines 'X dir' with ' dir', but for now
1603 ;; we just leave both in the results
1605 ;; My attempt to merge the lines uses skip-double-external-dir-entry-name
1606 ;; and externals-map
1607 (setq skip-double-external-dir-entry-name
(match-string-no-properties 1))
1608 ;; (message "Going to skip %s" skip-double-external-dir-entry-name)
1611 (setq svn-marks
(buffer-substring (point) (+ (point) svn-marks-length
))
1612 svn-file-mark
(elt svn-marks
0) ; 1st column - M,A,C,D,G,? etc
1613 svn-property-mark
(elt svn-marks
1) ; 2nd column - M,C (properties)
1614 svn-wc-locked-mark
(elt svn-marks
2) ; 3rd column - L or blank
1615 svn-with-history-mark
(elt svn-marks
3) ; 4th column - + or blank
1616 svn-switched-mark
(elt svn-marks
4) ; 5th column - S or blank
1617 svn-repo-locked-mark
(elt svn-marks
5)) ; 6th column - K,O,T,B or blank
1618 (when svn-status-remote
1619 (setq svn-update-mark
(elt svn-marks
7))) ; 8th column - * or blank
1620 (when (eq svn-property-mark ?\
) (setq svn-property-mark nil
))
1621 (when (eq svn-wc-locked-mark ?\
) (setq svn-wc-locked-mark nil
))
1622 (when (eq svn-with-history-mark ?\
) (setq svn-with-history-mark nil
))
1623 (when (eq svn-switched-mark ?\
) (setq svn-switched-mark nil
))
1624 (when (eq svn-update-mark ?\
) (setq svn-update-mark nil
))
1625 (when (eq svn-repo-locked-mark ?\
) (setq svn-repo-locked-mark nil
))
1626 (forward-char svn-marks-length
)
1627 (skip-chars-forward " ")
1628 ;; (message "after marks: '%s'" (buffer-substring (point) (line-end-position)))
1630 ((looking-at "\\([-?]\\|[0-9]+\\) +\\([-?]\\|[0-9]+\\) +\\([^ ]+\\) *\\(.+\\)$")
1631 (setq local-rev
(svn-parse-rev-num (match-string 1))
1632 last-change-rev
(svn-parse-rev-num (match-string 2))
1633 author
(match-string 3)
1634 path
(match-string 4)))
1635 ((looking-at "\\([-?]\\|[0-9]+\\) +\\([^ ]+\\)$")
1636 (setq local-rev
(svn-parse-rev-num (match-string 1))
1639 path
(match-string 2)))
1640 ((looking-at "\\(.*\\)")
1641 (setq path
(match-string 1)
1644 author
(if (eq svn-file-mark ?X
) "" "?"))) ;clear author of svn:externals dirs
1646 (error "Unknown status line format")))
1647 (unless path
(setq path
"."))
1648 (setq dir
(file-name-directory path
))
1649 (if (and (not svn-status-verbose
) dir
)
1650 (let ((dirname (directory-file-name dir
)))
1651 (if (not (member dirname dir-set
))
1652 (setq dir-set
(cons dirname dir-set
)))))
1653 (if (and skip-double-external-dir-entry-name
(string= skip-double-external-dir-entry-name path
))
1654 ;; merge this entry to a previous saved one
1655 (let ((info (gethash path externals-map
)))
1656 ;; (message "skip-double-external-dir-entry-name: %s - path: %s" skip-double-external-dir-entry-name path)
1659 (svn-status-line-info->set-localrev info local-rev
)
1660 (svn-status-line-info->set-lastchangerev info last-change-rev
)
1661 (svn-status-line-info->set-author info author
)
1662 (svn-status-message 3 "merging entry for %s to %s" path info
)
1663 (setq skip-double-external-dir-entry-name nil
))
1664 (message "psvn: %s not handled correct, please report this case." path
)))
1665 (setq svn-status-info
1666 (cons (svn-status-make-line-info path
1667 (gethash path old-ui-information
)
1675 svn-with-history-mark
1677 svn-repo-locked-mark
1678 nil
) ;;psvn-extra-info
1680 (when (eq svn-file-mark ?X
)
1681 (svn-puthash (match-string 1) (car svn-status-info
) externals-map
)
1682 (svn-status-message 3 "found external: %s %S" (match-string 1) (car svn-status-info
)))
1683 (setq revision-width
(max revision-width
1684 (length (number-to-string local-rev
))
1685 (length (number-to-string last-change-rev
))))
1686 (setq author-width
(max author-width
(length author
)))))
1688 (unless svn-status-verbose
1689 (setq svn-status-info
(svn-status-make-dummy-dirs dir-set
1690 old-ui-information
)))
1691 (setq svn-status-default-column
1692 (+ 6 revision-width revision-width author-width
1693 (if svn-status-short-mod-flag-p
3 0)))
1694 (setq svn-status-line-format
(format " %%c%%c%%c %%%ds %%%ds %%-%ds"
1698 (setq svn-status-info
(nreverse svn-status-info
))
1699 (when svn-status-sort-status-buffer
1700 (setq svn-status-info
(sort svn-status-info
'svn-status-sort-predicate
))))))
1702 ;;(string-lessp "." "%") => nil
1703 ;(svn-status-sort-predicate '(t t t ".") '(t t t "%")) => t
1704 (defun svn-status-sort-predicate (a b
)
1705 "Return t if A should appear before B in the `svn-status-buffer-name' buffer.
1706 A and B must be line-info's."
1707 (string-lessp (concat (svn-status-line-info->full-path a
) "/")
1708 (concat (svn-status-line-info->full-path b
) "/")))
1710 (defun svn-status-remove-temp-file-maybe ()
1711 "Remove any (no longer required) temporary files created by psvn.el."
1712 (when svn-status-temp-file-to-remove
1713 (when (file-exists-p svn-status-temp-file-to-remove
)
1714 (delete-file svn-status-temp-file-to-remove
))
1715 (when (file-exists-p svn-status-temp-arg-file
)
1716 (delete-file svn-status-temp-arg-file
))
1717 (setq svn-status-temp-file-to-remove nil
)))
1719 (defun svn-status-remove-control-M ()
1720 "Remove ^M at end of line in the whole buffer."
1722 (let ((buffer-read-only nil
))
1725 (goto-char (point-min))
1726 (while (re-search-forward "\r$" (point-max) t
)
1727 (replace-match "" nil nil
))))))
1730 ;;(easy-menu-add-item nil '("tools") ["SVN Status" svn-status t] "PCL-CVS")
1731 (easy-menu-add-item nil
'("tools") ["SVN Status" svn-status t
])
1732 (error (message "psvn: could not install menu")))
1734 (defvar svn-status-mode-map
() "Keymap used in `svn-status-mode' buffers.")
1735 (put 'svn-status-mode-map
'risky-local-variable t
) ;for Emacs 20.7
1736 (defvar svn-status-mode-mark-map
()
1737 "Subkeymap used in `svn-status-mode' for mark commands.")
1738 (put 'svn-status-mode-mark-map
'risky-local-variable t
) ;for Emacs 20.7
1739 (defvar svn-status-mode-property-map
()
1740 "Subkeymap used in `svn-status-mode' for property commands.")
1741 (put 'svn-status-mode-property-map
'risky-local-variable t
) ;for Emacs 20.7
1742 (defvar svn-status-mode-options-map
()
1743 "Subkeymap used in `svn-status-mode' for option commands.")
1744 (put 'svn-status-mode-options-map
'risky-local-variable t
) ;for Emacs 20.7
1745 (defvar svn-status-mode-trac-map
()
1746 "Subkeymap used in `svn-status-mode' for trac issue tracker commands.")
1747 (put 'svn-status-mode-trac-map
'risky-local-variable t
) ;for Emacs 20.7
1748 (defvar svn-status-mode-extension-map
()
1749 "Subkeymap used in `svn-status-mode' for some seldom used commands.")
1750 (put 'svn-status-mode-extension-map
'risky-local-variable t
) ;for Emacs 20.7
1751 (defvar svn-status-mode-branch-map
()
1752 "Subkeymap used in `svn-status-mode' for branching commands.")
1753 (put 'svn-status-mode-extension-map
'risky-local-variable t
) ;for Emacs 20.7
1755 (when (not svn-status-mode-map
)
1756 (setq svn-status-mode-map
(make-sparse-keymap))
1757 (suppress-keymap svn-status-mode-map
)
1758 ;; Don't use (kbd "<return>"); it's unreachable with GNU Emacs 21.3 on a TTY.
1759 (define-key svn-status-mode-map
(kbd "RET") 'svn-status-find-file-or-examine-directory
)
1760 (define-key svn-status-mode-map
(kbd "<mouse-2>") 'svn-status-mouse-find-file-or-examine-directory
)
1761 (define-key svn-status-mode-map
(kbd "^") 'svn-status-examine-parent
)
1762 (define-key svn-status-mode-map
(kbd "s") 'svn-status-show-process-buffer
)
1763 (define-key svn-status-mode-map
(kbd "h") 'svn-status-pop-to-partner-buffer
)
1764 (define-key svn-status-mode-map
(kbd "f") 'svn-status-find-files
)
1765 (define-key svn-status-mode-map
(kbd "o") 'svn-status-find-file-other-window
)
1766 (define-key svn-status-mode-map
(kbd "C-o") 'svn-status-find-file-other-window-noselect
)
1767 (define-key svn-status-mode-map
(kbd "v") 'svn-status-view-file-other-window
)
1768 (define-key svn-status-mode-map
(kbd "e") 'svn-status-toggle-edit-cmd-flag
)
1769 (define-key svn-status-mode-map
(kbd "g") 'svn-status-update
)
1770 (define-key svn-status-mode-map
(kbd "M-s") 'svn-status-update
) ;; PCL-CVS compatibility
1771 (define-key svn-status-mode-map
(kbd "q") 'svn-status-bury-buffer
)
1772 (define-key svn-status-mode-map
(kbd "x") 'svn-status-redraw-status-buffer
)
1773 (define-key svn-status-mode-map
(kbd "H") 'svn-status-use-history
)
1774 (define-key svn-status-mode-map
(kbd "m") 'svn-status-set-user-mark
)
1775 (define-key svn-status-mode-map
(kbd "u") 'svn-status-unset-user-mark
)
1776 ;; This matches a binding of `dired-unmark-all-files' in `dired-mode-map'
1777 ;; of both GNU Emacs and XEmacs. It seems unreachable with XEmacs on
1778 ;; TTY, but if that's a problem then its Dired needs fixing too.
1779 ;; Or you could just use "*!".
1780 (define-key svn-status-mode-map
"\M-\C-?" 'svn-status-unset-all-usermarks
)
1781 ;; The key that normally deletes characters backwards should here
1782 ;; instead unmark files backwards. In GNU Emacs, that would be (kbd
1783 ;; "DEL") aka [?\177], but XEmacs treats those as [(delete)] and
1784 ;; would bind a key that normally deletes forwards. [(backspace)]
1785 ;; is unreachable with GNU Emacs on a tty. Try to recognize the
1786 ;; dialect and act accordingly.
1788 ;; XEmacs has a `delete-forward-p' function that checks the
1789 ;; `delete-key-deletes-forward' option. We don't use those, for two
1790 ;; reasons: psvn.el may be loaded before user customizations, and
1791 ;; XEmacs allows simultaneous connections to multiple devices with
1792 ;; different keyboards.
1793 (define-key svn-status-mode-map
1794 (if (member (kbd "DEL") '([(delete)] [delete]))
1795 [(backspace)] ; XEmacs
1796 (kbd "DEL")) ; GNU Emacs
1797 'svn-status-unset-user-mark-backwards)
1798 (define-key svn-status-mode-map (kbd "$") 'svn-status-toggle-elide)
1799 (define-key svn-status-mode-map (kbd "w") 'svn-status-copy-current-line-info)
1800 (define-key svn-status-mode-map (kbd ".") 'svn-status-goto-root-or-return)
1801 (define-key svn-status-mode-map (kbd "I") 'svn-status-parse-info)
1802 (define-key svn-status-mode-map (kbd "V") 'svn-status-svnversion)
1803 (define-key svn-status-mode-map (kbd "?") 'svn-status-toggle-hide-unknown)
1804 (define-key svn-status-mode-map (kbd "_") 'svn-status-toggle-hide-unmodified)
1805 (define-key svn-status-mode-map (kbd "a") 'svn-status-add-file)
1806 (define-key svn-status-mode-map (kbd "A") 'svn-status-add-file-recursively)
1807 (define-key svn-status-mode-map (kbd "+") 'svn-status-make-directory)
1808 (define-key svn-status-mode-map (kbd "R") 'svn-status-mv)
1809 (define-key svn-status-mode-map (kbd "C") 'svn-status-cp)
1810 (define-key svn-status-mode-map (kbd "D") 'svn-status-rm)
1811 (define-key svn-status-mode-map (kbd "c") 'svn-status-commit)
1812 (define-key svn-status-mode-map (kbd "M-c") 'svn-status-cleanup)
1813 (define-key svn-status-mode-map (kbd "k") 'svn-status-lock)
1814 (define-key svn-status-mode-map (kbd "K") 'svn-status-unlock)
1815 (define-key svn-status-mode-map (kbd "U") 'svn-status-update-cmd)
1816 (define-key svn-status-mode-map (kbd "M-u") 'svn-status-update-cmd)
1817 (define-key svn-status-mode-map (kbd "r") 'svn-status-revert)
1818 (define-key svn-status-mode-map (kbd "l") 'svn-status-show-svn-log)
1819 (define-key svn-status-mode-map (kbd "i") 'svn-status-info)
1820 (define-key svn-status-mode-map (kbd "b") 'svn-status-blame)
1821 (define-key svn-status-mode-map (kbd "=") 'svn-status-show-svn-diff)
1822 ;; [(control ?=)] is unreachable on TTY, but you can use "*u" instead.
1823 ;; (Is the "u" mnemonic for something?)
1824 (define-key svn-status-mode-map (kbd "C-=") 'svn-status-show-svn-diff-for-marked-files)
1825 (define-key svn-status-mode-map (kbd "~") 'svn-status-get-specific-revision)
1826 (define-key svn-status-mode-map (kbd "E") 'svn-status-ediff-with-revision)
1828 (define-key svn-status-mode-map (kbd "n") 'svn-status-next-line)
1829 (define-key svn-status-mode-map (kbd "p") 'svn-status-previous-line)
1830 (define-key svn-status-mode-map (kbd "<down>") 'svn-status-next-line)
1831 (define-key svn-status-mode-map (kbd "<up>") 'svn-status-previous-line)
1832 (define-key svn-status-mode-map (kbd "C-x C-j") 'svn-status-dired-jump)
1833 (define-key svn-status-mode-map [down-mouse-3] 'svn-status-popup-menu)
1834 (setq svn-status-mode-mark-map (make-sparse-keymap))
1835 (define-key svn-status-mode-map (kbd "*") svn-status-mode-mark-map)
1836 (define-key svn-status-mode-mark-map (kbd "!") 'svn-status-unset-all-usermarks)
1837 (define-key svn-status-mode-mark-map (kbd "?") 'svn-status-mark-unknown)
1838 (define-key svn-status-mode-mark-map (kbd "A") 'svn-status-mark-added)
1839 (define-key svn-status-mode-mark-map (kbd "M") 'svn-status-mark-modified)
1840 (define-key svn-status-mode-mark-map (kbd "D") 'svn-status-mark-deleted)
1841 (define-key svn-status-mode-mark-map (kbd "*") 'svn-status-mark-changed)
1842 (define-key svn-status-mode-mark-map (kbd ".") 'svn-status-mark-by-file-ext)
1843 (define-key svn-status-mode-mark-map (kbd "%") 'svn-status-mark-filename-regexp)
1844 (define-key svn-status-mode-mark-map (kbd "u") 'svn-status-show-svn-diff-for-marked-files))
1845 (when (not svn-status-mode-property-map)
1846 (setq svn-status-mode-property-map (make-sparse-keymap))
1847 (define-key svn-status-mode-property-map (kbd "l") 'svn-status-property-list)
1848 (define-key svn-status-mode-property-map (kbd "s") 'svn-status-property-set)
1849 (define-key svn-status-mode-property-map (kbd "d") 'svn-status-property-delete)
1850 (define-key svn-status-mode-property-map (kbd "e") 'svn-status-property-edit-one-entry)
1851 (define-key svn-status-mode-property-map (kbd "i") 'svn-status-property-ignore-file)
1852 (define-key svn-status-mode-property-map (kbd "I") 'svn-status-property-ignore-file-extension)
1853 ;; XEmacs 21.4.15 on TTY (vt420) converts `C-i' to `TAB',
1854 ;; which [(control ?i)] won't match. Handle it separately.
1855 ;; On GNU Emacs, the following two forms bind the same key,
1856 ;; reducing clutter in `where-is'.
1857 (define-key svn-status-mode-property-map [(control ?i)] 'svn-status-property-edit-svn-ignore)
1858 (define-key svn-status-mode-property-map (kbd "TAB") 'svn-status-property-edit-svn-ignore)
1859 (define-key svn-status-mode-property-map (kbd "k") 'svn-status-property-set-keyword-list)
1860 (define-key svn-status-mode-property-map (kbd "Ki") 'svn-status-property-set-keyword-id)
1861 (define-key svn-status-mode-property-map (kbd "Kd") 'svn-status-property-set-keyword-date)
1862 (define-key svn-status-mode-property-map (kbd "y") 'svn-status-property-set-eol-style)
1863 (define-key svn-status-mode-property-map (kbd "x") 'svn-status-property-set-executable)
1864 (define-key svn-status-mode-property-map (kbd "m") 'svn-status-property-set-mime-type)
1865 ;; TODO: Why is `svn-status-select-line' in `svn-status-mode-property-map'?
1866 (define-key svn-status-mode-property-map (kbd "RET") 'svn-status-select-line)
1867 (define-key svn-status-mode-map (kbd "P") svn-status-mode-property-map))
1868 (when (not svn-status-mode-extension-map)
1869 (setq svn-status-mode-extension-map (make-sparse-keymap))
1870 (define-key svn-status-mode-extension-map (kbd "v") 'svn-status-resolved)
1871 (define-key svn-status-mode-extension-map (kbd "X") 'svn-status-resolve-conflicts)
1872 (define-key svn-status-mode-extension-map (kbd "e") 'svn-status-export)
1873 (define-key svn-status-mode-map (kbd "X") svn-status-mode-extension-map))
1874 (when (not svn-status-mode-options-map)
1875 (setq svn-status-mode-options-map (make-sparse-keymap))
1876 (define-key svn-status-mode-options-map (kbd "s") 'svn-status-save-state)
1877 (define-key svn-status-mode-options-map (kbd "l") 'svn-status-load-state)
1878 (define-key svn-status-mode-options-map (kbd "x") 'svn-status-toggle-sort-status-buffer)
1879 (define-key svn-status-mode-options-map (kbd "v") 'svn-status-toggle-svn-verbose-flag)
1880 (define-key svn-status-mode-options-map (kbd "f") 'svn-status-toggle-display-full-path)
1881 (define-key svn-status-mode-options-map (kbd "t") 'svn-status-set-trac-project-root)
1882 (define-key svn-status-mode-options-map (kbd "n") 'svn-status-set-module-name)
1883 (define-key svn-status-mode-options-map (kbd "c") 'svn-status-set-changelog-style)
1884 (define-key svn-status-mode-options-map (kbd "b") 'svn-status-set-branch-list)
1885 (define-key svn-status-mode-map (kbd "O") svn-status-mode-options-map))
1886 (when (not svn-status-mode-trac-map)
1887 (setq svn-status-mode-trac-map (make-sparse-keymap))
1888 (define-key svn-status-mode-trac-map (kbd "w") 'svn-trac-browse-wiki)
1889 (define-key svn-status-mode-trac-map (kbd "t") 'svn-trac-browse-timeline)
1890 (define-key svn-status-mode-trac-map (kbd "m") 'svn-trac-browse-roadmap)
1891 (define-key svn-status-mode-trac-map (kbd "r") 'svn-trac-browse-report)
1892 (define-key svn-status-mode-trac-map (kbd "s") 'svn-trac-browse-source)
1893 (define-key svn-status-mode-trac-map (kbd "i") 'svn-trac-browse-ticket)
1894 (define-key svn-status-mode-trac-map (kbd "c") 'svn-trac-browse-changeset)
1895 (define-key svn-status-mode-map (kbd "T") svn-status-mode-trac-map))
1896 (when (not svn-status-mode-branch-map)
1897 (setq svn-status-mode-branch-map (make-sparse-keymap))
1898 (define-key svn-status-mode-branch-map (kbd "d") 'svn-branch-diff)
1899 (define-key svn-status-mode-map (kbd "B") svn-status-mode-branch-map))
1901 (easy-menu-define svn-status-mode-menu svn-status-mode-map
1902 "'svn-status-mode' menu"
1904 ["svn status" svn-status-update t]
1905 ["svn update" svn-status-update-cmd t]
1906 ["svn commit" svn-status-commit t]
1907 ["svn log" svn-status-show-svn-log t]
1908 ["svn info" svn-status-info t]
1909 ["svn blame" svn-status-blame t]
1911 ["svn diff current file" svn-status-show-svn-diff t]
1912 ["svn diff marked files" svn-status-show-svn-diff-for-marked-files t]
1913 ["svn ediff current file" svn-status-ediff-with-revision t]
1914 ["svn resolve conflicts" svn-status-resolve-conflicts]
1916 ["svn cat ..." svn-status-get-specific-revision t]
1917 ["svn add" svn-status-add-file t]
1918 ["svn add recursively" svn-status-add-file-recursively t]
1919 ["svn mkdir..." svn-status-make-directory t]
1920 ["svn mv..." svn-status-mv t]
1921 ["svn cp..." svn-status-cp t]
1922 ["svn rm..." svn-status-rm t]
1923 ["svn export..." svn-status-export t]
1924 ["Up Directory" svn-status-examine-parent t]
1925 ["Elide Directory" svn-status-toggle-elide t]
1926 ["svn revert" svn-status-revert t]
1927 ["svn resolved" svn-status-resolved t]
1928 ["svn cleanup" svn-status-cleanup t]
1929 ["svn lock" svn-status-lock t]
1930 ["svn unlock" svn-status-unlock t]
1931 ["Show Process Buffer" svn-status-show-process-buffer t]
1933 ["diff" svn-branch-diff t]
1934 ["Set Branch list" svn-status-set-branch-list t]
1937 ["svn proplist" svn-status-property-list t]
1938 ["Set Multiple Properties..." svn-status-property-set t]
1939 ["Edit One Property..." svn-status-property-edit-one-entry t]
1940 ["svn propdel..." svn-status-property-delete t]
1942 ["svn:ignore File..." svn-status-property-ignore-file t]
1943 ["svn:ignore File Extension..." svn-status-property-ignore-file-extension t]
1944 ["Edit svn:ignore Property" svn-status-property-edit-svn-ignore t]
1946 ["Edit svn:keywords List" svn-status-property-set-keyword-list t]
1947 ["Add/Remove Id to/from svn:keywords" svn-status-property-set-keyword-id t]
1948 ["Add/Remove Date to/from svn:keywords" svn-status-property-set-keyword-date t]
1950 ["Select svn:eol-style" svn-status-property-set-eol-style t]
1951 ["Set svn:executable" svn-status-property-set-executable t]
1952 ["Set svn:mime-type" svn-status-property-set-mime-type t]
1955 ["Save Options" svn-status-save-state t]
1956 ["Load Options" svn-status-load-state t]
1957 ["Set Trac project root" svn-status-set-trac-project-root t]
1958 ["Set Short module name" svn-status-set-module-name t]
1959 ["Set Changelog style" svn-status-set-changelog-style t]
1960 ["Set Branch list" svn-status-set-branch-list t]
1961 ["Sort the *svn-status* buffer" svn-status-toggle-sort-status-buffer
1962 :style toggle :selected svn-status-sort-status-buffer]
1963 ["Use -v for svn status calls" svn-status-toggle-svn-verbose-flag
1964 :style toggle :selected svn-status-verbose]
1965 ["Display full path names" svn-status-toggle-display-full-path
1966 :style toggle :selected svn-status-display-full-path]
1969 ["Browse wiki" svn-trac-browse-wiki t]
1970 ["Browse timeline" svn-trac-browse-timeline t]
1971 ["Browse roadmap" svn-trac-browse-roadmap t]
1972 ["Browse source" svn-trac-browse-source t]
1973 ["Browse report" svn-trac-browse-report t]
1974 ["Browse ticket" svn-trac-browse-ticket t]
1975 ["Browse changeset" svn-trac-browse-changeset t]
1976 ["Set Trac project root" svn-status-set-trac-project-root t]
1979 ["Edit Next SVN Cmd Line" svn-status-toggle-edit-cmd-flag t]
1980 ["Work Directory History..." svn-status-use-history t]
1982 ["Mark" svn-status-set-user-mark t]
1983 ["Unmark" svn-status-unset-user-mark t]
1984 ["Unmark all" svn-status-unset-all-usermarks t]
1986 ["Mark/Unmark unknown" svn-status-mark-unknown t]
1987 ["Mark/Unmark added" svn-status-mark-added t]
1988 ["Mark/Unmark modified" svn-status-mark-modified t]
1989 ["Mark/Unmark deleted" svn-status-mark-deleted t]
1990 ["Mark/Unmark modified/added/deleted" svn-status-mark-changed t]
1991 ["Mark/Unmark filename by extension" svn-status-mark-by-file-ext t]
1992 ["Mark/Unmark filename by regexp" svn-status-mark-filename-regexp t]
1994 ["Hide Unknown" svn-status-toggle-hide-unknown
1995 :style toggle :selected svn-status-hide-unknown]
1996 ["Hide Unmodified" svn-status-toggle-hide-unmodified
1997 :style toggle :selected svn-status-hide-unmodified]
1998 ["Show Client versions" svn-status-version t]
1999 ["Prepare bug report" svn-prepare-bug-report t]
2002 (defvar svn-status-file-popup-menu-list
2003 '(["open" svn-status-find-file-other-window t]
2004 ["svn diff" svn-status-show-svn-diff t]
2005 ["svn commit" svn-status-commit t]
2006 ["svn log" svn-status-show-svn-log t]
2007 ["svn blame" svn-status-blame t]
2008 ["mark" svn-status-set-user-mark t]
2009 ["unmark" svn-status-unset-user-mark t]
2010 ["svn add" svn-status-add-file t]
2011 ["svn add recursively" svn-status-add-file-recursively t]
2012 ["svn mv..." svn-status-mv t]
2013 ["svn rm..." svn-status-rm t]
2014 ["svn lock" svn-status-lock t]
2015 ["svn unlock" svn-status-unlock t]
2016 ["svn info" svn-status-info t]
2017 ) "A list of menu entries for `svn-status-popup-menu'")
2019 ;; extend svn-status-file-popup-menu-list via:
2020 ;; (add-to-list 'svn-status-file-popup-menu-list ["commit" svn-status-commit t])
2022 (defun svn-status-popup-menu (event)
2023 "Display a file specific popup menu"
2025 (mouse-set-point event)
2026 (let* ((line-info (svn-status-get-line-information))
2027 (name (svn-status-line-info->filename line-info)))
2029 (easy-menu-define svn-status-actual-popup-menu nil nil
2030 (append (list name) svn-status-file-popup-menu-list))
2031 (svn-status-face-set-temporary-during-popup
2032 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
2033 svn-status-actual-popup-menu))))
2035 (defun svn-status-face-set-temporary-during-popup (face begin end menu &optional prefix)
2036 "Put FACE on BEGIN and END in the buffer during Popup MENU.
2037 PREFIX is passed to `popup-menu'."
2041 (setq o (make-overlay begin end))
2042 (overlay-put o 'face face)
2044 (popup-menu menu prefix))
2045 (delete-overlay o))))
2047 (defun svn-status-mode ()
2048 "Major mode used by psvn.el to display the output of \"svn status\".
2050 The Output has the following format:
2051 FPH BASE CMTD Author em File
2055 BASE = local base revision
2056 CMTD = last committed revision
2057 Author = author of change
2058 em = \"**\" or \"(Update Available)\" [see `svn-status-short-mod-flag-p']
2059 if file can be updated
2060 File = path/filename
2062 The following keys are defined:
2063 \\{svn-status-mode-map}"
2065 (kill-all-local-variables)
2067 (use-local-map svn-status-mode-map)
2068 (easy-menu-add svn-status-mode-menu)
2070 (setq major-mode 'svn-status-mode)
2071 (setq mode-name "svn-status")
2072 (setq mode-line-process 'svn-status-mode-line-process)
2073 (run-hooks 'svn-status-mode-hook)
2074 (let ((view-read-only nil))
2075 (toggle-read-only 1)))
2077 (defun svn-status-update-mode-line ()
2078 (setq svn-status-mode-line-process
2079 (concat svn-status-mode-line-process-edit-flag svn-status-mode-line-process-status))
2080 (force-mode-line-update))
2082 (defun svn-status-bury-buffer (arg)
2083 "Bury the buffers used by psvn.el
2085 `svn-status-buffer-name'
2086 `svn-process-buffer-name'
2087 `svn-log-edit-buffer-name'
2091 When called with a prefix argument, ARG, switch back to the window configuration that was
2092 in use before `svn-status' was called."
2095 (when svn-status-initial-window-configuration
2096 (set-window-configuration svn-status-initial-window-configuration)))
2098 (let ((bl `(,svn-log-edit-buffer-name "*svn-property-edit*" "*svn-log*" "*svn-info*" ,svn-process-buffer-name)))
2100 (when (get-buffer (car bl))
2101 (bury-buffer (car bl)))
2103 (when (string= (buffer-name) svn-status-buffer-name)
2106 (defun svn-status-save-some-buffers (&optional tree)
2107 "Save all buffers visiting a file in TREE.
2108 If TREE is not given, try `svn-status-base-dir' as TREE."
2110 ;; (message "svn-status-save-some-buffers: tree1: %s" tree)
2112 (tree (or (svn-status-base-dir)
2114 ;; (message "svn-status-save-some-buffers: tree2: %s" tree)
2116 (error "Not in a svn project tree"))
2117 (dolist (buffer (buffer-list))
2118 (with-current-buffer buffer
2119 (when (buffer-modified-p)
2120 (let ((file (buffer-file-name)))
2122 (let ((root (svn-status-base-dir (file-name-directory file))))
2123 ;; (message "svn-status-save-some-buffers: file: %s, root: %s" file root)
2126 ;; buffer is modified and in the tree TREE.
2127 (or (y-or-n-p (concat "Save buffer " (buffer-name) "? "))
2129 (save-buffer))))))))
2132 (defun svn-status-find-files ()
2133 "Open selected file(s) for editing.
2134 See `svn-status-marked-files' for what counts as selected."
2136 (let ((fnames (mapcar 'svn-status-line-info->full-path (svn-status-marked-files))))
2137 (mapc 'find-file fnames)))
2140 (defun svn-status-find-file-other-window ()
2141 "Open the file in the other window for editing."
2143 (svn-status-ensure-cursor-on-file)
2144 (find-file-other-window (svn-status-line-info->filename
2145 (svn-status-get-line-information))))
2147 (defun svn-status-find-file-other-window-noselect ()
2148 "Open the file in the other window for editing, but don't select it."
2150 (svn-status-ensure-cursor-on-file)
2152 (find-file-noselect (svn-status-line-info->filename
2153 (svn-status-get-line-information)))))
2155 (defun svn-status-view-file-other-window ()
2156 "Open the file in the other window for viewing."
2158 (svn-status-ensure-cursor-on-file)
2159 (view-file-other-window (svn-status-line-info->filename
2160 (svn-status-get-line-information))))
2162 (defun svn-status-find-file-or-examine-directory ()
2163 "If point is on a directory, run `svn-status' on that directory.
2164 Otherwise run `find-file'."
2166 (svn-status-ensure-cursor-on-file)
2167 (let ((line-info (svn-status-get-line-information)))
2168 (if (svn-status-line-info->directory-p line-info)
2169 (svn-status (svn-status-line-info->full-path line-info))
2170 (find-file (svn-status-line-info->filename line-info)))))
2172 (defun svn-status-examine-parent ()
2173 "Run `svn-status' on the parent of the current directory."
2175 (svn-status (expand-file-name "../")))
2177 (defun svn-status-mouse-find-file-or-examine-directory (event)
2178 "Move point to where EVENT occurred, and do `svn-status-find-file-or-examine-directory'
2179 EVENT could be \"mouse clicked\" or similar."
2181 (mouse-set-point event)
2182 (svn-status-find-file-or-examine-directory))
2184 (defun svn-status-line-info->ui-status (line-info)
2185 "Return the ui-status structure of LINE-INFO.
2186 See `svn-status-make-ui-status' for information about the ui-status."
2189 (defun svn-status-line-info->has-usermark (line-info) (nth 0 (nth 0 line-info)))
2190 (defun svn-status-line-info->user-elide (line-info) (nth 1 (nth 0 line-info)))
2192 (defun svn-status-line-info->filemark (line-info) (nth 1 line-info))
2193 (defun svn-status-line-info->propmark (line-info) (nth 2 line-info))
2194 (defun svn-status-line-info->filename (line-info) (nth 3 line-info))
2195 (defun svn-status-line-info->filename-nondirectory (line-info)
2196 (file-name-nondirectory (svn-status-line-info->filename line-info)))
2197 (defun svn-status-line-info->localrev (line-info)
2198 (if (>= (nth 4 line-info) 0)
2201 (defun svn-status-line-info->lastchangerev (line-info)
2202 "Return the last revision in which LINE-INFO was modified."
2203 (let ((l (nth 5 line-info)))
2204 (if (and l (>= l 0))
2207 (defun svn-status-line-info->author (line-info)
2208 "Return the last author that changed the item that is represented in LINE-INFO."
2210 (defun svn-status-line-info->update-available (line-info)
2211 "Return whether LINE-INFO is out of date.
2212 In other words, whether there is a newer version available in the
2213 repository than the working copy."
2215 (defun svn-status-line-info->locked (line-info)
2216 "Return whether LINE-INFO represents a locked file.
2217 This is column three of the `svn status' output.
2218 The result will be nil or \"L\".
2219 \(A file becomes locked when an operation is interupted; run \\[svn-status-cleanup]'
2222 (defun svn-status-line-info->historymark (line-info)
2223 "Mark from column four of output from `svn status'.
2224 This will be nil unless the file is scheduled for addition with
2225 history, when it will be \"+\"."
2227 (defun svn-status-line-info->switched (line-info)
2228 "Return whether LINE-INFO is switched relative to its parent.
2229 This is column five of the output from `svn status'.
2230 The result will be nil or \"S\"."
2232 (defun svn-status-line-info->repo-locked (line-info)
2233 "Return whether LINE-INFO contains some locking information.
2234 This is column six of the output from `svn status'.
2235 The result will be \"K\", \"O\", \"T\", \"B\" or nil."
2237 (defun svn-status-line-info->psvn-extra-info (line-info)
2238 "Return a list of extra information for psvn associated with LINE-INFO.
2239 This list holds currently only one element:
2240 * The action after a commit or update."
2243 (defun svn-status-line-info->is-visiblep (line-info)
2244 "Return whether the line is visible or not"
2245 (or (not (or (svn-status-line-info->hide-because-unknown line-info)
2246 (svn-status-line-info->hide-because-unmodified line-info)
2247 (svn-status-line-info->hide-because-custom-hide-function line-info)
2248 (svn-status-line-info->hide-because-user-elide line-info)))
2249 (svn-status-line-info->update-available line-info) ;; show the line, if an update is available
2250 (svn-status-line-info->psvn-extra-info line-info) ;; show the line, if there is some extra info displayed on this line
2253 (defun svn-status-line-info->hide-because-unknown (line-info)
2254 (and svn-status-hide-unknown
2255 (eq (svn-status-line-info->filemark line-info) ??)))
2257 (defun svn-status-line-info->hide-because-custom-hide-function (line-info)
2258 (and svn-status-custom-hide-function
2259 (apply svn-status-custom-hide-function (list line-info))))
2261 (defun svn-status-line-info->hide-because-unmodified (line-info)
2262 ;;(message " %S %S %S %S - %s" svn-status-hide-unmodified (svn-status-line-info->propmark line-info) ?_
2263 ;; (svn-status-line-info->filemark line-info) (svn-status-line-info->filename line-info))
2264 (and svn-status-hide-unmodified
2265 (and (or (eq (svn-status-line-info->filemark line-info) ?_)
2266 (eq (svn-status-line-info->filemark line-info) ? ))
2267 (or (eq (svn-status-line-info->propmark line-info) ?_)
2268 (eq (svn-status-line-info->propmark line-info) ? )
2269 (eq (svn-status-line-info->propmark line-info) nil)))))
2271 (defun svn-status-line-info->hide-because-user-elide (line-info)
2272 (eq (svn-status-line-info->user-elide line-info) t))
2274 (defun svn-status-line-info->show-user-elide-continuation (line-info)
2275 (eq (svn-status-line-info->user-elide line-info) 'directory))
2277 ;; modify the line-info
2278 (defun svn-status-line-info->set-filemark (line-info value)
2279 (setcar (nthcdr 1 line-info) value))
2281 (defun svn-status-line-info->set-propmark (line-info value)
2282 (setcar (nthcdr 2 line-info) value))
2284 (defun svn-status-line-info->set-localrev (line-info value)
2285 (setcar (nthcdr 4 line-info) value))
2287 (defun svn-status-line-info->set-author (line-info value)
2288 (setcar (nthcdr 6 line-info) value))
2290 (defun svn-status-line-info->set-lastchangerev (line-info value)
2291 (setcar (nthcdr 5 line-info) value))
2293 (defun svn-status-line-info->set-repo-locked (line-info value)
2294 (setcar (nthcdr 11 line-info) value))
2296 (defun svn-status-line-info->set-psvn-extra-info (line-info value)
2297 (setcar (nthcdr 12 line-info) value))
2299 (defun svn-status-copy-current-line-info (arg)
2300 "Copy the current file name at point, using `svn-status-copy-filename-as-kill'.
2301 If no file is at point, copy everything starting from ':' to the end of line."
2303 (if (svn-status-get-line-information)
2304 (svn-status-copy-filename-as-kill arg)
2306 (goto-char (svn-point-at-bol))
2307 (when (looking-at ".+?: *\\(.+\\)$")
2308 (kill-new (svn-match-string-no-properties 1))
2309 (message "Copied: %s" (svn-match-string-no-properties 1))))))
2311 (defun svn-status-copy-filename-as-kill (arg)
2312 "Copy the actual file name to the kill-ring.
2313 When called with the prefix argument 0, use the full path name."
2315 (let ((str (if (eq arg 0)
2316 (svn-status-line-info->full-path (svn-status-get-line-information))
2317 (svn-status-line-info->filename (svn-status-get-line-information)))))
2319 (message "Copied %s" str)))
2321 (defun svn-status-get-child-directories (&optional dir)
2322 "Return a list of subdirectories for DIR"
2324 (let ((this-dir (concat (expand-file-name (or dir (svn-status-line-info->filename (svn-status-get-line-information)))) "/"))
2327 ;;(message "this-dir %S" this-dir)
2328 (dolist (line-info svn-status-info)
2329 (when (svn-status-line-info->directory-p line-info)
2330 (setq test-dir (svn-status-line-info->full-path line-info))
2331 (when (string= (file-name-directory test-dir) this-dir)
2332 (add-to-list 'sub-dir-list (file-relative-name (svn-status-line-info->full-path line-info)) t))))
2335 (defun svn-status-toggle-elide (arg)
2336 "Toggle eliding of the current file or directory.
2337 When called with a prefix argument, toggle the hiding of all subdirectories for the current directory."
2340 (let ((cur-line (svn-status-line-info->filename (svn-status-get-line-information))))
2341 (when (svn-status-line-info->user-elide (svn-status-get-line-information))
2342 (svn-status-toggle-elide nil))
2343 (dolist (dir-name (svn-status-get-child-directories))
2344 (svn-status-goto-file-name dir-name)
2345 (svn-status-toggle-elide nil))
2346 (svn-status-goto-file-name cur-line))
2347 (let ((st-info svn-status-info)
2349 (test (svn-status-line-info->filename (svn-status-get-line-information)))
2354 (if (member test svn-status-elided-list)
2355 (setq svn-status-elided-list (delete test svn-status-elided-list))
2356 (add-to-list 'svn-status-elided-list test))
2357 (when (string= test ".")
2359 (setq len-test (length test))
2361 (setq fname (svn-status-line-info->filename (car st-info)))
2362 (setq len-fname (length fname))
2363 (when (and (>= len-fname len-test)
2364 (string= (substring fname 0 len-test) test))
2365 (setq elide-mark new-elide-mark)
2366 (when (or (string= fname ".")
2367 (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
2368 (message "Elided directory %s and all its files." fname)
2369 (setq new-elide-mark (not (svn-status-line-info->user-elide (car st-info))))
2370 (setq elide-mark (if new-elide-mark 'directory nil)))
2371 ;;(message "elide-mark: %S member: %S" elide-mark (member fname svn-status-elided-list))
2372 (when (and (member fname svn-status-elided-list) (not elide-mark))
2373 (setq svn-status-elided-list (delete fname svn-status-elided-list)))
2374 (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark))
2375 (setq st-info (cdr st-info))))
2376 ;;(message "svn-status-elided-list: %S" svn-status-elided-list)
2377 (svn-status-update-buffer)))
2379 (defun svn-status-apply-elide-list ()
2380 "Elide files/directories according to `svn-status-elided-list'."
2382 (let ((st-info svn-status-info)
2390 (setq fname (svn-status-line-info->filename (car st-info)))
2391 (setq len-fname (length fname))
2392 (setq elided-list svn-status-elided-list)
2393 (setq elide-mark nil)
2395 (setq test (car elided-list))
2396 (when (string= test ".")
2398 (setq len-test (length test))
2399 (when (and (>= len-fname len-test)
2400 (string= (substring fname 0 len-test) test))
2402 (when (or (string= fname ".")
2403 (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
2404 (setq elide-mark 'directory)))
2405 (setq elided-list (cdr elided-list)))
2406 ;;(message "fname: %s elide-mark: %S" fname elide-mark)
2407 (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark)
2408 (setq st-info (cdr st-info))))
2409 (svn-status-update-buffer))
2411 (defun svn-status-update-with-command-list (cmd-list)
2413 (set-buffer svn-status-buffer-name)
2417 (fname (svn-status-line-info->filename (svn-status-get-line-information)))
2419 (column (current-column)))
2420 (setq cmd-list (sort cmd-list '(lambda (item1 item2) (string-lessp (car item1) (car item2)))))
2422 (unless st-info (setq st-info svn-status-info))
2423 ;;(message "%S" (caar cmd-list))
2425 (while (and (not found) st-info)
2426 (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
2427 ;;(message "found: %S" found)
2428 (unless found (setq st-info (cdr st-info))))
2430 (svn-status-message 3 "psvn: continue to search for %s" (caar cmd-list))
2431 (setq st-info svn-status-info)
2432 (while (and (not found) st-info)
2433 (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
2434 (unless found (setq st-info (cdr st-info)))))
2436 ;;update the info line
2438 (setq action (cadar cmd-list))
2439 ;;(message "found %s, action: %S" (caar cmd-list) action)
2440 (svn-status-annotate-status-buffer-entry action (car st-info)))
2441 (svn-status-message 3 "psvn: did not find %s" (caar cmd-list)))
2442 (setq cmd-list (cdr cmd-list)))
2445 (goto-char fname-pos)
2446 (svn-status-goto-file-name fname)
2447 (goto-char (+ column (svn-point-at-bol))))
2448 (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column))))))
2450 (defun svn-status-annotate-status-buffer-entry (action line-info)
2452 (svn-status-goto-file-name (svn-status-line-info->filename line-info))
2453 (when (and (member action '(committed added))
2454 svn-status-commit-rev-number)
2455 (svn-status-line-info->set-localrev line-info svn-status-commit-rev-number)
2456 (svn-status-line-info->set-lastchangerev line-info svn-status-commit-rev-number))
2457 (when svn-status-last-commit-author
2458 (svn-status-line-info->set-author line-info svn-status-last-commit-author))
2459 (svn-status-line-info->set-psvn-extra-info line-info (list action))
2460 (cond ((equal action 'committed)
2461 (setq tag-string " <committed>")
2462 (when (member (svn-status-line-info->repo-locked line-info) '(?K))
2463 (svn-status-line-info->set-repo-locked line-info nil)))
2464 ((equal action 'added)
2465 (setq tag-string " <added>"))
2466 ((equal action 'deleted)
2467 (setq tag-string " <deleted>"))
2468 ((equal action 'replaced)
2469 (setq tag-string " <replaced>"))
2470 ((equal action 'updated)
2471 (setq tag-string " <updated>"))
2472 ((equal action 'updated-props)
2473 (setq tag-string " <updated-props>"))
2474 ((equal action 'conflicted)
2475 (setq tag-string " <conflicted>")
2476 (svn-status-line-info->set-filemark line-info ?C))
2477 ((equal action 'merged)
2478 (setq tag-string " <merged>"))
2479 ((equal action 'propset)
2480 ;;(setq tag-string " <propset>")
2481 (svn-status-line-info->set-propmark line-info svn-status-file-modified-after-save-flag))
2482 ((equal action 'added-wc)
2483 (svn-status-line-info->set-filemark line-info ?A)
2484 (svn-status-line-info->set-localrev line-info 0))
2485 ((equal action 'deleted-wc)
2486 (svn-status-line-info->set-filemark line-info ?D))
2488 (error "Unknown action '%s for %s" action (svn-status-line-info->filename line-info))))
2489 (when (and tag-string (not (member action '(conflicted merged))))
2490 (svn-status-line-info->set-filemark line-info ? )
2491 (svn-status-line-info->set-propmark line-info ? ))
2492 (let ((buffer-read-only nil))
2493 (delete-region (svn-point-at-bol) (svn-point-at-eol))
2494 (svn-insert-line-in-status-buffer line-info)
2497 (insert tag-string))
2502 ;; (svn-status-update-with-command-list '(("++ideas" committed) ("a.txt" committed) ("alf")))
2503 ;; (svn-status-update-with-command-list (svn-status-parse-commit-output))
2505 (defun svn-status-parse-commit-output ()
2506 "Parse the output of svn commit.
2507 Return a list that is suitable for `svn-status-update-with-command-list'"
2509 (set-buffer svn-process-buffer-name)
2514 (goto-char (point-min))
2515 (setq svn-status-commit-rev-number nil)
2516 (setq skip nil) ; set to t whenever we find a line not about a committed file
2517 (while (< (point) (point-max))
2518 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2520 ((looking-at "Sending")
2521 (setq action 'committed))
2522 ((looking-at "Adding")
2523 (setq action 'added))
2524 ((looking-at "Deleting")
2525 (setq action 'deleted))
2526 ((looking-at "Replacing")
2527 (setq action 'replaced))
2528 ((looking-at "Transmitting file data")
2530 ((looking-at "Committed revision \\([0-9]+\\)")
2531 (setq svn-status-commit-rev-number
2532 (string-to-number (svn-match-string-no-properties 1)))
2534 (t ;; this should never be needed(?)
2535 (setq action 'unknown)))
2536 (unless skip ;found an interesting line
2538 (when svn-status-operated-on-dot
2539 ;; when the commit used . as argument, delete the trailing directory
2540 ;; from the svn output
2541 (search-forward "/" nil t))
2542 (setq file-name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2543 (unless svn-status-last-commit-author
2544 (setq svn-status-last-commit-author (car (svn-status-info-for-path (expand-file-name (concat default-directory file-name))))))
2545 (setq result (cons (list file-name action)
2550 ;;(svn-status-parse-commit-output)
2551 ;;(svn-status-annotate-status-buffer-entry)
2553 (defun svn-status-parse-ar-output ()
2554 "Parse the output of svn add|remove.
2555 Return a list that is suitable for `svn-status-update-with-command-list'"
2557 (set-buffer svn-process-buffer-name)
2562 (goto-char (point-min))
2563 (while (< (point) (point-max))
2564 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2567 (setq action 'added-wc))
2569 (setq action 'deleted-wc))
2570 (t ;; this should never be needed(?)
2571 (setq action 'unknown)))
2572 (unless skip ;found an interesting line
2574 (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2575 (setq result (cons (list name action)
2580 ;; (svn-status-parse-ar-output)
2581 ;; (svn-status-update-with-command-list (svn-status-parse-ar-output))
2583 (defun svn-status-parse-update-output ()
2584 "Parse the output of svn update.
2585 Return a list that is suitable for `svn-status-update-with-command-list'"
2587 (set-buffer svn-process-buffer-name)
2588 (setq svn-status-update-rev-number nil)
2593 (goto-char (point-min))
2594 (while (< (point) (point-max))
2595 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2597 ((looking-at "Updated to revision \\([0-9]+\\)")
2598 (setq svn-status-update-rev-number
2599 (list t (string-to-number (svn-match-string-no-properties 1))))
2601 ((looking-at "At revision \\([0-9]+\\)")
2602 (setq svn-status-update-rev-number
2603 (list nil (string-to-number (svn-match-string-no-properties 1))))
2606 (setq action 'updated))
2608 (setq action 'added))
2611 ;;(setq action 'deleted)) ;;deleted files are not displayed in the svn status output.
2613 (setq action 'conflicted))
2615 (setq action 'merged))
2618 (setq action 'updated-props))
2620 (t ;; this should never be needed(?)
2621 (setq action (concat "parse-update: '"
2622 (buffer-substring-no-properties (point) (+ 2 (point))) "'"))))
2623 (unless skip ;found an interesting line
2625 (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2626 (setq result (cons (list name action)
2631 ;; (svn-status-parse-update-output)
2632 ;; (svn-status-update-with-command-list (svn-status-parse-update-output))
2634 (defun svn-status-parse-property-output ()
2635 "Parse the output of svn propset.
2636 Return a list that is suitable for `svn-status-update-with-command-list'"
2638 (set-buffer svn-process-buffer-name)
2640 (dolist (line (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n"))
2642 (when (string-match "property '\\(.+\\)' set on '\\(.+\\)'" line)
2643 ;;(message "property %s - file %s" (match-string 1 line) (match-string 2 line))
2644 (setq result (cons (list (match-string 2 line) 'propset) result))))
2647 ;; (svn-status-parse-property-output)
2648 ;; (svn-status-update-with-command-list (svn-status-parse-property-output))
2651 (defun svn-status-line-info->symlink-p (line-info)
2652 "Return non-nil if LINE-INFO refers to a symlink, nil otherwise.
2653 The value is the name of the file to which it is linked. \(See
2656 On win32 systems this won't work, even though symlinks are supported
2657 by subversion on such systems."
2658 ;; on win32 would need to see how svn does symlinks
2659 (file-symlink-p (svn-status-line-info->filename line-info)))
2661 (defun svn-status-line-info->directory-p (line-info)
2662 "Return t if LINE-INFO refers to a directory, nil otherwise.
2663 Symbolic links to directories count as directories (see `file-directory-p')."
2664 (file-directory-p (svn-status-line-info->filename line-info)))
2666 (defun svn-status-line-info->full-path (line-info)
2667 "Return the full path of the file represented by LINE-INFO."
2669 (svn-status-line-info->filename line-info)))
2671 ;;Not convinced that this is the fastest way, but...
2672 (defun svn-status-count-/ (string)
2673 "Return number of \"/\"'s in STRING."
2676 (while (setq last (string-match "/" string (1+ last)))
2680 (defun svn-insert-line-in-status-buffer (line-info)
2681 "Format LINE-INFO and insert the result in the current buffer."
2682 (let ((usermark (if (svn-status-line-info->has-usermark line-info) "*" " "))
2683 (update-available (if (svn-status-line-info->update-available line-info)
2684 (svn-add-face (if svn-status-short-mod-flag-p
2686 " (Update Available)")
2687 'svn-status-update-available-face)
2688 (if svn-status-short-mod-flag-p " " "")))
2689 (filename ;; <indentation>file or /path/to/file
2691 (if (or svn-status-display-full-path
2692 svn-status-hide-unmodified)
2694 (let ((dir-name (file-name-as-directory
2695 (svn-status-line-info->directory-containing-line-info
2697 (if (and (<= 2 (length dir-name))
2698 (= ?. (aref dir-name 0))
2699 (= ?/ (aref dir-name 1)))
2700 (substring dir-name 2)
2702 'svn-status-directory-face)
2703 ;; showing all files, so add indentation
2704 (make-string (* 2 (svn-status-count-/
2705 (svn-status-line-info->filename line-info)))
2707 ;;symlinks get a different face
2708 (let ((target (svn-status-line-info->symlink-p line-info)))
2711 ;; name gets symlink-face, target gets file/directory face
2713 (svn-add-face (svn-status-line-info->filename-nondirectory line-info)
2714 'svn-status-symlink-face)
2716 (svn-status-choose-face-to-add
2717 ;; TODO: could use different faces for
2718 ;; unversioned targets and broken symlinks?
2719 (svn-status-line-info->directory-p line-info)
2721 'svn-status-directory-face
2722 'svn-status-filename-face))
2723 ;; else target is not a link
2724 (svn-status-choose-face-to-add
2725 (svn-status-line-info->directory-p line-info)
2726 (svn-status-line-info->filename-nondirectory line-info)
2727 'svn-status-directory-face
2728 'svn-status-filename-face)))
2730 (elide-hint (if (svn-status-line-info->show-user-elide-continuation line-info) " ..." "")))
2731 (svn-puthash (svn-status-line-info->filename line-info)
2733 svn-status-filename-to-buffer-position-cache)
2734 (insert (svn-status-maybe-add-face
2735 (svn-status-line-info->has-usermark line-info)
2737 (format svn-status-line-format
2738 (svn-status-line-info->filemark line-info)
2739 (or (svn-status-line-info->propmark line-info) ? )
2740 (or (svn-status-line-info->historymark line-info) ? )
2741 (or (svn-status-line-info->localrev line-info) "")
2742 (or (svn-status-line-info->lastchangerev line-info) "")
2743 (svn-status-line-info->author line-info))
2744 (when svn-status-short-mod-flag-p update-available)
2746 (unless svn-status-short-mod-flag-p update-available)
2747 (svn-status-maybe-add-string (svn-status-line-info->locked line-info)
2748 " [ LOCKED ]" 'svn-status-locked-face)
2749 (svn-status-maybe-add-string (svn-status-line-info->repo-locked line-info)
2750 (let ((flag (svn-status-line-info->repo-locked line-info)))
2751 (cond ((eq flag ?K) " [ REPO-LOCK-HERE ]")
2752 ((eq flag ?O) " [ REPO-LOCK-OTHER ]")
2753 ((eq flag ?T) " [ REPO-LOCK-STOLEN ]")
2754 ((eq flag ?B) " [ REPO-LOCK-BROKEN ]")
2755 (t " [ REPO-LOCK-UNKNOWN ]")))
2756 'svn-status-locked-face)
2757 (svn-status-maybe-add-string (svn-status-line-info->switched line-info)
2758 " (switched)" 'svn-status-switched-face)
2760 'svn-status-marked-face)
2763 (defun svn-status-redraw-status-buffer ()
2764 "Redraw the `svn-status-buffer-name' buffer.
2765 Additionally clear the psvn-extra-info field in all line-info lists."
2767 (dolist (line-info svn-status-info)
2768 (svn-status-line-info->set-psvn-extra-info line-info nil))
2769 (svn-status-update-buffer))
2771 (defun svn-status-update-buffer ()
2772 "Update the `svn-status-buffer-name' buffer, using `svn-status-info'.
2773 This function does not access the repository."
2775 ;(message "buffer-name: %s" (buffer-name))
2776 (unless (string= (buffer-name) svn-status-buffer-name)
2777 (set-buffer svn-status-buffer-name))
2779 (when svn-status-refresh-info
2780 (when (eq svn-status-refresh-info 'once)
2781 (setq svn-status-refresh-info nil))
2782 (svn-status-parse-info t))
2783 (let ((st-info svn-status-info)
2784 (buffer-read-only nil)
2787 (unmodified-count 0) ;how many unmodified files are hidden
2788 (unknown-count 0) ;how many unknown files are hidden
2789 (custom-hide-count 0) ;how many files are hidden via svn-status-custom-hide-function
2790 (marked-count 0) ;how many files are elided
2791 (user-elide-count 0)
2793 (fname (svn-status-line-info->filename (svn-status-get-line-information)))
2795 (window-line-pos (svn-status-window-line-position (get-buffer-window (current-buffer))))
2796 (header-line-string)
2797 (column (current-column)))
2798 (delete-region (point-min) (point-max))
2800 ;; Insert all files and directories
2802 (setq start-pos (point))
2803 (cond ((or (svn-status-line-info->has-usermark (car st-info)) first-line)
2804 ;; Show a marked file and the "." always
2805 (svn-insert-line-in-status-buffer (car st-info))
2806 (setq first-line nil))
2807 ((svn-status-line-info->update-available (car st-info))
2808 (svn-insert-line-in-status-buffer (car st-info)))
2809 ((and svn-status-custom-hide-function
2810 (apply svn-status-custom-hide-function (list (car st-info))))
2811 (setq custom-hide-count (1+ custom-hide-count)))
2812 ((svn-status-line-info->hide-because-user-elide (car st-info))
2813 (setq user-elide-count (1+ user-elide-count)))
2814 ((svn-status-line-info->hide-because-unknown (car st-info))
2815 (setq unknown-count (1+ unknown-count)))
2816 ((svn-status-line-info->hide-because-unmodified (car st-info))
2817 (setq unmodified-count (1+ unmodified-count)))
2819 (svn-insert-line-in-status-buffer (car st-info))))
2820 (when (svn-status-line-info->has-usermark (car st-info))
2821 (setq marked-count (+ marked-count 1)))
2822 (setq overlay (make-overlay start-pos (point)))
2823 (overlay-put overlay 'svn-info (car st-info))
2824 (setq st-info (cdr st-info)))
2825 ;; Insert status information at the buffer beginning
2826 (goto-char (point-min))
2827 (insert (format "svn status for directory %s%s\n"
2829 (if svn-status-head-revision (format " (status against revision: %s)"
2830 svn-status-head-revision)
2832 (when svn-status-module-name
2833 (insert (format "Project name: %s\n" svn-status-module-name)))
2834 (when svn-status-branch-list
2835 (insert (format "Branches: %s\n" svn-status-branch-list)))
2836 (when svn-status-base-info
2837 (insert (concat "Repository Root: " (svn-status-base-info->repository-root) "\n"))
2838 (insert (concat "Repository Url: " (svn-status-base-info->url) "\n")))
2839 (when svn-status-hide-unknown
2841 (format "%d Unknown file(s) are hidden - press `?' to toggle hiding\n"
2843 (when svn-status-hide-unmodified
2845 (format "%d Unmodified file(s) are hidden - press `_' to toggle hiding\n"
2847 (when (> custom-hide-count 0)
2849 (format "%d file(s) are hidden via the svn-status-custom-hide-function\n"
2850 custom-hide-count)))
2851 (when (> user-elide-count 0)
2852 (insert (format "%d file(s) elided\n" user-elide-count)))
2853 (insert (format "%d file(s) marked\n" marked-count))
2854 (setq header-line-string (concat (format svn-status-line-format
2855 70 80 72 "BASE" "CMTD" "Author")
2856 (if svn-status-short-mod-flag-p "em " "")
2858 (cond ((eq svn-status-use-header-line t)
2859 (setq header-line-format (concat " " header-line-string)))
2860 ((eq svn-status-use-header-line 'inline)
2861 (insert "\n " header-line-string "\n")))
2862 (setq svn-start-of-file-list-line-number (+ (count-lines (point-min) (point)) 1))
2865 (goto-char fname-pos)
2866 (svn-status-goto-file-name fname)
2867 (goto-char (+ column (svn-point-at-bol)))
2868 (when window-line-pos
2869 (recenter window-line-pos)))
2870 (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column)))))
2872 (defun svn-status-parse-info (arg)
2873 "Parse the svn info output for the base directory.
2874 Show the repository url after this call in the `svn-status-buffer-name' buffer.
2875 When called with the prefix argument 0, reset the information to nil.
2876 This hides the repository information again.
2878 When ARG is t, don't update the svn status buffer. This is useful for
2879 non-interactive use."
2882 (setq svn-status-base-info nil)
2883 (let ((svn-process-buffer-name "*svn-info-output*"))
2884 (when (get-buffer svn-process-buffer-name)
2885 (kill-buffer svn-process-buffer-name))
2886 (svn-run nil t 'parse-info "info" ".")
2887 (svn-status-parse-info-result)))
2889 (svn-status-update-buffer)))
2891 (defun svn-status-parse-info-result ()
2892 "Parse the result from the svn info command.
2893 Put the found values in `svn-status-base-info'."
2896 (last-changed-author))
2898 (set-buffer svn-process-buffer-name)
2899 (goto-char (point-min))
2900 (let ((case-fold-search t))
2901 (search-forward "url: ")
2902 (setq url (buffer-substring-no-properties (point) (svn-point-at-eol)))
2903 (when (search-forward "repository root: " nil t)
2904 (setq repository-root (buffer-substring-no-properties (point) (svn-point-at-eol))))
2905 (when (search-forward "last changed author: " nil t)
2906 (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol))))))
2907 (setq svn-status-base-info `((url ,url) (repository-root ,repository-root) (last-changed-author ,last-changed-author)))))
2909 (defun svn-status-base-info->url ()
2910 "Extract the url part from `svn-status-base-info'."
2911 (if svn-status-base-info
2912 (cadr (assoc 'url svn-status-base-info))
2915 (defun svn-status-base-info->repository-root ()
2916 "Extract the repository-root part from `svn-status-base-info'."
2917 (if svn-status-base-info
2918 (cadr (assoc 'repository-root svn-status-base-info))
2921 (defun svn-status-checkout-prefix-path ()
2922 "When only a part of the svn repository is checked out, return the file path for this checkout."
2924 (svn-status-parse-info t)
2925 (let ((root (svn-status-base-info->repository-root))
2926 (url (svn-status-base-info->url))
2928 (base-dir (svn-status-base-dir))
2929 (wc-checkout-prefix))
2930 (setq p (substring url (length root)))
2931 (setq wc-checkout-prefix (file-relative-name default-directory base-dir))
2932 (when (string= wc-checkout-prefix "./")
2933 (setq wc-checkout-prefix ""))
2934 ;; (message "svn-status-checkout-prefix-path: wc-checkout-prefix: '%s' p: '%s' base-dir: %s" wc-checkout-prefix p base-dir)
2935 (setq p (substring p 0 (- (length p) (length wc-checkout-prefix))))
2936 (when (interactive-p)
2937 (message "svn-status-checkout-prefix-path: '%s'" p))
2940 (defun svn-status-ls (path &optional synchron)
2942 (interactive "sPath for svn ls: ")
2943 (svn-run (not synchron) t 'ls "ls" path)
2945 (split-string (with-current-buffer svn-process-buffer-name
2946 (buffer-substring-no-properties (point-min) (point-max))))))
2948 (defun svn-status-ls-branches ()
2949 "Show, which branches exist for the actual working copy.
2950 Note: this command assumes the proposed standard svn repository layout."
2952 (svn-status-parse-info t)
2953 (svn-status-ls (concat (svn-status-base-info->repository-root) "/branches")))
2955 (defun svn-status-ls-tags ()
2956 "Show, which tags exist for the actual working copy.
2957 Note: this command assumes the proposed standard svn repository layout."
2959 (svn-status-parse-info t)
2960 (svn-status-ls (concat (svn-status-base-info->repository-root) "/tags")))
2962 (defun svn-status-toggle-edit-cmd-flag (&optional reset)
2963 "Allow the user to edit the parameters for the next svn command.
2964 This command toggles between
2965 * editing the next command parameters (EditCmd)
2966 * editing all all command parameters (EditCmd#)
2967 * don't edit the command parameters ()
2968 The string in parentheses is shown in the status line to show the state."
2970 (cond ((or reset (eq svn-status-edit-svn-command 'sticky))
2971 (setq svn-status-edit-svn-command nil))
2972 ((eq svn-status-edit-svn-command nil)
2973 (setq svn-status-edit-svn-command t))
2974 ((eq svn-status-edit-svn-command t)
2975 (setq svn-status-edit-svn-command 'sticky)))
2976 (cond ((eq svn-status-edit-svn-command t)
2977 (setq svn-status-mode-line-process-edit-flag " EditCmd"))
2978 ((eq svn-status-edit-svn-command 'sticky)
2979 (setq svn-status-mode-line-process-edit-flag " EditCmd#"))
2981 (setq svn-status-mode-line-process-edit-flag "")))
2982 (svn-status-update-mode-line))
2984 (defun svn-status-goto-root-or-return ()
2985 "Bounce point between the root (\".\") and the current line."
2987 (if (string= (svn-status-line-info->filename (svn-status-get-line-information)) ".")
2988 (when svn-status-root-return-info
2989 (svn-status-goto-file-name
2990 (svn-status-line-info->filename svn-status-root-return-info)))
2991 (setq svn-status-root-return-info (svn-status-get-line-information))
2992 (svn-status-goto-file-name ".")))
2994 (defun svn-status-next-line (nr-of-lines)
2995 "Go to the next line that holds a file information.
2996 When called with a prefix argument advance the given number of lines."
2999 (forward-line nr-of-lines)
3001 (not (svn-status-get-line-information)))))
3002 (when (svn-status-get-line-information)
3003 (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
3005 (defun svn-status-previous-line (nr-of-lines)
3006 "Go to the previous line that holds a file information.
3007 When called with a prefix argument go back the given number of lines."
3010 (forward-line (- nr-of-lines))
3012 (not (svn-status-get-line-information)))))
3013 (when (svn-status-get-line-information)
3014 (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
3016 (defun svn-status-dired-jump ()
3017 "Jump to a dired buffer, containing the file at point."
3019 (let* ((line-info (svn-status-get-line-information))
3020 (file-full-path (svn-status-line-info->full-path line-info)))
3021 (let ((default-directory
3022 (file-name-as-directory
3023 (expand-file-name (svn-status-line-info->directory-containing-line-info line-info t)))))
3024 (if (fboundp 'dired-jump-back) (dired-jump-back) (dired-jump))) ;; Xemacs uses dired-jump-back
3025 (dired-goto-file file-full-path)))
3027 (defun svn-status-possibly-negate-meaning-of-arg (arg &optional command)
3028 "Negate arg, if this-command is a member of svn-status-possibly-negate-meaning-of-arg."
3030 (setq command this-command))
3031 (if (member command svn-status-negate-meaning-of-arg-commands)
3035 (defun svn-status-update (&optional arg)
3036 "Run 'svn status -v'.
3037 When called with a prefix argument run 'svn status -vu'."
3039 (unless (interactive-p)
3041 (set-buffer svn-process-buffer-name)
3042 (setq svn-status-update-previous-process-output
3043 (buffer-substring (point-min) (point-max)))))
3044 (svn-status default-directory arg))
3046 (defun svn-status-get-line-information ()
3047 "Find out about the file under point.
3048 The result may be parsed with the various `svn-status-line-info->...' functions."
3049 (if (eq major-mode 'svn-status-mode)
3050 (let ((svn-info nil))
3051 (dolist (overlay (overlays-at (point)))
3052 (setq svn-info (or svn-info
3053 (overlay-get overlay 'svn-info))))
3055 ;; different mode, means called not from the *svn-status* buffer
3056 (if svn-status-get-line-information-for-file
3057 (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
3058 (file-relative-name (buffer-file-name) (svn-status-base-dir))
3059 (buffer-file-name)))
3060 (svn-status-make-line-info "."))))
3063 (defun svn-status-get-file-list (use-marked-files)
3064 "Get either the selected files or the file under point.
3065 USE-MARKED-FILES decides which we do.
3066 See `svn-status-marked-files' for what counts as selected."
3067 (if use-marked-files
3068 (svn-status-marked-files)
3069 (list (svn-status-get-line-information))))
3071 (defun svn-status-get-file-list-names (use-marked-files)
3072 (mapcar 'svn-status-line-info->filename (svn-status-get-file-list use-marked-files)))
3074 (defun svn-status-get-file-information ()
3075 "Find out about the file under point.
3076 The result may be parsed with the various `svn-status-line-info->...' functions.
3077 When called from a *svn-status* buffer, do the same as `svn-status-get-line-information'.
3078 When called from a file buffer provide a structure that contains the filename."
3079 (cond ((eq major-mode 'svn-status-mode)
3080 (svn-status-get-line-information))
3082 ;; a fake strukture that contains the buffername for the current buffer
3083 (svn-status-make-line-info (buffer-file-name (current-buffer))))))
3085 (defun svn-status-select-line ()
3086 "Return information about the file under point.
3087 \(Only used for debugging\)"
3089 (let ((info (svn-status-get-line-information)))
3091 (message "%S hide-because-unknown: %S hide-because-unmodified: %S" info
3092 (svn-status-line-info->hide-because-unknown info)
3093 (svn-status-line-info->hide-because-unmodified info))
3094 (message "No file on this line"))))
3096 (defun svn-status-ensure-cursor-on-file ()
3097 "Raise an error unless point is on a valid file."
3098 (unless (svn-status-get-line-information)
3099 (error "No file on the current line")))
3101 (defun svn-status-directory-containing-point (allow-self)
3102 "Find the (full path of) directory containing the file under point.
3104 If ALLOW-SELF and the file is a directory, return that directory,
3105 otherwise return the directory containing the file under point."
3106 ;;the first `or' below is because s-s-g-l-i returns `nil' if
3107 ;;point was outside the file list, but we need
3108 ;;s-s-l-i->f to return a string to add to `default-directory'.
3109 (let ((line-info (or (svn-status-get-line-information)
3110 (svn-status-make-line-info))))
3111 (file-name-as-directory
3113 (svn-status-line-info->directory-containing-line-info line-info allow-self)))))
3115 (defun svn-status-line-info->directory-containing-line-info (line-info allow-self)
3116 "Find the directory containing for LINE-INFO.
3118 If ALLOW-SELF is t and LINE-INFO refers to a directory then return the
3119 directory itself, in all other cases find the parent directory"
3120 (if (and allow-self (svn-status-line-info->directory-p line-info))
3121 (svn-status-line-info->filename line-info)
3122 ;;The next `or' is because (file-name-directory "file") returns nil
3123 (or (file-name-directory (svn-status-line-info->filename line-info))
3126 (defun svn-status-set-user-mark (arg)
3127 "Set a user mark on the current file or directory.
3128 If the cursor is on a file this file is marked and the cursor advances to the next line.
3129 If the cursor is on a directory all files in this directory are marked.
3131 If this function is called with a prefix argument, only the current line is
3132 marked, even if it is a directory."
3134 (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
3135 (let ((info (svn-status-get-line-information)))
3138 (svn-status-apply-usermark t arg)
3139 (svn-status-next-line 1))
3140 (message "No file on this line - cannot set a mark"))))
3142 (defun svn-status-unset-user-mark (arg)
3143 "Remove a user mark on the current file or directory.
3144 If the cursor is on a file, this file is unmarked and the cursor advances to the next line.
3145 If the cursor is on a directory, all files in this directory are unmarked.
3147 If this function is called with a prefix argument, only the current line is
3148 unmarked, even if is a directory."
3150 (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
3151 (let ((info (svn-status-get-line-information)))
3154 (svn-status-apply-usermark nil arg)
3155 (svn-status-next-line 1))
3156 (message "No file on this line - cannot unset a mark"))))
3158 (defun svn-status-unset-user-mark-backwards ()
3159 "Remove a user mark from the previous file.
3160 Then move to that line."
3161 ;; This is consistent with `dired-unmark-backward' and
3162 ;; `cvs-mode-unmark-up'.
3164 (let ((info (save-excursion
3165 (svn-status-next-line -1)
3166 (svn-status-get-line-information))))
3169 (svn-status-next-line -1)
3170 (svn-status-apply-usermark nil t))
3171 (message "No file on previous line - cannot unset a mark"))))
3173 (defun svn-status-apply-usermark (set-mark only-this-line)
3174 "Do the work for the various marking/unmarking functions."
3175 (let* ((st-info svn-status-info)
3177 (line-info (svn-status-get-line-information))
3178 (file-name (svn-status-line-info->filename line-info))
3179 (sub-file-regexp (if (file-directory-p file-name)
3180 (concat "^" (regexp-quote
3181 (file-name-as-directory file-name)))
3183 (newcursorpos-fname)
3186 (current-line svn-start-of-file-list-line-number))
3188 (when (or (svn-status-line-info->is-visiblep (car st-info)) first-line)
3189 (setq current-line (1+ current-line))
3190 (setq first-line nil))
3191 (setq i-fname (svn-status-line-info->filename (car st-info)))
3192 (when (or (string= file-name i-fname)
3193 (when sub-file-regexp
3194 (string-match sub-file-regexp i-fname)))
3195 (when (svn-status-line-info->is-visiblep (car st-info))
3196 (when (or (not only-this-line) (string= file-name i-fname))
3197 (setq newcursorpos-fname i-fname)
3198 (unless (eq (car (svn-status-line-info->ui-status (car st-info))) set-mark)
3199 (setcar (svn-status-line-info->ui-status (car st-info)) set-mark)
3200 (setq mark-count (+ 1 mark-count))
3202 (let ((buffer-read-only nil))
3203 (goto-line current-line)
3204 (delete-region (svn-point-at-bol) (svn-point-at-eol))
3205 (svn-insert-line-in-status-buffer (car st-info))
3207 (message "%s %s" (if set-mark "Marked" "Unmarked") i-fname)))))
3208 (setq st-info (cdr st-info)))
3209 ;;(svn-status-update-buffer)
3210 (svn-status-goto-file-name newcursorpos-fname)
3211 (when (> mark-count 1)
3212 (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
3214 (defun svn-status-apply-usermark-checked (check-function set-mark)
3215 "Mark or unmark files, whether a given function returns t.
3216 The function is called with the line information. Therefore the
3217 svn-status-line-info->* functions can be used in the check."
3218 (let ((st-info svn-status-info)
3221 (when (apply check-function (list (car st-info)))
3222 (unless (eq (svn-status-line-info->has-usermark (car st-info)) set-mark)
3223 (setq mark-count (+ 1 mark-count))
3225 (if set-mark "Marked" "Unmarked")
3226 (svn-status-line-info->filename (car st-info))))
3227 (setcar (svn-status-line-info->ui-status (car st-info)) set-mark))
3228 (setq st-info (cdr st-info)))
3229 (svn-status-update-buffer)
3230 (when (> mark-count 1)
3231 (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
3233 (defun svn-status-mark-unknown (arg)
3234 "Mark all unknown files.
3235 These are the files marked with '?' in the `svn-status-buffer-name' buffer.
3236 If the function is called with a prefix arg, unmark all these files."
3238 (svn-status-apply-usermark-checked
3239 '(lambda (info) (eq (svn-status-line-info->filemark info) ??)) (not arg)))
3241 (defun svn-status-mark-added (arg)
3242 "Mark all added files.
3243 These are the files marked with 'A' in the `svn-status-buffer-name' buffer.
3244 If the function is called with a prefix ARG, unmark all these files."
3246 (svn-status-apply-usermark-checked
3247 '(lambda (info) (eq (svn-status-line-info->filemark info) ?A)) (not arg)))
3249 (defun svn-status-mark-modified (arg)
3250 "Mark all modified files.
3251 These are the files marked with 'M' in the `svn-status-buffer-name' buffer.
3252 If the function is called with a prefix ARG, unmark all these files."
3254 (svn-status-apply-usermark-checked
3255 '(lambda (info) (or (eq (svn-status-line-info->filemark info) ?M)
3256 (eq (svn-status-line-info->filemark info)
3257 svn-status-file-modified-after-save-flag)))
3260 (defun svn-status-mark-deleted (arg)
3261 "Mark all files scheduled for deletion.
3262 These are the files marked with 'D' in the `svn-status-buffer-name' buffer.
3263 If the function is called with a prefix ARG, unmark all these files."
3265 (svn-status-apply-usermark-checked
3266 '(lambda (info) (eq (svn-status-line-info->filemark info) ?D)) (not arg)))
3268 (defun svn-status-mark-changed (arg)
3269 "Mark all files that could be committed.
3271 * all modified files
3272 * all files scheduled for addition
3273 * all files scheduled for deletion
3275 The last two categories include all copied and moved files.
3276 If called with a prefix ARG, unmark all such files."
3278 (svn-status-mark-added arg)
3279 (svn-status-mark-modified arg)
3280 (svn-status-mark-deleted arg))
3282 (defun svn-status-unset-all-usermarks ()
3284 (svn-status-apply-usermark-checked '(lambda (info) t) nil))
3286 (defvar svn-status-regexp-history nil
3287 "History list of regular expressions used in svn status commands.")
3289 (defun svn-status-read-regexp (prompt)
3290 (read-from-minibuffer prompt nil nil nil 'svn-status-regexp-history))
3292 (defun svn-status-mark-filename-regexp (regexp &optional unmark)
3293 "Mark all files matching REGEXP.
3294 If the function is called with a prefix arg, unmark all these files."
3296 (list (svn-status-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3297 " files (regexp): "))
3298 (if current-prefix-arg t nil)))
3299 (svn-status-apply-usermark-checked
3300 '(lambda (info) (string-match regexp (svn-status-line-info->filename-nondirectory info))) (not unmark)))
3302 (defun svn-status-mark-by-file-ext (ext &optional unmark)
3303 "Mark all files matching the given file extension EXT.
3304 If the function is called with a prefix arg, unmark all these files."
3306 (list (read-string (concat (if current-prefix-arg "Unmark" "Mark")
3307 " files with extensions: "))
3308 (if current-prefix-arg t nil)))
3309 (svn-status-apply-usermark-checked
3310 '(lambda (info) (let ((case-fold-search nil))
3311 (string-match (concat "\\." ext "$") (svn-status-line-info->filename-nondirectory info)))) (not unmark)))
3313 (defun svn-status-toggle-hide-unknown ()
3315 (setq svn-status-hide-unknown (not svn-status-hide-unknown))
3316 (svn-status-update-buffer))
3318 (defun svn-status-toggle-hide-unmodified ()
3320 (setq svn-status-hide-unmodified (not svn-status-hide-unmodified))
3321 (svn-status-update-buffer))
3323 (defun svn-status-get-file-name-buffer-position (name)
3324 "Find the buffer position for a file.
3325 If the file is not found, return nil."
3326 (let ((start-pos (let ((cached-pos (gethash name
3327 svn-status-filename-to-buffer-position-cache)))
3329 (goto-char (previous-overlay-change cached-pos)))
3332 ;; performance optimization: search from point to end of buffer
3333 (while (and (not found) (< (point) (point-max)))
3334 (goto-char (next-overlay-change (point)))
3335 (when (string= name (svn-status-line-info->filename
3336 (svn-status-get-line-information)))
3337 (setq start-pos (+ (point) svn-status-default-column))
3339 ;; search from buffer start to point
3340 (goto-char (point-min))
3341 (while (and (not found) (< (point) start-pos))
3342 (goto-char (next-overlay-change (point)))
3343 (when (string= name (svn-status-line-info->filename
3344 (svn-status-get-line-information)))
3345 (setq start-pos (+ (point) svn-status-default-column))
3347 (and found start-pos)))
3349 (defun svn-status-goto-file-name (name)
3350 "Move the cursor the the line that displays NAME."
3351 (let ((pos (svn-status-get-file-name-buffer-position name)))
3354 (svn-status-message 7 "Note: svn-status-goto-file-name: %s not found" name))))
3356 (defun svn-status-find-info-for-file-name (name)
3357 (let* ((st-info svn-status-info)
3360 (when (string= name (svn-status-line-info->filename (car st-info)))
3361 (setq info (car st-info))
3362 (setq st-info nil)) ; terminate loop
3363 (setq st-info (cdr st-info)))
3366 (defun svn-status-marked-files ()
3367 "Return all files marked by `svn-status-set-user-mark',
3368 or (if no files were marked) the file under point."
3369 (if (eq major-mode 'svn-status-mode)
3370 (let* ((st-info svn-status-info)
3373 (when (svn-status-line-info->has-usermark (car st-info))
3374 (setq file-list (append file-list (list (car st-info)))))
3375 (setq st-info (cdr st-info)))
3377 (if (svn-status-get-line-information)
3378 (list (svn-status-get-line-information))
3380 ;; different mode, means called not from the *svn-status* buffer
3381 (if svn-status-get-line-information-for-file
3382 (list (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
3383 (file-relative-name (buffer-file-name) (svn-status-base-dir))
3384 (buffer-file-name))))
3385 (list (svn-status-make-line-info ".")))))
3387 (defun svn-status-marked-file-names ()
3388 (mapcar 'svn-status-line-info->filename (svn-status-marked-files)))
3390 (defun svn-status-some-files-marked-p ()
3391 "Return non-nil iff a file has been marked by `svn-status-set-user-mark'.
3392 Unlike `svn-status-marked-files', this does not select the file under point
3393 if no files have been marked."
3394 ;; `some' would be shorter but requires cl-seq at runtime.
3395 ;; (Because it accepts both lists and vectors, it is difficult to inline.)
3396 (loop for line-info in svn-status-info
3397 thereis (svn-status-line-info->has-usermark line-info)))
3399 (defun svn-status-only-dirs-or-nothing-marked-p ()
3400 "Return non-nil iff only dirs has been marked by `svn-status-set-user-mark'."
3401 ;; `some' would be shorter but requires cl-seq at runtime.
3402 ;; (Because it accepts both lists and vectors, it is difficult to inline.)
3403 (loop for line-info in svn-status-info
3404 thereis (and (not (svn-status-line-info->directory-p line-info))
3405 (svn-status-line-info->has-usermark line-info))))
3407 (defun svn-status-ui-information-hash-table ()
3408 (let ((st-info svn-status-info)
3409 (svn-status-ui-information (make-hash-table :test 'equal)))
3411 (svn-puthash (svn-status-line-info->filename (car st-info))
3412 (svn-status-line-info->ui-status (car st-info))
3413 svn-status-ui-information)
3414 (setq st-info (cdr st-info)))
3415 svn-status-ui-information))
3418 (defun svn-status-create-arg-file (file-name prefix file-info-list postfix)
3419 (with-temp-file file-name
3421 (let ((st-info file-info-list))
3423 (insert (svn-status-line-info->filename (car st-info)))
3425 (setq st-info (cdr st-info)))
3429 (defun svn-status-show-process-buffer-internal (&optional scroll-to-top)
3430 (let ((cur-buff (current-buffer)))
3431 (unless svn-status-preserve-window-configuration
3432 (when (string= (buffer-name) svn-status-buffer-name)
3433 (delete-other-windows)))
3434 (pop-to-buffer svn-process-buffer-name)
3437 (goto-char (point-min)))
3438 (pop-to-buffer cur-buff)))
3440 (defun svn-status-show-process-output (cmd &optional scroll-to-top)
3441 "Display the result of a svn command.
3442 Consider svn-status-window-alist to choose the buffer name."
3443 (let ((window-mode (cadr (assoc cmd svn-status-window-alist)))
3444 (process-default-directory))
3445 (cond ((eq window-mode nil) ;; use *svn-process* buffer
3446 (setq svn-status-last-output-buffer-name svn-process-buffer-name))
3447 ((eq window-mode t) ;; use *svn-info* buffer
3448 (setq svn-status-last-output-buffer-name "*svn-info*"))
3449 ((eq window-mode 'invisible) ;; don't display the buffer
3450 (setq svn-status-last-output-buffer-name nil))
3452 (setq svn-status-last-output-buffer-name window-mode)))
3453 (when svn-status-last-output-buffer-name
3456 (unless svn-status-preserve-window-configuration
3457 (when (string= (buffer-name) svn-status-buffer-name)
3458 (delete-other-windows)))
3459 (pop-to-buffer svn-process-buffer-name)
3460 (setq process-default-directory default-directory)
3461 (switch-to-buffer (get-buffer-create svn-status-last-output-buffer-name))
3462 (setq default-directory process-default-directory)
3463 (let ((buffer-read-only nil))
3464 (delete-region (point-min) (point-max))
3465 (insert-buffer-substring svn-process-buffer-name)
3467 (goto-char (point-min))))
3468 (when (eq window-mode t) ;; *svn-info* buffer
3471 (svn-status-show-process-buffer-internal scroll-to-top)))))
3473 (defun svn-status-svn-log-switches (arg)
3474 (cond ((eq arg 0) '())
3475 ((or (eq arg -1) (eq arg '-)) '("-q"))
3477 (t svn-status-default-log-arguments)))
3479 (defun svn-status-show-svn-log (arg)
3480 "Run `svn log' on selected files.
3481 The output is put into the *svn-log* buffer
3482 The optional prefix argument ARG determines which switches are passed to `svn log':
3483 no prefix --- use whatever is in the list `svn-status-default-log-arguments'
3484 prefix argument of -1: --- use the -q switch (quiet)
3485 prefix argument of 0 --- use no arguments
3486 other prefix arguments: --- use the -v switch (verbose)
3488 See `svn-status-marked-files' for what counts as selected."
3490 (let ((switches (svn-status-svn-log-switches arg))
3491 (svn-status-get-line-information-for-file t))
3492 ;; (message "svn-status-show-svn-log %S" arg)
3493 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3494 (svn-run t t 'log "log" "--targets" svn-status-temp-arg-file switches)))
3496 (defun svn-status-version ()
3497 "Show the version numbers for psvn.el and the svn command line client.
3498 The version number of the client is cached in `svn-client-version'."
3500 (let ((window-conf (current-window-configuration))
3502 (if (or (interactive-p) (not svn-status-cached-version-string))
3504 (svn-run nil t 'version "--version")
3505 (when (interactive-p)
3506 (svn-status-show-process-output 'info t))
3507 (with-current-buffer svn-status-last-output-buffer-name
3508 (goto-char (point-min))
3509 (setq svn-client-version
3510 (when (re-search-forward "svn, version \\([0-9\.]+\\) " nil t)
3511 (mapcar 'string-to-number (split-string (match-string 1) "\\."))))
3512 (let ((buffer-read-only nil))
3513 (goto-char (point-min))
3514 (insert (format "psvn.el revision: %s\n\n" svn-psvn-revision)))
3515 (setq version-string (buffer-substring-no-properties (point-min) (point-max))))
3516 (setq svn-status-cached-version-string version-string))
3517 (setq version-string svn-status-cached-version-string)
3518 (unless (interactive-p)
3519 (set-window-configuration window-conf)
3522 (defun svn-status-info ()
3523 "Run `svn info' on all selected files.
3524 See `svn-status-marked-files' for what counts as selected."
3526 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3527 (svn-run t t 'info "info" "--targets" svn-status-temp-arg-file))
3529 (defun svn-status-info-for-path (path)
3530 "Run svn info on the given PATH.
3531 Return some interesting parts of the resulting output.
3532 At the moment a list containing the last changed author is returned."
3533 (let ((svn-process-buffer-name "*svn-info-output*")
3534 (last-changed-author))
3535 (svn-run nil t 'info "info" path)
3536 (with-current-buffer svn-process-buffer-name
3537 (goto-char (point-min))
3538 (when (search-forward "last changed author: " nil t)
3539 (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol)))))
3540 (svn-status-message 7 "last-changed-author for '%s': %s" path last-changed-author)
3541 (list last-changed-author)))
3543 (defun svn-status-blame (revision)
3544 "Run `svn blame' on the current file.
3545 When called with a prefix argument, ask the user for the REVISION to use.
3546 When called from a file buffer, go to the current line in the resulting blame output."
3548 (when current-prefix-arg
3549 (setq revision (svn-status-read-revision-string "Blame for version: " "BASE")))
3550 (unless revision (setq revision "BASE"))
3551 (setq svn-status-blame-file-name (svn-status-line-info->filename (svn-status-get-file-information)))
3552 (svn-run t t 'blame "blame" svn-status-default-blame-arguments "-r" revision svn-status-blame-file-name))
3554 (defun svn-status-show-svn-diff (arg)
3555 "Run `svn diff' on the current file.
3556 If the current file is a directory, compare it recursively.
3557 If there is a newer revision in the repository, the diff is done against HEAD,
3558 otherwise compare the working copy with BASE.
3559 If ARG then prompt for revision to diff against (unless arg is '-)
3560 When called with a negative prefix argument, do a non recursive diff."
3562 (let ((non-recursive (or (and (numberp arg) (< arg 0)) (eq arg '-)))
3563 (revision (if (and (not (eq arg '-)) arg) :ask :auto)))
3564 (svn-status-ensure-cursor-on-file)
3565 (svn-status-show-svn-diff-internal (list (svn-status-get-line-information)) (not non-recursive)
3568 (defun svn-file-show-svn-diff (arg)
3569 "Run `svn diff' on the current file.
3570 If there is a newer revision in the repository, the diff is done against HEAD,
3571 otherwise compare the working copy with BASE.
3572 If ARG then prompt for revision to diff against."
3574 (svn-status-show-svn-diff-internal (list (svn-status-make-line-info buffer-file-name)) nil
3575 (if arg :ask :auto)))
3577 (defun svn-status-show-svn-diff-for-marked-files (arg)
3578 "Run `svn diff' on all selected files.
3579 If some files have been marked, compare those non-recursively;
3580 this is because marking a directory with \\[svn-status-set-user-mark]
3581 normally marks all of its files as well.
3582 If no files have been marked, compare recursively the file at point.
3583 If ARG then prompt for revision to diff against, else compare working copy with BASE."
3585 (svn-status-show-svn-diff-internal (svn-status-marked-files)
3586 (not (svn-status-some-files-marked-p))
3587 (if arg :ask "BASE")))
3589 (defun svn-status-diff-show-changeset (rev &optional user-confirmation)
3590 "Show the changeset for a given log entry.
3591 When called with a prefix argument, ask the user for the revision."
3592 (let* ((upper-rev rev)
3593 (lower-rev (number-to-string (- (string-to-number upper-rev) 1)))
3594 (rev-arg (concat lower-rev ":" upper-rev)))
3595 (when user-confirmation
3596 (setq rev-arg (read-string "Revision for changeset: " rev-arg)))
3597 (svn-run nil t 'diff "diff" (concat "-r" rev-arg))
3598 (svn-status-activate-diff-mode)))
3600 (defun svn-status-show-svn-diff-internal (line-infos recursive revision)
3601 ;; REVISION must be one of:
3602 ;; - a string: whatever the -r option allows.
3603 ;; - `:ask': asks the user to specify the revision, which then becomes
3604 ;; saved in `minibuffer-history' rather than in `command-history'.
3605 ;; - `:auto': use "HEAD" if an update is known to exist, "BASE" otherwise.
3606 ;; In the future, `nil' might mean omit the -r option entirely;
3607 ;; but that currently seems to imply "BASE", so we just use that.
3608 (when (eq revision :ask)
3609 (setq revision (svn-status-read-revision-string
3610 "Diff with files for version: " "PREV")))
3612 (setq svn-status-last-diff-options (list line-infos recursive revision))
3616 (dolist (line-info line-infos)
3617 (svn-run nil clear-buf 'diff "diff" svn-status-default-diff-arguments
3618 "-r" (if (eq revision :auto)
3619 (if (svn-status-line-info->update-available line-info)
3622 (unless recursive "--non-recursive")
3623 (svn-status-line-info->filename line-info))
3624 (setq clear-buf nil)
3626 ;; "svn diff --non-recursive" skips only subdirectories, not files.
3627 ;; But a non-recursive diff via psvn should skip files too, because
3628 ;; the user would have marked them if he wanted them to be compared.
3629 ;; So we'll look for the "Index: foo" line that marks the first file
3630 ;; in the diff output, and delete it and everything that follows.
3631 ;; This is made more complicated by the fact that `svn-status-activate-diff-mode'
3632 ;; expects the output to be left in the *svn-process* buffer.
3634 ;; Check `directory-p' relative to the `default-directory' of the
3635 ;; "*svn-status*" buffer, not that of the svn-process-buffer-name buffer.
3636 (let ((directory-p (svn-status-line-info->directory-p line-info)))
3637 (with-current-buffer svn-process-buffer-name
3639 (goto-char (or beginning (point-min)))
3640 (when (re-search-forward "^Index: " nil t)
3641 (delete-region (match-beginning 0) (point-max))))
3642 (goto-char (setq beginning (point-max))))))))
3643 (svn-status-activate-diff-mode))
3645 (defun svn-status-diff-save-current-defun-as-kill ()
3646 "Copy the function name for the change at point to the kill-ring.
3647 That function uses `add-log-current-defun'"
3649 (let ((func-name (add-log-current-defun)))
3652 (kill-new func-name)
3653 (message "Copied %S" func-name))
3654 (message "No current defun detected."))))
3656 (defun svn-status-diff-pop-to-commit-buffer ()
3657 "Temporary switch to the `svn-status-buffer-name' buffer and start a commit from there."
3659 (let ((window-conf (current-window-configuration)))
3660 (svn-status-switch-to-status-buffer)
3662 (set-window-configuration window-conf)
3663 (setq svn-status-pre-commit-window-configuration window-conf)
3664 (pop-to-buffer svn-log-edit-buffer-name)))
3666 (defun svn-status-activate-diff-mode ()
3667 "Show the `svn-process-buffer-name' buffer, using the diff-mode."
3668 (svn-status-show-process-output 'diff t)
3669 (let ((working-directory default-directory))
3671 (set-buffer svn-status-last-output-buffer-name)
3672 (setq default-directory working-directory)
3673 (svn-status-diff-mode)
3674 (setq buffer-read-only t))))
3676 (define-derived-mode svn-status-diff-mode fundamental-mode "svn-diff"
3677 "Major mode to display svn diffs. Derives from `diff-mode'.
3680 \\{svn-status-diff-mode-map}
3682 (let ((diff-mode-shared-map (copy-keymap svn-status-diff-mode-map))
3683 major-mode mode-name)
3685 (set (make-local-variable 'revert-buffer-function) 'svn-status-diff-update)))
3687 (defun svn-status-diff-update (arg noconfirm)
3688 "Rerun the last svn diff command and update the *svn-diff* buffer."
3690 (svn-status-save-some-buffers)
3691 (save-window-excursion
3692 (apply 'svn-status-show-svn-diff-internal svn-status-last-diff-options)))
3694 (defun svn-status-show-process-buffer ()
3695 "Show the content of the `svn-process-buffer-name' buffer"
3697 (svn-status-show-process-output nil))
3699 (defun svn-status-pop-to-partner-buffer ()
3700 "Pop to the `svn-status-partner-buffer' if that variable is set."
3702 (when svn-status-partner-buffer
3703 (let ((cur-buf (current-buffer)))
3704 (pop-to-buffer svn-status-partner-buffer)
3705 (setq svn-status-partner-buffer cur-buf))))
3707 (defun svn-status-pop-to-new-partner-buffer (buffer)
3708 "Call `pop-to-buffer' and register the current buffer as partner buffer for BUFFER."
3709 (let ((cur-buf (current-buffer)))
3710 (pop-to-buffer buffer)
3711 (setq svn-status-partner-buffer cur-buf)))
3713 (defun svn-status-add-file-recursively (arg)
3714 "Run `svn add' on all selected files.
3715 When a directory is added, add files recursively.
3716 See `svn-status-marked-files' for what counts as selected.
3717 When this function is called with a prefix argument, use the actual file instead."
3719 (message "adding: %S" (svn-status-get-file-list-names (not arg)))
3720 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
3721 (svn-run t t 'add "add" "--targets" svn-status-temp-arg-file))
3723 (defun svn-status-add-file (arg)
3724 "Run `svn add' on all selected files.
3725 When a directory is added, don't add the files of the directory
3726 (svn add --non-recursive <file-list> is called).
3727 See `svn-status-marked-files' for what counts as selected.
3728 When this function is called with a prefix argument, use the actual file instead."
3730 (message "adding: %S" (svn-status-get-file-list-names (not arg)))
3731 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
3732 (svn-run t t 'add "add" "--non-recursive" "--targets" svn-status-temp-arg-file))
3734 (defun svn-status-lock (arg)
3735 "Run `svn lock' on all selected files.
3736 See `svn-status-marked-files' for what counts as selected."
3738 (message "locking: %S" (svn-status-get-file-list-names t))
3739 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
3740 (svn-run t t 'lock "lock" "--targets" svn-status-temp-arg-file))
3742 (defun svn-status-unlock (arg)
3743 "Run `svn unlock' on all selected files.
3744 See `svn-status-marked-files' for what counts as selected."
3746 (message "unlocking: %S" (svn-status-get-file-list-names t))
3747 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
3748 (svn-run t t 'unlock "unlock" "--targets" svn-status-temp-arg-file))
3750 (defun svn-status-make-directory (dir)
3751 "Run `svn mkdir DIR'."
3752 ;; TODO: Allow entering a URI interactively.
3753 ;; Currently, `read-file-name' corrupts it.
3754 (interactive (list (read-file-name "Make directory: "
3755 (svn-status-directory-containing-point t))))
3756 (unless (string-match "^[^:/]+://" dir) ; Is it a URI?
3757 (setq dir (file-relative-name dir)))
3758 (svn-run t t 'mkdir "mkdir" "--" dir))
3760 (defun svn-status-mv ()
3761 "Prompt for a destination, and `svn mv' selected files there.
3762 See `svn-status-marked-files' for what counts as `selected'.
3764 If one file was selected then the destination DEST should be a
3765 filename to rename the selected file to, or a directory to move the
3766 file into; if multiple files were selected then DEST should be a
3767 directory to move the selected files into.
3769 The default DEST is the directory containing point.
3771 BUG: If we've marked some directory containging a file as well as the
3772 file itself, then we should just mv the directory, but this implementation
3773 doesn't check for that.
3774 SOLUTION: for each dir, umark all its contents (but not the dir
3775 itself) before running mv."
3777 (svn-status-mv-cp "mv" "Rename" "Move" "mv"))
3779 (defun svn-status-cp ()
3780 "See `svn-status-mv'"
3782 (svn-status-mv-cp "cp" "Copy" "Copy" "cp"))
3784 (defun svn-status-mv-cp (command singleprompt manyprompt fallback)
3785 "Run svn COMMAND on marked files, prompting for destination
3787 This function acts on `svn-status-marked-files': at the prompt the
3788 user can enter a new file name, or an existing directory: this is used as the argument for svn COMMAND.
3789 COMMAND --- string saying what to do: \"mv\" or \"cp\"
3790 SINGLEPROMPT --- string at start of prompt when one file marked
3791 MANYPROMPT --- string at start of prompt when multiple files marked
3792 FALLBACK --- If any marked file is unversioned, use this instead of 'svn COMMAND'"
3793 (let* ((marked-files (svn-status-marked-files))
3794 (num-of-files (length marked-files))
3796 (if (= 1 num-of-files)
3797 ;; one file to act on: new name, or directory to hold results
3798 (setq dest (read-file-name
3799 (format "%s %s to: " singleprompt
3800 (svn-status-line-info->filename (car marked-files)))
3801 (svn-status-directory-containing-point t)
3802 (svn-status-line-info->full-path (car marked-files))))
3803 ;;TODO: (when file-exists-p but-no-dir-p dest (error "%s already exists" dest))
3804 ;;multiple files selected, so prompt for existing directory to mv them into.
3805 (setq dest (svn-read-directory-name
3806 (format "%s %d files to directory: " manyprompt num-of-files)
3807 (svn-status-directory-containing-point t) nil t))
3808 (unless (file-directory-p dest)
3809 (error "%s is not a directory" dest)))
3810 (when (string= dest "")
3811 (error "No destination entered"))
3812 (unless (string-match "^[^:/]+://" dest) ; Is it a URI?
3813 (setq dest (file-relative-name dest)))
3815 ;;do the move: svn mv only lets us move things once at a time, so
3816 ;;we need to run svn mv once for each file (hence second arg to
3819 ;;TODO: before doing any moving, For every marked directory,
3820 ;;ensure none of its contents are also marked, since we dont want
3821 ;;to move both file *and* its parent...
3822 ;; what about elided files? what if user marks a dir+contents, then presses `_' ?
3824 ;; (dolist (original marked-files)
3825 ;; (when (svn-status-line-info->directory-p original)
3826 ;; ;; run svn-status-goto-file-name to move point to line of file
3827 ;; ;; run svn-status-unset-user-mark to unmark dir+all contents
3828 ;; ;; run svn-status-set-user-mark to remark dir
3829 ;; ;; maybe check for local mods here, and unmark if user does't say --force?
3831 (dolist (original marked-files)
3832 (let ((original-name (svn-status-line-info->filename original))
3833 (original-filemarks (svn-status-line-info->filemark original))
3834 (original-propmarks (svn-status-line-info->propmark original))
3837 ((or (eq original-filemarks ?M) ;local mods: maybe do `svn mv --force'
3838 (eq original-propmarks ?M)) ;local prop mods: maybe do `svn mv --force'
3840 (format "%s has local modifications; use `--force' to really move it? " original-name))
3842 (svn-status-run-mv-cp command original-name dest t)
3844 (message "Not acting on %s" original-name)))
3845 ((eq original-filemarks ??) ;original is unversioned: use fallback
3846 (if (yes-or-no-p (format "%s is unversioned. Use `%s -i -- %s %s'? "
3847 original-name fallback original-name dest))
3848 ;; TODO: consider svn-call-process-function here also...
3849 (progn (call-process fallback nil (get-buffer-create svn-process-buffer-name) nil
3850 "-i" "--" original-name dest)
3852 ;;new files created by fallback are not in *svn-status* now,
3853 ;;TODO: so call (svn-status-update) here?
3854 (message "Not acting on %s" original-name)))
3856 ((eq original-filemarks ?A) ;;`A' (`svn add'ed, but not committed)
3857 (message "Not acting on %s (commit it first)" original-name))
3859 ((eq original-filemarks ? ) ;original is unmodified: can proceed
3860 (svn-status-run-mv-cp command original-name dest)
3863 ;;file has some other mark (eg conflicted)
3866 (format "The status of %s looks scary. Risk moving it anyway? "
3869 (svn-status-run-mv-cp command original-name dest)
3871 (message "Not acting on %s" original-name))))
3873 (message "psvn: did '%s' from %s to %s" command original-name dest)
3874 ;; Silently rename the visited file of any buffer visiting this file.
3875 (when (get-file-buffer original-name)
3876 (with-current-buffer (get-file-buffer original-name)
3877 (set-visited-file-name dest nil t))))))
3878 (svn-status-update)))
3880 (defun svn-status-run-mv-cp (command original destination &optional force)
3881 "Actually run svn mv or svn cp.
3882 This is just to prevent duplication in `svn-status-prompt-and-act-on-files'"
3884 (svn-run nil t (intern command) command "--force" "--" original destination)
3885 (svn-run nil t (intern command) command "--" original destination))
3886 ;;;TODO: use something like the following instead of calling svn-status-update
3887 ;;; at the end of svn-status-mv-cp.
3888 ;; (let ((output (svn-status-parse-ar-output))
3890 ;; buffer-read-only) ; otherwise insert-line-in-status-buffer fails
3891 ;; (dolist (new-file output)
3892 ;; (when (eq (cadr new-file) 'added-wc)
3893 ;; ;; files with 'wc-added action do not exist in *svn-status*
3894 ;; ;; buffer yet, so give each of them their own line-info
3895 ;; ;; TODO: need to insert the new line-info in a sensible place, ie in the correct directory! [svn-status-filename-to-buffer-position-cache might help?]
3897 ;; (svn-insert-line-in-status-buffer
3898 ;; (svn-status-make-line-info (car new-file)))))
3899 ;; (svn-status-update-with-command-list output))
3902 (defun svn-status-revert ()
3903 "Run `svn revert' on all selected files.
3904 See `svn-status-marked-files' for what counts as selected."
3906 (let* ((marked-files (svn-status-marked-files))
3907 (num-of-files (length marked-files)))
3909 (if (= 1 num-of-files)
3910 (format "Revert %s? " (svn-status-line-info->filename (car marked-files)))
3911 (format "Revert %d files? " num-of-files)))
3912 (message "reverting: %S" (svn-status-marked-file-names))
3913 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3914 (svn-run t t 'revert "revert" "--targets" svn-status-temp-arg-file))))
3916 (defun svn-status-rm (force)
3917 "Run `svn rm' on all selected files.
3918 See `svn-status-marked-files' for what counts as selected.
3919 When called with a prefix argument add the command line switch --force.
3921 Forcing the deletion can also be used to delete files not under svn control."
3923 (let* ((marked-files (svn-status-marked-files))
3924 (num-of-files (length marked-files)))
3926 (if (= 1 num-of-files)
3927 (format "%sRemove %s? " (if force "Force " "") (svn-status-line-info->filename (car marked-files)))
3928 (format "%sRemove %d files? " (if force "Force " "") num-of-files)))
3929 (message "removing: %S" (svn-status-marked-file-names))
3930 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3933 (svn-run t t 'rm "rm" "--force" "--targets" svn-status-temp-arg-file)
3934 (dolist (to-delete (svn-status-marked-files))
3935 (when (eq (svn-status-line-info->filemark to-delete) ??)
3936 (svn-status-goto-file-name (svn-status-line-info->filename to-delete))
3937 (let ((buffer-read-only nil))
3938 (delete-region (svn-point-at-bol) (+ 1 (svn-point-at-eol)))
3939 (delete to-delete svn-status-info)))))
3940 (svn-run t t 'rm "rm" "--targets" svn-status-temp-arg-file)))))
3942 (defun svn-status-update-cmd (arg)
3944 When called with a prefix argument, ask the user for the revision to update to.
3945 When called with a negative prefix argument, only update the selected files."
3947 (let* ((selective-update (or (and (numberp arg) (< arg 0)) (eq arg '-)))
3948 (rev (when arg (svn-status-read-revision-string
3949 (if selective-update
3950 (format "Selected entries: Run svn update -r ")
3951 (format "Directory: %s: Run svn update -r " default-directory))
3952 (if selective-update "HEAD" nil)))))
3953 (if selective-update
3955 (message "Running svn-update for %s" (svn-status-marked-file-names))
3956 (svn-run t t 'update "update"
3957 (when rev (list "-r" rev))
3958 (list "--non-interactive")
3959 (svn-status-marked-file-names)))
3960 (message "Running svn-update for %s" default-directory)
3961 (svn-run t t 'update "update"
3962 (when rev (list "-r" rev))
3963 (list "--non-interactive")))))
3965 (defun svn-status-commit ()
3966 "Commit selected files.
3967 If some files have been marked, commit those non-recursively;
3968 this is because marking a directory with \\[svn-status-set-user-mark]
3969 normally marks all of its files as well.
3970 If no files have been marked, commit recursively the file at point."
3972 (svn-status-save-some-buffers)
3973 (let* ((selected-files (svn-status-marked-files)))
3974 (setq svn-status-files-to-commit selected-files
3975 svn-status-recursive-commit (not (svn-status-only-dirs-or-nothing-marked-p)))
3976 (svn-log-edit-show-files-to-commit)
3977 (svn-status-pop-to-commit-buffer)
3978 (when svn-log-edit-insert-files-to-commit
3979 (svn-log-edit-insert-files-to-commit))
3980 (when svn-log-edit-show-diff-for-commit
3981 (svn-log-edit-svn-diff nil))))
3983 (defun svn-status-pop-to-commit-buffer ()
3984 "Pop to the svn commit buffer.
3985 If a saved log message exists in `svn-log-edit-file-name' insert it in the buffer."
3987 (setq svn-status-pre-commit-window-configuration (current-window-configuration))
3988 (let* ((use-existing-buffer (get-buffer svn-log-edit-buffer-name))
3989 (commit-buffer (get-buffer-create svn-log-edit-buffer-name))
3990 (dir default-directory)
3991 (log-edit-file-name))
3992 (pop-to-buffer commit-buffer)
3993 (setq default-directory dir)
3994 (setq log-edit-file-name (svn-log-edit-file-name))
3995 (unless use-existing-buffer
3996 (when (and log-edit-file-name (file-readable-p log-edit-file-name))
3997 (insert-file-contents log-edit-file-name)))
3998 (svn-log-edit-mode)))
4000 (defun svn-status-switch-to-status-buffer ()
4001 "Switch to the `svn-status-buffer-name' buffer."
4003 (switch-to-buffer svn-status-buffer-name))
4005 (defun svn-status-pop-to-status-buffer ()
4006 "Pop to the `svn-status-buffer-name' buffer."
4008 (pop-to-buffer svn-status-buffer-name))
4010 (defun svn-status-via-bookmark (bookmark)
4011 "Allows a quick selection of a bookmark in `svn-bookmark-list'.
4012 Run `svn-status' on the selected bookmark."
4015 (let ((completion-ignore-case t))
4016 (funcall svn-status-completing-read-function "SVN status bookmark: " svn-bookmark-list))))
4018 (error "No bookmark specified"))
4019 (let ((directory (cdr (assoc bookmark svn-bookmark-list))))
4020 (if (file-directory-p directory)
4021 (svn-status directory)
4022 (error "%s is not a directory" directory))))
4024 (defun svn-status-export ()
4025 "Run `svn export' for the current working copy.
4026 Ask the user for the destination path.
4027 `svn-status-default-export-directory' is suggested as export directory."
4029 (let* ((src default-directory)
4030 (dir1-name (nth 1 (nreverse (split-string src "/"))))
4031 (dest (read-file-name (format "Export %s to " src) (concat svn-status-default-export-directory dir1-name))))
4032 (svn-run t t 'export "export" (expand-file-name src) (expand-file-name dest))
4033 (message "svn-status-export %s %s" src dest)))
4035 (defun svn-status-cleanup (arg)
4036 "Run `svn cleanup' on all selected files.
4037 See `svn-status-marked-files' for what counts as selected.
4038 When this function is called with a prefix argument, use the actual file instead."
4040 (let ((file-names (svn-status-get-file-list-names (not arg))))
4043 (message "svn-status-cleanup %S" file-names)
4044 (svn-run t t 'cleanup (append (list "cleanup") file-names)))
4045 (message "No valid file selected - No status cleanup possible"))))
4047 (defun svn-status-resolved ()
4048 "Run `svn resolved' on all selected files.
4049 See `svn-status-marked-files' for what counts as selected."
4051 (let* ((marked-files (svn-status-marked-files))
4052 (num-of-files (length marked-files)))
4054 (if (= 1 num-of-files)
4055 (format "Resolve %s? " (svn-status-line-info->filename (car marked-files)))
4056 (format "Resolve %d files? " num-of-files)))
4057 (message "resolving: %S" (svn-status-marked-file-names))
4058 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
4059 (svn-run t t 'resolved "resolved" "--targets" svn-status-temp-arg-file))))
4062 (defun svn-status-svnversion ()
4063 "Run svnversion on the directory that contains the file at point."
4065 (svn-status-ensure-cursor-on-file)
4066 (let ((simple-path (svn-status-line-info->filename (svn-status-get-line-information)))
4067 (full-path (svn-status-line-info->full-path (svn-status-get-line-information)))
4069 (unless (file-directory-p simple-path)
4070 (setq simple-path (or (file-name-directory simple-path) "."))
4071 (setq full-path (file-name-directory full-path)))
4072 (setq version (shell-command-to-string (concat "svnversion -n " full-path)))
4073 (message "svnversion for '%s': %s" simple-path version)
4076 ;; --------------------------------------------------------------------------------
4077 ;; Update the `svn-status-buffer-name' buffer, when a file is saved
4078 ;; --------------------------------------------------------------------------------
4080 (defvar svn-status-file-modified-after-save-flag ?m
4081 "Flag shown whenever a file is modified and saved in Emacs.
4082 The flag is shown in the `svn-status-buffer-name' buffer.
4083 Recommended values are ?m or ?M.")
4084 (defun svn-status-after-save-hook ()
4085 "Set a modified indication, when a file is saved from a svn working copy."
4086 (let* ((svn-dir (car-safe svn-status-directory-history))
4087 (svn-dir (when svn-dir (expand-file-name svn-dir)))
4088 (file-dir (file-name-directory (buffer-file-name)))
4089 (svn-dir-len (length (or svn-dir "")))
4090 (file-dir-len (length file-dir))
4092 (when (and (get-buffer svn-status-buffer-name)
4094 (>= file-dir-len svn-dir-len)
4095 (string= (substring file-dir 0 svn-dir-len) svn-dir))
4096 (setq file-name (substring (buffer-file-name) svn-dir-len))
4097 ;;(message "In svn-status directory %S" file-name)
4098 (let ((st-info svn-status-info)
4101 (setq i-fname (svn-status-line-info->filename (car st-info)))
4102 ;;(message "i-fname=%S" i-fname)
4103 (when (and (string= file-name i-fname)
4104 (not (eq (svn-status-line-info->filemark (car st-info)) ??)))
4105 (svn-status-line-info->set-filemark (car st-info)
4106 svn-status-file-modified-after-save-flag)
4107 (save-window-excursion
4108 (set-buffer svn-status-buffer-name)
4110 (let ((buffer-read-only nil)
4111 (pos (svn-status-get-file-name-buffer-position i-fname)))
4115 (delete-region (svn-point-at-bol) (svn-point-at-eol))
4116 (svn-insert-line-in-status-buffer (car st-info))
4118 (svn-status-message 3 "psvn: file %s not found, updating %s buffer content..."
4119 i-fname svn-status-buffer-name)
4120 (svn-status-update-buffer))))))
4121 (setq st-info (cdr st-info))))))
4124 (add-hook 'after-save-hook 'svn-status-after-save-hook)
4126 ;; --------------------------------------------------------------------------------
4127 ;; Getting older revisions
4128 ;; --------------------------------------------------------------------------------
4130 (defun svn-status-get-specific-revision (arg)
4131 "Retrieve older revisions.
4132 The older revisions are stored in backup files named F.~REVISION~.
4134 When the function is called without a prefix argument: get all marked files.
4135 With a prefix argument: get only the actual file."
4137 (svn-status-get-specific-revision-internal
4138 (svn-status-get-file-list (not arg)) :ask t))
4140 (defun svn-status-get-specific-revision-internal (line-infos revision handle-relative-svn-status-dir)
4141 "Retrieve older revisions of files.
4142 LINE-INFOS is a list of line-info structures (see
4143 `svn-status-get-line-information').
4145 - a string: whatever the -r option allows.
4146 - `:ask': asks the user to specify the revision, which then becomes
4147 saved in `minibuffer-history' rather than in `command-history'.
4148 - `:auto': Use \"HEAD\" if an update is known to exist, \"BASE\" otherwise.
4150 After the call, `svn-status-get-revision-file-info' will be an alist
4151 \((WORKING-FILE-NAME . RETRIEVED-REVISION-FILE-NAME) ...). These file
4152 names are relative to the directory where `svn-status' was run."
4153 ;; In `svn-status-show-svn-diff-internal', there is a comment
4154 ;; that REVISION `nil' might mean omitting the -r option entirely.
4155 ;; That doesn't seem like a good idea with svn cat.
4157 ;; (message "svn-status-get-specific-revision-internal: %S %S" line-infos revision)
4159 (when (eq revision :ask)
4160 (setq revision (svn-status-read-revision-string
4161 "Get files for version: " "PREV")))
4163 (let ((count (length line-infos)))
4165 (let ((line-info (car line-infos)))
4166 (message "Getting revision %s of %s"
4167 (if (eq revision :auto)
4168 (if (svn-status-line-info->update-available line-info)
4171 (svn-status-line-info->filename line-info)))
4172 ;; We could compute "Getting HEAD of 8 files and BASE of 11 files"
4173 ;; but that'd be more bloat than it's worth.
4174 (message "Getting revision %s of %d files"
4175 (if (eq revision :auto) "HEAD or BASE" revision)
4178 (let ((svn-status-get-specific-revision-file-info '()))
4179 (dolist (line-info line-infos)
4180 (let* ((revision (if (eq revision :auto)
4181 (if (svn-status-line-info->update-available line-info)
4183 revision)) ;must be a string by this point
4184 (file-name (svn-status-line-info->filename line-info))
4185 ;; If REVISION is e.g. "HEAD", should we find out the actual
4186 ;; revision number and save "foo.~123~" rather than "foo.~HEAD~"?
4187 ;; OTOH, `auto-mode-alist' already ignores ".~HEAD~" suffixes,
4188 ;; and if users often want to know the revision numbers of such
4189 ;; files, they can use svn:keywords.
4190 (file-name-with-revision (concat (file-name-nondirectory file-name) ".~" revision "~"))
4191 (default-directory (concat (svn-status-base-dir)
4192 (if handle-relative-svn-status-dir
4193 (file-relative-name default-directory (svn-status-base-dir))
4195 (file-name-directory file-name))))
4196 ;; `add-to-list' would unnecessarily check for duplicates.
4197 (push (cons file-name (concat (file-name-directory file-name) file-name-with-revision))
4198 svn-status-get-specific-revision-file-info)
4199 (svn-status-message 3 "svn-status-get-specific-revision-internal: file: %s, default-directory: %s"
4200 file-name default-directory)
4201 (svn-status-message 3 "svn-status-get-specific-revision-internal: file-name-with-revision: %s %S"
4202 file-name-with-revision (file-exists-p file-name-with-revision))
4204 (if (or (not (file-exists-p file-name-with-revision)) ;; file does not exist
4205 (not (string= (number-to-string (string-to-number revision)) revision))) ;; revision is not a number
4207 (message "Getting revision %s of %s, target: %s" revision file-name
4208 (expand-file-name(concat default-directory file-name-with-revision)))
4211 (if (string= revision "BASE")
4212 (insert-file-contents (concat (svn-wc-adm-dir-name)
4214 (file-name-nondirectory file-name)
4217 (svn-run nil t 'cat "cat" "-r" revision
4218 (concat default-directory (file-name-nondirectory file-name)))
4219 ;;todo: error processing
4220 ;;svn: Filesystem has no item
4221 ;;svn: file not found: revision `15', path `/trunk/file.txt'
4222 (insert-buffer-substring svn-process-buffer-name)))
4224 (find-file file-name-with-revision)
4225 (setq buffer-read-only nil)
4226 (erase-buffer) ;Widen, because we'll save the whole buffer.
4228 (goto-char (point-min))
4229 (let ((write-file-functions nil)
4230 (require-final-newline nil))
4232 (find-file file-name-with-revision)))))
4233 ;;(message "default-directory: %s revision-file-info: %S" default-directory svn-status-get-specific-revision-file-info)
4234 (nreverse svn-status-get-specific-revision-file-info)))
4236 (defun svn-status-ediff-with-revision (arg)
4237 "Run ediff on the current file with a different revision.
4238 If there is a newer revision in the repository, the diff is done against HEAD,
4239 otherwise compare the working copy with BASE.
4240 If ARG then prompt for revision to diff against."
4242 (let* ((svn-status-get-specific-revision-file-info
4243 (svn-status-get-specific-revision-internal
4244 (list (svn-status-make-line-info
4246 (svn-status-line-info->full-path (svn-status-get-line-information))
4247 (svn-status-base-dir))
4248 nil nil nil nil nil nil
4249 (svn-status-line-info->update-available (svn-status-get-line-information))))
4252 (ediff-after-quit-destination-buffer (current-buffer))
4253 (default-directory (svn-status-base-dir))
4254 (my-buffer (find-file-noselect (caar svn-status-get-specific-revision-file-info)))
4255 (base-buff (find-file-noselect (cdar svn-status-get-specific-revision-file-info)))
4256 (svn-transient-buffers (list my-buffer base-buff))
4257 (startup-hook '(svn-ediff-startup-hook)))
4258 (ediff-buffers base-buff my-buffer startup-hook)))
4260 (defun svn-ediff-startup-hook ()
4261 ;; (message "svn-ediff-startup-hook: ediff-after-quit-hook-internal: %S" ediff-after-quit-hook-internal)
4262 (add-hook 'ediff-after-quit-hook-internal
4264 (svn-ediff-exit-hook
4265 ',ediff-after-quit-destination-buffer ',svn-transient-buffers))
4268 (defun svn-ediff-exit-hook (svn-buf tmp-bufs)
4269 ;; (message "svn-ediff-exit-hook: svn-buf: %s, tmp-bufs: %s" svn-buf tmp-bufs)
4270 ;; kill the temp buffers (and their associated windows)
4271 (dolist (tb tmp-bufs)
4272 (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
4273 (let* ((win (get-buffer-window tb t))
4274 (file-name (buffer-file-name tb))
4275 (is-temp-file (numberp (string-match "~\\([0-9]+\\|BASE\\)~" file-name))))
4276 ;; (message "svn-ediff-exit-hook - is-temp-file: %s, temp-buf:: %s - %s " is-temp-file (current-buffer) file-name)
4277 (when (and win (> (count-windows) 1)
4278 (delete-window win)))
4280 (when (and is-temp-file svn-status-ediff-delete-temporary-files)
4281 (when (or (eq svn-status-ediff-delete-temporary-files t)
4282 (y-or-n-p (format "Delete File '%s' ? " file-name)))
4283 (delete-file file-name))))))
4284 ;; switch back to the *svn* buffer
4285 (when (and svn-buf (buffer-live-p svn-buf)
4286 (not (get-buffer-window svn-buf t)))
4287 (ignore-errors (switch-to-buffer svn-buf))))
4290 (defun svn-status-read-revision-string (prompt &optional default-value)
4291 "Prompt the user for a svn revision number."
4293 (read-string prompt default-value))
4295 (defun svn-file-show-svn-ediff (arg)
4296 "Run ediff on the current file with a previous revision.
4297 If ARG then prompt for revision to diff against."
4299 (let ((svn-status-get-line-information-for-file 'relative)
4300 (default-directory (svn-status-base-dir)))
4301 (svn-status-ediff-with-revision arg)))
4303 ;; --------------------------------------------------------------------------------
4304 ;; SVN process handling
4305 ;; --------------------------------------------------------------------------------
4307 (defun svn-process-kill ()
4308 "Kill the current running svn process."
4310 (let ((process (get-process "svn")))
4312 (delete-process process)
4313 (message "No running svn process"))))
4315 (defun svn-process-send-string (string &optional send-passwd)
4316 "Send a string to the running svn process.
4317 This is useful, if the running svn process asks the user a question.
4318 Note: use C-q C-j to send a line termination character."
4319 (interactive "sSend string to svn process: ")
4321 (set-buffer svn-process-buffer-name)
4322 (goto-char (point-max))
4323 (let ((buffer-read-only nil))
4324 (insert (if send-passwd (make-string (length string) ?.) string)))
4325 (set-marker (process-mark (get-process "svn")) (point)))
4326 (process-send-string "svn" string))
4328 (defun svn-process-send-string-and-newline (string &optional send-passwd)
4329 "Send a string to the running svn process.
4330 Just call `svn-process-send-string' with STRING and an end of line termination.
4331 When called with a prefix argument, read the data from user as password."
4332 (interactive (let* ((use-passwd current-prefix-arg)
4334 (read-passwd "Send secret line to svn process: ")
4335 (read-string "Send line to svn process: "))))
4336 (list s use-passwd)))
4337 (svn-process-send-string (concat string "\n") send-passwd))
4339 ;; --------------------------------------------------------------------------------
4340 ;; Property List stuff
4341 ;; --------------------------------------------------------------------------------
4343 (defun svn-status-property-list ()
4345 (let ((file-names (svn-status-marked-file-names)))
4348 (svn-run t t 'proplist (append (list "proplist" "-v") file-names)))
4349 (message "No valid file selected - No property listing possible"))))
4351 (defun svn-status-proplist-start ()
4352 (svn-status-ensure-cursor-on-file)
4353 (svn-run t t 'proplist-parse "proplist" (svn-status-line-info->filename
4354 (svn-status-get-line-information))))
4355 (defun svn-status-property-edit-one-entry (arg)
4357 When called with a prefix argument, it is possible to enter a new property."
4359 (setq svn-status-property-edit-must-match-flag (not arg))
4360 (svn-status-proplist-start))
4362 (defun svn-status-property-set ()
4364 (setq svn-status-property-edit-must-match-flag nil)
4365 (svn-status-proplist-start))
4367 (defun svn-status-property-delete ()
4369 (setq svn-status-property-edit-must-match-flag t)
4370 (svn-status-proplist-start))
4372 (defun svn-status-property-parse-property-names ()
4373 ;(svn-status-show-process-buffer-internal t)
4374 (message "svn-status-property-parse-property-names")
4379 (set-buffer svn-process-buffer-name)
4380 (goto-char (point-min))
4382 (while (looking-at " \\(.+\\)")
4383 (setq pl (append pl (list (match-string 1))))
4385 ;(cond last-command: svn-status-property-set, svn-status-property-edit-one-entry
4386 (cond ((eq last-command 'svn-status-property-edit-one-entry)
4387 ;;(message "svn-status-property-edit-one-entry")
4389 (completing-read "Set Property - Name: " (mapcar 'list pl)
4390 nil svn-status-property-edit-must-match-flag))
4391 (unless (string= prop-name "")
4393 (set-buffer svn-status-buffer-name)
4394 (svn-status-property-edit (list (svn-status-get-line-information))
4396 ((eq last-command 'svn-status-property-set)
4397 (message "svn-status-property-set")
4399 (completing-read "Set Property - Name: " (mapcar 'list pl) nil nil))
4400 (setq prop-value (read-from-minibuffer "Property value: "))
4401 (unless (string= prop-name "")
4403 (set-buffer svn-status-buffer-name)
4404 (message "Setting property %s := %s for %S" prop-name prop-value
4405 (svn-status-marked-file-names))
4406 (let ((file-names (svn-status-marked-file-names)))
4408 (svn-run nil t 'propset
4409 (append (list "propset" prop-name prop-value) file-names))
4412 (message "propset finished.")
4414 ((eq last-command 'svn-status-property-delete)
4416 (completing-read "Delete Property - Name: " (mapcar 'list pl) nil t))
4417 (unless (string= prop-name "")
4419 (set-buffer svn-status-buffer-name)
4420 (let ((file-names (svn-status-marked-file-names)))
4422 (message "Going to delete prop %s for %s" prop-name file-names)
4423 (svn-run t t 'propdel
4424 (append (list "propdel" prop-name) file-names))))))))))
4426 (defun svn-status-property-edit (file-info-list prop-name &optional new-prop-value remove-values)
4427 (let* ((commit-buffer (get-buffer-create "*svn-property-edit*"))
4428 (dir default-directory)
4429 ;; now only one file is implemented ...
4430 (file-name (svn-status-line-info->filename (car file-info-list)))
4432 (message "Edit property %s for file %s" prop-name file-name)
4433 (svn-run nil t 'propget-parse "propget" prop-name file-name)
4435 (set-buffer svn-process-buffer-name)
4436 (setq prop-value (if (> (point-max) 1)
4437 (buffer-substring (point-min) (- (point-max) 1))
4439 (setq svn-status-propedit-property-name prop-name)
4440 (setq svn-status-propedit-file-list file-info-list)
4441 (setq svn-status-pre-propedit-window-configuration (current-window-configuration))
4442 (pop-to-buffer commit-buffer)
4443 ;; If the buffer has been narrowed, `svn-prop-edit-done' will use
4444 ;; only the accessible part. So we need not erase the rest here.
4445 (delete-region (point-min) (point-max))
4446 (setq default-directory dir)
4448 (svn-status-remove-control-M)
4449 (when new-prop-value
4450 (when (listp new-prop-value)
4452 (message "Remove prop values %S " new-prop-value)
4453 (message "Adding new prop values %S " new-prop-value))
4454 (while new-prop-value
4455 (goto-char (point-min))
4456 (if (re-search-forward (concat "^" (regexp-quote (car new-prop-value)) "$") nil t)
4458 (kill-whole-line 1))
4459 (unless remove-values
4460 (goto-char (point-max))
4461 (when (> (current-column) 0) (insert "\n"))
4462 (insert (car new-prop-value))))
4463 (setq new-prop-value (cdr new-prop-value)))))
4464 (svn-prop-edit-mode)))
4466 (defun svn-status-property-set-property (file-info-list prop-name prop-value)
4467 "Set a property on a given file list."
4469 (set-buffer (get-buffer-create "*svn-property-edit*"))
4470 ;; If the buffer has been narrowed, `svn-prop-edit-do-it' will use
4471 ;; only the accessible part. So we need not erase the rest here.
4472 (delete-region (point-min) (point-max))
4473 (insert prop-value))
4474 (setq svn-status-propedit-file-list (svn-status-marked-files))
4475 (setq svn-status-propedit-property-name prop-name)
4476 (svn-prop-edit-do-it nil)
4477 (svn-status-update))
4480 (defun svn-status-get-directory (line-info)
4481 (let* ((file-name (svn-status-line-info->filename line-info))
4482 (file-dir (file-name-directory file-name)))
4483 ;;(message "file-dir: %S" file-dir)
4485 (substring file-dir 0 (- (length file-dir) 1))
4488 (defun svn-status-get-file-list-per-directory (files)
4489 ;;(message "%S" files)
4490 (let ((dir-list nil)
4495 (setq dir (svn-status-get-directory (car i)))
4496 (setq j (assoc dir dir-list))
4499 ;;(message "dir already present %S %s" j dir)
4500 (setcdr j (append (cdr j) (list (car i)))))
4501 (setq dir-list (append dir-list (list (list dir (car i))))))
4503 ;;(message "svn-status-get-file-list-per-directory: %S" dir-list)
4506 (defun svn-status-property-ignore-file ()
4508 (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
4513 (setq dir (caar d-list))
4514 (setq f-info (cdar d-list))
4515 (setq ext-list (mapcar '(lambda (i)
4516 (svn-status-line-info->filename-nondirectory i)) f-info))
4517 ;;(message "ignore in dir %s: %S" dir f-info)
4518 (save-window-excursion
4519 (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
4520 (svn-status-property-edit
4521 (list (svn-status-find-info-for-file-name dir)) "svn:ignore" ext-list)
4522 (svn-prop-edit-do-it nil))) ; synchronous
4523 (setq d-list (cdr d-list)))
4524 (svn-status-update)))
4526 (defun svn-status-property-ignore-file-extension ()
4528 (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
4533 (setq dir (caar d-list))
4534 (setq f-info (cdar d-list))
4535 ;;(message "ignore in dir %s: %S" dir f-info)
4538 (add-to-list 'ext-list (concat "*."
4539 (file-name-extension
4540 (svn-status-line-info->filename (car f-info)))))
4541 (setq f-info (cdr f-info)))
4542 ;;(message "%S" ext-list)
4543 (save-window-excursion
4544 (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
4545 (svn-status-property-edit
4546 (list (svn-status-find-info-for-file-name dir)) "svn:ignore"
4548 (svn-prop-edit-do-it nil)))
4549 (setq d-list (cdr d-list)))
4550 (svn-status-update)))
4552 (defun svn-status-property-edit-svn-ignore ()
4554 (let* ((line-info (svn-status-get-line-information))
4555 (dir (if (svn-status-line-info->directory-p line-info)
4556 (svn-status-line-info->filename line-info)
4557 (svn-status-get-directory line-info))))
4558 (svn-status-property-edit
4559 (list (svn-status-find-info-for-file-name dir)) "svn:ignore")
4560 (message "Edit svn:ignore on %s" dir)))
4563 (defun svn-status-property-set-keyword-list ()
4564 "Edit the svn:keywords property on the marked files."
4566 ;;(message "Set svn:keywords for %S" (svn-status-marked-file-names))
4567 (svn-status-property-edit (svn-status-marked-files) "svn:keywords"))
4569 (defun svn-status-property-set-keyword-id (arg)
4570 "Set/Remove Id from the svn:keywords property.
4571 Normally Id is added to the svn:keywords property.
4573 When called with the prefix arg -, remove Id from the svn:keywords property."
4575 (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Id") (eq arg '-))
4576 (svn-prop-edit-do-it nil))
4578 (defun svn-status-property-set-keyword-date (arg)
4579 "Set/Remove Date from the svn:keywords property.
4580 Normally Date is added to the svn:keywords property.
4582 When called with the prefix arg -, remove Date from the svn:keywords property."
4584 (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Date") (eq arg '-))
4585 (svn-prop-edit-do-it nil))
4588 (defun svn-status-property-set-eol-style ()
4589 "Edit the svn:eol-style property on the marked files."
4591 (svn-status-property-set-property
4592 (svn-status-marked-files) "svn:eol-style"
4593 (completing-read "Set svn:eol-style for the marked files: "
4594 (mapcar 'list '("native" "CRLF" "LF" "CR"))
4597 (defun svn-status-property-set-executable ()
4598 "Set the svn:executable property on the marked files."
4600 (svn-status-property-set-property (svn-status-marked-files) "svn:executable" "*"))
4602 (defun svn-status-property-set-mime-type ()
4603 "Set the svn:mime-type property on the marked files."
4605 (require 'mailcap nil t)
4606 (let ((completion-ignore-case t)
4607 (mime-types (when (fboundp 'mailcap-mime-types)
4608 (mailcap-mime-types))))
4609 (svn-status-property-set-property
4610 (svn-status-marked-files) "svn:mime-type"
4611 (funcall svn-status-completing-read-function "Set svn:mime-type for the marked files: "
4612 (mapcar (lambda (x) (cons x x)) ; for Emacs 21
4613 (sort mime-types 'string<))))))
4615 ;; --------------------------------------------------------------------------------
4616 ;; svn-prop-edit-mode:
4617 ;; --------------------------------------------------------------------------------
4619 (defvar svn-prop-edit-mode-map () "Keymap used in `svn-prop-edit-mode' buffers.")
4620 (put 'svn-prop-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
4622 (when (not svn-prop-edit-mode-map)
4623 (setq svn-prop-edit-mode-map (make-sparse-keymap))
4624 (define-key svn-prop-edit-mode-map [(control ?c) (control ?c)] 'svn-prop-edit-done)
4625 (define-key svn-prop-edit-mode-map [(control ?c) (control ?d)] 'svn-prop-edit-svn-diff)
4626 (define-key svn-prop-edit-mode-map [(control ?c) (control ?s)] 'svn-prop-edit-svn-status)
4627 (define-key svn-prop-edit-mode-map [(control ?c) (control ?l)] 'svn-prop-edit-svn-log)
4628 (define-key svn-prop-edit-mode-map [(control ?c) (control ?q)] 'svn-prop-edit-abort))
4630 (easy-menu-define svn-prop-edit-mode-menu svn-prop-edit-mode-map
4631 "'svn-prop-edit-mode' menu"
4633 ["Commit" svn-prop-edit-done t]
4634 ["Show Diff" svn-prop-edit-svn-diff t]
4635 ["Show Status" svn-prop-edit-svn-status t]
4636 ["Show Log" svn-prop-edit-svn-log t]
4637 ["Abort" svn-prop-edit-abort t]))
4639 (defun svn-prop-edit-mode ()
4640 "Major Mode to edit file properties of files under svn control.
4642 \\{svn-prop-edit-mode-map}"
4644 (kill-all-local-variables)
4645 (use-local-map svn-prop-edit-mode-map)
4646 (easy-menu-add svn-prop-edit-mode-menu)
4647 (setq major-mode 'svn-prop-edit-mode)
4648 (setq mode-name "svn-prop-edit"))
4650 (defun svn-prop-edit-abort ()
4653 (set-window-configuration svn-status-pre-propedit-window-configuration))
4655 (defun svn-prop-edit-done ()
4657 (svn-prop-edit-do-it t))
4659 (defun svn-prop-edit-do-it (async)
4660 "Run svn propset `svn-status-propedit-property-name' with the content of the
4661 *svn-property-edit* buffer."
4662 (message "svn propset %s on %s"
4663 svn-status-propedit-property-name
4664 (mapcar 'svn-status-line-info->filename svn-status-propedit-file-list))
4666 (set-buffer (get-buffer "*svn-property-edit*"))
4667 (when (fboundp 'set-buffer-file-coding-system)
4668 (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
4669 (setq svn-status-temp-file-to-remove
4670 (concat svn-status-temp-dir "svn-prop-edit.txt" svn-temp-suffix))
4671 (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1))
4672 (when svn-status-propedit-file-list ; there are files to change properties
4673 (svn-status-create-arg-file svn-status-temp-arg-file ""
4674 svn-status-propedit-file-list "")
4675 (setq svn-status-propedit-file-list nil)
4676 (svn-run async t 'propset "propset"
4677 svn-status-propedit-property-name
4678 "--targets" svn-status-temp-arg-file
4679 (when (eq svn-status-svn-file-coding-system 'utf-8)
4680 '("--encoding" "UTF-8"))
4681 "-F" (concat svn-status-temp-dir "svn-prop-edit.txt" svn-temp-suffix))
4682 (unless async (svn-status-remove-temp-file-maybe)))
4683 (when svn-status-pre-propedit-window-configuration
4684 (set-window-configuration svn-status-pre-propedit-window-configuration)))
4686 (defun svn-prop-edit-svn-diff (arg)
4688 (set-buffer svn-status-buffer-name)
4689 ;; Because propedit is not recursive in our use, neither is this diff.
4690 (svn-status-show-svn-diff-internal svn-status-propedit-file-list nil
4691 (if arg :ask "BASE")))
4693 (defun svn-prop-edit-svn-log (arg)
4695 (set-buffer svn-status-buffer-name)
4696 (svn-status-show-svn-log arg))
4698 (defun svn-prop-edit-svn-status ()
4700 (pop-to-buffer svn-status-buffer-name)
4703 ;; --------------------------------------------------------------------------------
4704 ;; svn-log-edit-mode:
4705 ;; --------------------------------------------------------------------------------
4707 (defvar svn-log-edit-mode-map () "Keymap used in `svn-log-edit-mode' buffers.")
4708 (put 'svn-log-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
4710 (defvar svn-log-edit-mode-menu) ;really defined with `easy-menu-define' below.
4712 (defun svn-log-edit-common-setup ()
4713 (set (make-local-variable 'paragraph-start) svn-log-edit-paragraph-start)
4714 (set (make-local-variable 'paragraph-separate) svn-log-edit-paragraph-separate))
4716 (if svn-log-edit-use-log-edit-mode
4717 (define-derived-mode svn-log-edit-mode log-edit-mode "svn-log-edit"
4718 "Wrapper around `log-edit-mode' for psvn.el"
4719 (easy-menu-add svn-log-edit-mode-menu)
4720 (setq svn-log-edit-update-log-entry nil)
4721 (set (make-local-variable 'log-edit-callback) 'svn-log-edit-done)
4722 (set (make-local-variable 'log-edit-listfun) 'svn-log-edit-files-to-commit)
4723 (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
4724 (svn-log-edit-common-setup)
4725 (message "Press %s when you are done editing."
4726 (substitute-command-keys "\\[log-edit-done]"))
4728 (defun svn-log-edit-mode ()
4729 "Major Mode to edit svn log messages.
4731 \\{svn-log-edit-mode-map}"
4733 (kill-all-local-variables)
4734 (use-local-map svn-log-edit-mode-map)
4735 (easy-menu-add svn-log-edit-mode-menu)
4736 (setq major-mode 'svn-log-edit-mode)
4737 (setq mode-name "svn-log-edit")
4738 (setq svn-log-edit-update-log-entry nil)
4739 (svn-log-edit-common-setup)
4740 (run-hooks 'svn-log-edit-mode-hook)))
4742 (when (not svn-log-edit-mode-map)
4743 (setq svn-log-edit-mode-map (make-sparse-keymap))
4744 (unless svn-log-edit-use-log-edit-mode
4745 (define-key svn-log-edit-mode-map (kbd "C-c C-c") 'svn-log-edit-done))
4746 (define-key svn-log-edit-mode-map (kbd "C-c C-d") 'svn-log-edit-svn-diff)
4747 (define-key svn-log-edit-mode-map (kbd "C-c C-s") 'svn-log-edit-save-message)
4748 (define-key svn-log-edit-mode-map (kbd "C-c C-i") 'svn-log-edit-svn-status)
4749 (define-key svn-log-edit-mode-map (kbd "C-c C-l") 'svn-log-edit-svn-log)
4750 (define-key svn-log-edit-mode-map (kbd "C-c C-?") 'svn-log-edit-show-files-to-commit)
4751 (define-key svn-log-edit-mode-map (kbd "C-c C-z") 'svn-log-edit-erase-edit-buffer)
4752 (define-key svn-log-edit-mode-map (kbd "C-c C-q") 'svn-log-edit-abort))
4754 (easy-menu-define svn-log-edit-mode-menu svn-log-edit-mode-map
4755 "'svn-log-edit-mode' menu"
4757 ["Save to disk" svn-log-edit-save-message t]
4758 ["Commit" svn-log-edit-done t]
4759 ["Show Diff" svn-log-edit-svn-diff t]
4760 ["Show Status" svn-log-edit-svn-status t]
4761 ["Show Log" svn-log-edit-svn-log t]
4762 ["Show files to commit" svn-log-edit-show-files-to-commit t]
4763 ["Erase buffer" svn-log-edit-erase-edit-buffer]
4764 ["Abort" svn-log-edit-abort t]))
4765 (put 'svn-log-edit-mode-menu 'risky-local-variable t)
4767 (defun svn-log-edit-abort ()
4770 (set-window-configuration svn-status-pre-commit-window-configuration))
4772 (defun svn-log-edit-done ()
4773 "Finish editing the log message and run svn commit."
4775 (svn-status-save-some-buffers)
4777 (set-buffer (get-buffer svn-log-edit-buffer-name))
4778 (when svn-log-edit-insert-files-to-commit
4779 (svn-log-edit-remove-comment-lines))
4780 (when (fboundp 'set-buffer-file-coding-system)
4781 (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
4782 (when (or svn-log-edit-update-log-entry svn-status-files-to-commit)
4783 (setq svn-status-temp-file-to-remove
4784 (concat svn-status-temp-dir "svn-log-edit.txt" svn-temp-suffix))
4785 (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1))
4787 (if svn-log-edit-update-log-entry
4788 (when (y-or-n-p "Update the log entry? ")
4789 ;; svn propset svn:log --revprop -r11672 -F file
4790 (svn-run nil t 'propset "propset" "svn:log" "--revprop"
4791 (concat "-r" svn-log-edit-update-log-entry)
4792 "-F" svn-status-temp-file-to-remove)
4794 (set-buffer svn-process-buffer-name)
4795 (message "%s" (buffer-substring (point-min) (- (point-max) 1)))))
4796 (when svn-status-files-to-commit ; there are files to commit
4797 (setq svn-status-operated-on-dot
4798 (and (= 1 (length svn-status-files-to-commit))
4799 (string= "." (svn-status-line-info->filename (car svn-status-files-to-commit)))))
4800 (svn-status-create-arg-file svn-status-temp-arg-file ""
4801 svn-status-files-to-commit "")
4802 (svn-run t t 'commit "commit"
4803 (unless svn-status-recursive-commit "--non-recursive")
4804 "--targets" svn-status-temp-arg-file
4805 "-F" svn-status-temp-file-to-remove
4806 (when (eq svn-status-svn-file-coding-system 'utf-8)
4807 '("--encoding" "UTF-8"))
4808 svn-status-default-commit-arguments))
4809 (set-window-configuration svn-status-pre-commit-window-configuration)
4810 (message "svn-log editing done")))
4812 (defun svn-log-edit-svn-diff (arg)
4813 "Show the diff we are about to commit.
4814 If ARG then show diff between some other version of the selected files."
4816 (set-buffer svn-status-buffer-name) ; TODO: is this necessary?
4817 ;; This call is very much like `svn-status-show-svn-diff-for-marked-files'
4818 ;; but uses commit-specific variables instead of the current marks.
4819 (svn-status-show-svn-diff-internal svn-status-files-to-commit
4820 svn-status-recursive-commit
4821 (if arg :ask "BASE")))
4823 (defun svn-log-edit-svn-log (arg)
4825 (set-buffer svn-status-buffer-name)
4826 (svn-status-show-svn-log arg))
4828 (defun svn-log-edit-svn-status ()
4830 (pop-to-buffer svn-status-buffer-name)
4833 (defun svn-log-edit-files-to-commit ()
4834 (mapcar 'svn-status-line-info->filename svn-status-files-to-commit))
4836 (defun svn-log-edit-show-files-to-commit ()
4838 (message "Files to commit%s: %S"
4839 (if svn-status-recursive-commit " recursively" "")
4840 (svn-log-edit-files-to-commit)))
4842 (defun svn-log-edit-save-message ()
4843 "Save the current log message to the file `svn-log-edit-file-name'."
4845 (let ((log-edit-file-name (svn-log-edit-file-name)))
4846 (if (string= buffer-file-name log-edit-file-name)
4848 (write-region (point-min) (point-max) log-edit-file-name))))
4850 (defun svn-log-edit-erase-edit-buffer ()
4851 "Delete everything in the `svn-log-edit-buffer-name' buffer."
4853 (set-buffer svn-log-edit-buffer-name)
4856 (defun svn-log-edit-insert-files-to-commit ()
4858 (svn-log-edit-remove-comment-lines)
4859 (let ((buf-size (- (point-max) (point-min))))
4861 (goto-char (point-min))
4862 (insert "## Lines starting with '## ' will be removed from the log message.\n")
4863 (insert "## File(s) to commit"
4864 (if svn-status-recursive-commit " recursively" "") ":\n")
4865 (let ((file-list svn-status-files-to-commit))
4867 (insert (concat "## " (svn-status-line-info->filename (car file-list)) "\n"))
4868 (setq file-list (cdr file-list)))))
4869 (when (= 0 buf-size)
4870 (goto-char (point-max)))))
4872 (defun svn-log-edit-remove-comment-lines ()
4875 (goto-char (point-min))
4876 (flush-lines "^## .*")))
4878 (defun svn-file-add-to-changelog (prefix-arg)
4879 "Create a changelog entry for the function at point.
4880 The variable `svn-status-changelog-style' allows to select the used changlog style"
4882 (cond ((eq svn-status-changelog-style 'changelog)
4883 (svn-file-add-to-log-changelog-style prefix-arg))
4884 ((eq svn-status-changelog-style 'svn-dev)
4885 (svn-file-add-to-log-svn-dev-style prefix-arg))
4886 ((fboundp svn-status-changelog-style)
4887 (funcall svn-status-changelog-style prefix-arg))
4889 (error "Invalid setting for `svn-status-changelog-style'"))))
4891 (defun svn-file-add-to-log-changelog-style (curdir)
4892 "Create a changelog entry for the function at point.
4893 `add-change-log-entry-other-window' creates the header information.
4894 If CURDIR, save the log file in the current directory, otherwise in the base directory of this working copy."
4896 (add-change-log-entry-other-window nil (svn-log-edit-file-name curdir))
4897 (svn-log-edit-mode))
4899 ;; taken from svn-dev.el: svn-log-path-derive
4900 (defun svn-dev-log-path-derive (path)
4901 "Derive a relative directory path for absolute PATH, for a log entry."
4903 (let ((base (file-name-nondirectory path))
4904 (chop-spot (string-match
4905 "\\(code/\\)\\|\\(src/\\)\\|\\(projects/\\)"
4909 (setq path (substring path (match-end 0)))
4910 ;; Kluge for Subversion developers.
4911 (if (string-match "subversion/" path)
4912 (substring path (+ (match-beginning 0) 11))
4914 (string-match (expand-file-name "~/") path)
4915 (substring path (match-end 0))))))
4917 ;; taken from svn-dev.el: svn-log-message
4918 (defun svn-file-add-to-log-svn-dev-style (prefix-arg)
4919 "Add to an in-progress log message, based on context around point.
4920 If PREFIX-ARG is negative, then use basenames only in
4921 log messages, otherwise use full paths. The current defun name is
4924 If PREFIX-ARG is a list (e.g. by using C-u), save the log file in
4925 the current directory, otherwise in the base directory of this
4928 If the log message already contains material about this defun, then put
4929 point there, so adding to that material is easy.
4931 Else if the log message already contains material about this file, put
4932 point there, and push onto the kill ring the defun name with log
4933 message dressing around it, plus the raw defun name, so yank and
4934 yank-next are both useful.
4936 Else if there is no material about this defun nor file anywhere in the
4937 log message, then put point at the end of the message and insert a new
4938 entry for file with defun.
4941 (let* ((short-file-names (and (numberp prefix-arg) (< prefix-arg 0)))
4942 (curdir (listp prefix-arg))
4943 (this-file (if short-file-names
4944 (file-name-nondirectory buffer-file-name)
4945 (svn-dev-log-path-derive buffer-file-name)))
4946 (this-defun (or (add-log-current-defun)
4949 (if (eq major-mode 'c-mode)
4951 (if (fboundp 'c-beginning-of-statement-1)
4952 (c-beginning-of-statement-1)
4953 (c-beginning-of-statement))
4954 (search-forward "(" nil t)
4959 (progn (forward-sexp 1) (point)))))))))
4960 (log-file (svn-log-edit-file-name curdir)))
4961 (find-file log-file)
4962 (goto-char (point-min))
4963 ;; Strip text properties from strings
4964 (set-text-properties 0 (length this-file) nil this-file)
4965 (set-text-properties 0 (length this-defun) nil this-defun)
4966 ;; If log message for defun already in progress, add to it
4968 this-defun ;; we have a defun to work with
4969 (search-forward this-defun nil t) ;; it's in the log msg already
4970 (save-excursion ;; and it's about the same file
4972 (if (re-search-backward ; Ick, I want a real filename regexp!
4973 "^\\*\\s-+\\([a-zA-Z0-9-_.@=+^$/%!?(){}<>]+\\)" nil t)
4974 (string-equal (match-string 1) this-file)
4976 (if (re-search-forward ":" nil t)
4977 (if (looking-at " ") (forward-char 1)))
4978 ;; Else no log message for this defun in progress...
4979 (goto-char (point-min))
4980 ;; But if log message for file already in progress, add to it.
4981 (if (search-forward this-file nil t)
4983 (if this-defun (progn
4984 (kill-new (format "(%s): " this-defun))
4985 (kill-new this-defun)))
4986 (search-forward ")" nil t)
4987 (if (looking-at " ") (forward-char 1)))
4988 ;; Found neither defun nor its file, so create new entry.
4989 (goto-char (point-max))
4990 (if (not (bolp)) (insert "\n"))
4991 (insert (format "\n* %s (%s): " this-file (or this-defun "")))
4992 ;; Finally, if no derived defun, put point where the user can
4993 ;; type it themselves.
4994 (if (not this-defun) (forward-char -3))))))
4996 ;; --------------------------------------------------------------------------------
4997 ;; svn-log-view-mode:
4998 ;; --------------------------------------------------------------------------------
5000 (defvar svn-log-view-mode-map () "Keymap used in `svn-log-view-mode' buffers.")
5001 (put 'svn-log-view-mode-map 'risky-local-variable t) ;for Emacs 20.7
5003 (when (not svn-log-view-mode-map)
5004 (setq svn-log-view-mode-map (make-sparse-keymap))
5005 (suppress-keymap svn-log-view-mode-map)
5006 (define-key svn-log-view-mode-map (kbd "p") 'svn-log-view-prev)
5007 (define-key svn-log-view-mode-map (kbd "n") 'svn-log-view-next)
5008 (define-key svn-log-view-mode-map (kbd "~") 'svn-log-get-specific-revision)
5009 (define-key svn-log-view-mode-map (kbd "E") 'svn-log-ediff-specific-revision)
5010 (define-key svn-log-view-mode-map (kbd "=") 'svn-log-view-diff)
5011 (define-key svn-log-view-mode-map (kbd "TAB") 'svn-log-next-link)
5012 (define-key svn-log-view-mode-map [backtab] 'svn-log-prev-link)
5013 (define-key svn-log-view-mode-map (kbd "RET") 'svn-log-find-file-at-point)
5014 (define-key svn-log-view-mode-map (kbd "e") 'svn-log-edit-log-entry)
5015 (define-key svn-log-view-mode-map (kbd "q") 'bury-buffer))
5017 (defvar svn-log-view-popup-menu-map ()
5018 "Keymap used to show popup menu in `svn-log-view-mode' buffers.")
5019 (put 'svn-log-view-popup-menu-map 'risky-local-variable t) ;for Emacs 20.7
5020 (when (not svn-log-view-popup-menu-map)
5021 (setq svn-log-view-popup-menu-map (make-sparse-keymap))
5022 (suppress-keymap svn-log-view-popup-menu-map)
5023 (define-key svn-log-view-popup-menu-map [down-mouse-3] 'svn-log-view-popup-menu))
5025 (easy-menu-define svn-log-view-mode-menu svn-log-view-mode-map
5026 "'svn-log-view-mode' menu"
5028 ["Show Changeset" svn-log-view-diff t]
5029 ["Ediff file at point" svn-log-ediff-specific-revision t]
5030 ["Find file at point" svn-log-find-file-at-point t]
5031 ["Get older revision for file at point" svn-log-get-specific-revision t]
5032 ["Edit log message" svn-log-edit-log-entry t]))
5034 (defun svn-log-view-popup-menu (event)
5036 (mouse-set-point event)
5037 (let* ((rev (svn-log-revision-at-point)))
5039 (svn-status-face-set-temporary-during-popup
5040 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
5041 svn-log-view-mode-menu))))
5043 (defvar svn-log-view-font-lock-basic-keywords
5044 '(("^r[0-9]+ .+" (0 `(face font-lock-keyword-face
5045 mouse-face highlight
5046 keymap ,svn-log-view-popup-menu-map))))
5047 "Basic keywords in `svn-log-view-mode'.")
5048 (put 'svn-log-view-font-basic-lock-keywords 'risky-local-variable t) ;for Emacs 20.7
5050 (defvar svn-log-view-font-lock-keywords)
5051 (define-derived-mode svn-log-view-mode fundamental-mode "svn-log-view"
5052 "Major Mode to show the output from svn log.
5054 \\{svn-log-view-mode-map}
5056 (use-local-map svn-log-view-mode-map)
5057 (easy-menu-add svn-log-view-mode-menu)
5058 (set (make-local-variable 'svn-log-view-font-lock-keywords) svn-log-view-font-lock-basic-keywords)
5059 (dolist (lh svn-log-link-handlers)
5060 (add-to-list 'svn-log-view-font-lock-keywords (gethash lh svn-log-registered-link-handlers)))
5061 (set (make-local-variable 'font-lock-defaults) '(svn-log-view-font-lock-keywords t)))
5063 (defun svn-log-view-next ()
5065 (when (re-search-forward "^r[0-9]+" nil t)
5066 (beginning-of-line 2)
5067 (unless (looking-at "Changed paths:")
5068 (beginning-of-line 1))))
5070 (defun svn-log-view-prev ()
5072 (when (re-search-backward "^r[0-9]+" nil t 2)
5073 (beginning-of-line 2)
5074 (unless (looking-at "Changed paths:")
5075 (beginning-of-line 1))))
5077 (defun svn-log-revision-at-point ()
5080 (re-search-backward "^r\\([0-9]+\\)")
5081 (svn-match-string-no-properties 1)))
5083 (defun svn-log-file-name-at-point (respect-checkout-prefix-path)
5084 (let ((full-file-name)
5086 (checkout-prefix-path (if respect-checkout-prefix-path
5088 (svn-status-checkout-prefix-path))
5092 (when (looking-at " [MA] /\\(.+\\)$")
5093 (setq full-file-name (svn-match-string-no-properties 1))))
5094 (when (string= checkout-prefix-path "")
5095 (setq checkout-prefix-path "/"))
5096 (if (null full-file-name)
5098 (message "No file at point")
5101 (if (eq (string-match (regexp-quote (substring checkout-prefix-path 1)) full-file-name) 0)
5102 (substring full-file-name (- (length checkout-prefix-path) (if (string= checkout-prefix-path "/") 1 0)))
5104 ;; (message "svn-log-file-name-at-point %s prefix: '%s', full-file-name: %s" file-name checkout-prefix-path full-file-name)
5107 (defun svn-log-find-file-at-point ()
5109 (let ((file-name (svn-log-file-name-at-point t)))
5111 (let ((default-directory (svn-status-base-dir)))
5112 ;;(message "svn-log-file-name-at-point: %s, default-directory: %s" file-name default-directory)
5113 (find-file file-name)))))
5115 (defun svn-log-next-link ()
5116 "Jump to the next external link in this buffer"
5118 (let ((start-pos (if (get-text-property (point) 'link-handler)
5119 (next-single-property-change (point) 'link-handler)
5121 (goto-char (or (next-single-property-change start-pos 'link-handler) (point)))))
5123 (defun svn-log-prev-link ()
5124 "Jump to the previous external link in this buffer"
5126 (let ((start-pos (if (get-text-property (point) 'link-handler)
5127 (previous-single-property-change (point) 'link-handler)
5129 (goto-char (or (previous-single-property-change (or start-pos (point)) 'link-handler) (point)))))
5131 (defun svn-log-view-diff (arg)
5132 "Show the changeset for a given log entry.
5133 When called with a prefix argument, ask the user for the revision."
5135 (svn-status-diff-show-changeset (svn-log-revision-at-point) arg))
5137 (defun svn-log-get-specific-revision ()
5138 "Get an older revision of the file at point via svn cat."
5140 ;; (message "%S" (svn-status-make-line-info (svn-log-file-name-at-point t)))
5141 (let ((default-directory (svn-status-base-dir)))
5142 (svn-status-get-specific-revision-internal
5143 (list (svn-status-make-line-info (svn-log-file-name-at-point t)))
5144 (svn-log-revision-at-point)
5147 (defun svn-log-ediff-specific-revision ()
5148 "Call ediff for the file at point to view a changeset"
5150 ;; (message "svn-log-ediff-specific-revision: %s" (svn-log-file-name-at-point t))
5151 (let* ((cur-buf (current-buffer))
5152 (upper-rev (svn-log-revision-at-point))
5153 (lower-rev (number-to-string (- (string-to-number upper-rev) 1)))
5154 (file-name (svn-log-file-name-at-point t))
5155 (default-directory (svn-status-base-dir))
5156 (upper-rev-file-name (when file-name
5157 (cdar (svn-status-get-specific-revision-internal
5158 (list (svn-status-make-line-info file-name)) upper-rev nil))))
5159 (lower-rev-file-name (when file-name
5160 (cdar (svn-status-get-specific-revision-internal
5161 (list (svn-status-make-line-info file-name)) lower-rev nil)))))
5162 ;;(message "%S %S" upper-rev-file-name lower-rev-file-name)
5164 (let* ((ediff-after-quit-destination-buffer cur-buf)
5165 (newer-buffer (find-file-noselect upper-rev-file-name))
5166 (base-buff (find-file-noselect lower-rev-file-name))
5167 (svn-transient-buffers (list base-buff newer-buffer))
5168 (startup-hook '(svn-ediff-startup-hook)))
5169 (ediff-buffers base-buff newer-buffer startup-hook))
5170 (message "No file at point"))))
5172 (defun svn-log-edit-log-entry ()
5173 "Edit the given log entry."
5175 (let ((rev (svn-log-revision-at-point))
5177 (svn-run nil t 'propget-parse "propget" "--revprop" (concat "-r" rev) "svn:log")
5179 (set-buffer svn-process-buffer-name)
5180 (setq log-message (if (> (point-max) 1)
5181 (buffer-substring (point-min) (- (point-max) 1))
5183 (svn-status-pop-to-commit-buffer)
5184 ;; If the buffer has been narrowed, `svn-log-edit-done' will use
5185 ;; only the accessible part. So we need not erase the rest here.
5186 (delete-region (point-min) (point-max))
5187 (insert log-message)
5188 (goto-char (point-min))
5189 (setq svn-log-edit-update-log-entry rev)))
5192 ;; allow additional hyperlinks in log view buffers
5193 (defvar svn-log-link-keymap ()
5194 "Keymap used to resolve links `svn-log-view-mode' buffers.")
5195 (put 'svn-log-link-keymap 'risky-local-variable t) ;for Emacs 20.7
5196 (when (not svn-log-link-keymap)
5197 (setq svn-log-link-keymap (make-sparse-keymap))
5198 (suppress-keymap svn-log-link-keymap)
5199 (define-key svn-log-link-keymap [mouse-2] 'svn-log-resolve-mouse-link)
5200 (define-key svn-log-link-keymap (kbd "RET") 'svn-log-resolve-link))
5202 (defun svn-log-resolve-mouse-link (event)
5204 (mouse-set-point event)
5205 (svn-log-resolve-link))
5207 (defun svn-log-resolve-link ()
5209 (let* ((point-adjustment (if (not (get-text-property (- (point) 1) 'link-handler)) 1
5210 (if (not (get-text-property (+ (point) 1) 'link-handler)) -1 0)))
5211 (link-name (buffer-substring-no-properties (previous-single-property-change (+ (point) point-adjustment) 'link-handler)
5212 (next-single-property-change (+ (point) point-adjustment) 'link-handler))))
5213 ;; (message "svn-log-resolve-link '%s'" link-name)
5214 (funcall (get-text-property (point) 'link-handler) link-name)))
5216 (defun svn-log-register-link-handler (handler-id link-regexp handler-function)
5217 "Register a link handler for external links in *svn-log* buffers
5218 HANDLER-ID is a symbolic name for this handler. The link handler is active when HANDLER-ID
5219 is registered in `svn-log-link-handlers'.
5220 LINK-REGEXP specifies a regular expression that matches the external link.
5221 HANDLER-FUNCTION is called with the match of LINK-REGEXP when the user clicks at the external link."
5222 (let ((font-lock-desc (list link-regexp '(0 `(face font-lock-function-name-face
5223 mouse-face highlight
5224 link-handler invalid-handler-function
5225 keymap ,svn-log-link-keymap)))))
5226 ;; no idea, how to use handler-function in invalid-handler-function above, so set it here
5227 (setcar (nthcdr 5 (nth 1 (nth 1 (nth 1 font-lock-desc)))) handler-function)
5228 (svn-puthash handler-id font-lock-desc svn-log-registered-link-handlers)))
5230 ;; example: add support for ditrack links and handle them via svn-log-resolve-ditrack
5231 ;;(svn-log-register-link-handler 'ditrack-issue "i#[0-9]+" 'svn-log-resolve-ditrack)
5232 ;;(defun svn-log-resolve-ditrack (link-name)
5234 ;; (message "svn-log-resolve-ditrack %s" link-name))
5237 (defun svn-log-resolve-trac-ticket-short (link-name)
5238 "Show the trac ticket specified by LINK-NAME via `svn-trac-browse-ticket'."
5240 (let ((ticket-nr (string-to-number (substring-no-properties link-name 1))))
5241 (svn-trac-browse-ticket ticket-nr)))
5243 ;; register the out of the box provided link handlers
5244 (svn-log-register-link-handler 'trac-ticket-short "#[0-9]+" 'svn-log-resolve-trac-ticket-short)
5246 ;; the actually used link handlers are specified in svn-log-link-handlers
5248 ;; --------------------------------------------------------------------------------
5250 ;; --------------------------------------------------------------------------------
5251 (defvar svn-info-mode-map () "Keymap used in `svn-info-mode' buffers.")
5252 (put 'svn-info-mode-map 'risky-local-variable t) ;for Emacs 20.7
5254 (when (not svn-info-mode-map)
5255 (setq svn-info-mode-map (make-sparse-keymap))
5256 (define-key svn-info-mode-map [?s] 'svn-status-pop-to-status-buffer)
5257 (define-key svn-info-mode-map (kbd "h") 'svn-status-pop-to-partner-buffer)
5258 (define-key svn-info-mode-map (kbd "n") 'next-line)
5259 (define-key svn-info-mode-map (kbd "p") 'previous-line)
5260 (define-key svn-info-mode-map (kbd "RET") 'svn-info-show-context)
5261 (define-key svn-info-mode-map [?q] 'bury-buffer))
5263 (defun svn-info-mode ()
5264 "Major Mode to view informative output from svn."
5266 (kill-all-local-variables)
5267 (use-local-map svn-info-mode-map)
5268 (setq major-mode 'svn-info-mode)
5269 (setq mode-name "svn-info")
5270 (toggle-read-only 1))
5272 (defun svn-info-show-context ()
5273 "Show the context for a line in the info buffer.
5274 Currently is the output from the svn update command known."
5276 (cond ((save-excursion
5277 (goto-char (point-max))
5280 (looking-at "Updated to revision"))
5281 ;; svn-info contains info from an svn update
5282 (let ((cur-pos (point))
5283 (file-name (buffer-substring-no-properties
5284 (progn (beginning-of-line) (re-search-forward ".. +") (point))
5285 (line-end-position)))
5288 (with-current-buffer svn-status-buffer-name
5289 (setq pos (svn-status-get-file-name-buffer-position file-name)))
5291 (svn-status-pop-to-new-partner-buffer svn-status-buffer-name)
5292 (goto-char pos))))))
5294 ;; --------------------------------------------------------------------------------
5295 ;; svn blame minor mode
5296 ;; --------------------------------------------------------------------------------
5298 (unless (assq 'svn-blame-mode minor-mode-alist)
5299 (setq minor-mode-alist
5300 (cons (list 'svn-blame-mode " SvnBlame")
5303 (defvar svn-blame-mode-map () "Keymap used in `svn-blame-mode' buffers.")
5304 (put 'svn-blame-mode-map 'risky-local-variable t) ;for Emacs 20.7
5306 (when (not svn-blame-mode-map)
5307 (setq svn-blame-mode-map (make-sparse-keymap))
5308 (define-key svn-blame-mode-map [?s] 'svn-status-pop-to-status-buffer)
5309 (define-key svn-blame-mode-map (kbd "n") 'next-line)
5310 (define-key svn-blame-mode-map (kbd "p") 'previous-line)
5311 (define-key svn-blame-mode-map (kbd "RET") 'svn-blame-open-source-file)
5312 (define-key svn-blame-mode-map (kbd "a") 'svn-blame-highlight-author)
5313 (define-key svn-blame-mode-map (kbd "r") 'svn-blame-highlight-revision)
5314 (define-key svn-blame-mode-map (kbd "=") 'svn-blame-show-changeset)
5315 (define-key svn-blame-mode-map (kbd "l") 'svn-blame-show-log)
5316 (define-key svn-blame-mode-map [?q] 'bury-buffer))
5318 (easy-menu-define svn-blame-mode-menu svn-blame-mode-map
5319 "svn blame minor mode menu"
5321 ["Jump to source location" svn-blame-open-source-file t]
5322 ["Show changeset" svn-blame-show-changeset t]
5323 ["Show log" svn-blame-show-log t]
5324 ["Highlight by author" svn-blame-highlight-author t]
5325 ["Highlight by revision" svn-blame-highlight-revision t]))
5327 (or (assq 'svn-blame-mode minor-mode-map-alist)
5328 (setq minor-mode-map-alist
5329 (cons (cons 'svn-blame-mode svn-blame-mode-map) minor-mode-map-alist)))
5331 (make-variable-buffer-local 'svn-blame-mode)
5333 (defun svn-blame-mode (&optional arg)
5334 "Toggle svn blame minor mode.
5335 With ARG, turn svn blame minor mode on if ARG is positive, off otherwise.
5337 Note: This mode does not yet work on XEmacs...
5338 It is probably because the revisions are in 'before-string properties of overlays
5341 \\{svn-blame-mode-map}"
5343 (setq svn-blame-mode (if (null arg)
5344 (not svn-blame-mode)
5345 (> (prefix-numeric-value arg) 0)))
5348 (easy-menu-add svn-blame-mode-menu)
5349 (toggle-read-only 1))
5350 (easy-menu-remove svn-blame-mode-menu))
5351 (force-mode-line-update))
5353 (defun svn-status-activate-blame-mode ()
5354 "Activate the svn blame minor in the current buffer.
5355 The current buffer must contain a valid output from svn blame"
5357 (goto-char (point-min))
5358 (let ((buffer-read-only nil)
5359 (line (svn-line-number-at-pos))
5361 (info-end-col (save-excursion (forward-word 2) (+ (current-column) 1)))
5364 ;; remove the old overlays (only for testing)
5365 ;; (dolist (ov (overlays-in (point) limit))
5366 ;; (when (overlay-get ov 'svn-blame-line-info)
5367 ;; (delete-overlay ov)))
5368 (while (and (not (eobp)) (< (point) limit))
5369 (setq ov (make-overlay (point) (point)))
5370 (overlay-put ov 'svn-blame-line-info t)
5371 (setq s (buffer-substring-no-properties (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col)))
5372 (overlay-put ov 'before-string (propertize s 'face 'svn-status-blame-rev-number-face))
5373 (overlay-put ov 'rev-info (delete "" (split-string s " ")))
5374 (delete-region (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col))
5376 (setq line (1+ line)))))
5377 (let* ((buf-name (format "*svn-blame: %s*" (file-relative-name svn-status-blame-file-name)))
5378 (buffer (get-buffer buf-name)))
5380 (kill-buffer buffer))
5381 (rename-buffer buf-name))
5382 ;; use the correct mode for the displayed blame output
5383 (let ((buffer-file-name svn-status-blame-file-name))
5385 (set (make-local-variable 'svn-status-blame-file-name) svn-status-blame-file-name))
5386 (font-lock-fontify-buffer)
5389 (defun svn-blame-open-source-file ()
5390 "Jump to the source file location for the current position in the svn blame buffer"
5392 (let ((src-line-number (svn-line-number-at-pos))
5393 (src-line-col (current-column)))
5394 (find-file-other-window svn-status-blame-file-name)
5395 (goto-line src-line-number)
5396 (forward-char src-line-col)))
5398 (defun svn-blame-rev-at-point ()
5400 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5401 (when (overlay-get ov 'svn-blame-line-info)
5402 (setq rev (car (overlay-get ov 'rev-info)))))
5405 (defun svn-blame-show-changeset (arg)
5406 "Show a diff for the revision at point.
5407 When called with a prefix argument, allow the user to edit the revision."
5409 (svn-status-diff-show-changeset (svn-blame-rev-at-point) arg))
5411 (defun svn-blame-show-log (arg)
5412 "Show the log for the revision at point.
5413 The output is put into the *svn-log* buffer
5414 The optional prefix argument ARG determines which switches are passed to `svn log':
5415 no prefix --- use whatever is in the list `svn-status-default-log-arguments'
5416 prefix argument of -1: --- use the -q switch (quiet)
5417 prefix argument of 0 --- use no arguments
5418 other prefix arguments: --- use the -v switch (verbose)"
5420 (let ((switches (svn-status-svn-log-switches arg))
5421 (rev (svn-blame-rev-at-point)))
5422 (svn-run t t 'log "log" "--revision" rev switches)))
5424 (defun svn-blame-highlight-line-maybe (compare-func)
5425 (let ((reference-value)
5427 (consider-this-line)
5429 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5430 (when (overlay-get ov 'svn-blame-line-info)
5431 (setq reference-value (funcall compare-func ov)))
5432 (when (overlay-get ov 'svn-blame-highlighted)
5433 (setq is-highlighted t)))
5435 (goto-char (point-min))
5437 (setq consider-this-line nil)
5438 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5439 (when (overlay-get ov 'svn-blame-line-info)
5440 (when (string= reference-value (funcall compare-func ov))
5441 (setq consider-this-line t))))
5442 (when consider-this-line
5443 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5444 (when (and (overlay-get ov 'svn-blame-highlighted) is-highlighted)
5445 (delete-overlay ov))
5446 (unless is-highlighted
5447 (setq hl-ov (make-overlay (svn-point-at-bol) (line-end-position)))
5448 (overlay-put hl-ov 'svn-blame-highlighted t)
5449 (overlay-put hl-ov 'face 'svn-status-blame-highlight-face))))
5452 (defun svn-blame-highlight-author-field (ov)
5453 (cadr (overlay-get ov 'rev-info)))
5455 (defun svn-blame-highlight-author ()
5456 "(Un)Highlight all lines with the same author."
5458 (svn-blame-highlight-line-maybe 'svn-blame-highlight-author-field))
5460 (defun svn-blame-highlight-revision-field (ov)
5461 (car (overlay-get ov 'rev-info)))
5463 (defun svn-blame-highlight-revision ()
5464 "(Un)Highlight all lines with the same revision."
5466 (svn-blame-highlight-line-maybe 'svn-blame-highlight-revision-field))
5468 ;; --------------------------------------------------------------------------------
5470 ;; --------------------------------------------------------------------------------
5471 (defvar svn-process-mode-map () "Keymap used in `svn-process-mode' buffers.")
5472 (put 'svn-process-mode-map 'risky-local-variable t) ;for Emacs 20.7
5474 (when (not svn-process-mode-map)
5475 (setq svn-process-mode-map (make-sparse-keymap))
5476 (define-key svn-process-mode-map (kbd "RET") 'svn-process-send-string-and-newline)
5477 (define-key svn-process-mode-map [?s] 'svn-process-send-string)
5478 (define-key svn-process-mode-map [?q] 'bury-buffer))
5480 (easy-menu-define svn-process-mode-menu svn-process-mode-map
5481 "'svn-process-mode' menu"
5483 ["Send line to process" svn-process-send-string-and-newline t]
5484 ["Send raw string to process" svn-process-send-string t]
5485 ["Bury process buffer" bury-buffer t]))
5487 (defun svn-process-mode ()
5488 "Major Mode to view process output from svn.
5490 You can send a new line terminated string to the process via \\[svn-process-send-string-and-newline]
5491 You can send raw data to the process via \\[svn-process-send-string]."
5493 (kill-all-local-variables)
5494 (use-local-map svn-process-mode-map)
5495 (easy-menu-add svn-log-view-mode-menu)
5496 (setq major-mode 'svn-process-mode)
5497 (setq mode-name "svn-process"))
5499 ;; --------------------------------------------------------------------------------
5500 ;; svn status persistent options
5501 ;; --------------------------------------------------------------------------------
5503 (defun svn-status-repo-for-path (directory)
5504 "Find the repository root for DIRECTORY."
5505 (let ((old-process-default-dir))
5506 (with-current-buffer (get-buffer-create svn-process-buffer-name)
5507 (setq old-process-default-dir default-directory)
5508 (setq default-directory directory)) ;; update the default-directory for the *svn-process* buffer
5509 (svn-run nil t 'parse-info "info" ".")
5510 (with-current-buffer svn-process-buffer-name
5511 ;; (message "svn-status-repo-for-path: %s: default-directory: %s directory: %s old-process-default-dir: %s" svn-process-buffer-name default-directory directory old-process-default-dir)
5512 (setq default-directory old-process-default-dir)
5513 (goto-char (point-min))
5514 (let ((case-fold-search t))
5515 (if (search-forward "repository root: " nil t)
5516 (buffer-substring-no-properties (point) (svn-point-at-eol))
5517 (when (search-forward "repository uuid: " nil t)
5518 (message "psvn.el: Detected an old svn working copy in '%s'. Please check it out again to get a 'Repository Root' entry in the svn info output."
5520 (concat "Svn Repo UUID: " (buffer-substring-no-properties (point) (svn-point-at-eol)))))))))
5522 (defun svn-status-base-dir (&optional start-directory)
5523 "Find the svn root directory for the current working copy.
5524 Return nil, if not in a svn working copy."
5525 (let* ((start-dir (expand-file-name (or start-directory default-directory)))
5526 (base-dir (gethash start-dir svn-status-base-dir-cache 'not-found)))
5527 ;;(message "svn-status-base-dir: %S %S" start-dir base-dir)
5528 (if (not (eq base-dir 'not-found))
5530 ;; (message "calculating base-dir for %s" start-dir)
5531 (unless svn-client-version
5532 (svn-status-version))
5533 (let* ((base-dir start-dir)
5534 (repository-root (svn-status-repo-for-path base-dir))
5535 (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
5536 (in-tree (and repository-root (file-exists-p dot-svn-dir)))
5537 (dir-below (expand-file-name base-dir)))
5538 ;; (message "repository-root: %s start-dir: %s" repository-root start-dir)
5539 (if (and (<= (car svn-client-version) 1) (< (cadr svn-client-version) 3))
5540 (setq base-dir (svn-status-base-dir-for-ancient-svn-client start-dir)) ;; svn version < 1.3
5541 (while (when (and dir-below (file-exists-p dot-svn-dir))
5542 (setq base-dir (file-name-directory dot-svn-dir))
5543 (string-match "\\(.+/\\).+/" dir-below)
5545 (and (string-match "\\(.*/\\)[^/]+/" dir-below)
5546 (match-string 1 dir-below)))
5547 ;; (message "base-dir: %s, dir-below: %s, dot-svn-dir: %s in-tree: %s" base-dir dir-below dot-svn-dir in-tree)
5549 (if (string= (svn-status-repo-for-path dir-below) repository-root)
5550 (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))
5551 (setq dir-below nil)))))
5552 (setq base-dir (and in-tree base-dir)))
5553 (svn-puthash start-dir base-dir svn-status-base-dir-cache)
5554 (svn-status-message 7 "svn-status-base-dir %s => %s" start-dir base-dir)
5557 (defun svn-status-base-dir-for-ancient-svn-client (&optional start-directory)
5558 "Find the svn root directory for the current working copy.
5559 Return nil, if not in a svn working copy.
5560 This function is used for svn clients version 1.2 and below."
5561 (let* ((base-dir (expand-file-name (or start-directory default-directory)))
5562 (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
5563 (in-tree (file-exists-p dot-svn-dir))
5564 (dir-below (expand-file-name default-directory)))
5565 (while (when (and dir-below (file-exists-p dot-svn-dir))
5566 (setq base-dir (file-name-directory dot-svn-dir))
5567 (string-match "\\(.+/\\).+/" dir-below)
5569 (and (string-match "\\(.*/\\)[^/]+/" dir-below)
5570 (match-string 1 dir-below)))
5571 (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))))
5572 (and in-tree base-dir)))
5574 (defun svn-status-save-state ()
5575 "Save psvn persistent options for this working copy to a file."
5577 (let ((buf (find-file (concat (svn-status-base-dir) "++psvn.state"))))
5578 (erase-buffer) ;Widen, because we'll save the whole buffer.
5579 ;; TO CHECK: why is svn-status-options a global variable??
5580 (setq svn-status-options
5582 (list "svn-trac-project-root" svn-trac-project-root)
5583 (list "sort-status-buffer" svn-status-sort-status-buffer)
5584 (list "elide-list" svn-status-elided-list)
5585 (list "module-name" svn-status-module-name)
5586 (list "branch-list" svn-status-branch-list)
5587 (list "changelog-style" svn-status-changelog-style)
5589 (insert (pp-to-string svn-status-options))
5593 (defun svn-status-load-state (&optional no-error)
5594 "Load psvn persistent options for this working copy from a file."
5596 (let ((file (concat (svn-status-base-dir) "++psvn.state")))
5597 (if (file-readable-p file)
5599 (insert-file-contents file)
5600 (setq svn-status-options (read (current-buffer)))
5601 (setq svn-status-sort-status-buffer
5602 (nth 1 (assoc "sort-status-buffer" svn-status-options)))
5603 (setq svn-trac-project-root
5604 (nth 1 (assoc "svn-trac-project-root" svn-status-options)))
5605 (setq svn-status-elided-list
5606 (nth 1 (assoc "elide-list" svn-status-options)))
5607 (setq svn-status-module-name
5608 (nth 1 (assoc "module-name" svn-status-options)))
5609 (setq svn-status-branch-list
5610 (nth 1 (assoc "branch-list" svn-status-options)))
5611 (setq svn-status-changelog-style
5612 (nth 1 (assoc "changelog-style" svn-status-options)))
5613 (when (and (interactive-p) svn-status-elided-list (svn-status-apply-elide-list)))
5614 (message "psvn.el: loaded %s" file))
5616 (setq svn-trac-project-root nil
5617 svn-status-elided-list nil
5618 svn-status-module-name nil
5619 svn-status-branch-list nil
5620 svn-status-changelog-style 'changelog)
5621 (error "psvn.el: %s is not readable." file)))))
5623 (defun svn-status-toggle-sort-status-buffer ()
5624 "Toggle sorting of the *svn-status* buffer.
5626 If you turn off sorting, you can speed up \\[svn-status]. However,
5627 the buffer is not correctly sorted then. This function will be
5628 removed again, when a faster parsing and display routine for
5629 `svn-status' is available."
5631 (setq svn-status-sort-status-buffer (not svn-status-sort-status-buffer))
5632 (message "The %s buffer will %sbe sorted." svn-status-buffer-name
5633 (if svn-status-sort-status-buffer "" "not ")))
5635 (defun svn-status-toggle-svn-verbose-flag ()
5636 "Toggle `svn-status-verbose'. "
5638 (setq svn-status-verbose (not svn-status-verbose))
5639 (message "svn status calls will %suse the -v flag." (if svn-status-verbose "" "not ")))
5641 (defun svn-status-toggle-display-full-path ()
5642 "Toggle displaying the full path in the `svn-status-buffer-name' buffer"
5644 (setq svn-status-display-full-path (not svn-status-display-full-path))
5645 (message "The %s buffer will%s use full path names." svn-status-buffer-name
5646 (if svn-status-display-full-path "" " not"))
5647 (svn-status-update-buffer))
5649 (defun svn-status-set-trac-project-root ()
5651 (setq svn-trac-project-root
5652 (read-string "Trac project root (e.g.: http://projects.edgewall.com/trac/): "
5653 svn-trac-project-root))
5654 (when (yes-or-no-p "Save the new setting for svn-trac-project-root to disk? ")
5655 (svn-status-save-state)))
5657 (defun svn-status-set-module-name ()
5658 "Interactively set `svn-status-module-name'."
5660 (setq svn-status-module-name
5661 (read-string "Short Unit Name (e.g.: MyProject): "
5662 svn-status-module-name))
5663 (when (yes-or-no-p "Save the new setting for svn-status-module-name to disk? ")
5664 (svn-status-save-state)))
5666 (defun svn-status-set-changelog-style ()
5667 "Interactively set `svn-status-changelog-style'."
5669 (setq svn-status-changelog-style
5670 (intern (funcall svn-status-completing-read-function "svn-status on directory: " '("changelog" "svn-dev" "other"))))
5671 (when (string= svn-status-changelog-style 'other)
5672 (setq svn-status-changelog-style (car (find-function-read))))
5673 (when (yes-or-no-p "Save the new setting for svn-status-changelog-style to disk? ")
5674 (svn-status-save-state)))
5676 (defun svn-status-set-branch-list ()
5677 "Interactively set `svn-status-branch-list'."
5679 (setq svn-status-branch-list
5680 (split-string (read-string "Branch list: "
5681 (mapconcat 'identity svn-status-branch-list " "))))
5682 (when (yes-or-no-p "Save the new setting for svn-status-branch-list to disk? ")
5683 (svn-status-save-state)))
5685 (defun svn-browse-url (url)
5686 "Call `browse-url', using `svn-browse-url-function'."
5687 (let ((browse-url-browser-function (or svn-browse-url-function
5688 browse-url-browser-function)))
5691 ;; --------------------------------------------------------------------------------
5692 ;; svn status trac integration
5693 ;; --------------------------------------------------------------------------------
5694 (defun svn-trac-browse-wiki ()
5695 "Open the trac wiki view for the current svn repository."
5697 (unless svn-trac-project-root
5698 (svn-status-set-trac-project-root))
5699 (svn-browse-url (concat svn-trac-project-root "wiki")))
5701 (defun svn-trac-browse-timeline ()
5702 "Open the trac timeline view for the current svn repository."
5704 (unless svn-trac-project-root
5705 (svn-status-set-trac-project-root))
5706 (svn-browse-url (concat svn-trac-project-root "timeline")))
5708 (defun svn-trac-browse-roadmap ()
5709 "Open the trac roadmap view for the current svn repository."
5711 (unless svn-trac-project-root
5712 (svn-status-set-trac-project-root))
5713 (svn-browse-url (concat svn-trac-project-root "roadmap")))
5715 (defun svn-trac-browse-source ()
5716 "Open the trac source browser for the current svn repository."
5718 (unless svn-trac-project-root
5719 (svn-status-set-trac-project-root))
5720 (svn-browse-url (concat svn-trac-project-root "browser")))
5722 (defun svn-trac-browse-report (arg)
5723 "Open the trac report view for the current svn repository.
5724 When called with a prefix argument, display the given report number."
5726 (unless svn-trac-project-root
5727 (svn-status-set-trac-project-root))
5728 (svn-browse-url (concat svn-trac-project-root "report" (if (numberp arg) (format "/%s" arg) ""))))
5730 (defun svn-trac-browse-changeset (changeset-nr)
5731 "Show a changeset in the trac issue tracker."
5732 (interactive (list (read-number "Browse changeset number: " (number-at-point))))
5733 (unless svn-trac-project-root
5734 (svn-status-set-trac-project-root))
5735 (svn-browse-url (concat svn-trac-project-root "changeset/" (number-to-string changeset-nr))))
5737 (defun svn-trac-browse-ticket (ticket-nr)
5738 "Show a ticket in the trac issue tracker."
5739 (interactive (list (read-number "Browse ticket number: " (number-at-point))))
5740 (unless svn-trac-project-root
5741 (svn-status-set-trac-project-root))
5742 (svn-browse-url (concat svn-trac-project-root "ticket/" (number-to-string ticket-nr))))
5744 ;;;------------------------------------------------------------
5745 ;;; resolve conflicts using ediff
5746 ;;;------------------------------------------------------------
5747 (defun svn-resolve-conflicts-ediff (&optional name-A name-B)
5748 "Invoke ediff to resolve conflicts in the current buffer.
5749 The conflicts must be marked with rcsmerge conflict markers."
5752 (file-name (file-name-nondirectory buffer-file-name))
5753 (your-buffer (generate-new-buffer
5754 (concat "*" file-name
5755 " " (or name-A "WORKFILE") "*")))
5756 (other-buffer (generate-new-buffer
5757 (concat "*" file-name
5758 " " (or name-B "CHECKED-IN") "*")))
5759 (result-buffer (current-buffer)))
5761 (set-buffer your-buffer)
5763 (insert-buffer-substring result-buffer)
5764 (goto-char (point-min))
5765 (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
5768 (if (not (re-search-forward "^=======\n" nil t))
5769 (error "Malformed conflict marker"))
5771 (let ((start (point)))
5772 (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
5773 (error "Malformed conflict marker"))
5774 (delete-region start (point))))
5777 (kill-buffer your-buffer)
5778 (kill-buffer other-buffer)
5779 (error "No conflict markers found")))
5780 (set-buffer other-buffer)
5782 (insert-buffer-substring result-buffer)
5783 (goto-char (point-min))
5784 (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
5785 (let ((start (match-beginning 0)))
5786 (if (not (re-search-forward "^=======\n" nil t))
5787 (error "Malformed conflict marker"))
5788 (delete-region start (point))
5789 (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
5790 (error "Malformed conflict marker"))
5791 (replace-match "")))
5792 (let ((config (current-window-configuration))
5793 (ediff-default-variant 'default-B))
5797 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
5799 ;; Ediff is now set up, and we are in the control buffer.
5800 ;; Do a few further adjustments and take precautions for exit.
5802 (make-local-variable 'svn-ediff-windows)
5803 (setq svn-ediff-windows config)
5804 (make-local-variable 'svn-ediff-result)
5805 (setq svn-ediff-result result-buffer)
5806 (make-local-variable 'ediff-quit-hook)
5807 (setq ediff-quit-hook
5809 (let ((buffer-A ediff-buffer-A)
5810 (buffer-B ediff-buffer-B)
5811 (buffer-C ediff-buffer-C)
5812 (result svn-ediff-result)
5813 (windows svn-ediff-windows))
5814 (ediff-cleanup-mess)
5817 (insert-buffer-substring buffer-C)
5818 (kill-buffer buffer-A)
5819 (kill-buffer buffer-B)
5820 (kill-buffer buffer-C)
5821 (set-window-configuration windows)
5822 (message "Conflict resolution finished; you may save the buffer"))))
5823 (message "Please resolve conflicts now; exit ediff when done")
5826 (defun svn-resolve-conflicts (filename)
5827 (let ((buff (find-file-noselect filename)))
5829 (progn (switch-to-buffer buff)
5830 (svn-resolve-conflicts-ediff))
5831 (error "can not open file %s" filename))))
5833 (defun svn-status-resolve-conflicts ()
5834 "Resolve conflict in the selected file"
5836 (let ((file-info (svn-status-get-line-information)))
5838 (= ?C (svn-status-line-info->filemark file-info))
5839 (svn-resolve-conflicts
5840 (svn-status-line-info->full-path file-info)))
5841 (error "can not resolve conflicts at this point"))))
5844 ;; --------------------------------------------------------------------------------
5845 ;; Working with branches
5846 ;; --------------------------------------------------------------------------------
5848 (defun svn-branch-select (&optional prompt)
5849 "Select a branch interactively from `svn-status-branch-list'"
5852 (setq prompt "Select branch: "))
5853 (let* ((branch (funcall svn-status-completing-read-function prompt svn-status-branch-list))
5856 (when (string-match "#\\(1#\\)?\\(.+\\)" branch)
5857 (setq directory (match-string 2 branch))
5858 (setq base-url (concat (svn-status-base-info->repository-root) "/" directory))
5860 (svn-status-parse-info t))
5861 (if (eq (length (match-string 1 branch)) 0)
5862 (setq branch base-url)
5863 (let ((svn-status-branch-list (svn-status-ls base-url t)))
5864 (setq branch (concat (svn-status-base-info->repository-root) "/"
5866 (svn-branch-select (format "Select branch from '%s': " directory)))))))
5869 (defun svn-branch-diff (branch1 branch2)
5870 "Show the diff between two svn repository urls.
5871 When called interactively, use `svn-branch-select' to choose two branches from `svn-status-branch-list'."
5873 (let* ((branch1 (svn-branch-select "svn diff branch1: "))
5874 (branch2 (svn-branch-select (format "svn diff %s against: " branch1))))
5875 (list branch1 branch2)))
5876 (svn-run t t 'diff "diff" svn-status-default-diff-arguments branch1 branch2))
5878 ;; --------------------------------------------------------------------------------
5879 ;; svnadmin interface
5880 ;; --------------------------------------------------------------------------------
5881 (defun svn-admin-create (dir)
5882 "Run svnadmin create DIR."
5883 (interactive (list (expand-file-name
5884 (svn-read-directory-name "Create a svn repository at: "
5885 svn-admin-default-create-directory nil nil))))
5886 (shell-command-to-string (concat "svnadmin create " dir))
5887 (setq svn-admin-last-repository-dir (concat "file://" dir))
5888 (message "Svn repository created at %s" dir)
5889 (run-hooks 'svn-admin-create-hook))
5891 ;; - Import an empty directory
5892 ;; cd to an empty directory
5893 ;; svn import -m "Initial import" . file:///home/stefan/svn_repos/WaldiConfig/trunk
5894 (defun svn-admin-create-trunk-directory ()
5895 "Import an empty trunk directory to `svn-admin-last-repository-dir'.
5896 Set `svn-admin-last-repository-dir' to the new created trunk url."
5898 (let ((empty-temp-dir-name (make-temp-name svn-status-temp-dir)))
5899 (make-directory empty-temp-dir-name t)
5900 (setq svn-admin-last-repository-dir (concat svn-admin-last-repository-dir "/trunk"))
5901 (svn-run nil t 'import "import" "-m" "Created trunk directory"
5902 empty-temp-dir-name svn-admin-last-repository-dir)
5903 (delete-directory empty-temp-dir-name)))
5905 (defun svn-admin-start-import ()
5906 "Start to import the current working directory in a subversion repository.
5907 The user is asked to perform the following two steps:
5908 1. Create a local repository
5909 2. Add a trunk directory to that repository
5911 After that step the empty base directory (either the root directory or
5912 the trunk directory of the selected repository) is checked out in the current
5915 (if (y-or-n-p "Create local repository? ")
5917 (call-interactively 'svn-admin-create)
5918 (when (y-or-n-p "Add a trunk directory? ")
5919 (svn-admin-create-trunk-directory)))
5920 (setq svn-admin-last-repository-dir (read-string "Repository Url: ")))
5921 (svn-checkout svn-admin-last-repository-dir "."))
5923 ;; --------------------------------------------------------------------------------
5924 ;; svn status profiling
5925 ;; --------------------------------------------------------------------------------
5926 ;;; Note about profiling psvn:
5927 ;; (load-library "elp")
5928 ;; M-x elp-reset-all
5929 ;; (elp-instrument-package "svn-")
5933 (defun svn-status-elp-init ()
5937 (elp-instrument-package "svn-")
5938 (message "Run the desired svn command (e.g. M-x svn-status), then use M-x elp-results."))
5940 (defun svn-status-last-commands (&optional string-prefix)
5941 "Return a string with the last executed svn commands"
5943 (unless string-prefix
5944 (setq string-prefix ""))
5945 (with-output-to-string
5946 (dolist (e (ring-elements svn-last-cmd-ring))
5947 (princ (format "%s%s: svn %s <%s>\n" string-prefix (nth 0 e) (mapconcat 'concat (nth 1 e) " ") (nth 2 e))))))
5949 ;; --------------------------------------------------------------------------------
5951 ;; --------------------------------------------------------------------------------
5952 (defun svn-insert-indented-lines (text)
5953 "Helper function to insert TEXT, indented by two characters."
5954 (dolist (line (split-string text "\n"))
5955 (insert (format " %s\n" line))))
5957 (defun svn-prepare-bug-report ()
5958 "Create the buffer *psvn-bug-report*. This buffer can be useful to debug problems with psvn.el"
5960 (let* ((last-output-buffer-name (or svn-status-last-output-buffer-name svn-process-buffer-name))
5961 (last-svn-cmd-output (with-current-buffer last-output-buffer-name
5962 (buffer-substring-no-properties (point-min) (point-max)))))
5963 (switch-to-buffer "*psvn-bug-report*")
5964 (delete-region (point-min) (point-max))
5965 (insert "This buffer holds some debug informations for psvn.el\n")
5966 (insert "Please enter a description of the observed and the wanted behaviour\n")
5967 (insert "and send it to the author (stefan@xsteve.at) to allow easier debugging\n\n")
5968 (insert "Revisions:\n")
5969 (svn-insert-indented-lines (svn-status-version))
5970 (insert "Language environment:\n")
5971 (dolist (elem (svn-process-environment))
5972 (when (member (car (split-string elem "=")) '("LC_MESSAGES" "LC_ALL" "LANG"))
5973 (insert (format " %s\n" elem))))
5974 (insert "\nLast svn commands:\n")
5975 (svn-insert-indented-lines (svn-status-last-commands))
5976 (insert (format "\nContent of the <%s> buffer:\n" last-output-buffer-name))
5977 (svn-insert-indented-lines last-svn-cmd-output)
5978 (goto-char (point-min))))
5980 ;; --------------------------------------------------------------------------------
5981 ;; Make it easier to reload psvn, if a distribution has an older version
5982 ;; Just add the following to your .emacs:
5983 ;; (svn-prepare-for-reload)
5984 ;; (load "/path/to/psvn.el")
5986 ;; Note the above will only work, if the loaded psvn.el has already the
5987 ;; function svn-prepare-for-reload
5988 ;; If this is not the case, do the following:
5989 ;; (load "/path/to/psvn.el");;make svn-prepare-for-reload available
5990 ;; (svn-prepare-for-reload)
5991 ;; (load "/path/to/psvn.el");; update the keybindings
5992 ;; --------------------------------------------------------------------------------
5994 (defvar svn-prepare-for-reload-dont-touch-list '() "A list of variables that should not be touched by `svn-prepare-for-reload'")
5995 (defvar svn-prepare-for-reload-variables-list '(svn-global-keymap svn-status-diff-mode-map svn-global-trac-map svn-status-mode-map
5996 svn-status-mode-property-map svn-status-mode-extension-map
5997 svn-status-mode-options-map svn-status-mode-trac-map svn-status-mode-branch-map
5998 svn-log-edit-mode-map svn-log-view-mode-map
5999 svn-log-view-popup-menu-map svn-info-mode-map svn-blame-mode-map svn-process-mode-map)
6000 "A list of variables that should be set to nil via M-x `svn-prepare-for-reload'")
6001 (defun svn-prepare-for-reload ()
6002 "This function resets some psvn.el variables to nil.
6003 It makes reloading a newer version of psvn.el easier, if for example the used
6004 GNU/Linux distribution uses an older version.
6006 The variables specified in `svn-prepare-for-reload-variables-list' will be reseted by this function.
6008 A variable will keep its value, if it is specified in `svn-prepare-for-reload-dont-touch-list'."
6010 (dolist (var svn-prepare-for-reload-variables-list)
6011 (unless (member var svn-prepare-for-reload-dont-touch-list)
6012 (message (format "Resetting value of %s to nil" var)))
6018 ;; indent-tabs-mode: nil
6020 ;;; psvn.el ends here