changelog shortlog tags changeset files revisions annotate raw

psvn.el

changeset 66: 5b737eefe5ea
parent:1fae210bc469
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;;; psvn.el --- Subversion interface for emacs
2;; Copyright (C) 2002-2009 by Stefan Reichoer
3
4;; Author: Stefan Reichoer <stefan@xsteve.at>
5;; $Id: psvn.el 40299 2009-10-29 19:38:54Z xsteve $
6
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)
10;; any later version.
11
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.
16
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.
21
22;;; Commentary
23
24;; psvn.el is tested with GNU Emacs 21.3 on windows, debian linux,
25;; freebsd5, red hat el4, ubuntu intrepid with svn 1.5.1
26
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
29
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:
34;;
35;; M-x svn-status: run 'svn -status -v'
36;; M-x svn-examine (like pcl-cvs cvs-examine) is alias for svn-status
37;;
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 g - svn-status-grep-files
70;; S s - svn-status-search-files
71;; s - svn-status-show-process-buffer
72;; h - svn-status-pop-to-partner-buffer
73;; e - svn-status-toggle-edit-cmd-flag
74;; ? - svn-status-toggle-hide-unknown
75;; _ - svn-status-toggle-hide-unmodified
76;; z - svn-status-toggle-hide-externals
77;; m - svn-status-set-user-mark
78;; u - svn-status-unset-user-mark
79;; $ - svn-status-toggle-elide
80;; w - svn-status-copy-current-line-info
81;; DEL - svn-status-unset-user-mark-backwards
82;; * ! - svn-status-unset-all-usermarks
83;; * ? - svn-status-mark-unknown
84;; * A - svn-status-mark-added
85;; * M - svn-status-mark-modified
86;; * P - svn-status-mark-modified-properties
87;; * D - svn-status-mark-deleted
88;; * * - svn-status-mark-changed
89;; * . - svn-status-mark-by-file-ext
90;; * % - svn-status-mark-filename-regexp
91;; * s - svn-status-store-usermarks
92;; * l - svn-status-load-usermarks
93;; . - svn-status-goto-root-or-return
94;; f - svn-status-find-file
95;; o - svn-status-find-file-other-window
96;; C-o - svn-status-find-file-other-window-noselect
97;; v - svn-status-view-file-other-window
98;; I - svn-status-parse-info
99;; V - svn-status-svnversion
100;; P l - svn-status-property-list
101;; P s - svn-status-property-set
102;; P d - svn-status-property-delete
103;; P e - svn-status-property-edit-one-entry
104;; P i - svn-status-property-ignore-file
105;; P I - svn-status-property-ignore-file-extension
106;; P C-i - svn-status-property-edit-svn-ignore
107;; P X e - svn-status-property-edit-svn-externals
108;; P k - svn-status-property-set-keyword-list
109;; P K i - svn-status-property-set-keyword-id
110;; P K d - svn-status-property-set-keyword-date
111;; P y - svn-status-property-set-eol-style
112;; P x - svn-status-property-set-executable
113;; P m - svn-status-property-set-mime-type
114;; H - svn-status-use-history
115;; x - svn-status-update-buffer
116;; q - svn-status-bury-buffer
117
118;; C-x C-j - svn-status-dired-jump
119
120;; The output in the buffer contains this header to ease reading
121;; of svn output:
122;; FPH BASE CMTD Author em File
123;; F = Filemark
124;; P = Property mark
125;; H = History mark
126;; BASE = local base revision
127;; CMTD = last committed revision
128;; Author = author of change
129;; em = "**" or "(Update Available)" [see `svn-status-short-mod-flag-p']
130;; if file can be updated
131;; File = path/filename
132;;
133
134;; To use psvn.el put the following line in your .emacs:
135;; (require 'psvn)
136;; Start the svn interface with M-x svn-status
137
138;; The latest version of psvn.el can be found at:
139;; http://www.xsteve.at/prg/emacs/psvn.el
140;; Or you can check it out from the subversion repository:
141;; svn co http://svn.collab.net/repos/svn/trunk/contrib/client-side/emacs emacs-svn
142
143;; TODO:
144;; * shortcut for svn propset svn:keywords "Date" psvn.el
145;; * docstrings for the functions
146;; * perhaps shortcuts for ranges, dates
147;; * when editing the command line - offer help from the svn client
148;; * finish svn-status-property-set
149;; * Add repository browser
150;; * Get rid of all byte-compiler warnings
151;; * SVK working copy support
152;; * multiple independent buffers in svn-status-mode
153;; There are "TODO" comments in other parts of this file as well.
154
155;; Overview over the implemented/not (yet) implemented svn sub-commands:
156;; * add implemented
157;; * blame implemented
158;; * cat implemented
159;; * checkout (co) implemented
160;; * cleanup implemented
161;; * commit (ci) implemented
162;; * copy (cp) implemented
163;; * delete (del, remove, rm) implemented
164;; * diff (di) implemented
165;; * export implemented
166;; * help (?, h)
167;; * import used (in svn-admin-create-trunk-directory)
168;; * info implemented
169;; * list (ls) implemented
170;; * lock implemented
171;; * log implemented
172;; * merge
173;; * mkdir implemented
174;; * move (mv, rename, ren) implemented
175;; * propdel (pdel) implemented
176;; * propedit (pedit, pe) not needed
177;; * propget (pget, pg) used (in svn-status-property-edit)
178;; * proplist (plist, pl) implemented
179;; * propset (pset, ps) used (in svn-prop-edit-do-it)
180;; * resolved implemented
181;; * revert implemented
182;; * status (stat, st) implemented
183;; * switch (sw)
184;; * unlock implemented
185;; * update (up) implemented
186
187;; For the not yet implemented commands you should use the command line
188;; svn client. If there are user requests for any missing commands I will
189;; probably implement them.
190
191;; There is also limited support for the web-based software project management and bug/issue tracking system trac
192;; Trac ticket links can be enabled in the *svn-log* buffers when using the following:
193;; (setq svn-log-link-handlers '(trac-ticket-short))
194
195;; ---------------------------
196;; Frequently asked questions:
197;; ---------------------------
198
199;; Q1: I need support for user names with blanks/spaces
200;; A1: Add the user names to svn-user-names-including-blanks and set the
201;; svn-pre-parse-status-hook.
202;; The problem is, that the user names and the file names from the svn status
203;; output can both contain blanks. Blanks in file names are supported.
204;; the svn-user-names-including-blanks list is used to replace the spaces
205;; in the user names with - to overcome this problem
206
207;; Q2: My svn-update command it taking a really long time. How can I
208;; see what's going on?
209;; A2: In the *svn-status* buffer press "s".
210
211;; Q3: How do I enter a username and password?
212;; A3: In the *svn-status* buffer press "s", switch to the
213;; *svn-process* buffer and press enter. You will be prompted for
214;; username and password.
215
216;; Q4: What does "?", "M", and "C" in the first column of the
217;; *svn-status* buffer mean?
218;; A4: "?" means the file(s) is not under Subversion control
219;; "M" means you have a locally modified file
220;; "C" means there is a conflict
221;; "@$&#!" means someone is saying nasty things to you
222
223
224;; Comments / suggestions and bug reports are welcome!
225
226;; Development notes
227;; -----------------
228
229;; "svn-" is the package prefix used in psvn.el. There are also longer
230;; prefixes which clarify the code and help symbol completion, but they
231;; are not intended to prevent name clashes with other packages. All
232;; interactive commands meant to be used only in a specific mode should
233;; have names beginning with the name of that mode: for example,
234;; "svn-status-add-file" in "svn-status-mode". "psvn" should be used
235;; only in names of files, customization groups, and features. If SVK
236;; support is ever added, it should use "svn-svk-" when no existing
237;; prefix is applicable.
238
239;; Many of the variables marked as `risky-local-variable' are probably
240;; impossible to abuse, as the commands that read them are used only in
241;; buffers that are not visiting any files. Better safe than sorry.
242
243;;; Code:
244
245(require 'easymenu)
246
247(eval-when-compile (require 'dired))
248(eval-when-compile (require 'ediff-util))
249(eval-when-compile (require 'ediff-wind))
250(eval-when-compile (require 'vc-hooks))
251(eval-when-compile (require 'elp))
252(eval-when-compile (require 'pp))
253
254(condition-case nil
255 (progn
256 (require 'diff-mode))
257 (error nil))
258
259(defconst svn-psvn-revision "$Id: psvn.el 40299 2009-10-29 19:38:54Z xsteve $"
260 "The revision number of psvn.")
261
262;;; user setable variables
263(defcustom svn-status-verbose t
264 "*Add '-v' to svn status call.
265This can be toggled with \\[svn-status-toggle-svn-verbose-flag]."
266 :type 'boolean
267 :group 'psvn)
268(defcustom svn-log-edit-file-name "++svn-log++"
269 "*Name of a saved log file.
270This can be either absolute, or relative to the default directory
271of the `svn-log-edit-buffer-name' buffer."
272 :type 'file
273 :group 'psvn)
274(put 'svn-log-edit-file-name 'risky-local-variable t)
275(defcustom svn-log-edit-insert-files-to-commit t
276 "*Insert the filelist to commit in the *svn-log* buffer"
277 :type 'boolean
278 :group 'psvn)
279(defcustom svn-log-edit-show-diff-for-commit nil
280 "*Show the diff being committed when you run `svn-status-commit.'."
281 :type 'boolean
282 :group 'psvn)
283(defcustom svn-log-edit-use-log-edit-mode
284 (and (condition-case nil (require 'log-edit) (error nil)) t)
285 "*Use log-edit-mode as base for svn-log-edit-mode
286This variable takes effect only when psvn.el is being loaded."
287 :type 'boolean
288 :group 'psvn)
289(defcustom svn-log-edit-paragraph-start
290 "$\\|[ \t]*$\\|##.*$\\|\\*.*:.*$\\|[ \t]+(.+):.*$"
291 "*Value used for `paragraph-start' in `svn-log-edit-buffer-name' buffer."
292 :type 'regexp
293 :group 'psvn)
294(defcustom svn-log-edit-paragraph-separate "$\\|##.*$"
295 "*Value used for `paragraph-separate' in `svn-log-edit-buffer-name' buffer."
296 :type 'regexp
297 :group 'psvn)
298(defcustom svn-status-hide-unknown nil
299 "*Hide unknown files in `svn-status-buffer-name' buffer.
300This can be toggled with \\[svn-status-toggle-hide-unknown]."
301 :type 'boolean
302 :group 'psvn)
303(defcustom svn-status-hide-unmodified nil
304 "*Hide unmodified files in `svn-status-buffer-name' buffer.
305This can be toggled with \\[svn-status-toggle-hide-unmodified]."
306 :type 'boolean
307 :group 'psvn)
308(defcustom svn-status-hide-externals nil
309 "*Hide external files in `svn-status-buffer-name' buffer.
310This can be toggled with \\[svn-status-toggle-hide-externals]."
311 :type 'boolean
312 :group 'psvn)
313(defcustom svn-status-sort-status-buffer t
314 "*Whether to sort the `svn-status-buffer-name' buffer.
315
316Setting this variable to nil speeds up \\[M-x svn-status], however the
317listing may then become incorrect.
318
319This can be toggled with \\[svn-status-toggle-sort-status-buffer]."
320 :type 'boolean
321 :group 'psvn)
322
323(defcustom svn-status-ediff-delete-temporary-files nil
324 "*Whether to delete temporary ediff files. If set to ask, ask the user"
325 :type '(choice (const t)
326 (const nil)
327 (const ask))
328 :group 'psvn)
329
330(defcustom svn-status-changelog-style 'changelog
331 "*The changelog style that is used for `svn-file-add-to-changelog'.
332Possible values are:
333 'changelog: use `add-change-log-entry-other-window'
334 'svn-dev: use commit messages that are used by the svn developers
335 a function: This function is called to add a new entry to the changelog file.
336"
337 :type '(set (const changelog)
338 (const svn-dev))
339 :group 'psvn)
340
341(defcustom svn-status-unmark-files-after-list '(commit revert)
342 "*List of operations after which all user marks will be removed.
343Possible values are: commit, revert."
344 :type '(set (const commit)
345 (const revert))
346 :group 'psvn)
347
348(defcustom svn-status-preserve-window-configuration t
349 "*Try to preserve the window configuration."
350 :type 'boolean
351 :group 'psvn)
352
353(defcustom svn-status-auto-revert-buffers t
354 "*Auto revert buffers that have changed on disk."
355 :type 'boolean
356 :group 'psvn)
357
358(defcustom svn-status-fancy-file-state-in-modeline t
359 "*Show a color dot in the modeline that describes the state of the current file."
360 :type 'boolean
361 :group 'psvn)
362
363(defcustom svn-status-negate-meaning-of-arg-commands '()
364 "*List of operations that should use a negated meaning of the prefix argument.
365The supported functions are `svn-status' and `svn-status-set-user-mark'."
366 :type '(set (function-item svn-status)
367 (function-item svn-status-set-user-mark))
368 :group 'psvn)
369
370(defcustom svn-status-svn-executable "svn"
371 "*The name of the svn executable.
372This can be either absolute or looked up on `exec-path'."
373 ;; Don't use (file :must-match t). It doesn't know about `exec-path'.
374 :type 'file
375 :group 'psvn)
376(put 'svn-status-svn-executable 'risky-local-variable t)
377
378(defcustom svn-status-default-export-directory "~/" "*The default directory that is suggested svn export."
379 :type 'file
380 :group 'psvn)
381
382(defcustom svn-status-svn-environment-var-list '("LC_MESSAGES=C" "LC_ALL=")
383 "*A list of environment variables that should be set for that svn process.
384Each element is either a string \"VARIABLE=VALUE\" which will be added to
385the environment when svn is run, or just \"VARIABLE\" which causes that
386variable to be entirely removed from the environment.
387
388The default setting is '(\"LC_MESSAGES=C\" \"LC_ALL=\"). This ensures that the svn command
389line client does not output localized strings. psvn.el relies on the english
390messages."
391 :type '(repeat string)
392 :group 'psvn)
393(put 'svn-status-svn-environment-var-list 'risky-local-variable t)
394
395(defcustom svn-browse-url-function nil
396 ;; If the user hasn't changed `svn-browse-url-function', then changing
397 ;; `browse-url-browser-function' should affect psvn even after it has
398 ;; been loaded.
399 "Function to display a Subversion related WWW page in a browser.
400So far, this is used only for \"trac\" issue tracker integration.
401By default, this is nil, which means use `browse-url-browser-function'.
402Any non-nil value overrides that variable, with the same syntax."
403 ;; It would be nice to show the full list of browsers supported by
404 ;; browse-url, but (custom-variable-type 'browse-url-browser-function)
405 ;; returns just `function' if browse-url has not yet been loaded,
406 ;; and there seems to be no easy way to autoload browse-url when
407 ;; the custom-type of svn-browse-url-function is actually needed.
408 ;; So I'll only offer enough choices to cover all supported types.
409 :type `(choice (const :tag "Specified by `browse-url-browser-function'" nil)
410 (function :value browse-url-default-browser
411 ;; In XEmacs 21.4.17, the `function' widget matches
412 ;; all objects. Constrain it here so that alists
413 ;; fall through to the next choice. Accept either
414 ;; a symbol (fbound or not) or a lambda expression.
415 :match ,(lambda (widget value)
416 (or (symbolp value) (functionp value))))
417 (svn-alist :tag "Regexp/function association list"
418 :key-type regexp :value-type function
419 :value (("." . browse-url-default-browser))))
420 :link '(emacs-commentary-link "browse-url")
421 :group 'psvn)
422;; (put 'svn-browse-url-function 'risky-local-variable t)
423;; already implied by "-function" suffix
424
425(defcustom svn-log-edit-header
426 "## Lines starting with '## ' will be removed from the log message.\n"
427 "*Header content of the *svn-log* buffer"
428 :type 'string
429 :group 'psvn)
430
431(defcustom svn-status-window-alist
432 '((diff "*svn-diff*") (log "*svn-log*") (info t) (blame t) (proplist t) (update t))
433 "An alist to specify which windows should be used for svn command outputs.
434The following keys are supported: diff, log, info, blame, proplist, update.
435The following values can be given:
436nil ... show in `svn-process-buffer-name' buffer
437t ... show in dedicated *svn-info* buffer
438invisible ... don't show the buffer (eventually useful for update)
439a string ... show in a buffer named string"
440 :type '(svn-alist
441 :key-type symbol
442 :value-type (group
443 (choice
444 (const :tag "Show in *svn-process* buffer" nil)
445 (const :tag "Show in dedicated *svn-info* buffer" t)
446 (const :tag "Don't show the output" invisible)
447 (string :tag "Show in a buffer named"))))
448 :options '(diff log info blame proplist update)
449 :group 'psvn)
450
451(defcustom svn-status-short-mod-flag-p t
452 "*Whether the mark for out of date files is short or long.
453
454If this variable is is t, and a file is out of date (i.e., there is a newer
455version in the repository than the working copy), then the file will
456be marked by \"**\"
457
458If this variable is nil, and the file is out of date then the longer phrase
459\"(Update Available)\" is used.
460
461In either case the mark gets the face
462`svn-status-update-available-face', and will only be visible if
463`\\[svn-status-update]' is run with a prefix argument"
464 :type '(choice (const :tag "Short \"**\"" t)
465 (const :tag "Long \"(Update Available)\"" nil))
466 :group 'psvn)
467
468(defvar svn-status-debug-level 0 "The psvn.el debugging verbosity level.
469The higher the number, the more debug messages are shown.
470
471See `svn-status-message' for the meaning of values for that variable.")
472
473(defvar svn-bookmark-list nil "A list of locations for a quick access via `svn-status-via-bookmark'")
474;;(setq svn-bookmark-list '(("proj1" . "~/work/proj1")
475;; ("doc1" . "~/docs/doc1")))
476
477(defvar svn-status-buffer-name "*svn-status*" "Name for the svn status buffer")
478(defvar svn-process-buffer-name " *svn-process*" "Name for the svn process buffer")
479(defvar svn-log-edit-buffer-name "*svn-log-edit*" "Name for the svn log-edit buffer")
480
481(defcustom svn-status-use-header-line
482 (if (boundp 'header-line-format) t 'inline)
483 "*Whether a header line should be used.
484When t: Use the emacs header line
485When 'inline: Insert the header line in the `svn-status-buffer-name' buffer
486Otherwise: Don't display a header line"
487 :type '(choice (const :tag "Show column titles as a header line" t)
488 (const :tag "Insert column titles as text in the buffer" inline)
489 (other :tag "No column titles" nil))
490 :group 'psvn)
491
492;;; default arguments to pass to svn commands
493;; TODO: When customizing, an option menu or completion might be nice....
494(defcustom svn-status-default-log-arguments '("-v")
495 "*List of arguments to pass to svn log.
496\(used in `svn-status-show-svn-log'; override these by giving prefixes\)."
497 :type '(repeat string)
498 :group 'psvn)
499(put 'svn-status-default-log-arguments 'risky-local-variable t)
500
501(defcustom svn-status-default-commit-arguments '()
502 "*List of arguments to pass to svn commit.
503If you don't like recursive commits, set this value to (\"-N\")
504or mark the directory before committing it.
505Do not put an empty string here, except as an argument of an option:
506Subversion and the operating system may treat that as a file name
507equivalent to \".\", so you would commit more than you intended."
508 :type '(repeat string)
509 :group 'psvn)
510(put 'svn-status-default-commit-arguments 'risky-local-variable t)
511
512(defcustom svn-status-default-diff-arguments '("-x" "--ignore-eol-style")
513 "*A list of arguments that is passed to the svn diff command.
514When the built in diff command is used,
515the following options are available: --ignore-eol-style, --ignore-space-change,
516--ignore-all-space, --ignore-eol-style.
517The following setting ignores eol style changes and all white space changes:
518'(\"-x\" \"--ignore-eol-style --ignore-all-space\")
519
520If you'd like to suppress whitespace changes using the external diff command
521use the following value:
522'(\"--diff-cmd\" \"diff\" \"-x\" \"-wbBu\")
523
524"
525 :type '(repeat string)
526 :group 'psvn)
527(put 'svn-status-default-diff-arguments 'risky-local-variable t)
528
529(defcustom svn-status-default-status-arguments '()
530 "*A list of arguments that is passed to the svn status command.
531The following options are available: --ignore-externals
532
533"
534 :type '(repeat string)
535 :group 'psvn)
536(put 'svn-status-default-status-arguments 'risky-local-variable t)
537
538(defcustom svn-status-default-blame-arguments '("-x" "--ignore-eol-style")
539 "*A list of arguments that is passed to the svn blame command.
540See `svn-status-default-diff-arguments' for some examples."
541 :type '(repeat string)
542 :group 'psvn)
543
544(put 'svn-status-default-blame-arguments 'risky-local-variable t)
545
546(defvar svn-trac-project-root nil
547 "Path for an eventual existing trac issue tracker.
548This can be set with \\[svn-status-set-trac-project-root].")
549
550(defvar svn-status-module-name nil
551 "*A short name for the actual project.
552This can be set with \\[svn-status-set-module-name].")
553
554(defvar svn-status-branch-list nil
555 "*A list of known branches for the actual project
556This can be set with \\[svn-status-set-branch-list].
557
558The list contains full repository paths or shortcuts starting with \#
559\# at the beginning is replaced by the repository url.
560\#1\# has the special meaning that all paths below the given directory
561will be considered for interactive selections.
562
563A useful setting might be: '\(\"\#trunk\" \"\#1\#tags\" \"\#1\#branches\")")
564
565(defvar svn-status-load-state-before-svn-status t
566 "*Whether to automatically restore state from ++psvn.state file before running svn-status.")
567
568(defvar svn-log-link-handlers nil "A list of link handlers in *svn-log* buffers.
569These link handlers must be registered via `svn-log-register-link-handler'")
570
571;;; hooks
572(defvar svn-status-mode-hook nil "Hook run when entering `svn-status-mode'.")
573(defvar svn-log-edit-mode-hook nil "Hook run when entering `svn-log-edit-mode'.")
574(defvar svn-log-edit-done-hook nil "Hook run after commiting files via svn.")
575;; (put 'svn-log-edit-mode-hook 'risky-local-variable t)
576;; (put 'svn-log-edit-done-hook 'risky-local-variable t)
577;; already implied by "-hook" suffix
578
579(defvar svn-post-process-svn-output-hook 'svn-fixup-tramp-output-maybe "Hook that can be used to preprocess the output from svn.
580The function `svn-status-remove-control-M' can be useful for that hook")
581
582(when (eq system-type 'windows-nt)
583 (add-hook 'svn-post-process-svn-output-hook 'svn-status-remove-control-M))
584
585(defvar svn-status-svn-process-coding-system (when (boundp 'locale-coding-system) locale-coding-system)
586 "The coding system that is used for the svn command line client.
587It is used in svn-run, if it is not nil.")
588
589(defvar svn-status-svn-file-coding-system 'undecided-unix
590 "The coding system that is used to save files that are loaded as
591parameter or data files via the svn command line client.
592It is used in the following functions: `svn-prop-edit-do-it', `svn-log-edit-done'.
593You could set it to 'utf-8")
594
595(defcustom svn-status-use-ido-completion
596 (fboundp 'ido-completing-read)
597 "*Use ido completion functionality."
598 :type 'boolean
599 :group 'psvn)
600
601(defvar svn-status-completing-read-function
602 (if svn-status-use-ido-completion 'ido-completing-read 'completing-read))
603
604;;; experimental features
605(defvar svn-status-track-user-input nil "Track user/password queries.
606This feature is implemented via a process filter.
607It is an experimental feature.")
608
609(defvar svn-status-refresh-info nil "Whether `svn-status-update-buffer' should call `svn-status-parse-info'.")
610
611;;; Customize group
612(defgroup psvn nil
613 "Subversion interface for Emacs."
614 :group 'tools)
615
616(defgroup psvn-faces nil
617 "psvn faces."
618 :group 'psvn)
619
620
621(eval-and-compile
622 (require 'cl)
623 (defconst svn-xemacsp (featurep 'xemacs))
624 (if svn-xemacsp
625 (require 'overlay)
626 (require 'overlay nil t)))
627
628(defcustom svn-status-display-full-path nil
629 "Specifies how the filenames look like in the listing.
630If t, their full path name will be displayed, else only the filename."
631 :type 'boolean
632 :group 'psvn)
633
634(defcustom svn-status-prefix-key [(control x) (meta s)]
635 "Prefix key for the psvn commands in the global keymap."
636 :type '(choice (const [(control x) ?v ?S])
637 (const [(super s)])
638 (const [(hyper s)])
639 (const [(control x) ?v])
640 (const [(control x) ?V])
641 (sexp))
642 :group 'psvn
643 :set (lambda (var value)
644 (if (boundp var)
645 (global-unset-key (symbol-value var)))
646 (set var value)
647 (global-set-key (symbol-value var) 'svn-global-keymap)))
648
649(defcustom svn-admin-default-create-directory "~/"
650 "*The default directory that is suggested for `svn-admin-create'."
651 :type 'string
652 :group 'psvn)
653
654(defvar svn-status-custom-hide-function nil
655 "A function that receives a line-info and decides whether to hide that line.
656See psvn.el for an example function.")
657;; (put 'svn-status-custom-hide-function 'risky-local-variable t)
658;; already implied by "-function" suffix
659
660
661;; Use the normally used mode for files ending in .~HEAD~, .~BASE~, ...
662(add-to-list 'auto-mode-alist '("\\.~?\\(HEAD\\|BASE\\|PREV\\)~?\\'" ignore t))
663
664;;; internal variables
665(defvar svn-status-directory-history nil "List of visited svn working directories.")
666(defvar svn-process-cmd nil)
667(defvar svn-status-info nil)
668(defvar svn-status-filename-to-buffer-position-cache (make-hash-table :test 'equal :weakness t))
669(defvar svn-status-base-info nil "The parsed result from the svn info command.")
670(defvar svn-status-initial-window-configuration nil)
671(defvar svn-status-default-column 23)
672(defvar svn-status-default-revision-width 4)
673(defvar svn-status-default-author-width 9)
674(defvar svn-status-line-format " %c%c%c %4s %4s %-9s")
675(defvar svn-start-of-file-list-line-number 0)
676(defvar svn-status-files-to-commit nil
677 "List of files to commit at `svn-log-edit-done'.
678This is always set together with `svn-status-recursive-commit'.")
679(defvar svn-status-recursive-commit nil
680 "Non-nil if the next commit should be recursive.
681This is always set together with `svn-status-files-to-commit'.")
682(defvar svn-log-edit-update-log-entry nil
683 "Revision number whose log entry is being edited.
684This is nil if the log entry is for a new commit.")
685(defvar svn-status-pre-commit-window-configuration nil)
686(defvar svn-status-pre-propedit-window-configuration nil)
687(defvar svn-status-head-revision nil)
688(defvar svn-status-root-return-info nil)
689(defvar svn-status-property-edit-must-match-flag nil)
690(defvar svn-status-propedit-property-name nil "The property name for the actual svn propset command")
691(defvar svn-status-propedit-file-list nil)
692(defvar svn-status-mode-line-process "")
693(defvar svn-status-mode-line-process-status "")
694(defvar svn-status-mode-line-process-edit-flag "")
695(defvar svn-status-edit-svn-command nil)
696(defvar svn-status-update-previous-process-output nil)
697(defvar svn-pre-run-asynch-recent-keys nil)
698(defvar svn-pre-run-mode-line-process nil)
699(defvar svn-status-temp-dir
700 (expand-file-name
701 (or
702 (when (boundp 'temporary-file-directory) temporary-file-directory) ;emacs
703 ;; XEmacs 21.4.17 can return "/tmp/kalle" from (temp-directory).
704 ;; `file-name-as-directory' adds a slash so we can append a file name.
705 (when (fboundp 'temp-directory) (file-name-as-directory (temp-directory)))
706 "/tmp/")) "The directory that is used to store temporary files for psvn.")
707;; Because `temporary-file-directory' is not a risky local variable in
708;; GNU Emacs 22.0.51, we don't mark `svn-status-temp-dir' as such either.
709(defvar svn-temp-suffix (make-temp-name "."))
710(put 'svn-temp-suffix 'risky-local-variable t)
711(defvar svn-status-temp-file-to-remove nil)
712(put 'svn-status-temp-file-to-remove 'risky-local-variable t)
713(defvar svn-status-temp-arg-file (concat svn-status-temp-dir "svn.arg" svn-temp-suffix))
714(put 'svn-status-temp-arg-file 'risky-local-variable t)
715(defvar svn-status-options nil)
716(defvar svn-status-remote)
717(defvar svn-status-commit-rev-number nil)
718(defvar svn-status-update-rev-number nil)
719(defvar svn-status-operated-on-dot nil)
720(defvar svn-status-last-commit-author nil)
721(defvar svn-status-elided-list nil)
722(defvar svn-status-last-output-buffer-name nil "The buffer name for the buffer that holds the output from the last executed svn command")
723(defvar svn-status-pre-run-svn-buffer nil)
724(defvar svn-status-update-list nil)
725(defvar svn-transient-buffers)
726(defvar svn-ediff-windows)
727(defvar svn-ediff-result)
728(defvar svn-status-last-diff-options nil)
729(defvar svn-status-blame-file-name nil)
730(defvar svn-status-blame-revision nil)
731(defvar svn-admin-last-repository-dir nil "The last repository url for various operations.")
732(defvar svn-last-cmd-ring (make-ring 30) "Ring that holds the last executed svn commands (for debugging purposes)")
733(defvar svn-status-cached-version-string nil)
734(defvar svn-client-version nil "The version number of the used svn client")
735(defvar svn-status-get-line-information-for-file nil)
736(defvar svn-status-base-dir-cache (make-hash-table :test 'equal :weakness nil))
737(defvar svn-status-usermark-storage (make-hash-table :test 'equal :weakness nil))
738(defvar svn-log-registered-link-handlers (make-hash-table :test 'eql :weakness nil))
739
740(defvar svn-status-partner-buffer nil "The partner buffer for this svn related buffer")
741(make-variable-buffer-local 'svn-status-partner-buffer)
742
743;; Emacs 21 defines these in ediff-init.el but it seems more robust
744;; to just declare the variables here than try to load that file.
745;; It is Ediff's job to declare these as risky-local-variable if needed.
746(defvar ediff-buffer-A)
747(defvar ediff-buffer-B)
748(defvar ediff-buffer-C)
749(defvar ediff-quit-hook)
750
751;; Ditto for log-edit.el.
752(defvar log-edit-initial-files)
753(defvar log-edit-callback)
754(defvar log-edit-listfun)
755
756;; Ediff does not use this variable in GNU Emacs 20.7, GNU Emacs 21.4,
757;; nor XEmacs 21.4.17. However, pcl-cvs (a.k.a. pcvs) does.
758;; TODO: Check if this should be moved into the "svn-" namespace.
759(defvar ediff-after-quit-destination-buffer)
760
761;; That is an example for the svn-status-custom-hide-function:
762;; Note: For many cases it is a better solution to ignore files or
763;; file extensions via the svn-ignore properties (on P i, P I)
764;; (setq svn-status-custom-hide-function 'svn-status-hide-pyc-files)
765;; (defun svn-status-hide-pyc-files (info)
766;; "Hide all pyc files in the `svn-status-buffer-name' buffer."
767;; (let* ((fname (svn-status-line-info->filename-nondirectory info))
768;; (fname-len (length fname)))
769;; (and (> fname-len 4) (string= (substring fname (- fname-len 4)) ".pyc"))))
770
771;;; faces
772(defface svn-status-marked-face
773 '((((type tty) (class color)) (:foreground "green" :weight light))
774 (((class color) (background light)) (:foreground "green3"))
775 (((class color) (background dark)) (:foreground "palegreen2"))
776 (t (:weight bold)))
777 "Face to highlight the mark for user marked files in svn status buffers."
778 :group 'psvn-faces)
779
780(defface svn-status-marked-popup-face
781 '((((type tty) (class color)) (:foreground "green" :weight light))
782 (((class color) (background light)) (:foreground "green3"))
783 (((class color) (background dark)) (:foreground "palegreen2"))
784 (t (:weight bold)))
785 "Face to highlight the actual file, if a popup menu is activated."
786 :group 'psvn-faces)
787
788(defface svn-status-update-available-face
789 '((((type tty) (class color)) (:foreground "magenta" :weight light))
790 (((class color) (background light)) (:foreground "magenta"))
791 (((class color) (background dark)) (:foreground "yellow"))
792 (t (:weight bold)))
793 "Face used to highlight the 'out of date' mark.
794\(i.e., the mark used when there is a newer version in the repository
795than the working copy.\)
796
797See also `svn-status-short-mod-flag-p'."
798 :group 'psvn-faces)
799
800;based on cvs-filename-face
801(defface svn-status-directory-face
802 '((((type tty) (class color)) (:foreground "lightblue" :weight light))
803 (((class color) (background light)) (:foreground "blue4"))
804 (((class color) (background dark)) (:foreground "lightskyblue1"))
805 (t (:weight bold)))
806 "Face for directories in *svn-status* buffers.
807See `svn-status--line-info->directory-p' for what counts as a directory."
808 :group 'psvn-faces)
809
810;based on font-lock-comment-face
811(defface svn-status-filename-face
812 '((((class color) (background light)) (:foreground "chocolate"))
813 (((class color) (background dark)) (:foreground "beige")))
814 "Face for non-directories in *svn-status* buffers.
815See `svn-status--line-info->directory-p' for what counts as a directory."
816 :group 'psvn-faces)
817
818;not based on anything, may be horribly ugly!
819(defface svn-status-symlink-face
820 '((((class color) (background light)) (:foreground "cornflower blue"))
821 (((class color) (background dark)) (:foreground "cyan")))
822 "Face for symlinks in *svn-status* buffers.
823
824This is the face given to the actual link (i.e., the versioned item),
825the target of the link gets either `svn-status-filename-face' or
826`svn-status-directory-face'."
827 :group 'psvn-faces)
828
829;based on font-lock-warning-face
830(defface svn-status-locked-face
831 '((t
832 (:weight bold :foreground "Red")))
833 "Face for the phrase \"[ LOCKED ]\" `svn-status-buffer-name' buffers."
834 :group 'psvn-faces)
835
836;based on vhdl-font-lock-directive-face
837(defface svn-status-switched-face
838 '((((class color)
839 (background light))
840 (:foreground "CadetBlue"))
841 (((class color)
842 (background dark))
843 (:foreground "Aquamarine"))
844 (t
845 (:bold t :italic t)))
846 "Face for the phrase \"(switched)\" non-directories in svn status buffers."
847 :group 'psvn-faces)
848
849(if svn-xemacsp
850 (defface svn-status-blame-highlight-face
851 '((((type tty) (class color)) (:foreground "green" :weight light))
852 (((class color) (background light)) (:foreground "green3"))
853 (((class color) (background dark)) (:foreground "palegreen2"))
854 (t (:weight bold)))
855 "Default face for highlighting a line in svn status blame mode."
856 :group 'psvn-faces)
857 (defface svn-status-blame-highlight-face
858 '((t :inherit highlight))
859 "Default face for highlighting a line in svn status blame mode."
860 :group 'psvn-faces))
861
862(if svn-xemacsp
863 (defface svn-log-partner-highlight-face
864 '((((type tty) (class color)) (:foreground "yellow" :weight light))
865 (((class color) (background light)) (:foreground "gold"))
866 (((class color) (background dark)) (:foreground "gold"))
867 (t (:weight bold)))
868 "Default face for highlighting the partner in svn log mode."
869 :group 'psvn-faces)
870 (defface svn-log-partner-highlight-face
871 '((((class color) (background light))
872 (:background "light goldenrod" :weight bold))
873 (t (:weight bold)))
874 "Default face for highlighting the partner in svn log mode."
875 :group 'psvn-faces))
876
877(defface svn-status-blame-rev-number-face
878 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
879 (((class color) (background dark)) (:foreground "LightGoldenrod"))
880 (t (:weight bold :slant italic)))
881 "Face to highlight revision numbers in the svn-blame mode."
882 :group 'psvn-faces)
883
884(defvar svn-highlight t)
885;; stolen from PCL-CVS
886(defun svn-add-face (str face &optional keymap)
887 "Return string STR decorated with the specified FACE.
888If `svn-highlight' is nil then just return STR."
889 (when svn-highlight
890 ;; Do not use `list*'; cl.el might not have been loaded. We could
891 ;; put (require 'cl) at the top but let's try to manage without.
892 (add-text-properties 0 (length str)
893 `(face ,face
894 mouse-face highlight)
895;; 18.10.2004: the keymap parameter is not used (yet) in psvn.el
896;; ,@(when keymap
897;; `(mouse-face highlight
898;; local-map ,keymap)))
899 str))
900 str)
901
902(defun svn-status-maybe-add-face (condition text face)
903 "If CONDITION then add FACE to TEXT.
904Else return TEXT unchanged."
905 (if condition
906 (svn-add-face text face)
907 text))
908
909(defun svn-status-choose-face-to-add (condition text face1 face2)
910 "If CONDITION then add FACE1 to TEXT, else add FACE2 to TEXT."
911 (if condition
912 (svn-add-face text face1)
913 (svn-add-face text face2)))
914
915(defun svn-status-maybe-add-string (condition string face)
916 "If CONDITION then return STRING decorated with FACE.
917Otherwise, return \"\"."
918 (if condition
919 (svn-add-face string face)
920 ""))
921
922;; compatibility
923;; emacs 20
924(defalias 'svn-point-at-eol
925 (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position))
926(defalias 'svn-point-at-bol
927 (if (fboundp 'point-at-bol) 'point-at-bol 'line-beginning-position))
928(defalias 'svn-read-directory-name
929 (if (fboundp 'read-directory-name) 'read-directory-name 'read-file-name))
930
931(eval-when-compile
932 (if (not (fboundp 'gethash))
933 (require 'cl-macs)))
934(defalias 'svn-puthash (if (fboundp 'puthash) 'puthash 'cl-puthash))
935
936;; emacs 21
937(if (fboundp 'line-number-at-pos)
938 (defalias 'svn-line-number-at-pos 'line-number-at-pos)
939 (defun svn-line-number-at-pos (&optional pos)
940 "Return (narrowed) buffer line number at position POS.
941If POS is nil, use current buffer location."
942 (let ((opoint (or pos (point))) start)
943 (save-excursion
944 (goto-char (point-min))
945 (setq start (point))
946 (goto-char opoint)
947 (forward-line 0)
948 (1+ (count-lines start (point)))))))
949
950(defun svn-substring-no-properties (string &optional from to)
951 (if (fboundp 'substring-no-properties)
952 (substring-no-properties string from to)
953 (substring string (or from 0) to)))
954
955; xemacs
956;; Evaluate the defsubst at compile time, so that the byte compiler
957;; knows the definition and can inline calls. It cannot detect the
958;; defsubst automatically from within the if form.
959(eval-and-compile
960 (if (fboundp 'match-string-no-properties)
961 (defalias 'svn-match-string-no-properties 'match-string-no-properties)
962 (defsubst svn-match-string-no-properties (match)
963 (buffer-substring-no-properties (match-beginning match) (match-end match)))))
964
965; XEmacs doesn't have a function `help-buffer'
966(eval-and-compile
967 (if (fboundp 'help-buffer)
968 (defalias 'svn-help-buffer 'help-buffer) ; FSF Emacs
969 (defun svn-help-buffer ()
970 (buffer-name (get-buffer-create (help-buffer-name "SVN")))))) ; XEmacs
971
972
973;; XEmacs 21.4.17 does not have an `alist' widget. Define a replacement.
974;; To find out whether the `alist' widget exists, we cannot check just
975;; (get 'alist 'widget-type), because GNU Emacs 21.4 defines it in
976;; "wid-edit.el", which is not preloaded; it will be autoloaded when
977;; `widget-create' is called. Instead, we call `widgetp', which is
978;; also autoloaded from "wid-edit.el". XEmacs 21.4.17 does not have
979;; `widgetp' either, so we check that first.
980(if (and (fboundp 'widgetp) (widgetp 'alist))
981 (define-widget 'svn-alist 'alist
982 "An association list.
983Use this instead of `alist', for XEmacs 21.4 compatibility.")
984 (define-widget 'svn-alist 'list
985 "An association list.
986Use this instead of `alist', for XEmacs 21.4 compatibility."
987 :convert-widget 'svn-alist-convert-widget
988 :tag "Association List"
989 :key-type 'sexp
990 :value-type 'sexp)
991 (defun svn-alist-convert-widget (widget)
992 (let* ((value-type (widget-get widget :value-type))
993 (option-widgets (loop for option in (widget-get widget :options)
994 collect `(cons :format "%v"
995 (const :format "%t: %v\n"
996 :tag "Key"
997 ,option)
998 ,value-type))))
999 (widget-put widget :args
1000 `(,@(when option-widgets
1001 `((set :inline t :format "%v"
1002 ,@option-widgets)))
1003 (editable-list :inline t
1004 (cons :format "%v"
1005 ,(widget-get widget :key-type)
1006 ,value-type)))))
1007 widget))
1008
1009;; process launch functions
1010(defvar svn-call-process-function (if (fboundp 'process-file) 'process-file 'call-process))
1011(defvar svn-start-process-function (if (fboundp 'start-file-process) 'start-file-process 'start-process))
1012
1013
1014;;; keymaps
1015
1016(defvar svn-global-keymap nil "Global keymap for psvn.el.
1017To bind this to a different key, customize `svn-status-prefix-key'.")
1018(put 'svn-global-keymap 'risky-local-variable t)
1019(when (not svn-global-keymap)
1020 (setq svn-global-keymap (make-sparse-keymap))
1021 (define-key svn-global-keymap (kbd "v") 'svn-status-version)
1022 (define-key svn-global-keymap (kbd "s") 'svn-status-this-directory)
1023 (define-key svn-global-keymap (kbd "b") 'svn-status-via-bookmark)
1024 (define-key svn-global-keymap (kbd "h") 'svn-status-use-history)
1025 (define-key svn-global-keymap (kbd "u") 'svn-status-update-cmd)
1026 (define-key svn-global-keymap (kbd "=") 'svn-status-show-svn-diff)
1027 (define-key svn-global-keymap (kbd "f =") 'svn-file-show-svn-diff)
1028 (define-key svn-global-keymap (kbd "f e") 'svn-file-show-svn-ediff)
1029 (define-key svn-global-keymap (kbd "f l") 'svn-status-show-svn-log)
1030 (define-key svn-global-keymap (kbd "f b") 'svn-status-blame)
1031 (define-key svn-global-keymap (kbd "f a") 'svn-file-add-to-changelog)
1032 (define-key svn-global-keymap (kbd "f r") 'svn-file-revert)
1033 (define-key svn-global-keymap (kbd "c") 'svn-status-commit)
1034 (define-key svn-global-keymap (kbd "S") 'svn-status-switch-to-status-buffer)
1035 (define-key svn-global-keymap (kbd "o") 'svn-status-pop-to-status-buffer)
1036 (define-key svn-global-keymap (kbd "C-k") 'svn-process-kill))
1037
1038(defvar svn-status-diff-mode-map ()
1039 "Keymap used in `svn-status-diff-mode' for additional commands that are not defined in diff-mode.")
1040(put 'svn-status-diff-mode-map 'risky-local-variable t) ;for Emacs 20.7
1041
1042(when (not svn-status-diff-mode-map)
1043 (setq svn-status-diff-mode-map (copy-keymap diff-mode-shared-map))
1044 (define-key svn-status-diff-mode-map [?g] 'revert-buffer)
1045 (define-key svn-status-diff-mode-map [?s] 'svn-status-pop-to-status-buffer)
1046 (define-key svn-status-diff-mode-map [?c] 'svn-status-diff-pop-to-commit-buffer)
1047 (define-key svn-status-diff-mode-map [?w] 'svn-status-diff-save-current-defun-as-kill))
1048
1049(defvar svn-global-trac-map ()
1050 "Subkeymap used in `svn-global-keymap' for trac issue tracker commands.")
1051(put 'svn-global-trac-map 'risky-local-variable t) ;for Emacs 20.7
1052(when (not svn-global-trac-map)
1053 (setq svn-global-trac-map (make-sparse-keymap))
1054 (define-key svn-global-trac-map (kbd "w") 'svn-trac-browse-wiki)
1055 (define-key svn-global-trac-map (kbd "t") 'svn-trac-browse-timeline)
1056 (define-key svn-global-trac-map (kbd "m") 'svn-trac-browse-roadmap)
1057 (define-key svn-global-trac-map (kbd "s") 'svn-trac-browse-source)
1058 (define-key svn-global-trac-map (kbd "r") 'svn-trac-browse-report)
1059 (define-key svn-global-trac-map (kbd "i") 'svn-trac-browse-ticket)
1060 (define-key svn-global-trac-map (kbd "c") 'svn-trac-browse-changeset)
1061 (define-key svn-global-keymap (kbd "t") svn-global-trac-map))
1062
1063;; The setter of `svn-status-prefix-key' makes a binding in the global
1064;; map refer to the `svn-global-keymap' symbol, rather than directly
1065;; to the keymap. Emacs then implicitly uses the symbol-function.
1066;; This has the advantage that `describe-bindings' (C-h b) can show
1067;; the name of the keymap and link to its documentation.
1068(defalias 'svn-global-keymap svn-global-keymap)
1069;; `defalias' of GNU Emacs 21.4 doesn't allow a docstring argument.
1070(put 'svn-global-keymap 'function-documentation
1071 '(documentation-property 'svn-global-keymap 'variable-documentation t))
1072
1073
1074;; named after SVN_WC_ADM_DIR_NAME in svn_wc.h
1075(defun svn-wc-adm-dir-name ()
1076 "Return the name of the \".svn\" subdirectory or equivalent."
1077 (if (and (eq system-type 'windows-nt)
1078 (getenv "SVN_ASP_DOT_NET_HACK"))
1079 "_svn"
1080 ".svn"))
1081
1082(defun svn-log-edit-file-name (&optional curdir)
1083 "Get the name of the saved log edit file
1084If curdir, return `svn-log-edit-file-name'
1085Otherwise position svn-log-edit-file-name in the root directory of this working copy"
1086 (if curdir
1087 svn-log-edit-file-name
1088 (concat (svn-status-base-dir) svn-log-edit-file-name)))
1089
1090(defun svn-status-message (level &rest args)
1091 "If LEVEL is lower than `svn-status-debug-level' print ARGS using `message'.
1092
1093Guideline for numbers:
10941 - error messages, 3 - non-serious error messages, 5 - messages for things
1095that take a long time, 7 - not very important messages on stuff, 9 - messages
1096inside loops."
1097 (if (<= level svn-status-debug-level)
1098 (apply 'message args)))
1099
1100(defun svn-status-flatten-list (list)
1101 "Flatten any lists within ARGS, so that there are no sublists."
1102 (loop for item in list
1103 if (listp item) nconc (svn-status-flatten-list item)
1104 else collect item))
1105
1106(defun svn-status-window-line-position (w)
1107 "Return the window line at point for window W, or nil if W is nil."
1108 (svn-status-message 3 "About to count lines; selected window is %s" (selected-window))
1109 (and w (count-lines (window-start w) (point))))
1110
1111;;;###autoload
1112(defun svn-checkout (repos-url path)
1113 "Run svn checkout REPOS-URL PATH."
1114 (interactive (list (read-string "Checkout from repository Url: ")
1115 (svn-read-directory-name "Checkout to directory: ")))
1116 (svn-run t t 'checkout "checkout" repos-url (expand-file-name path)))
1117
1118;;;###autoload (defalias 'svn-examine 'svn-status)
1119(defalias 'svn-examine 'svn-status)
1120
1121;;;###autoload
1122(defun svn-status (dir &optional arg)
1123 "Examine the status of Subversion working copy in directory DIR.
1124If ARG is -, allow editing of the parameters. One could add -N to
1125run svn status non recursively to make it faster.
1126For every other non nil ARG pass the -u argument to `svn status', which
1127asks svn to connect to the repository and check to see if there are updates
1128there.
1129
1130If there is no .svn directory, examine if there is CVS and run
1131`cvs-examine'. Otherwise ask if to run `dired'."
1132 (interactive (list (svn-read-directory-name "SVN status directory: "
1133 nil default-directory nil)
1134 current-prefix-arg))
1135 (let ((svn-dir (format "%s%s"
1136 (file-name-as-directory dir)
1137 (svn-wc-adm-dir-name)))
1138 (cvs-dir (format "%sCVS" (file-name-as-directory dir))))
1139 (cond
1140 ((file-directory-p svn-dir)
1141 (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status))
1142 (svn-status-1 dir arg))
1143 ((and (file-directory-p cvs-dir)
1144 (fboundp 'cvs-examine))
1145 (cvs-examine dir nil))
1146 (t
1147 (when (y-or-n-p
1148 (format
1149 (concat
1150 "%s "
1151 "is not Subversion controlled (missing %s "
1152 "directory). "
1153 "Run dired instead? ")
1154 dir
1155 (svn-wc-adm-dir-name)))
1156 (dired dir))))))
1157
1158(defvar svn-status-display-new-status-buffer nil)
1159(defun svn-status-1 (dir &optional arg)
1160 "Examine DIR. See `svn-status' for more information."
1161 (unless (file-directory-p dir)
1162 (error "%s is not a directory" dir))
1163 (setq dir (file-name-as-directory dir))
1164 (when svn-status-load-state-before-svn-status
1165 (unless (string= dir (car svn-status-directory-history))
1166 (let ((default-directory dir)) ;otherwise svn-status-base-dir looks in the wrong place
1167 (svn-status-load-state t))))
1168 (setq svn-status-directory-history (delete dir svn-status-directory-history))
1169 (add-to-list 'svn-status-directory-history dir)
1170 (if (string= (buffer-name) svn-status-buffer-name)
1171 (setq svn-status-display-new-status-buffer nil)
1172 (setq svn-status-display-new-status-buffer t)
1173 ;;(message "psvn: Saving initial window configuration")
1174 (setq svn-status-initial-window-configuration
1175 (current-window-configuration)))
1176 (let* ((cur-buf (current-buffer))
1177 (status-buf (get-buffer-create svn-status-buffer-name))
1178 (proc-buf (get-buffer-create svn-process-buffer-name))
1179 (want-edit (eq arg '-))
1180 (status-option (if want-edit
1181 (if svn-status-verbose "-v" "")
1182 (if svn-status-verbose
1183 (if arg "-uv" "-v")
1184 (if arg "-u" "")))))
1185 (save-excursion
1186 (set-buffer status-buf)
1187 (buffer-disable-undo)
1188 (setq default-directory dir)
1189 (set-buffer proc-buf)
1190 (setq default-directory dir
1191 svn-status-remote (when arg t))
1192 (set-buffer cur-buf)
1193 (if want-edit
1194 (let ((svn-status-edit-svn-command t))
1195 (svn-run t t 'status "status" svn-status-default-status-arguments status-option))
1196 (svn-run t t 'status "status" svn-status-default-status-arguments status-option)))))
1197
1198(defun svn-status-this-directory (arg)
1199 "Run `svn-status' for the `default-directory'"
1200 (interactive "P")
1201 (svn-status default-directory arg))
1202
1203(defun svn-status-use-history ()
1204 "Interactively select a different directory from `svn-status-directory-history'."
1205 (interactive)
1206 (let* ((in-status-buffer (eq major-mode 'svn-status-mode))
1207 (hist (if in-status-buffer (cdr svn-status-directory-history) svn-status-directory-history))
1208 (dir (funcall svn-status-completing-read-function "svn-status on directory: " hist))
1209 (svn-status-buffer (get-buffer svn-status-buffer-name))
1210 (svn-buffer-available (and svn-status-buffer
1211 (with-current-buffer svn-status-buffer-name (string= default-directory dir)))))
1212 (if (file-directory-p dir)
1213 (if svn-buffer-available
1214 (svn-status-switch-to-status-buffer)
1215 (unless svn-status-refresh-info
1216 (setq svn-status-refresh-info 'once))
1217 (svn-status dir))
1218 (error "%s is not a directory" dir))))
1219
1220(defun svn-had-user-input-since-asynch-run ()
1221 (not (equal (recent-keys) svn-pre-run-asynch-recent-keys)))
1222
1223(defun svn-expand-filename-for-remote-access (file-name)
1224 "Convert the given local part of a filename to a full file name to allow accessing remote files"
1225 ;; when running svn on a remote host: expand local file names to get full names to access the file on the remote host via emacs
1226 (if (and (fboundp 'file-remote-p) (file-remote-p default-directory))
1227 (concat (file-remote-p default-directory) file-name)
1228 file-name))
1229
1230(defun svn-local-filename-for-remote-access (file-name)
1231 "Convert a full file name to a local file name that can be used for a local svn invocation."
1232 (if (and (fboundp 'file-remote-p) (file-remote-p file-name))
1233 (tramp-file-name-localname (tramp-dissect-file-name file-name))
1234 file-name))
1235
1236(defun svn-process-environment ()
1237 "Construct the environment for the svn process.
1238It is a combination of `svn-status-svn-environment-var-list' and
1239the usual `process-environment'."
1240 ;; If there are duplicate elements in `process-environment', then GNU
1241 ;; Emacs 21.4 guarantees that the first one wins; but GNU Emacs 20.7
1242 ;; and XEmacs 21.4.17 don't document what happens. We'll just remove
1243 ;; any duplicates ourselves, then. This also gives us an opportunity
1244 ;; to handle the "VARIABLE" syntax that none of them supports.
1245 (loop with found = '()
1246 for elt in (append svn-status-svn-environment-var-list
1247 process-environment)
1248 for has-value = (string-match "=" elt)
1249 for name = (substring elt 0 has-value)
1250 unless (member name found)
1251 do (push name found)
1252 and when has-value
1253 collect elt))
1254
1255(defun svn-run (run-asynchron clear-process-buffer cmdtype &rest arglist)
1256 "Run svn with arguments ARGLIST.
1257
1258If RUN-ASYNCHRON is t then run svn asynchronously.
1259
1260If CLEAR-PROCESS-BUFFER is t then erase the contents of the
1261`svn-process-buffer-name' buffer before commencing.
1262
1263CMDTYPE is a symbol such as 'mv, 'revert, or 'add, representing the
1264command to run.
1265
1266ARGLIST is a list of arguments \(which must include the command name,
1267for example: '(\"revert\" \"file1\"\)
1268ARGLIST is flattened and any every nil value is discarded.
1269
1270If the variable `svn-status-edit-svn-command' is non-nil then the user
1271can edit ARGLIST before running svn.
1272
1273The hook svn-pre-run-hook allows to monitor/modify the ARGLIST."
1274 (setq arglist (svn-status-flatten-list arglist))
1275 (if (eq (process-status "svn") nil)
1276 (progn
1277 (when svn-status-edit-svn-command
1278 (setq arglist (append
1279 (list (car arglist))
1280 (split-string
1281 (read-from-minibuffer
1282 (format "svn %s flags: " (car arglist))
1283 (mapconcat 'identity (cdr arglist) " ")))))
1284 (when (eq svn-status-edit-svn-command t)
1285 (svn-status-toggle-edit-cmd-flag t))
1286 (message "svn-run %s: %S" cmdtype arglist))
1287 (run-hooks 'svn-pre-run-hook)
1288 (unless (eq mode-line-process 'svn-status-mode-line-process)
1289 (setq svn-pre-run-mode-line-process mode-line-process)
1290 (setq mode-line-process 'svn-status-mode-line-process))
1291 (setq svn-status-pre-run-svn-buffer (current-buffer))
1292 (let* ((proc-buf (get-buffer-create svn-process-buffer-name))
1293 (svn-exe svn-status-svn-executable)
1294 (svn-proc))
1295 (when (listp (car arglist))
1296 (setq arglist (car arglist)))
1297 (save-excursion
1298 (set-buffer proc-buf)
1299 (unless (file-executable-p default-directory)
1300 (message "psvn: workaround in %s needed: %s no longer exists" (current-buffer) default-directory)
1301 (cd (expand-file-name "~")))
1302 (setq buffer-read-only nil)
1303 (buffer-disable-undo)
1304 (fundamental-mode)
1305 (if clear-process-buffer
1306 (delete-region (point-min) (point-max))
1307 (goto-char (point-max)))
1308 (setq svn-process-cmd cmdtype)
1309 (setq svn-status-last-commit-author nil)
1310 (setq svn-status-mode-line-process-status (format " running %s" cmdtype))
1311 (svn-status-update-mode-line)
1312 (save-excursion (sit-for 0.1))
1313 (ring-insert svn-last-cmd-ring (list (current-time-string) arglist default-directory))
1314 (if run-asynchron
1315 (progn
1316 ;;(message "running asynchron: %s %S" svn-exe arglist)
1317 (setq svn-pre-run-asynch-recent-keys (recent-keys))
1318 (let ((process-environment (svn-process-environment))
1319 (process-connection-type nil))
1320 ;; Communicate with the subprocess via pipes rather
1321 ;; than via a pseudoterminal, so that if the svn+ssh
1322 ;; scheme is being used, SSH will not ask for a
1323 ;; passphrase via stdio; psvn.el is currently unable
1324 ;; to answer such prompts. Instead, SSH will run
1325 ;; x11-ssh-askpass if possible. If Emacs is being
1326 ;; run on a TTY without $DISPLAY, this will fail; in
1327 ;; such cases, the user should start ssh-agent and
1328 ;; then run ssh-add explicitly.
1329 (setq svn-proc (apply svn-start-process-function "svn" proc-buf svn-exe arglist)))
1330 (when svn-status-svn-process-coding-system
1331 (set-process-coding-system svn-proc svn-status-svn-process-coding-system
1332 svn-status-svn-process-coding-system))
1333 (set-process-sentinel svn-proc 'svn-process-sentinel)
1334 (when svn-status-track-user-input
1335 (set-process-filter svn-proc 'svn-process-filter)))
1336 ;;(message "running synchron: %s %S" svn-exe arglist)
1337 (let ((process-environment (svn-process-environment)))
1338 ;; `call-process' ignores `process-connection-type' and
1339 ;; never opens a pseudoterminal.
1340 (apply svn-call-process-function svn-exe nil proc-buf nil arglist))
1341 (setq svn-status-last-output-buffer-name svn-process-buffer-name)
1342 (run-hooks 'svn-post-process-svn-output-hook)
1343 (setq svn-status-mode-line-process-status "")
1344 (svn-status-update-mode-line)
1345 (when svn-pre-run-mode-line-process
1346 (setq mode-line-process svn-pre-run-mode-line-process)
1347 (setq svn-pre-run-mode-line-process nil))))))
1348 (error "You can only run one svn process at once!")))
1349
1350(defun svn-process-sentinel-fixup-path-seperators ()
1351 "Convert all path separators to UNIX style.
1352\(This is a no-op unless `system-type' is windows-nt\)"
1353 (when (eq system-type 'windows-nt)
1354 (save-excursion
1355 (goto-char (point-min))
1356 (while (search-forward "\\" nil t)
1357 (replace-match "/")))))
1358
1359(defun svn-process-sentinel (process event)
1360 "Called after a svn process has finished."
1361 ;;(princ (format "Process: %s had the event `%s'" process event)))
1362 (let ((act-buf (current-buffer)))
1363 (when svn-pre-run-mode-line-process
1364 (with-current-buffer svn-status-pre-run-svn-buffer
1365 (setq mode-line-process svn-pre-run-mode-line-process))
1366 (setq svn-pre-run-mode-line-process nil))
1367 (set-buffer (process-buffer process))
1368 (setq svn-status-mode-line-process-status "")
1369 (svn-status-update-mode-line)
1370 (cond ((string= event "finished\n")
1371 (run-hooks 'svn-post-process-svn-output-hook)
1372 (cond ((eq svn-process-cmd 'status)
1373 ;;(message "svn status finished")
1374 (svn-process-sentinel-fixup-path-seperators)
1375 (svn-parse-status-result)
1376 (svn-status-apply-elide-list)
1377 (when svn-status-update-previous-process-output
1378 (set-buffer (process-buffer process))
1379 (delete-region (point-min) (point-max))
1380 (insert "Output from svn command:\n")
1381 (insert svn-status-update-previous-process-output)
1382 (goto-char (point-min))
1383 (setq svn-status-update-previous-process-output nil))
1384 (when svn-status-update-list
1385 ;; (message "Using svn-status-update-list: %S" svn-status-update-list)
1386 (save-excursion
1387 (svn-status-update-with-command-list svn-status-update-list))
1388 (setq svn-status-update-list nil))
1389 (when svn-status-display-new-status-buffer
1390 (set-window-configuration svn-status-initial-window-configuration)
1391 (if (svn-had-user-input-since-asynch-run)
1392 (message "svn status finished")
1393 (switch-to-buffer svn-status-buffer-name))))
1394 ((eq svn-process-cmd 'log)
1395 (svn-status-show-process-output 'log t)
1396 (pop-to-buffer svn-status-last-output-buffer-name)
1397 (svn-log-view-mode)
1398 (forward-line 2)
1399 (unless (looking-at "Changed paths:")
1400 (forward-line 1))
1401 (font-lock-fontify-buffer)
1402 (message "svn log finished"))
1403 ((eq svn-process-cmd 'info)
1404 (svn-status-show-process-output 'info t)
1405 (message "svn info finished"))
1406 ((eq svn-process-cmd 'ls)
1407 (svn-status-show-process-output 'info t)
1408 (message "svn ls finished"))
1409 ((eq svn-process-cmd 'diff)
1410 (svn-status-activate-diff-mode)
1411 (message "svn diff finished"))
1412 ((eq svn-process-cmd 'parse-info)
1413 (svn-status-parse-info-result))
1414 ((eq svn-process-cmd 'blame)
1415 (svn-status-show-process-output 'blame t)
1416 (when svn-status-pre-run-svn-buffer
1417 (with-current-buffer svn-status-pre-run-svn-buffer
1418 (unless (eq major-mode 'svn-status-mode)
1419 (let ((src-line-number (svn-line-number-at-pos)))
1420 (pop-to-buffer (get-buffer svn-status-last-output-buffer-name))
1421 (goto-line src-line-number)))))
1422 (with-current-buffer (get-buffer svn-status-last-output-buffer-name)
1423 (svn-status-activate-blame-mode))
1424 (message "svn blame finished"))
1425 ((eq svn-process-cmd 'commit)
1426 (svn-process-sentinel-fixup-path-seperators)
1427 (svn-status-remove-temp-file-maybe)
1428 (when (member 'commit svn-status-unmark-files-after-list)
1429 (svn-status-unset-all-usermarks))
1430 (svn-status-update-with-command-list (svn-status-parse-commit-output))
1431 (svn-revert-some-buffers)
1432 (run-hooks 'svn-log-edit-done-hook)
1433 (setq svn-status-files-to-commit nil
1434 svn-status-recursive-commit nil)
1435 (if (null svn-status-commit-rev-number)
1436 (message "No revision to commit.")
1437 (message "svn: Committed revision %s." svn-status-commit-rev-number)))
1438 ((eq svn-process-cmd 'update)
1439 (svn-status-show-process-output 'update t)
1440 (setq svn-status-update-list (svn-status-parse-update-output))
1441 (svn-revert-some-buffers)
1442 (svn-status-update)
1443 (if (car svn-status-update-rev-number)
1444 (message "svn: Updated to revision %s." (cadr svn-status-update-rev-number))
1445 (message "svn: At revision %s." (cadr svn-status-update-rev-number))))
1446 ((eq svn-process-cmd 'add)
1447 (svn-status-update-with-command-list (svn-status-parse-ar-output))
1448 (message "svn add finished"))
1449 ((eq svn-process-cmd 'lock)
1450 (svn-status-update)
1451 (message "svn lock finished"))
1452 ((eq svn-process-cmd 'unlock)
1453 (svn-status-update)
1454 (message "svn unlock finished"))
1455 ((eq svn-process-cmd 'mkdir)
1456 (svn-status-update)
1457 (message "svn mkdir finished"))
1458 ((eq svn-process-cmd 'revert)
1459 (when (member 'revert svn-status-unmark-files-after-list)
1460 (svn-status-unset-all-usermarks))
1461 (svn-revert-some-buffers)
1462 (svn-status-update)
1463 (message "svn revert finished"))
1464 ((eq svn-process-cmd 'resolved)
1465 (svn-status-update)
1466 (message "svn resolved finished"))
1467 ((eq svn-process-cmd 'rm)
1468 (svn-status-update-with-command-list (svn-status-parse-ar-output))
1469 (message "svn rm finished"))
1470 ((eq svn-process-cmd 'cleanup)
1471 (message "svn cleanup finished"))
1472 ((eq svn-process-cmd 'proplist)
1473 (svn-status-show-process-output 'proplist t)
1474 (message "svn proplist finished"))
1475 ((eq svn-process-cmd 'checkout)
1476 (svn-status default-directory))
1477 ((eq svn-process-cmd 'proplist-parse)
1478 (svn-status-property-parse-property-names))
1479 ((eq svn-process-cmd 'propset)
1480 (svn-status-remove-temp-file-maybe)
1481 (if (member svn-status-propedit-property-name '("svn:keywords"))
1482 (svn-status-update-with-command-list (svn-status-parse-property-output))
1483 (svn-status-update)))
1484 ((eq svn-process-cmd 'propdel)
1485 (svn-status-update))))
1486 ((string= event "killed\n")
1487 (message "svn process killed"))
1488 ((string-match "exited abnormally" event)
1489 (while (accept-process-output process 0 100))
1490 ;; find last error message and show it.
1491 (goto-char (point-max))
1492 (if (re-search-backward "^svn: " nil t)
1493 (let ((error-strings)
1494 (beginning-of-buffer))
1495 (while (and (looking-at "^svn: ") (not beginning-of-buffer))
1496 (setq error-strings (append error-strings (list (buffer-substring-no-properties (+ 5 (svn-point-at-bol)) (svn-point-at-eol)))))
1497 (setq beginning-of-buffer (bobp))
1498 (forward-line -1))
1499 (svn-process-handle-error (mapconcat 'identity (reverse error-strings) "\n")))
1500 (message "svn failed: %s" event)))
1501 (t
1502 (message "svn process had unknown event: %s" event))
1503 (svn-status-show-process-output nil t))))
1504
1505(defvar svn-process-handle-error-msg nil)
1506(defvar svn-handle-error-function nil
1507 "A function that will be called with an error string received from the svn client.
1508When this function resets `svn-process-handle-error-msg' to nil, the default error handling
1509(just show the error message) is not executed.")
1510(defun svn-process-handle-error (error-msg)
1511 (let ((svn-process-handle-error-msg error-msg))
1512 (when (functionp svn-handle-error-function)
1513 (funcall svn-handle-error-function error-msg))
1514 (when svn-process-handle-error-msg
1515 (electric-helpify 'svn-process-help-with-error-msg))))
1516
1517(defun svn-process-help-with-error-msg ()
1518 (interactive)
1519 (let ((help-msg (cadr (assoc svn-process-handle-error-msg
1520 '(("Cannot non-recursively commit a directory deletion"
1521 "Please unmark all files and position point at the directory you would like to remove.\nThen run commit again."))))))
1522 (if help-msg
1523 (save-excursion
1524 (with-output-to-temp-buffer (svn-help-buffer)
1525 (princ (format "svn failed: %s\n\n%s" svn-process-handle-error-msg help-msg))))
1526 (message "svn failed:\n%s" svn-process-handle-error-msg))))
1527
1528
1529(defun svn-process-filter (process str)
1530 "Track the svn process output and ask user questions in the minibuffer when appropriate."
1531 (save-window-excursion
1532 (set-buffer svn-process-buffer-name)
1533 ;;(message "svn-process-filter: %s" str)
1534 (goto-char (point-max))
1535 (insert str)
1536 (save-excursion
1537 (goto-char (svn-point-at-bol))
1538 (when (looking-at "Password for '\\(.*\\)': ")
1539 ;(svn-status-show-process-buffer)
1540 (let ((passwd (read-passwd
1541 (format "Enter svn password for %s: " (match-string 1)))))
1542 (svn-process-send-string-and-newline passwd t)))
1543 (when (looking-at "Username: ")
1544 (let ((user-name (with-local-quit (read-string "Username for svn operation: "))))
1545 (svn-process-send-string-and-newline user-name)))
1546 (when (looking-at "(R)eject, accept (t)emporarily or accept (p)ermanently")
1547 (svn-status-show-process-buffer)
1548 (let ((answer (with-local-quit (read-string "(R)eject, accept (t)emporarily or accept (p)ermanently? "))))
1549 (svn-process-send-string (substring answer 0 1)))))))
1550
1551(defun svn-revert-some-buffers (&optional tree)
1552 "Reverts all buffers visiting a file in TREE that aren't modified.
1553To be run after a commit, an update or a merge."
1554 (interactive)
1555 (let ((tree (or (svn-status-base-dir) tree)))
1556 (dolist (buffer (buffer-list))
1557 (with-current-buffer buffer
1558 (when (not (buffer-modified-p))
1559 (let ((file (buffer-file-name)))
1560 (when file
1561 (let ((root (svn-status-base-dir (file-name-directory file)))
1562 (point-pos (point)))
1563 (when (and root
1564 (string= root tree)
1565 ;; buffer is modified and in the tree TREE.
1566 svn-status-auto-revert-buffers)
1567 (when svn-status-fancy-file-state-in-modeline
1568 (svn-status-update-modeline))
1569 ;; (message "svn-revert-some-buffers: %s %s" (buffer-file-name) (verify-visited-file-modtime (current-buffer)))
1570 ;; Keep the buffer if the file doesn't exist
1571 (when (and (file-exists-p file) (not (verify-visited-file-modtime (current-buffer))))
1572 (revert-buffer t t)
1573 (goto-char point-pos)))))))))))
1574
1575(defun svn-parse-rev-num (str)
1576 (if (and str (stringp str)
1577 (save-match-data (string-match "^[0-9]+" str)))
1578 (string-to-number str)
1579 -1))
1580
1581(defsubst svn-status-make-ui-status ()
1582 "Make a ui-status structure for a file in a svn working copy.
1583The initial values in the structure returned by this function
1584are good for a file or directory that the user hasn't seen before.
1585
1586The ui-status structure keeps track of how the file or directory
1587should be displayed in svn-status mode. Updating the svn-status
1588buffer from the working copy preserves the ui-status if possible.
1589User commands modify this structure; each file or directory must
1590thus have its own copy.
1591
1592Currently, the ui-status is a list (USER-MARK USER-ELIDE).
1593USER-MARK is non-nil iff the user has marked the file or directory,
1594 typically with `svn-status-set-user-mark'. To read USER-MARK,
1595 call `svn-status-line-info->has-usermark'.
1596USER-ELIDE is non-nil iff the user has elided the file or directory
1597 from the svn-status buffer, typically with `svn-status-toggle-elide'.
1598 To read USER-ELIDE, call `svn-status-line-info->user-elide'.
1599
1600Call `svn-status-line-info->ui-status' to access the whole ui-status
1601structure."
1602 (list nil nil))
1603
1604(defun svn-status-make-dummy-dirs (dir-list old-ui-information)
1605 "Calculate additionally necessary directories that were not shown in the output
1606of 'svn status'"
1607 ;; (message "svn-status-make-dummy-dirs %S" dir-list)
1608 (let ((candidate)
1609 (base-dir))
1610 (dolist (dir dir-list)
1611 (setq base-dir (file-name-directory dir))
1612 (while base-dir
1613 ;;(message "dir: %S dir-list: %S, base-dir: %S" dir dir-list base-dir)
1614 (setq candidate (replace-regexp-in-string "/+$" "" base-dir))
1615 (setq base-dir (file-name-directory candidate))
1616 ;; (message "dir: %S, candidate: %S" dir candidate)
1617 (add-to-list 'dir-list candidate))))
1618 ;; (message "svn-status-make-dummy-dirs %S" dir-list)
1619 (append (mapcar (lambda (dir)
1620 (svn-status-make-line-info
1621 dir
1622 (gethash dir old-ui-information)))
1623 dir-list)
1624 svn-status-info))
1625
1626(defun svn-status-make-line-info (&optional
1627 path
1628 ui
1629 file-mark prop-mark
1630 local-rev last-change-rev
1631 author
1632 update-mark
1633 locked-mark
1634 with-history-mark
1635 switched-mark
1636 locked-repo-mark
1637 psvn-extra-info)
1638 "Create a new line-info from the given arguments
1639Anything left nil gets a sensible default.
1640nb: LOCKED-MARK refers to the kind of locks you get after an error,
1641 LOCKED-REPO-MARK is the kind managed with `svn lock'"
1642 (list (or ui (svn-status-make-ui-status))
1643 (or file-mark ? )
1644 (or prop-mark ? )
1645 (or path "")
1646 (or local-rev ? )
1647 (or last-change-rev ? )
1648 (or author "")
1649 update-mark
1650 locked-mark
1651 with-history-mark
1652 switched-mark
1653 locked-repo-mark
1654 psvn-extra-info))
1655
1656(defvar svn-user-names-including-blanks nil "A list of svn user names that include blanks.
1657To add support for the names \"feng shui\" and \"mister blank\", place the following in your .emacs:
1658 (setq svn-user-names-including-blanks '(\"feng shui\" \"mister blank\"))
1659 (add-hook 'svn-pre-parse-status-hook 'svn-status-parse-fixup-user-names-including-blanks)
1660")
1661;;(setq svn-user-names-including-blanks '("feng shui" "mister blank"))
1662;;(add-hook 'svn-pre-parse-status-hook 'svn-status-parse-fixup-user-names-including-blanks)
1663
1664(defun svn-status-parse-fixup-user-names-including-blanks ()
1665 "Helper function to allow user names that include blanks.
1666Add this function to the `svn-pre-parse-status-hook'. The variable
1667`svn-user-names-including-blanks' must be configured to hold all user names that contain
1668blanks. This function replaces the blanks with '-' to allow further processing with
1669the usual parsing functionality in `svn-parse-status-result'."
1670 (when svn-user-names-including-blanks
1671 (goto-char (point-min))
1672 (let ((search-string (concat " \\(" (mapconcat 'concat svn-user-names-including-blanks "\\|") "\\) ")))
1673 (save-match-data
1674 (save-excursion
1675 (while (re-search-forward search-string (point-max) t)
1676 (replace-match (replace-regexp-in-string " " "-" (match-string 1)) nil nil nil 1)))))))
1677
1678(defun svn-parse-status-result ()
1679 "Parse the `svn-process-buffer-name' buffer.
1680The results are used to build the `svn-status-info' variable."
1681 (setq svn-status-head-revision nil)
1682 (save-excursion
1683 (let ((old-ui-information (svn-status-ui-information-hash-table))
1684 (svn-marks)
1685 (svn-file-mark)
1686 (svn-property-mark)
1687 (svn-wc-locked-mark)
1688 (svn-repo-locked-mark)
1689 (svn-with-history-mark)
1690 (svn-switched-mark)
1691 (svn-update-mark)
1692 (local-rev)
1693 (last-change-rev)
1694 (author)
1695 (path)
1696 (dir)
1697 (revision-width svn-status-default-revision-width)
1698 (author-width svn-status-default-author-width)
1699 (svn-marks-length (if svn-status-verbose
1700 (if svn-status-remote
1701 8 6)
1702 (if svn-status-remote
1703 ;; not verbose
1704 8 7)))
1705 (dir-set '("."))
1706 (externals-map (make-hash-table :test 'equal))
1707 (skip-double-external-dir-entry-name nil))
1708 (set-buffer svn-process-buffer-name)
1709 (setq svn-status-info nil)
1710 (run-hooks 'svn-pre-parse-status-hook)
1711 (goto-char (point-min))
1712 (while (< (point) (point-max))
1713 (cond
1714 ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
1715 nil)
1716 ((looking-at "Status against revision:[ ]+\\([0-9]+\\)")
1717 ;; the above message appears for the main listing plus once for each svn:externals entry
1718 (unless svn-status-head-revision
1719 (setq svn-status-head-revision (match-string 1))))
1720 ((looking-at "Performing status on external item at '\\(.*\\)'")
1721 ;; The *next* line has info about the directory named in svn:externals
1722 ;; [ie the directory in (match-string 1)]
1723 ;; we should parse it, and merge the info with what we have already know
1724 ;; but for now just ignore the line completely
1725 ; (forward-line)
1726 ;; Actually, this seems to not always be the case
1727 ;; I have an example where we are in an svn:external which
1728 ;; is itself inside a svn:external, this need not be true:
1729 ;; the next line is not 'X dir' but just 'dir', so we
1730 ;; actually need to parse that line, or the results will
1731 ;; not contain dir!
1732 ;; so we should merge lines 'X dir' with ' dir', but for now
1733 ;; we just leave both in the results
1734
1735 ;; My attempt to merge the lines uses skip-double-external-dir-entry-name
1736 ;; and externals-map
1737 (setq skip-double-external-dir-entry-name (svn-match-string-no-properties 1))
1738 ;; (message "Going to skip %s" skip-double-external-dir-entry-name)
1739 nil)
1740 ((looking-at "--- Changelist") ; skip svn changelist header lines
1741 ;; See: http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
1742 nil)
1743 (t
1744 (setq svn-marks (buffer-substring (point) (+ (point) svn-marks-length))
1745 svn-file-mark (elt svn-marks 0) ; 1st column - M,A,C,D,G,? etc
1746 svn-property-mark (elt svn-marks 1) ; 2nd column - M,C (properties)
1747 svn-wc-locked-mark (elt svn-marks 2) ; 3rd column - L or blank
1748 svn-with-history-mark (elt svn-marks 3) ; 4th column - + or blank
1749 svn-switched-mark (elt svn-marks 4) ; 5th column - S,X or blank
1750 svn-repo-locked-mark (elt svn-marks 5)) ; 6th column - K,O,T,B or blank
1751 (when svn-status-remote
1752 (setq svn-update-mark (elt svn-marks 7))) ; 8th column - * or blank
1753 (when (eq svn-property-mark ?\ ) (setq svn-property-mark nil))
1754 (when (eq svn-wc-locked-mark ?\ ) (setq svn-wc-locked-mark nil))
1755 (when (eq svn-with-history-mark ?\ ) (setq svn-with-history-mark nil))
1756 (when (eq svn-switched-mark ?\ ) (setq svn-switched-mark nil))
1757 (when (eq svn-update-mark ?\ ) (setq svn-update-mark nil))
1758 (when (eq svn-repo-locked-mark ?\ ) (setq svn-repo-locked-mark nil))
1759 (forward-char svn-marks-length)
1760 (skip-chars-forward " ")
1761 ;; (message "after marks: '%s'" (buffer-substring (point) (line-end-position)))
1762 (cond
1763 ((looking-at "\\([-?]\\|[0-9]+\\) +\\([-?]\\|[0-9]+\\) +\\([^ ]+\\) *\\(.+\\)$")
1764 (setq local-rev (svn-parse-rev-num (match-string 1))
1765 last-change-rev (svn-parse-rev-num (match-string 2))
1766 author (match-string 3)
1767 path (match-string 4)))
1768 ((looking-at "\\([-?]\\|[0-9]+\\) +\\([^ ]+\\)$")
1769 (setq local-rev (svn-parse-rev-num (match-string 1))
1770 last-change-rev -1
1771 author "?"
1772 path (match-string 2)))
1773 ((looking-at "\\(.*\\)")
1774 (setq path (match-string 1)
1775 local-rev -1
1776 last-change-rev -1
1777 author (if (eq svn-file-mark ?X) "" "?"))) ;clear author of svn:externals dirs
1778 (t
1779 (error "Unknown status line format")))
1780 (unless path (setq path "."))
1781 (setq dir (file-name-directory path))
1782 (if (and (not svn-status-verbose) dir)
1783 (let ((dirname (directory-file-name dir)))
1784 (if (not (member dirname dir-set))
1785 (setq dir-set (cons dirname dir-set)))))
1786 (if (and skip-double-external-dir-entry-name (string= skip-double-external-dir-entry-name path))
1787 ;; merge this entry to a previous saved one
1788 (let ((info (gethash path externals-map)))
1789 ;; (message "skip-double-external-dir-entry-name: %s - path: %s" skip-double-external-dir-entry-name path)
1790 (if info
1791 (progn
1792 (svn-status-line-info->set-localrev info local-rev)
1793 (svn-status-line-info->set-lastchangerev info last-change-rev)
1794 (svn-status-line-info->set-author info author)
1795 (svn-status-message 3 "merging entry for %s to %s" path info)
1796 (setq skip-double-external-dir-entry-name nil))
1797 (message "psvn: %s not handled correct, please report this case." path)))
1798 (setq svn-status-info
1799 (cons (svn-status-make-line-info path
1800 (gethash path old-ui-information)
1801 svn-file-mark
1802 svn-property-mark
1803 local-rev
1804 last-change-rev
1805 author
1806 svn-update-mark
1807 svn-wc-locked-mark
1808 svn-with-history-mark
1809 svn-switched-mark
1810 svn-repo-locked-mark
1811 nil) ;;psvn-extra-info
1812 svn-status-info)))
1813 (when (eq svn-file-mark ?X)
1814 (svn-puthash (match-string 1) (car svn-status-info) externals-map)
1815 (svn-status-message 3 "found external: %s %S" (match-string 1) (car svn-status-info)))
1816 (setq revision-width (max revision-width
1817 (length (number-to-string local-rev))
1818 (length (number-to-string last-change-rev))))
1819 (setq author-width (max author-width (length author)))))
1820 (forward-line 1))
1821 (unless svn-status-verbose
1822 (setq svn-status-info (svn-status-make-dummy-dirs dir-set
1823 old-ui-information)))
1824 (setq svn-status-default-column
1825 (+ 6 revision-width revision-width author-width
1826 (if svn-status-short-mod-flag-p 3 0)))
1827 (setq svn-status-line-format (format " %%c%%c%%c %%%ds %%%ds %%-%ds"
1828 revision-width
1829 revision-width
1830 author-width))
1831 (setq svn-status-info (nreverse svn-status-info))
1832 (when svn-status-sort-status-buffer
1833 (setq svn-status-info (sort svn-status-info 'svn-status-sort-predicate))))))
1834
1835;;(string-lessp "." "%") => nil
1836;;(svn-status-sort-predicate '(t t t ".") '(t t t "%")) => t
1837(defun svn-status-sort-predicate (a b)
1838 "Return t if A should appear before B in the `svn-status-buffer-name' buffer.
1839A and B must be line-info's."
1840 (string-lessp (concat (svn-status-line-info->full-path a) "/")
1841 (concat (svn-status-line-info->full-path b) "/")))
1842
1843(defun svn-status-remove-temp-file-maybe ()
1844 "Remove any (no longer required) temporary files created by psvn.el."
1845 (when svn-status-temp-file-to-remove
1846 (when (file-exists-p svn-status-temp-file-to-remove)
1847 (delete-file svn-status-temp-file-to-remove))
1848 (when (file-exists-p svn-status-temp-arg-file)
1849 (delete-file svn-status-temp-arg-file))
1850 (setq svn-status-temp-file-to-remove nil)))
1851
1852(defun svn-status-remove-control-M ()
1853 "Remove ^M at end of line in the whole buffer."
1854 (interactive)
1855 (let ((buffer-read-only nil))
1856 (save-match-data
1857 (save-excursion
1858 (goto-char (point-min))
1859 (while (re-search-forward "\r$" (point-max) t)
1860 (replace-match "" nil nil))))))
1861
1862(defun svn-fixup-tramp-exit ()
1863 "Helper function to handle tramp connections stopping with an exit output."
1864 (goto-char (point-max))
1865 (when (eq (svn-point-at-bol) (svn-point-at-eol))
1866 (forward-line -1))
1867 (beginning-of-line)
1868 (when (looking-at "exit")
1869 (delete-region (point) (svn-point-at-eol))))
1870
1871(defun svn-fixup-tramp-output-maybe ()
1872 "Fixup leftover output when running via tramp"
1873 (when (fboundp 'file-remote-p)
1874 (when (file-remote-p default-directory)
1875 (svn-fixup-tramp-exit))))
1876
1877(condition-case nil
1878 ;;(easy-menu-add-item nil '("tools") ["SVN Status" svn-status t] "PCL-CVS")
1879 (easy-menu-add-item nil '("tools") ["SVN Status" svn-status t])
1880 (error (message "psvn: could not install menu")))
1881
1882(defvar svn-status-mode-map () "Keymap used in `svn-status-mode' buffers.")
1883(put 'svn-status-mode-map 'risky-local-variable t) ;for Emacs 20.7
1884(defvar svn-status-mode-mark-map ()
1885 "Subkeymap used in `svn-status-mode' for mark commands.")
1886(put 'svn-status-mode-mark-map 'risky-local-variable t) ;for Emacs 20.7
1887(defvar svn-status-mode-property-map ()
1888 "Subkeymap used in `svn-status-mode' for property commands.")
1889(put 'svn-status-mode-property-map 'risky-local-variable t) ;for Emacs 20.7
1890(defvar svn-status-mode-options-map ()
1891 "Subkeymap used in `svn-status-mode' for option commands.")
1892(put 'svn-status-mode-options-map 'risky-local-variable t) ;for Emacs 20.7
1893(defvar svn-status-mode-trac-map ()
1894 "Subkeymap used in `svn-status-mode' for trac issue tracker commands.")
1895(put 'svn-status-mode-trac-map 'risky-local-variable t) ;for Emacs 20.7
1896(defvar svn-status-mode-extension-map ()
1897 "Subkeymap used in `svn-status-mode' for some seldom used commands.")
1898(put 'svn-status-mode-extension-map 'risky-local-variable t) ;for Emacs 20.7
1899(defvar svn-status-mode-branch-map ()
1900 "Subkeymap used in `svn-status-mode' for branching commands.")
1901(put 'svn-status-mode-extension-map 'risky-local-variable t) ;for Emacs 20.7
1902(defvar svn-status-mode-search-map ()
1903 "Subkeymap used in `svn-status-mode' for search commands.")
1904(put 'svn-status-mode-search-map 'risky-local-variable t) ;for Emacs 20.7
1905
1906(when (not svn-status-mode-map)
1907 (setq svn-status-mode-map (make-sparse-keymap))
1908 (suppress-keymap svn-status-mode-map)
1909 ;; Don't use (kbd "<return>"); it's unreachable with GNU Emacs 21.3 on a TTY.
1910 (define-key svn-status-mode-map (kbd "RET") 'svn-status-find-file-or-examine-directory)
1911 (define-key svn-status-mode-map (kbd "<mouse-2>") 'svn-status-mouse-find-file-or-examine-directory)
1912 (define-key svn-status-mode-map (kbd "^") 'svn-status-examine-parent)
1913 (define-key svn-status-mode-map (kbd "s") 'svn-status-show-process-buffer)
1914 (define-key svn-status-mode-map (kbd "h") 'svn-status-pop-to-partner-buffer)
1915 (define-key svn-status-mode-map (kbd "f") 'svn-status-find-files)
1916 (define-key svn-status-mode-map (kbd "o") 'svn-status-find-file-other-window)
1917 (define-key svn-status-mode-map (kbd "C-o") 'svn-status-find-file-other-window-noselect)
1918 (define-key svn-status-mode-map (kbd "v") 'svn-status-view-file-other-window)
1919 (define-key svn-status-mode-map (kbd "e") 'svn-status-toggle-edit-cmd-flag)
1920 (define-key svn-status-mode-map (kbd "g") 'svn-status-update)
1921 (define-key svn-status-mode-map (kbd "M-s") 'svn-status-update) ;; PCL-CVS compatibility
1922 (define-key svn-status-mode-map (kbd "q") 'svn-status-bury-buffer)
1923 (define-key svn-status-mode-map (kbd "x") 'svn-status-redraw-status-buffer)
1924 (define-key svn-status-mode-map (kbd "H") 'svn-status-use-history)
1925 (define-key svn-status-mode-map (kbd "m") 'svn-status-set-user-mark)
1926 (define-key svn-status-mode-map (kbd "u") 'svn-status-unset-user-mark)
1927 ;; This matches a binding of `dired-unmark-all-files' in `dired-mode-map'
1928 ;; of both GNU Emacs and XEmacs. It seems unreachable with XEmacs on
1929 ;; TTY, but if that's a problem then its Dired needs fixing too.
1930 ;; Or you could just use "*!".
1931 (define-key svn-status-mode-map "\M-\C-?" 'svn-status-unset-all-usermarks)
1932 ;; The key that normally deletes characters backwards should here
1933 ;; instead unmark files backwards. In GNU Emacs, that would be (kbd
1934 ;; "DEL") aka [?\177], but XEmacs treats those as [(delete)] and
1935 ;; would bind a key that normally deletes forwards. [(backspace)]
1936 ;; is unreachable with GNU Emacs on a tty. Try to recognize the
1937 ;; dialect and act accordingly.
1938 ;;
1939 ;; XEmacs has a `delete-forward-p' function that checks the
1940 ;; `delete-key-deletes-forward' option. We don't use those, for two
1941 ;; reasons: psvn.el may be loaded before user customizations, and
1942 ;; XEmacs allows simultaneous connections to multiple devices with
1943 ;; different keyboards.
1944 (define-key svn-status-mode-map
1945 (if (member (kbd "DEL") '([(delete)] [delete]))
1946 [(backspace)] ; XEmacs
1947 (kbd "DEL")) ; GNU Emacs
1948 'svn-status-unset-user-mark-backwards)
1949 (define-key svn-status-mode-map (kbd "$") 'svn-status-toggle-elide)
1950 (define-key svn-status-mode-map (kbd "w") 'svn-status-copy-current-line-info)
1951 (define-key svn-status-mode-map (kbd ".") 'svn-status-goto-root-or-return)
1952 (define-key svn-status-mode-map (kbd "I") 'svn-status-parse-info)
1953 (define-key svn-status-mode-map (kbd "V") 'svn-status-svnversion)
1954 (define-key svn-status-mode-map (kbd "?") 'svn-status-toggle-hide-unknown)
1955 (define-key svn-status-mode-map (kbd "_") 'svn-status-toggle-hide-unmodified)
1956 (define-key svn-status-mode-map (kbd "z") 'svn-status-toggle-hide-externals)
1957 (define-key svn-status-mode-map (kbd "a") 'svn-status-add-file)
1958 (define-key svn-status-mode-map (kbd "A") 'svn-status-add-file-recursively)
1959 (define-key svn-status-mode-map (kbd "+") 'svn-status-make-directory)
1960 (define-key svn-status-mode-map (kbd "R") 'svn-status-mv)
1961 (define-key svn-status-mode-map (kbd "C") 'svn-status-cp)
1962 (define-key svn-status-mode-map (kbd "D") 'svn-status-rm)
1963 (define-key svn-status-mode-map (kbd "c") 'svn-status-commit)
1964 (define-key svn-status-mode-map (kbd "M-c") 'svn-status-cleanup)
1965 (define-key svn-status-mode-map (kbd "k") 'svn-status-lock)
1966 (define-key svn-status-mode-map (kbd "K") 'svn-status-unlock)
1967 (define-key svn-status-mode-map (kbd "U") 'svn-status-update-cmd)
1968 (define-key svn-status-mode-map (kbd "M-u") 'svn-status-update-cmd)
1969 (define-key svn-status-mode-map (kbd "r") 'svn-status-revert)
1970 (define-key svn-status-mode-map (kbd "l") 'svn-status-show-svn-log)
1971 (define-key svn-status-mode-map (kbd "i") 'svn-status-info)
1972 (define-key svn-status-mode-map (kbd "b") 'svn-status-blame)
1973 (define-key svn-status-mode-map (kbd "=") 'svn-status-show-svn-diff)
1974 ;; [(control ?=)] is unreachable on TTY, but you can use "*u" instead.
1975 ;; (Is the "u" mnemonic for something?)
1976 (define-key svn-status-mode-map (kbd "C-=") 'svn-status-show-svn-diff-for-marked-files)
1977 (define-key svn-status-mode-map (kbd "~") 'svn-status-get-specific-revision)
1978 (define-key svn-status-mode-map (kbd "E") 'svn-status-ediff-with-revision)
1979
1980 (define-key svn-status-mode-map (kbd "n") 'svn-status-next-line)
1981 (define-key svn-status-mode-map (kbd "p") 'svn-status-previous-line)
1982 (define-key svn-status-mode-map (kbd "<down>") 'svn-status-next-line)
1983 (define-key svn-status-mode-map (kbd "<up>") 'svn-status-previous-line)
1984 (define-key svn-status-mode-map (kbd "C-x C-j") 'svn-status-dired-jump)
1985 (define-key svn-status-mode-map [down-mouse-3] 'svn-status-popup-menu))
1986
1987(when (not svn-status-mode-mark-map)
1988 (setq svn-status-mode-mark-map (make-sparse-keymap))
1989 (define-key svn-status-mode-map (kbd "*") svn-status-mode-mark-map)
1990 (define-key svn-status-mode-mark-map (kbd "!") 'svn-status-unset-all-usermarks)
1991 (define-key svn-status-mode-mark-map (kbd "?") 'svn-status-mark-unknown)
1992 (define-key svn-status-mode-mark-map (kbd "A") 'svn-status-mark-added)
1993 (define-key svn-status-mode-mark-map (kbd "M") 'svn-status-mark-modified)
1994 (define-key svn-status-mode-mark-map (kbd "P") 'svn-status-mark-modified-properties)
1995 (define-key svn-status-mode-mark-map (kbd "D") 'svn-status-mark-deleted)
1996 (define-key svn-status-mode-mark-map (kbd "*") 'svn-status-mark-changed)
1997 (define-key svn-status-mode-mark-map (kbd ".") 'svn-status-mark-by-file-ext)
1998 (define-key svn-status-mode-mark-map (kbd "%") 'svn-status-mark-filename-regexp)
1999 (define-key svn-status-mode-mark-map (kbd "s") 'svn-status-store-usermarks)
2000 (define-key svn-status-mode-mark-map (kbd "l") 'svn-status-load-usermarks)
2001 (define-key svn-status-mode-mark-map (kbd "u") 'svn-status-show-svn-diff-for-marked-files))
2002
2003(when (not svn-status-mode-search-map)
2004 (setq svn-status-mode-search-map (make-sparse-keymap))
2005 (define-key svn-status-mode-search-map (kbd "g") 'svn-status-grep-files)
2006 (define-key svn-status-mode-search-map (kbd "s") 'svn-status-search-files)
2007 (define-key svn-status-mode-map (kbd "S") svn-status-mode-search-map))
2008
2009(when (not svn-status-mode-property-map)
2010 (setq svn-status-mode-property-map (make-sparse-keymap))
2011 (define-key svn-status-mode-property-map (kbd "l") 'svn-status-property-list)
2012 (define-key svn-status-mode-property-map (kbd "s") 'svn-status-property-set)
2013 (define-key svn-status-mode-property-map (kbd "d") 'svn-status-property-delete)
2014 (define-key svn-status-mode-property-map (kbd "e") 'svn-status-property-edit-one-entry)
2015 (define-key svn-status-mode-property-map (kbd "i") 'svn-status-property-ignore-file)
2016 (define-key svn-status-mode-property-map (kbd "I") 'svn-status-property-ignore-file-extension)
2017 ;; XEmacs 21.4.15 on TTY (vt420) converts `C-i' to `TAB',
2018 ;; which [(control ?i)] won't match. Handle it separately.
2019 ;; On GNU Emacs, the following two forms bind the same key,
2020 ;; reducing clutter in `where-is'.
2021 (define-key svn-status-mode-property-map [(control ?i)] 'svn-status-property-edit-svn-ignore)
2022 (define-key svn-status-mode-property-map (kbd "TAB") 'svn-status-property-edit-svn-ignore)
2023 (define-key svn-status-mode-property-map (kbd "Xe") 'svn-status-property-edit-svn-externals)
2024 (define-key svn-status-mode-property-map (kbd "k") 'svn-status-property-set-keyword-list)
2025 (define-key svn-status-mode-property-map (kbd "Ki") 'svn-status-property-set-keyword-id)
2026 (define-key svn-status-mode-property-map (kbd "Kd") 'svn-status-property-set-keyword-date)
2027 (define-key svn-status-mode-property-map (kbd "y") 'svn-status-property-set-eol-style)
2028 (define-key svn-status-mode-property-map (kbd "x") 'svn-status-property-set-executable)
2029 (define-key svn-status-mode-property-map (kbd "m") 'svn-status-property-set-mime-type)
2030 ;; TODO: Why is `svn-status-select-line' in `svn-status-mode-property-map'?
2031 (define-key svn-status-mode-property-map (kbd "RET") 'svn-status-select-line)
2032 (define-key svn-status-mode-map (kbd "P") svn-status-mode-property-map))
2033(when (not svn-status-mode-extension-map)
2034 (setq svn-status-mode-extension-map (make-sparse-keymap))
2035 (define-key svn-status-mode-extension-map (kbd "v") 'svn-status-resolved)
2036 (define-key svn-status-mode-extension-map (kbd "X") 'svn-status-resolve-conflicts)
2037 (define-key svn-status-mode-extension-map (kbd "e") 'svn-status-export)
2038 (define-key svn-status-mode-map (kbd "X") svn-status-mode-extension-map))
2039(when (not svn-status-mode-options-map)
2040 (setq svn-status-mode-options-map (make-sparse-keymap))
2041 (define-key svn-status-mode-options-map (kbd "s") 'svn-status-save-state)
2042 (define-key svn-status-mode-options-map (kbd "l") 'svn-status-load-state)
2043 (define-key svn-status-mode-options-map (kbd "x") 'svn-status-toggle-sort-status-buffer)
2044 (define-key svn-status-mode-options-map (kbd "v") 'svn-status-toggle-svn-verbose-flag)
2045 (define-key svn-status-mode-options-map (kbd "f") 'svn-status-toggle-display-full-path)
2046 (define-key svn-status-mode-options-map (kbd "t") 'svn-status-set-trac-project-root)
2047 (define-key svn-status-mode-options-map (kbd "n") 'svn-status-set-module-name)
2048 (define-key svn-status-mode-options-map (kbd "c") 'svn-status-set-changelog-style)
2049 (define-key svn-status-mode-options-map (kbd "b") 'svn-status-set-branch-list)
2050 (define-key svn-status-mode-map (kbd "O") svn-status-mode-options-map))
2051(when (not svn-status-mode-trac-map)
2052 (setq svn-status-mode-trac-map (make-sparse-keymap))
2053 (define-key svn-status-mode-trac-map (kbd "w") 'svn-trac-browse-wiki)
2054 (define-key svn-status-mode-trac-map (kbd "t") 'svn-trac-browse-timeline)
2055 (define-key svn-status-mode-trac-map (kbd "m") 'svn-trac-browse-roadmap)
2056 (define-key svn-status-mode-trac-map (kbd "r") 'svn-trac-browse-report)
2057 (define-key svn-status-mode-trac-map (kbd "s") 'svn-trac-browse-source)
2058 (define-key svn-status-mode-trac-map (kbd "i") 'svn-trac-browse-ticket)
2059 (define-key svn-status-mode-trac-map (kbd "c") 'svn-trac-browse-changeset)
2060 (define-key svn-status-mode-map (kbd "T") svn-status-mode-trac-map))
2061(when (not svn-status-mode-branch-map)
2062 (setq svn-status-mode-branch-map (make-sparse-keymap))
2063 (define-key svn-status-mode-branch-map (kbd "d") 'svn-branch-diff)
2064 (define-key svn-status-mode-map (kbd "B") svn-status-mode-branch-map))
2065
2066(easy-menu-define svn-status-mode-menu svn-status-mode-map
2067 "'svn-status-mode' menu"
2068 '("SVN"
2069 ["svn status" svn-status-update t]
2070 ["svn update" svn-status-update-cmd t]
2071 ["svn commit" svn-status-commit t]
2072 ["svn log" svn-status-show-svn-log t]
2073 ["svn info" svn-status-info t]
2074 ["svn blame" svn-status-blame t]
2075 ("Diff"
2076 ["svn diff current file" svn-status-show-svn-diff t]
2077 ["svn diff marked files" svn-status-show-svn-diff-for-marked-files t]
2078 ["svn ediff current file" svn-status-ediff-with-revision t]
2079 ["svn resolve conflicts" svn-status-resolve-conflicts]
2080 )
2081 ("Search"
2082 ["Grep marked files" svn-status-grep-files t]
2083 ["Search marked files" svn-status-search-files t]
2084 )
2085 ["svn cat ..." svn-status-get-specific-revision t]
2086 ["svn add" svn-status-add-file t]
2087 ["svn add recursively" svn-status-add-file-recursively t]
2088 ["svn mkdir..." svn-status-make-directory t]
2089 ["svn mv..." svn-status-mv t]
2090 ["svn cp..." svn-status-cp t]
2091 ["svn rm..." svn-status-rm t]
2092 ["svn export..." svn-status-export t]
2093 ["Up Directory" svn-status-examine-parent t]
2094 ["Elide Directory" svn-status-toggle-elide t]
2095 ["svn revert" svn-status-revert t]
2096 ["svn resolved" svn-status-resolved t]
2097 ["svn cleanup" svn-status-cleanup t]
2098 ["svn lock" svn-status-lock t]
2099 ["svn unlock" svn-status-unlock t]
2100 ["Show Process Buffer" svn-status-show-process-buffer t]
2101 ("Branch"
2102 ["diff" svn-branch-diff t]
2103 ["Set Branch list" svn-status-set-branch-list t]
2104 )
2105 ("Property"
2106 ["svn proplist" svn-status-property-list t]
2107 ["Set Multiple Properties..." svn-status-property-set t]
2108 ["Edit One Property..." svn-status-property-edit-one-entry t]
2109 ["svn propdel..." svn-status-property-delete t]
2110 "---"
2111 ["svn:ignore File..." svn-status-property-ignore-file t]
2112 ["svn:ignore File Extension..." svn-status-property-ignore-file-extension t]
2113 ["Edit svn:ignore Property" svn-status-property-edit-svn-ignore t]
2114 "---"
2115 ["Edit svn:externals Property" svn-status-property-edit-svn-externals t]
2116 "---"
2117 ["Edit svn:keywords List" svn-status-property-set-keyword-list t]
2118 ["Add/Remove Id to/from svn:keywords" svn-status-property-set-keyword-id t]
2119 ["Add/Remove Date to/from svn:keywords" svn-status-property-set-keyword-date t]
2120 "---"
2121 ["Select svn:eol-style" svn-status-property-set-eol-style t]
2122 ["Set svn:executable" svn-status-property-set-executable t]
2123 ["Set svn:mime-type" svn-status-property-set-mime-type t]
2124 )
2125 ("Options"
2126 ["Save Options" svn-status-save-state t]
2127 ["Load Options" svn-status-load-state t]
2128 ["Set Trac project root" svn-status-set-trac-project-root t]
2129 ["Set Short module name" svn-status-set-module-name t]
2130 ["Set Changelog style" svn-status-set-changelog-style t]
2131 ["Set Branch list" svn-status-set-branch-list t]
2132 ["Sort the *svn-status* buffer" svn-status-toggle-sort-status-buffer
2133 :style toggle :selected svn-status-sort-status-buffer]
2134 ["Use -v for svn status calls" svn-status-toggle-svn-verbose-flag
2135 :style toggle :selected svn-status-verbose]
2136 ["Display full path names" svn-status-toggle-display-full-path
2137 :style toggle :selected svn-status-display-full-path]
2138 )
2139 ("Trac"
2140 ["Browse wiki" svn-trac-browse-wiki t]
2141 ["Browse timeline" svn-trac-browse-timeline t]
2142 ["Browse roadmap" svn-trac-browse-roadmap t]
2143 ["Browse source" svn-trac-browse-source t]
2144 ["Browse report" svn-trac-browse-report t]
2145 ["Browse ticket" svn-trac-browse-ticket t]
2146 ["Browse changeset" svn-trac-browse-changeset t]
2147 ["Set Trac project root" svn-status-set-trac-project-root t]
2148 )
2149 "---"
2150 ["Edit Next SVN Cmd Line" svn-status-toggle-edit-cmd-flag t]
2151 ["Work Directory History..." svn-status-use-history t]
2152 ("Mark / Unmark"
2153 ["Mark" svn-status-set-user-mark t]
2154 ["Unmark" svn-status-unset-user-mark t]
2155 ["Unmark all" svn-status-unset-all-usermarks t]
2156 "---"
2157 ["Mark/Unmark unknown" svn-status-mark-unknown t]
2158 ["Mark/Unmark modified" svn-status-mark-modified t]
2159 ["Mark/Unmark modified properties" svn-status-mark-modified-properties t]
2160 ["Mark/Unmark added" svn-status-mark-added t]
2161 ["Mark/Unmark deleted" svn-status-mark-deleted t]
2162 ["Mark/Unmark modified/added/deleted" svn-status-mark-changed t]
2163 ["Mark/Unmark filename by extension" svn-status-mark-by-file-ext t]
2164 ["Mark/Unmark filename by regexp" svn-status-mark-filename-regexp t]
2165 ["Store Usermarks" svn-status-store-usermarks t]
2166 ["Load Usermarks" svn-status-load-usermarks t]
2167 )
2168 ["Hide Unknown" svn-status-toggle-hide-unknown
2169 :style toggle :selected svn-status-hide-unknown]
2170 ["Hide Unmodified" svn-status-toggle-hide-unmodified
2171 :style toggle :selected svn-status-hide-unmodified]
2172 ["Hide Externals" svn-status-toggle-hide-externals
2173 :style toggle :selected svn-status-hide-externals]
2174 ["Show Client versions" svn-status-version t]
2175 ["Prepare bug report" svn-prepare-bug-report t]
2176 ))
2177
2178(defvar svn-status-file-popup-menu-list
2179 '(["open" svn-status-find-file-other-window t]
2180 ["svn diff" svn-status-show-svn-diff t]
2181 ["svn commit" svn-status-commit t]
2182 ["svn log" svn-status-show-svn-log t]
2183 ["svn blame" svn-status-blame t]
2184 ["mark" svn-status-set-user-mark t]
2185 ["unmark" svn-status-unset-user-mark t]
2186 ["svn add" svn-status-add-file t]
2187 ["svn add recursively" svn-status-add-file-recursively t]
2188 ["svn mv..." svn-status-mv t]
2189 ["svn rm..." svn-status-rm t]
2190 ["svn lock" svn-status-lock t]
2191 ["svn unlock" svn-status-unlock t]
2192 ["svn info" svn-status-info t]
2193 ) "A list of menu entries for `svn-status-popup-menu'")
2194
2195;; extend svn-status-file-popup-menu-list via:
2196;; (add-to-list 'svn-status-file-popup-menu-list ["commit" svn-status-commit t])
2197
2198(defun svn-status-popup-menu (event)
2199 "Display a file specific popup menu"
2200 (interactive "e")
2201 (mouse-set-point event)
2202 (let* ((line-info (svn-status-get-line-information))
2203 (name (svn-status-line-info->filename line-info)))
2204 (when line-info
2205 (easy-menu-define svn-status-actual-popup-menu nil nil
2206 (append (list name) svn-status-file-popup-menu-list))
2207 (svn-status-face-set-temporary-during-popup
2208 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
2209 svn-status-actual-popup-menu))))
2210
2211(defun svn-status-face-set-temporary-during-popup (face begin end menu &optional prefix)
2212 "Put FACE on BEGIN and END in the buffer during Popup MENU.
2213PREFIX is passed to `popup-menu'."
2214 (let (o)
2215 (unwind-protect
2216 (progn
2217 (setq o (make-overlay begin end))
2218 (overlay-put o 'face face)
2219 (save-excursion (sit-for 0))
2220 (popup-menu menu prefix))
2221 (delete-overlay o))))
2222
2223(defun svn-status-mode ()
2224 "Major mode used by psvn.el to display the output of \"svn status\".
2225
2226The Output has the following format:
2227 FPH BASE CMTD Author em File
2228F = Filemark
2229P = Property mark
2230H = History mark
2231BASE = local base revision
2232CMTD = last committed revision
2233Author = author of change
2234em = \"**\" or \"(Update Available)\" [see `svn-status-short-mod-flag-p']
2235 if file can be updated
2236File = path/filename
2237
2238The following keys are defined:
2239\\{svn-status-mode-map}"
2240 (interactive)
2241 (kill-all-local-variables)
2242
2243 (use-local-map svn-status-mode-map)
2244 (easy-menu-add svn-status-mode-menu)
2245
2246 (setq major-mode 'svn-status-mode)
2247 (setq mode-name "svn-status")
2248 (setq mode-line-process 'svn-status-mode-line-process)
2249 (run-hooks 'svn-status-mode-hook)
2250 (let ((view-read-only nil))
2251 (toggle-read-only 1)))
2252
2253(defun svn-status-update-mode-line ()
2254 (setq svn-status-mode-line-process
2255 (concat svn-status-mode-line-process-edit-flag svn-status-mode-line-process-status))
2256 (force-mode-line-update))
2257
2258(defun svn-status-bury-buffer (arg)
2259 "Bury the buffers used by psvn.el
2260Currently this is:
2261 `svn-status-buffer-name'
2262 `svn-process-buffer-name'
2263 `svn-log-edit-buffer-name'
2264 *svn-property-edit*
2265 *svn-log*
2266 *svn-info*
2267When called with a prefix argument, ARG, switch back to the window configuration that was
2268in use before `svn-status' was called."
2269 (interactive "P")
2270 (cond (arg
2271 (when svn-status-initial-window-configuration
2272 (set-window-configuration svn-status-initial-window-configuration)))
2273 (t
2274 (let ((bl `(,svn-log-edit-buffer-name "*svn-property-edit*" "*svn-log*" "*svn-info*" ,svn-process-buffer-name)))
2275 (while bl
2276 (when (get-buffer (car bl))
2277 (bury-buffer (car bl)))
2278 (setq bl (cdr bl)))
2279 (when (string= (buffer-name) svn-status-buffer-name)
2280 (bury-buffer))))))
2281
2282(defun svn-status-save-some-buffers (&optional tree)
2283 "Save all buffers visiting a file in TREE.
2284If TREE is not given, try `svn-status-base-dir' as TREE."
2285 (interactive)
2286 ;; (message "svn-status-save-some-buffers: tree1: %s" tree)
2287 (let ((ok t)
2288 (tree (or (svn-status-base-dir)
2289 tree)))
2290 ;; (message "svn-status-save-some-buffers: tree2: %s" tree)
2291 (unless tree
2292 (error "Not in a svn project tree"))
2293 (dolist (buffer (buffer-list))
2294 (with-current-buffer buffer
2295 (when (buffer-modified-p)
2296 (let ((file (buffer-file-name)))
2297 (when file
2298 (let ((root (svn-status-base-dir (file-name-directory file))))
2299 ;; (message "svn-status-save-some-buffers: file: %s, root: %s" file root)
2300 (when (and root
2301 (string= root tree)
2302 ;; buffer is modified and in the tree TREE.
2303 (or (y-or-n-p (concat "Save buffer " (buffer-name) "? "))
2304 (setq ok nil)))
2305 (save-buffer))))))))
2306 ok))
2307
2308(defun svn-status-find-files ()
2309 "Open selected file(s) for editing.
2310See `svn-status-marked-files' for what counts as selected."
2311 (interactive)
2312 (let ((fnames (mapcar 'svn-status-line-info->full-path (svn-status-marked-files))))
2313 (mapc 'find-file fnames)))
2314
2315
2316(defun svn-status-find-file-other-window ()
2317 "Open the file in the other window for editing."
2318 (interactive)
2319 (svn-status-ensure-cursor-on-file)
2320 (find-file-other-window (svn-status-line-info->filename
2321 (svn-status-get-line-information))))
2322
2323(defun svn-status-find-file-other-window-noselect ()
2324 "Open the file in the other window for editing, but don't select it."
2325 (interactive)
2326 (svn-status-ensure-cursor-on-file)
2327 (display-buffer
2328 (find-file-noselect (svn-status-line-info->filename
2329 (svn-status-get-line-information)))))
2330
2331(defun svn-status-view-file-other-window ()
2332 "Open the file in the other window for viewing."
2333 (interactive)
2334 (svn-status-ensure-cursor-on-file)
2335 (view-file-other-window (svn-status-line-info->filename
2336 (svn-status-get-line-information))))
2337
2338(defun svn-status-find-file-or-examine-directory ()
2339 "If point is on a directory, run `svn-status' on that directory.
2340Otherwise run `find-file'."
2341 (interactive)
2342 (svn-status-ensure-cursor-on-file)
2343 (let ((line-info (svn-status-get-line-information)))
2344 (if (svn-status-line-info->directory-p line-info)
2345 (svn-status (svn-status-line-info->full-path line-info))
2346 (find-file (svn-status-line-info->filename line-info)))))
2347
2348(defun svn-status-examine-parent ()
2349 "Run `svn-status' on the parent of the current directory."
2350 (interactive)
2351 (svn-status (expand-file-name "../")))
2352
2353(defun svn-status-mouse-find-file-or-examine-directory (event)
2354 "Move point to where EVENT occurred, and do `svn-status-find-file-or-examine-directory'
2355EVENT could be \"mouse clicked\" or similar."
2356 (interactive "e")
2357 (mouse-set-point event)
2358 (svn-status-find-file-or-examine-directory))
2359
2360(defun svn-status-line-info->ui-status (line-info)
2361 "Return the ui-status structure of LINE-INFO.
2362See `svn-status-make-ui-status' for information about the ui-status."
2363 (nth 0 line-info))
2364
2365(defun svn-status-line-info->has-usermark (line-info) (nth 0 (nth 0 line-info)))
2366(defun svn-status-line-info->user-elide (line-info) (nth 1 (nth 0 line-info)))
2367
2368(defun svn-status-line-info->filemark (line-info) (nth 1 line-info))
2369(defun svn-status-line-info->propmark (line-info) (nth 2 line-info))
2370(defun svn-status-line-info->filename (line-info) (nth 3 line-info))
2371(defun svn-status-line-info->filename-nondirectory (line-info)
2372 (file-name-nondirectory (svn-status-line-info->filename line-info)))
2373(defun svn-status-line-info->localrev (line-info)
2374 (if (>= (nth 4 line-info) 0)
2375 (nth 4 line-info)
2376 nil))
2377(defun svn-status-line-info->lastchangerev (line-info)
2378 "Return the last revision in which LINE-INFO was modified."
2379 (let ((l (nth 5 line-info)))
2380 (if (and l (>= l 0))
2381 l
2382 nil)))
2383(defun svn-status-line-info->author (line-info)
2384 "Return the last author that changed the item that is represented in LINE-INFO."
2385 (nth 6 line-info))
2386(defun svn-status-line-info->update-available (line-info)
2387 "Return whether LINE-INFO is out of date.
2388In other words, whether there is a newer version available in the
2389repository than the working copy."
2390 (nth 7 line-info))
2391(defun svn-status-line-info->locked (line-info)
2392 "Return whether LINE-INFO represents a locked file.
2393This is column three of the `svn status' output.
2394The result will be nil or \"L\".
2395\(A file becomes locked when an operation is interrupted; run \\[svn-status-cleanup]'
2396to unlock it.\)"
2397 (nth 8 line-info))
2398(defun svn-status-line-info->historymark (line-info)
2399 "Mark from column four of output from `svn status'.
2400This will be nil unless the file is scheduled for addition with
2401history, when it will be \"+\"."
2402 (nth 9 line-info))
2403(defun svn-status-line-info->switched (line-info)
2404 "Return whether LINE-INFO is switched relative to its parent.
2405This is column five of the output from `svn status'.
2406The result will be \"S\", \"X\" or nil."
2407 (nth 10 line-info))
2408(defun svn-status-line-info->repo-locked (line-info)
2409 "Return whether LINE-INFO contains some locking information.
2410This is column six of the output from `svn status'.
2411The result will be \"K\", \"O\", \"T\", \"B\" or nil."
2412 (nth 11 line-info))
2413(defun svn-status-line-info->psvn-extra-info (line-info)
2414 "Return a list of extra information for psvn associated with LINE-INFO.
2415This list holds currently only one element:
2416* The action after a commit or update."
2417 (nth 12 line-info))
2418
2419(defun svn-status-line-info->is-visiblep (line-info)
2420 "Return whether the line is visible or not"
2421 (or (not (or (svn-status-line-info->hide-because-unknown line-info)
2422 (svn-status-line-info->hide-because-unmodified line-info)
2423 (svn-status-line-info->hide-because-externals line-info)
2424 (svn-status-line-info->hide-because-custom-hide-function line-info)
2425 (svn-status-line-info->hide-because-user-elide line-info)))
2426 (svn-status-line-info->update-available line-info) ;; show the line, if an update is available
2427 (svn-status-line-info->psvn-extra-info line-info) ;; show the line, if there is some extra info displayed on this line
2428 ))
2429
2430(defun svn-status-line-info->hide-because-unknown (line-info)
2431 (and svn-status-hide-unknown
2432 (eq (svn-status-line-info->filemark line-info) ??)))
2433
2434(defun svn-status-line-info->hide-because-externals (line-info)
2435 (and svn-status-hide-externals
2436 (eq (svn-status-line-info->filemark line-info) ?X)))
2437
2438(defun svn-status-line-info->hide-because-custom-hide-function (line-info)
2439 (and svn-status-custom-hide-function
2440 (apply svn-status-custom-hide-function (list line-info))))
2441
2442(defun svn-status-line-info->hide-because-unmodified (line-info)
2443 ;;(message " %S %S %S %S - %s" svn-status-hide-unmodified (svn-status-line-info->propmark line-info) ?_
2444 ;; (svn-status-line-info->filemark line-info) (svn-status-line-info->filename line-info))
2445 (and svn-status-hide-unmodified
2446 (and (or (eq (svn-status-line-info->filemark line-info) ?_)
2447 (eq (svn-status-line-info->filemark line-info) ? ))
2448 (or (eq (svn-status-line-info->propmark line-info) ?_)
2449 (eq (svn-status-line-info->propmark line-info) ? )
2450 (eq (svn-status-line-info->propmark line-info) nil)))))
2451
2452(defun svn-status-line-info->hide-because-user-elide (line-info)
2453 (eq (svn-status-line-info->user-elide line-info) t))
2454
2455(defun svn-status-line-info->show-user-elide-continuation (line-info)
2456 (eq (svn-status-line-info->user-elide line-info) 'directory))
2457
2458;; modify the line-info
2459(defun svn-status-line-info->set-filemark (line-info value)
2460 (setcar (nthcdr 1 line-info) value))
2461
2462(defun svn-status-line-info->set-propmark (line-info value)
2463 (setcar (nthcdr 2 line-info) value))
2464
2465(defun svn-status-line-info->set-localrev (line-info value)
2466 (setcar (nthcdr 4 line-info) value))
2467
2468(defun svn-status-line-info->set-author (line-info value)
2469 (setcar (nthcdr 6 line-info) value))
2470
2471(defun svn-status-line-info->set-lastchangerev (line-info value)
2472 (setcar (nthcdr 5 line-info) value))
2473
2474(defun svn-status-line-info->set-repo-locked (line-info value)
2475 (setcar (nthcdr 11 line-info) value))
2476
2477(defun svn-status-line-info->set-psvn-extra-info (line-info value)
2478 (setcar (nthcdr 12 line-info) value))
2479
2480(defun svn-status-copy-current-line-info (arg)
2481 "Copy the current file name at point, using `svn-status-copy-filename-as-kill'.
2482If no file is at point, copy everything starting from ':' to the end of line."
2483 (interactive "P")
2484 (if (svn-status-get-line-information)
2485 (svn-status-copy-filename-as-kill arg)
2486 (save-excursion
2487 (goto-char (svn-point-at-bol))
2488 (when (looking-at ".+?: *\\(.+\\)$")
2489 (kill-new (svn-match-string-no-properties 1))
2490 (message "Copied: %s" (svn-match-string-no-properties 1))))))
2491
2492(defun svn-status-copy-filename-as-kill (arg)
2493 "Copy the actual file name to the kill-ring.
2494When called with the prefix argument 0, use the full path name."
2495 (interactive "P")
2496 (let ((str (if (eq arg 0)
2497 (svn-status-line-info->full-path (svn-status-get-line-information))
2498 (svn-status-line-info->filename (svn-status-get-line-information)))))
2499 (kill-new str)
2500 (message "Copied %s" str)))
2501
2502(defun svn-status-get-child-directories (&optional dir)
2503 "Return a list of subdirectories for DIR"
2504 (interactive)
2505 (let ((this-dir (concat (expand-file-name (or dir (svn-status-line-info->filename (svn-status-get-line-information)))) "/"))
2506 (test-dir)
2507 (sub-dir-list))
2508 ;;(message "this-dir %S" this-dir)
2509 (dolist (line-info svn-status-info)
2510 (when (svn-status-line-info->directory-p line-info)
2511 (setq test-dir (svn-status-line-info->full-path line-info))
2512 (when (string= (file-name-directory test-dir) this-dir)
2513 (add-to-list 'sub-dir-list (file-relative-name (svn-status-line-info->full-path line-info)) t))))
2514 sub-dir-list))
2515
2516(defun svn-status-toggle-elide (arg)
2517 "Toggle eliding of the current file or directory.
2518When called with a prefix argument, toggle the hiding of all subdirectories for the current directory."
2519 (interactive "P")
2520 (if arg
2521 (let ((cur-line (svn-status-line-info->filename (svn-status-get-line-information))))
2522 (when (svn-status-line-info->user-elide (svn-status-get-line-information))
2523 (svn-status-toggle-elide nil))
2524 (dolist (dir-name (svn-status-get-child-directories))
2525 (svn-status-goto-file-name dir-name)
2526 (svn-status-toggle-elide nil))
2527 (svn-status-goto-file-name cur-line))
2528 (let ((st-info svn-status-info)
2529 (fname)
2530 (test (svn-status-line-info->filename (svn-status-get-line-information)))
2531 (len-test)
2532 (len-fname)
2533 (new-elide-mark t)
2534 (elide-mark))
2535 (if (member test svn-status-elided-list)
2536 (setq svn-status-elided-list (delete test svn-status-elided-list))
2537 (add-to-list 'svn-status-elided-list test))
2538 (when (string= test ".")
2539 (setq test ""))
2540 (setq len-test (length test))
2541 (while st-info
2542 (setq fname (svn-status-line-info->filename (car st-info)))
2543 (setq len-fname (length fname))
2544 (when (and (>= len-fname len-test)
2545 (string= (substring fname 0 len-test) test))
2546 (setq elide-mark new-elide-mark)
2547 (when (or (string= fname ".")
2548 (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
2549 (message "Elided directory %s and all its files." fname)
2550 (setq new-elide-mark (not (svn-status-line-info->user-elide (car st-info))))
2551 (setq elide-mark (if new-elide-mark 'directory nil)))
2552 ;;(message "elide-mark: %S member: %S" elide-mark (member fname svn-status-elided-list))
2553 (when (and (member fname svn-status-elided-list) (not elide-mark))
2554 (setq svn-status-elided-list (delete fname svn-status-elided-list)))
2555 (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark))
2556 (setq st-info (cdr st-info))))
2557 ;;(message "svn-status-elided-list: %S" svn-status-elided-list)
2558 (svn-status-update-buffer)))
2559
2560(defun svn-status-apply-elide-list ()
2561 "Elide files/directories according to `svn-status-elided-list'."
2562 (interactive)
2563 (let ((st-info svn-status-info)
2564 (fname)
2565 (len-fname)
2566 (test)
2567 (len-test)
2568 (elided-list)
2569 (elide-mark))
2570 (when svn-status-elided-list
2571 (while st-info
2572 (setq fname (svn-status-line-info->filename (car st-info)))
2573 (setq len-fname (length fname))
2574 (setq elided-list svn-status-elided-list)
2575 (setq elide-mark nil)
2576 (while elided-list
2577 (setq test (car elided-list))
2578 (when (string= test ".")
2579 (setq test ""))
2580 (setq len-test (length test))
2581 (when (and (>= len-fname len-test)
2582 (string= (substring fname 0 len-test) test))
2583 (setq elide-mark t)
2584 (when (or (string= fname ".")
2585 (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
2586 (setq elide-mark 'directory)))
2587 (setq elided-list (cdr elided-list)))
2588 ;;(message "fname: %s elide-mark: %S" fname elide-mark)
2589 (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark)
2590 (setq st-info (cdr st-info)))))
2591 (svn-status-update-buffer))
2592
2593(defun svn-status-update-with-command-list (cmd-list)
2594 (save-excursion
2595 (set-buffer svn-status-buffer-name)
2596 (let ((st-info)
2597 (found)
2598 (action)
2599 (fname (svn-status-line-info->filename (svn-status-get-line-information)))
2600 (fname-pos (point))
2601 (column (current-column)))
2602 (setq cmd-list (sort cmd-list '(lambda (item1 item2) (string-lessp (car item1) (car item2)))))
2603 (while cmd-list
2604 (unless st-info (setq st-info svn-status-info))
2605 ;;(message "%S" (caar cmd-list))
2606 (setq found nil)
2607 (while (and (not found) st-info)
2608 (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
2609 ;;(message "found: %S" found)
2610 (unless found (setq st-info (cdr st-info))))
2611 (unless found
2612 (svn-status-message 3 "psvn: continue to search for %s" (caar cmd-list))
2613 (setq st-info svn-status-info)
2614 (while (and (not found) st-info)
2615 (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
2616 (unless found (setq st-info (cdr st-info)))))
2617 (if found
2618 ;;update the info line
2619 (progn
2620 (setq action (cadar cmd-list))
2621 ;;(message "found %s, action: %S" (caar cmd-list) action)
2622 (svn-status-annotate-status-buffer-entry action (car st-info)))
2623 (svn-status-message 3 "psvn: did not find %s" (caar cmd-list)))
2624 (setq cmd-list (cdr cmd-list)))
2625 (if fname
2626 (progn
2627 (goto-char fname-pos)
2628 (svn-status-goto-file-name fname)
2629 (goto-char (+ column (svn-point-at-bol))))
2630 (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column))))))
2631
2632(defun svn-status-annotate-status-buffer-entry (action line-info)
2633 (let ((tag-string))
2634 (svn-status-goto-file-name (svn-status-line-info->filename line-info))
2635 (when (and (member action '(committed added))
2636 svn-status-commit-rev-number)
2637 (svn-status-line-info->set-localrev line-info svn-status-commit-rev-number)
2638 (svn-status-line-info->set-lastchangerev line-info svn-status-commit-rev-number))
2639 (when svn-status-last-commit-author
2640 (svn-status-line-info->set-author line-info svn-status-last-commit-author))
2641 (svn-status-line-info->set-psvn-extra-info line-info (list action))
2642 (cond ((equal action 'committed)
2643 (setq tag-string " <committed>")
2644 (when (member (svn-status-line-info->repo-locked line-info) '(?K))
2645 (svn-status-line-info->set-repo-locked line-info nil)))
2646 ((equal action 'added)
2647 (setq tag-string " <added>"))
2648 ((equal action 'deleted)
2649 (setq tag-string " <deleted>"))
2650 ((equal action 'replaced)
2651 (setq tag-string " <replaced>"))
2652 ((equal action 'updated)
2653 (setq tag-string " <updated>"))
2654 ((equal action 'updated-props)
2655 (setq tag-string " <updated-props>"))
2656 ((equal action 'conflicted)
2657 (setq tag-string " <conflicted>")
2658 (svn-status-line-info->set-filemark line-info ?C))
2659 ((equal action 'merged)
2660 (setq tag-string " <merged>"))
2661 ((equal action 'propset)
2662 ;;(setq tag-string " <propset>")
2663 (svn-status-line-info->set-propmark line-info svn-status-file-modified-after-save-flag))
2664 ((equal action 'added-wc)
2665 (svn-status-line-info->set-filemark line-info ?A)
2666 (svn-status-line-info->set-localrev line-info 0))
2667 ((equal action 'deleted-wc)
2668 (svn-status-line-info->set-filemark line-info ?D))
2669 (t
2670 (error "Unknown action '%s for %s" action (svn-status-line-info->filename line-info))))
2671 (when (and tag-string (not (member action '(conflicted merged))))
2672 (svn-status-line-info->set-filemark line-info ? )
2673 (svn-status-line-info->set-propmark line-info ? ))
2674 (let ((buffer-read-only nil))
2675 (delete-region (svn-point-at-bol) (svn-point-at-eol))
2676 (svn-insert-line-in-status-buffer line-info)
2677 (backward-char 1)
2678 (when tag-string
2679 (insert tag-string))
2680 (delete-char 1))))
2681
2682
2683
2684;; (svn-status-update-with-command-list '(("++ideas" committed) ("a.txt" committed) ("alf")))
2685;; (svn-status-update-with-command-list (svn-status-parse-commit-output))
2686
2687(defun svn-status-parse-commit-output ()
2688 "Parse the output of svn commit.
2689Return a list that is suitable for `svn-status-update-with-command-list'"
2690 (save-excursion
2691 (set-buffer svn-process-buffer-name)
2692 (let ((action)
2693 (file-name)
2694 (skip)
2695 (result))
2696 (goto-char (point-min))
2697 (setq svn-status-commit-rev-number nil)
2698 (setq skip nil) ; set to t whenever we find a line not about a committed file
2699 (while (< (point) (point-max))
2700 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2701 (setq skip t))
2702 ((looking-at "Sending")
2703 (setq action 'committed))
2704 ((looking-at "Adding")
2705 (setq action 'added))
2706 ((looking-at "Deleting")
2707 (setq action 'deleted))
2708 ((looking-at "Replacing")
2709 (setq action 'replaced))
2710 ((looking-at "Transmitting file data")
2711 (setq skip t))
2712 ((looking-at "Committed revision \\([0-9]+\\)")
2713 (setq svn-status-commit-rev-number
2714 (string-to-number (svn-match-string-no-properties 1)))
2715 (setq skip t))
2716 (t ;; this should never be needed(?)
2717 (setq action 'unknown)))
2718 (unless skip ;found an interesting line
2719 (forward-char 15)
2720 (when svn-status-operated-on-dot
2721 ;; when the commit used . as argument, delete the trailing directory
2722 ;; from the svn output
2723 (search-forward "/" nil t))
2724 (setq file-name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2725 (unless svn-status-last-commit-author
2726 (setq svn-status-last-commit-author (car (svn-status-info-for-path (expand-file-name (concat default-directory file-name))))))
2727 (setq result (cons (list file-name action)
2728 result))
2729 (setq skip nil))
2730 (forward-line 1))
2731 result)))
2732;;(svn-status-parse-commit-output)
2733;;(svn-status-annotate-status-buffer-entry)
2734
2735(defun svn-status-parse-ar-output ()
2736 "Parse the output of svn add|remove.
2737Return a list that is suitable for `svn-status-update-with-command-list'"
2738 (save-excursion
2739 (set-buffer svn-process-buffer-name)
2740 (let ((action)
2741 (name)
2742 (skip)
2743 (result))
2744 (goto-char (point-min))
2745 (while (< (point) (point-max))
2746 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2747 (setq skip t))
2748 ((looking-at "A")
2749 (setq action 'added-wc))
2750 ((looking-at "D")
2751 (setq action 'deleted-wc))
2752 (t ;; this should never be needed(?)
2753 (setq action 'unknown)))
2754 (unless skip ;found an interesting line
2755 (forward-char 10)
2756 (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2757 (setq result (cons (list name action)
2758 result))
2759 (setq skip nil))
2760 (forward-line 1))
2761 result)))
2762;; (svn-status-parse-ar-output)
2763;; (svn-status-update-with-command-list (svn-status-parse-ar-output))
2764
2765(defun svn-status-parse-update-output ()
2766 "Parse the output of svn update.
2767Return a list that is suitable for `svn-status-update-with-command-list'"
2768 (save-excursion
2769 (set-buffer svn-process-buffer-name)
2770 (setq svn-status-update-rev-number nil)
2771 (let ((action)
2772 (name)
2773 (skip)
2774 (result))
2775 (goto-char (point-min))
2776 (while (< (point) (point-max))
2777 (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
2778 (setq skip t))
2779 ((looking-at "Updated to revision \\([0-9]+\\)")
2780 (setq svn-status-update-rev-number
2781 (list t (string-to-number (svn-match-string-no-properties 1))))
2782 (setq skip t))
2783 ((looking-at "At revision \\([0-9]+\\)")
2784 (setq svn-status-update-rev-number
2785 (list nil (string-to-number (svn-match-string-no-properties 1))))
2786 (setq skip t))
2787 ((looking-at "U")
2788 (setq action 'updated))
2789 ((looking-at "A")
2790 (setq action 'added))
2791 ((looking-at "D")
2792 (setq skip t))
2793 ;;(setq action 'deleted)) ;;deleted files are not displayed in the svn status output.
2794 ((looking-at "C")
2795 (setq action 'conflicted))
2796 ((looking-at "G")
2797 (setq action 'merged))
2798
2799 ((looking-at " U")
2800 (setq action 'updated-props))
2801
2802 (t ;; this should never be needed(?)
2803 (setq action (concat "parse-update: '"
2804 (buffer-substring-no-properties (point) (+ 2 (point))) "'"))))
2805 (unless skip ;found an interesting line
2806 (forward-char 3)
2807 (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
2808 (setq result (cons (list name action)
2809 result))
2810 (setq skip nil))
2811 (forward-line 1))
2812 result)))
2813;; (svn-status-parse-update-output)
2814;; (svn-status-update-with-command-list (svn-status-parse-update-output))
2815
2816(defun svn-status-parse-property-output ()
2817 "Parse the output of svn propset.
2818Return a list that is suitable for `svn-status-update-with-command-list'"
2819 (save-excursion
2820 (set-buffer svn-process-buffer-name)
2821 (let ((result))
2822 (dolist (line (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n"))
2823 (message "%s" line)
2824 (when (string-match "property '\\(.+\\)' set on '\\(.+\\)'" line)
2825 ;;(message "property %s - file %s" (match-string 1 line) (match-string 2 line))
2826 (setq result (cons (list (match-string 2 line) 'propset) result))))
2827 result)))
2828
2829;; (svn-status-parse-property-output)
2830;; (svn-status-update-with-command-list (svn-status-parse-property-output))
2831
2832
2833(defun svn-status-line-info->symlink-p (line-info)
2834 "Return non-nil if LINE-INFO refers to a symlink, nil otherwise.
2835The value is the name of the file to which it is linked. \(See
2836`file-symlink-p'.\)
2837
2838On win32 systems this won't work, even though symlinks are supported
2839by subversion on such systems."
2840 ;; on win32 would need to see how svn does symlinks
2841 (file-symlink-p (svn-status-line-info->filename line-info)))
2842
2843(defun svn-status-line-info->directory-p (line-info)
2844 "Return t if LINE-INFO refers to a directory, nil otherwise.
2845Symbolic links to directories count as directories (see `file-directory-p')."
2846 (file-directory-p (svn-status-line-info->filename line-info)))
2847
2848(defun svn-status-line-info->full-path (line-info)
2849 "Return the full path of the file represented by LINE-INFO."
2850 (expand-file-name
2851 (svn-status-line-info->filename line-info)))
2852
2853;;Not convinced that this is the fastest way, but...
2854(defun svn-status-count-/ (string)
2855 "Return number of \"/\"'s in STRING."
2856 (let ((n 0)
2857 (last 0))
2858 (while (setq last (string-match "/" string (1+ last)))
2859 (setq n (1+ n)))
2860 n))
2861
2862(defun svn-insert-line-in-status-buffer (line-info)
2863 "Format LINE-INFO and insert the result in the current buffer."
2864 (let ((usermark (if (svn-status-line-info->has-usermark line-info) "*" " "))
2865 (update-available (if (svn-status-line-info->update-available line-info)
2866 (svn-add-face (if svn-status-short-mod-flag-p
2867 "** "
2868 " (Update Available)")
2869 'svn-status-update-available-face)
2870 (if svn-status-short-mod-flag-p " " "")))
2871 (filename ;; <indentation>file or /path/to/file
2872 (concat
2873 (if (or svn-status-display-full-path
2874 svn-status-hide-unmodified
2875 svn-status-hide-externals)
2876 (svn-add-face
2877 (let ((dir-name (file-name-as-directory
2878 (svn-status-line-info->directory-containing-line-info
2879 line-info nil))))
2880 (if (and (<= 2 (length dir-name))
2881 (= ?. (aref dir-name 0))
2882 (= ?/ (aref dir-name 1)))
2883 (substring dir-name 2)
2884 dir-name))
2885 'svn-status-directory-face)
2886 ;; showing all files, so add indentation
2887 (make-string (* 2 (svn-status-count-/
2888 (svn-status-line-info->filename line-info)))
2889 32))
2890 ;;symlinks get a different face
2891 (let ((target (svn-status-line-info->symlink-p line-info)))
2892 (if target
2893 ;; name -> trget
2894 ;; name gets symlink-face, target gets file/directory face
2895 (concat
2896 (svn-add-face (svn-status-line-info->filename-nondirectory line-info)
2897 'svn-status-symlink-face)
2898 " -> "
2899 (svn-status-choose-face-to-add
2900 ;; TODO: could use different faces for
2901 ;; unversioned targets and broken symlinks?
2902 (svn-status-line-info->directory-p line-info)
2903 target
2904 'svn-status-directory-face
2905 'svn-status-filename-face))
2906 ;; else target is not a link
2907 (svn-status-choose-face-to-add
2908 (svn-status-line-info->directory-p line-info)
2909 (svn-status-line-info->filename-nondirectory line-info)
2910 'svn-status-directory-face
2911 'svn-status-filename-face)))
2912 ))
2913 (elide-hint (if (svn-status-line-info->show-user-elide-continuation line-info) " ..." "")))
2914 (svn-puthash (svn-status-line-info->filename line-info)
2915 (point)
2916 svn-status-filename-to-buffer-position-cache)
2917 (insert (svn-status-maybe-add-face
2918 (svn-status-line-info->has-usermark line-info)
2919 (concat usermark
2920 (format svn-status-line-format
2921 (svn-status-line-info->filemark line-info)
2922 (or (svn-status-line-info->propmark line-info) ? )
2923 (or (svn-status-line-info->historymark line-info) ? )
2924 (or (svn-status-line-info->localrev line-info) "")
2925 (or (svn-status-line-info->lastchangerev line-info) "")
2926 (svn-status-line-info->author line-info))
2927 (when svn-status-short-mod-flag-p update-available)
2928 filename
2929 (unless svn-status-short-mod-flag-p update-available)
2930 (svn-status-maybe-add-string (svn-status-line-info->locked line-info)
2931 " [ LOCKED ]" 'svn-status-locked-face)
2932 (svn-status-maybe-add-string (svn-status-line-info->repo-locked line-info)
2933 (let ((flag (svn-status-line-info->repo-locked line-info)))
2934 (cond ((eq flag ?K) " [ REPO-LOCK-HERE ]")
2935 ((eq flag ?O) " [ REPO-LOCK-OTHER ]")
2936 ((eq flag ?T) " [ REPO-LOCK-STOLEN ]")
2937 ((eq flag ?B) " [ REPO-LOCK-BROKEN ]")
2938 (t " [ REPO-LOCK-UNKNOWN ]")))
2939 'svn-status-locked-face)
2940 (svn-status-maybe-add-string (eq (svn-status-line-info->switched line-info) ?S)
2941 " (switched)" 'svn-status-switched-face)
2942 elide-hint)
2943 'svn-status-marked-face)
2944 "\n")))
2945
2946(defun svn-status-redraw-status-buffer ()
2947 "Redraw the `svn-status-buffer-name' buffer.
2948Additionally clear the psvn-extra-info field in all line-info lists."
2949 (interactive)
2950 (dolist (line-info svn-status-info)
2951 (svn-status-line-info->set-psvn-extra-info line-info nil))
2952 (svn-status-update-buffer))
2953
2954(defun svn-status-update-buffer ()
2955 "Update the `svn-status-buffer-name' buffer, using `svn-status-info'.
2956 This function does not access the repository."
2957 (interactive)
2958 ;(message "buffer-name: %s" (buffer-name))
2959 (unless (string= (buffer-name) svn-status-buffer-name)
2960 (set-buffer svn-status-buffer-name))
2961 (svn-status-mode)
2962 (when svn-status-refresh-info
2963 (when (eq svn-status-refresh-info 'once)
2964 (setq svn-status-refresh-info nil))
2965 (svn-status-parse-info t))
2966 (let ((st-info svn-status-info)
2967 (buffer-read-only nil)
2968 (start-pos)
2969 (overlay)
2970 (unmodified-count 0) ;how many unmodified files are hidden
2971 (unknown-count 0) ;how many unknown files are hidden
2972 (externals-count 0) ;how many svn:externals files are hidden
2973 (custom-hide-count 0) ;how many files are hidden via svn-status-custom-hide-function
2974 (marked-count 0) ;how many files are elided
2975 (user-elide-count 0)
2976 (first-line t)
2977 (fname (svn-status-line-info->filename (svn-status-get-line-information)))
2978 (fname-pos (point))
2979 (window-line-pos (svn-status-window-line-position (get-buffer-window (current-buffer))))
2980 (header-line-string)
2981 (column (current-column)))
2982 (delete-region (point-min) (point-max))
2983 (insert "\n")
2984 ;; Insert all files and directories
2985 (while st-info
2986 (setq start-pos (point))
2987 (cond ((or (svn-status-line-info->has-usermark (car st-info)) first-line)
2988 ;; Show a marked file and the "." always
2989 (svn-insert-line-in-status-buffer (car st-info))
2990 (setq first-line nil))
2991 ((svn-status-line-info->update-available (car st-info))
2992 (svn-insert-line-in-status-buffer (car st-info)))
2993 ((and svn-status-custom-hide-function
2994 (apply svn-status-custom-hide-function (list (car st-info))))
2995 (setq custom-hide-count (1+ custom-hide-count)))
2996 ((svn-status-line-info->hide-because-user-elide (car st-info))
2997 (setq user-elide-count (1+ user-elide-count)))
2998 ((svn-status-line-info->hide-because-unknown (car st-info))
2999 (setq unknown-count (1+ unknown-count)))
3000 ((svn-status-line-info->hide-because-unmodified (car st-info))
3001 (setq unmodified-count (1+ unmodified-count)))
3002 ((svn-status-line-info->hide-because-externals (car st-info))
3003 (setq externals-count (1+ externals-count)))
3004 (t
3005 (svn-insert-line-in-status-buffer (car st-info))))
3006 (when (svn-status-line-info->has-usermark (car st-info))
3007 (setq marked-count (+ marked-count 1)))
3008 (setq overlay (make-overlay start-pos (point)))
3009 (overlay-put overlay 'svn-info (car st-info))
3010 (overlay-put overlay 'evaporate t)
3011 (setq st-info (cdr st-info)))
3012 ;; Insert status information at the buffer beginning
3013 (goto-char (point-min))
3014 (insert (format "svn status for directory %s%s\n"
3015 default-directory
3016 (if svn-status-head-revision (format " (status against revision: %s)"
3017 svn-status-head-revision)
3018 "")))
3019 (when svn-status-module-name
3020 (insert (format "Project name: %s\n" svn-status-module-name)))
3021 (when svn-status-branch-list
3022 (insert (format "Branches: %s\n" svn-status-branch-list)))
3023 (when svn-status-base-info
3024 (insert (concat "Repository Root: " (svn-status-base-info->repository-root) "\n"))
3025 (insert (concat "Repository Url: " (svn-status-base-info->url) "\n")))
3026 (when svn-status-hide-unknown
3027 (insert
3028 (format "%d Unknown file(s) are hidden - press `?' to toggle hiding\n"
3029 unknown-count)))
3030 (when svn-status-hide-unmodified
3031 (insert
3032 (format "%d Unmodified file(s) are hidden - press `_' to toggle hiding\n"
3033 unmodified-count)))
3034 (when svn-status-hide-externals
3035 (insert
3036 (format "%d Externals file(s) are hidden - press `z' to toggle hiding\n"
3037 externals-count)))
3038 (when (> custom-hide-count 0)
3039 (insert
3040 (format "%d file(s) are hidden via the svn-status-custom-hide-function\n"
3041 custom-hide-count)))
3042 (when (> user-elide-count 0)
3043 (insert (format "%d file(s) elided\n" user-elide-count)))
3044 (insert (format "%d file(s) marked\n" marked-count))
3045 (setq header-line-string (concat (format svn-status-line-format
3046 70 80 72 "BASE" "CMTD" "Author")
3047 (if svn-status-short-mod-flag-p "em " "")
3048 "File"))
3049 (cond ((eq svn-status-use-header-line t)
3050 (setq header-line-format (concat " " header-line-string)))
3051 ((eq svn-status-use-header-line 'inline)
3052 (insert "\n " header-line-string "\n")))
3053 (setq svn-start-of-file-list-line-number (+ (count-lines (point-min) (point)) 1))
3054 (if fname
3055 (progn
3056 (goto-char fname-pos)
3057 (svn-status-goto-file-name fname)
3058 (goto-char (+ column (svn-point-at-bol)))
3059 (when window-line-pos
3060 (recenter window-line-pos)))
3061 (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column)))))
3062
3063(defun svn-status-parse-info (arg)
3064 "Parse the svn info output for the base directory.
3065Show the repository url after this call in the `svn-status-buffer-name' buffer.
3066When called with the prefix argument 0, reset the information to nil.
3067This hides the repository information again.
3068
3069When ARG is t, don't update the svn status buffer. This is useful for
3070non-interactive use."
3071 (interactive "P")
3072 (if (eq arg 0)
3073 (setq svn-status-base-info nil)
3074 (let ((svn-process-buffer-name "*svn-info-output*"))
3075 (when (get-buffer svn-process-buffer-name)
3076 (kill-buffer svn-process-buffer-name))
3077 (svn-run nil t 'parse-info "info" ".")
3078 (svn-status-parse-info-result)))
3079 (unless (eq arg t)
3080 (svn-status-update-buffer)))
3081
3082(defun svn-status-parse-info-result ()
3083 "Parse the result from the svn info command.
3084Put the found values in `svn-status-base-info'."
3085 (let ((url)
3086 (repository-root)
3087 (last-changed-author))
3088 (save-excursion
3089 (set-buffer svn-process-buffer-name)
3090 (goto-char (point-min))
3091 (let ((case-fold-search t))
3092 (search-forward "url: ")
3093 (setq url (buffer-substring-no-properties (point) (svn-point-at-eol)))
3094 (when (search-forward "repository root: " nil t)
3095 (setq repository-root (buffer-substring-no-properties (point) (svn-point-at-eol))))
3096 (when (search-forward "last changed author: " nil t)
3097 (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol))))))
3098 (setq svn-status-base-info `((url ,url) (repository-root ,repository-root) (last-changed-author ,last-changed-author)))))
3099
3100(defun svn-status-base-info->url ()
3101 "Extract the url part from `svn-status-base-info'."
3102 (if svn-status-base-info
3103 (cadr (assoc 'url svn-status-base-info))
3104 ""))
3105
3106(defun svn-status-base-info->repository-root ()
3107 "Extract the repository-root part from `svn-status-base-info'."
3108 (if svn-status-base-info
3109 (cadr (assoc 'repository-root svn-status-base-info))
3110 ""))
3111
3112(defun svn-status-checkout-prefix-path ()
3113 "When only a part of the svn repository is checked out, return the file path for this checkout."
3114 (interactive)
3115 (svn-status-parse-info t)
3116 (let ((root (svn-status-base-info->repository-root))
3117 (url (svn-status-base-info->url))
3118 (p)
3119 (base-dir (svn-status-base-dir))
3120 (wc-checkout-prefix))
3121 (setq p (substring url (length root)))
3122 (setq wc-checkout-prefix (file-relative-name default-directory base-dir))
3123 (when (string= wc-checkout-prefix "./")
3124 (setq wc-checkout-prefix ""))
3125 ;; (message "svn-status-checkout-prefix-path: wc-checkout-prefix: '%s' p: '%s' base-dir: %s" wc-checkout-prefix p base-dir)
3126 (setq p (substring p 0 (- (length p) (length wc-checkout-prefix))))
3127 (when (interactive-p)
3128 (message "svn-status-checkout-prefix-path: '%s'" p))
3129 p))
3130
3131(defun svn-status-ls (path &optional synchron)
3132 "Run svn ls PATH."
3133 (interactive "sPath for svn ls: ")
3134 (svn-run (not synchron) t 'ls "ls" path)
3135 (when synchron
3136 (split-string (with-current-buffer svn-process-buffer-name
3137 (buffer-substring-no-properties (point-min) (point-max))))))
3138
3139(defun svn-status-ls-branches ()
3140 "Show, which branches exist for the actual working copy.
3141Note: this command assumes the proposed standard svn repository layout."
3142 (interactive)
3143 (svn-status-parse-info t)
3144 (svn-status-ls (concat (svn-status-base-info->repository-root) "/branches")))
3145
3146(defun svn-status-ls-tags ()
3147 "Show, which tags exist for the actual working copy.
3148Note: this command assumes the proposed standard svn repository layout."
3149 (interactive)
3150 (svn-status-parse-info t)
3151 (svn-status-ls (concat (svn-status-base-info->repository-root) "/tags")))
3152
3153(defun svn-status-toggle-edit-cmd-flag (&optional reset)
3154 "Allow the user to edit the parameters for the next svn command.
3155This command toggles between
3156* editing the next command parameters (EditCmd)
3157* editing all all command parameters (EditCmd#)
3158* don't edit the command parameters ()
3159The string in parentheses is shown in the status line to show the state."
3160 (interactive)
3161 (cond ((or reset (eq svn-status-edit-svn-command 'sticky))
3162 (setq svn-status-edit-svn-command nil))
3163 ((eq svn-status-edit-svn-command nil)
3164 (setq svn-status-edit-svn-command t))
3165 ((eq svn-status-edit-svn-command t)
3166 (setq svn-status-edit-svn-command 'sticky)))
3167 (cond ((eq svn-status-edit-svn-command t)
3168 (setq svn-status-mode-line-process-edit-flag " EditCmd"))
3169 ((eq svn-status-edit-svn-command 'sticky)
3170 (setq svn-status-mode-line-process-edit-flag " EditCmd#"))
3171 (t
3172 (setq svn-status-mode-line-process-edit-flag "")))
3173 (svn-status-update-mode-line))
3174
3175(defun svn-status-goto-root-or-return ()
3176 "Bounce point between the root (\".\") and the current line."
3177 (interactive)
3178 (if (string= (svn-status-line-info->filename (svn-status-get-line-information)) ".")
3179 (when svn-status-root-return-info
3180 (svn-status-goto-file-name
3181 (svn-status-line-info->filename svn-status-root-return-info)))
3182 (setq svn-status-root-return-info (svn-status-get-line-information))
3183 (svn-status-goto-file-name ".")))
3184
3185(defun svn-status-next-line (nr-of-lines)
3186 "Go to the next line that holds a file information.
3187When called with a prefix argument advance the given number of lines."
3188 (interactive "p")
3189 (while (progn
3190 (forward-line nr-of-lines)
3191 (and (not (eobp))
3192 (not (svn-status-get-line-information)))))
3193 (when (svn-status-get-line-information)
3194 (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
3195
3196(defun svn-status-previous-line (nr-of-lines)
3197 "Go to the previous line that holds a file information.
3198When called with a prefix argument go back the given number of lines."
3199 (interactive "p")
3200 (while (progn
3201 (forward-line (- nr-of-lines))
3202 (and (not (bobp))
3203 (not (svn-status-get-line-information)))))
3204 (when (svn-status-get-line-information)
3205 (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
3206
3207(defun svn-status-dired-jump ()
3208 "Jump to a dired buffer, containing the file at point."
3209 (interactive)
3210 (let* ((line-info (svn-status-get-line-information))
3211 (file-full-path (if line-info
3212 (svn-status-line-info->full-path line-info)
3213 default-directory)))
3214 (let ((default-directory
3215 (file-name-as-directory
3216 (expand-file-name (if line-info
3217 (svn-status-line-info->directory-containing-line-info line-info t)
3218 default-directory)))))
3219 (if (fboundp 'dired-jump-back) (dired-jump-back) (dired-jump))) ;; Xemacs uses dired-jump-back
3220 (dired-goto-file file-full-path)))
3221
3222(defun svn-status-possibly-negate-meaning-of-arg (arg &optional command)
3223 "Negate arg, if this-command is a member of svn-status-possibly-negate-meaning-of-arg."
3224 (unless command
3225 (setq command this-command))
3226 (if (member command svn-status-negate-meaning-of-arg-commands)
3227 (not arg)
3228 arg))
3229
3230(defun svn-status-update (&optional arg)
3231 "Run 'svn status -v'.
3232When called with a prefix argument run 'svn status -vu'."
3233 (interactive "P")
3234 (unless (interactive-p)
3235 (save-excursion
3236 (set-buffer svn-process-buffer-name)
3237 (setq svn-status-update-previous-process-output
3238 (buffer-substring (point-min) (point-max)))))
3239 (svn-status default-directory arg))
3240
3241(defun svn-status-get-line-information ()
3242 "Find out about the file under point.
3243The result may be parsed with the various `svn-status-line-info->...' functions."
3244 (if (eq major-mode 'svn-status-mode)
3245 (let ((svn-info nil))
3246 (dolist (overlay (overlays-at (point)))
3247 (setq svn-info (or svn-info
3248 (overlay-get overlay 'svn-info))))
3249 svn-info)
3250 ;; different mode, means called not from the *svn-status* buffer
3251 (if svn-status-get-line-information-for-file
3252 (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
3253 (file-relative-name (buffer-file-name) (svn-status-base-dir))
3254 (buffer-file-name)))
3255 (svn-status-make-line-info "."))))
3256
3257
3258(defun svn-status-get-file-list (use-marked-files)
3259 "Get either the selected files or the file under point.
3260USE-MARKED-FILES decides which we do.
3261See `svn-status-marked-files' for what counts as selected."
3262 (if use-marked-files
3263 (svn-status-marked-files)
3264 (list (svn-status-get-line-information))))
3265
3266(defun svn-status-get-file-list-names (use-marked-files)
3267 (mapcar 'svn-status-line-info->filename (svn-status-get-file-list use-marked-files)))
3268
3269(defun svn-status-get-file-information ()
3270 "Find out about the file under point.
3271The result may be parsed with the various `svn-status-line-info->...' functions.
3272When called from a *svn-status* buffer, do the same as `svn-status-get-line-information'.
3273When called from a file buffer provide a structure that contains the filename."
3274 (cond ((eq major-mode 'svn-status-mode)
3275 (svn-status-get-line-information))
3276 (t
3277 ;; a fake structure that contains the buffername for the current buffer
3278 (svn-status-make-line-info (buffer-file-name (current-buffer))))))
3279
3280(defun svn-status-select-line ()
3281 "Return information about the file under point.
3282\(Only used for debugging\)"
3283 (interactive)
3284 (let ((info (svn-status-get-line-information)))
3285 (if info
3286 (message "%S hide-because-unknown: %S hide-because-unmodified: %S hide-because-externals: %S" info
3287 (svn-status-line-info->hide-because-unknown info)
3288 (svn-status-line-info->hide-because-unmodified info)
3289 (svn-status-line-info->hide-because-externals info))
3290 (message "No file on this line"))))
3291 (defun svn-status-ensure-cursor-on-file ()
3292 "Raise an error unless point is on a valid file."
3293 (unless (svn-status-get-line-information)
3294 (error "No file on the current line")))
3295
3296(defun svn-status-directory-containing-point (allow-self)
3297 "Find the (full path of) directory containing the file under point.
3298
3299If ALLOW-SELF and the file is a directory, return that directory,
3300otherwise return the directory containing the file under point."
3301 ;;the first `or' below is because s-s-g-l-i returns `nil' if
3302 ;;point was outside the file list, but we need
3303 ;;s-s-l-i->f to return a string to add to `default-directory'.
3304 (let ((line-info (or (svn-status-get-line-information)
3305 (svn-status-make-line-info))))
3306 (file-name-as-directory
3307 (expand-file-name
3308 (svn-status-line-info->directory-containing-line-info line-info allow-self)))))
3309
3310(defun svn-status-line-info->directory-containing-line-info (line-info allow-self)
3311 "Find the directory containing for LINE-INFO.
3312
3313If ALLOW-SELF is t and LINE-INFO refers to a directory then return the
3314directory itself, in all other cases find the parent directory"
3315 (if (and allow-self (svn-status-line-info->directory-p line-info))
3316 (svn-status-line-info->filename line-info)
3317 ;;The next `or' is because (file-name-directory "file") returns nil
3318 (or (file-name-directory (svn-status-line-info->filename line-info))
3319 ".")))
3320
3321(defun svn-status-set-user-mark (arg)
3322 "Set a user mark on the current file or directory.
3323If the cursor is on a file this file is marked and the cursor advances to the next line.
3324If the cursor is on a directory all files in this directory are marked.
3325
3326If this function is called with a prefix argument, only the current line is
3327marked, even if it is a directory."
3328 (interactive "P")
3329 (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
3330 (let ((info (svn-status-get-line-information)))
3331 (if info
3332 (progn
3333 (svn-status-apply-usermark t arg)
3334 (svn-status-next-line 1))
3335 (message "No file on this line - cannot set a mark"))))
3336
3337(defun svn-status-unset-user-mark (arg)
3338 "Remove a user mark on the current file or directory.
3339If the cursor is on a file, this file is unmarked and the cursor advances to the next line.
3340If the cursor is on a directory, all files in this directory are unmarked.
3341
3342If this function is called with a prefix argument, only the current line is
3343unmarked, even if is a directory."
3344 (interactive "P")
3345 (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
3346 (let ((info (svn-status-get-line-information)))
3347 (if info
3348 (progn
3349 (svn-status-apply-usermark nil arg)
3350 (svn-status-next-line 1))
3351 (message "No file on this line - cannot unset a mark"))))
3352
3353(defun svn-status-unset-user-mark-backwards ()
3354 "Remove a user mark from the previous file.
3355Then move to that line."
3356 ;; This is consistent with `dired-unmark-backward' and
3357 ;; `cvs-mode-unmark-up'.
3358 (interactive)
3359 (let ((info (save-excursion
3360 (svn-status-next-line -1)
3361 (svn-status-get-line-information))))
3362 (if info
3363 (progn
3364 (svn-status-next-line -1)
3365 (svn-status-apply-usermark nil t))
3366 (message "No file on previous line - cannot unset a mark"))))
3367
3368(defun svn-status-apply-usermark (set-mark only-this-line)
3369 "Do the work for the various marking/unmarking functions."
3370 (let* ((st-info svn-status-info)
3371 (mark-count 0)
3372 (line-info (svn-status-get-line-information))
3373 (file-name (svn-status-line-info->filename line-info))
3374 (sub-file-regexp (if (file-directory-p file-name)
3375 (concat "^" (regexp-quote
3376 (file-name-as-directory file-name)))
3377 nil))
3378 (newcursorpos-fname)
3379 (i-fname)
3380 (first-line t)
3381 (current-line svn-start-of-file-list-line-number))
3382 (while st-info
3383 (when (or (svn-status-line-info->is-visiblep (car st-info)) first-line)
3384 (setq current-line (1+ current-line))
3385 (setq first-line nil))
3386 (setq i-fname (svn-status-line-info->filename (car st-info)))
3387 (when (or (string= file-name i-fname)
3388 (when sub-file-regexp
3389 (string-match sub-file-regexp i-fname)))
3390 (when (svn-status-line-info->is-visiblep (car st-info))
3391 (when (or (not only-this-line) (string= file-name i-fname))
3392 (setq newcursorpos-fname i-fname)
3393 (unless (eq (car (svn-status-line-info->ui-status (car st-info))) set-mark)
3394 (setcar (svn-status-line-info->ui-status (car st-info)) set-mark)
3395 (setq mark-count (+ 1 mark-count))
3396 (save-excursion
3397 (let ((buffer-read-only nil))
3398 (goto-line current-line)
3399 (delete-region (svn-point-at-bol) (svn-point-at-eol))
3400 (svn-insert-line-in-status-buffer (car st-info))
3401 (delete-char 1)))
3402 (message "%s %s" (if set-mark "Marked" "Unmarked") i-fname)))))
3403 (setq st-info (cdr st-info)))
3404 ;;(svn-status-update-buffer)
3405 (svn-status-goto-file-name newcursorpos-fname)
3406 (when (> mark-count 1)
3407 (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
3408
3409(defun svn-status-apply-usermark-checked (check-function set-mark)
3410 "Mark or unmark files, whether a given function returns t.
3411The function is called with the line information. Therefore the
3412svn-status-line-info->* functions can be used in the check."
3413 (let ((st-info svn-status-info)
3414 (mark-count 0))
3415 (while st-info
3416 (when (apply check-function (list (car st-info)))
3417 (unless (eq (svn-status-line-info->has-usermark (car st-info)) set-mark)
3418 (setq mark-count (+ 1 mark-count))
3419 (message "%s %s"
3420 (if set-mark "Marked" "Unmarked")
3421 (svn-status-line-info->filename (car st-info))))
3422 (setcar (svn-status-line-info->ui-status (car st-info)) set-mark))
3423 (setq st-info (cdr st-info)))
3424 (svn-status-update-buffer)
3425 (when (> mark-count 1)
3426 (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
3427
3428(defun svn-status-mark-unknown (arg)
3429 "Mark all unknown files.
3430These are the files marked with '?' in the `svn-status-buffer-name' buffer.
3431If the function is called with a prefix arg, unmark all these files."
3432 (interactive "P")
3433 (svn-status-apply-usermark-checked
3434 '(lambda (info) (eq (svn-status-line-info->filemark info) ??)) (not arg)))
3435
3436(defun svn-status-mark-added (arg)
3437 "Mark all added files.
3438These are the files marked with 'A' in the `svn-status-buffer-name' buffer.
3439If the function is called with a prefix ARG, unmark all these files."
3440 (interactive "P")
3441 (svn-status-apply-usermark-checked
3442 '(lambda (info) (eq (svn-status-line-info->filemark info) ?A)) (not arg)))
3443
3444(defun svn-status-mark-modified (arg)
3445 "Mark all modified files.
3446These are the files marked with 'M' in the `svn-status-buffer-name' buffer.
3447Changed properties are considered.
3448If the function is called with a prefix ARG, unmark all these files."
3449 (interactive "P")
3450 (svn-status-apply-usermark-checked
3451 '(lambda (info) (or (eq (svn-status-line-info->filemark info) ?M)
3452 (eq (svn-status-line-info->filemark info)
3453 svn-status-file-modified-after-save-flag)
3454 (eq (svn-status-line-info->propmark info) ?M)))
3455 (not arg)))
3456
3457(defun svn-status-mark-modified-properties (arg)
3458 "Mark all files and directories with modified properties.
3459If the function is called with a prefix ARG, unmark all these entries."
3460 (interactive "P")
3461 (svn-status-apply-usermark-checked
3462 '(lambda (info) (or (eq (svn-status-line-info->propmark info) ?M)))
3463 (not arg)))
3464
3465(defun svn-status-mark-deleted (arg)
3466 "Mark all files scheduled for deletion.
3467These are the files marked with 'D' in the `svn-status-buffer-name' buffer.
3468If the function is called with a prefix ARG, unmark all these files."
3469 (interactive "P")
3470 (svn-status-apply-usermark-checked
3471 '(lambda (info) (eq (svn-status-line-info->filemark info) ?D)) (not arg)))
3472
3473(defun svn-status-mark-changed (arg)
3474 "Mark all files that could be committed.
3475This means we mark
3476* all modified files
3477* all files scheduled for addition
3478* all files scheduled for deletion
3479* all files with modified properties
3480
3481The last two categories include all copied and moved files.
3482If called with a prefix ARG, unmark all such files."
3483 (interactive "P")
3484 (svn-status-mark-added arg)
3485 (svn-status-mark-modified arg)
3486 (svn-status-mark-deleted arg)
3487 (svn-status-mark-modified-properties arg))
3488
3489(defun svn-status-unset-all-usermarks ()
3490 (interactive)
3491 (svn-status-apply-usermark-checked '(lambda (info) t) nil))
3492
3493(defun svn-status-store-usermarks (arg)
3494 "Store the current usermarks in `svn-status-usermark-storage'.
3495When called with a prefix argument it is possible to store different sets of marks."
3496 (interactive "P")
3497 (let ((file-list (svn-status-get-file-list-names t)))
3498 (svn-puthash arg file-list svn-status-usermark-storage)
3499 (message "psvn stored %d user marks" (length file-list))))
3500
3501(defun svn-status-load-usermarks (arg)
3502 "Load previously stored user marks from `svn-status-usermark-storage'.
3503When called with a prefix argument it is possible to store/load different sets of marks."
3504 (interactive "P")
3505 (let ((file-list (gethash arg svn-status-usermark-storage)))
3506 (svn-status-apply-usermark-checked
3507 '(lambda (info) (member (svn-status-line-info->filename info) file-list)) t)))
3508
3509(defvar svn-status-regexp-history nil
3510 "History list of regular expressions used in svn status commands.")
3511
3512(defun svn-status-read-regexp (prompt)
3513 (read-from-minibuffer prompt nil nil nil 'svn-status-regexp-history))
3514
3515(defun svn-status-mark-filename-regexp (regexp &optional unmark)
3516 "Mark all files matching REGEXP.
3517If the function is called with a prefix arg, unmark all these files."
3518 (interactive
3519 (list (svn-status-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3520 " files (regexp): "))
3521 (if current-prefix-arg t nil)))
3522 (svn-status-apply-usermark-checked
3523 '(lambda (info) (string-match regexp (svn-status-line-info->filename-nondirectory info))) (not unmark)))
3524
3525(defun svn-status-mark-by-file-ext (ext &optional unmark)
3526 "Mark all files matching the given file extension EXT.
3527If the function is called with a prefix arg, unmark all these files."
3528 (interactive
3529 (list (read-string (concat (if current-prefix-arg "Unmark" "Mark")
3530 " files with extensions: "))
3531 (if current-prefix-arg t nil)))
3532 (svn-status-apply-usermark-checked
3533 '(lambda (info) (let ((case-fold-search nil))
3534 (string-match (concat "\\." ext "$") (svn-status-line-info->filename-nondirectory info)))) (not unmark)))
3535
3536(defun svn-status-toggle-hide-unknown ()
3537 (interactive)
3538 (setq svn-status-hide-unknown (not svn-status-hide-unknown))
3539 (svn-status-update-buffer))
3540
3541(defun svn-status-toggle-hide-unmodified ()
3542 (interactive)
3543 (setq svn-status-hide-unmodified (not svn-status-hide-unmodified))
3544 (svn-status-update-buffer))
3545
3546(defun svn-status-toggle-hide-externals ()
3547 (interactive)
3548 (setq svn-status-hide-externals (not svn-status-hide-externals))
3549 (svn-status-update-buffer))
3550
3551(defun svn-status-get-file-name-buffer-position (name)
3552 "Find the buffer position for a file.
3553If the file is not found, return nil."
3554 (let ((start-pos (let ((cached-pos (gethash name
3555 svn-status-filename-to-buffer-position-cache)))
3556 (when cached-pos
3557 (goto-char (previous-overlay-change cached-pos)))
3558 (point)))
3559 (found))
3560 ;; performance optimization: search from point to end of buffer
3561 (while (and (not found) (< (point) (point-max)))
3562 (goto-char (next-overlay-change (point)))
3563 (when (string= name (svn-status-line-info->filename
3564 (svn-status-get-line-information)))
3565 (setq start-pos (+ (point) svn-status-default-column))
3566 (setq found t)))
3567 ;; search from buffer start to point
3568 (goto-char (point-min))
3569 (while (and (not found) (< (point) start-pos))
3570 (goto-char (next-overlay-change (point)))
3571 (when (string= name (svn-status-line-info->filename
3572 (svn-status-get-line-information)))
3573 (setq start-pos (+ (point) svn-status-default-column))
3574 (setq found t)))
3575 (and found start-pos)))
3576
3577(defun svn-status-goto-file-name (name)
3578 "Move the cursor the the line that displays NAME."
3579 (let ((pos (svn-status-get-file-name-buffer-position name)))
3580 (if pos
3581 (goto-char pos)
3582 (svn-status-message 7 "Note: svn-status-goto-file-name: %s not found" name))))
3583
3584(defun svn-status-find-info-for-file-name (name)
3585 (let* ((st-info svn-status-info)
3586 (info))
3587 (while st-info
3588 (when (string= name (svn-status-line-info->filename (car st-info)))
3589 (setq info (car st-info))
3590 (setq st-info nil)) ; terminate loop
3591 (setq st-info (cdr st-info)))
3592 info))
3593
3594(defun svn-status-marked-files ()
3595 "Return all files marked by `svn-status-set-user-mark',
3596or (if no files were marked) the file under point."
3597 (if (eq major-mode 'svn-status-mode)
3598 (let* ((st-info svn-status-info)
3599 (file-list))
3600 (while st-info
3601 (when (svn-status-line-info->has-usermark (car st-info))
3602 (setq file-list (append file-list (list (car st-info)))))
3603 (setq st-info (cdr st-info)))
3604 (or file-list
3605 (if (svn-status-get-line-information)
3606 (list (svn-status-get-line-information))
3607 nil)))
3608 ;; different mode, means called not from the *svn-status* buffer
3609 (if svn-status-get-line-information-for-file
3610 (list (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
3611 (file-relative-name (buffer-file-name) (svn-status-base-dir))
3612 (buffer-file-name))))
3613 (list (svn-status-make-line-info ".")))))
3614
3615(defun svn-status-marked-file-names ()
3616 (mapcar 'svn-status-line-info->filename (svn-status-marked-files)))
3617
3618(defun svn-status-some-files-marked-p ()
3619 "Return non-nil iff a file has been marked by `svn-status-set-user-mark'.
3620Unlike `svn-status-marked-files', this does not select the file under point
3621if no files have been marked."
3622 ;; `some' would be shorter but requires cl-seq at runtime.
3623 ;; (Because it accepts both lists and vectors, it is difficult to inline.)
3624 (loop for line-info in svn-status-info
3625 thereis (svn-status-line-info->has-usermark line-info)))
3626
3627(defun svn-status-only-dirs-or-nothing-marked-p ()
3628 "Return non-nil iff only dirs has been marked by `svn-status-set-user-mark'."
3629 ;; `some' would be shorter but requires cl-seq at runtime.
3630 ;; (Because it accepts both lists and vectors, it is difficult to inline.)
3631 (loop for line-info in svn-status-info
3632 thereis (and (not (svn-status-line-info->directory-p line-info))
3633 (svn-status-line-info->has-usermark line-info))))
3634
3635(defun svn-status-ui-information-hash-table ()
3636 (let ((st-info svn-status-info)
3637 (svn-status-ui-information (make-hash-table :test 'equal)))
3638 (while st-info
3639 (svn-puthash (svn-status-line-info->filename (car st-info))
3640 (svn-status-line-info->ui-status (car st-info))
3641 svn-status-ui-information)
3642 (setq st-info (cdr st-info)))
3643 svn-status-ui-information))
3644
3645
3646(defun svn-status-create-arg-file (file-name prefix file-info-list postfix)
3647 "Create an svn client argument file"
3648 ;; create the arg file on the remote host when we will run svn on this host!
3649 (setq file-name (svn-expand-filename-for-remote-access file-name))
3650 ;; (message "svn-status-create-arg-file %s: %s" default-directory file-name)
3651 (with-temp-file file-name
3652 (insert prefix)
3653 (let ((st-info file-info-list))
3654 (while st-info
3655 (insert (svn-status-line-info->filename (car st-info)))
3656 (insert "\n")
3657 (setq st-info (cdr st-info)))
3658
3659 (insert postfix))))
3660
3661(defun svn-status-show-process-buffer-internal (&optional scroll-to-top)
3662 (let ((cur-buff (current-buffer)))
3663 (unless svn-status-preserve-window-configuration
3664 (when (string= (buffer-name) svn-status-buffer-name)
3665 (delete-other-windows)))
3666 (pop-to-buffer svn-process-buffer-name)
3667 (svn-process-mode)
3668 (when scroll-to-top
3669 (goto-char (point-min)))
3670 (pop-to-buffer cur-buff)))
3671
3672(defun svn-status-show-process-output (cmd &optional scroll-to-top)
3673 "Display the result of a svn command.
3674Consider svn-status-window-alist to choose the buffer name."
3675 (let ((window-mode (cadr (assoc cmd svn-status-window-alist)))
3676 (process-default-directory))
3677 (cond ((eq window-mode nil) ;; use *svn-process* buffer
3678 (setq svn-status-last-output-buffer-name svn-process-buffer-name))
3679 ((eq window-mode t) ;; use *svn-info* buffer
3680 (setq svn-status-last-output-buffer-name "*svn-info*"))
3681 ((eq window-mode 'invisible) ;; don't display the buffer
3682 (setq svn-status-last-output-buffer-name nil))
3683 (t
3684 (setq svn-status-last-output-buffer-name window-mode)))
3685 (when svn-status-last-output-buffer-name
3686 (if window-mode
3687 (progn
3688 (unless svn-status-preserve-window-configuration
3689 (when (string= (buffer-name) svn-status-buffer-name)
3690 (delete-other-windows)))
3691 (pop-to-buffer svn-process-buffer-name)
3692 (setq process-default-directory default-directory)
3693 (switch-to-buffer (get-buffer-create svn-status-last-output-buffer-name))
3694 (setq default-directory process-default-directory)
3695 (let ((buffer-read-only nil))
3696 (delete-region (point-min) (point-max))
3697 (insert-buffer-substring svn-process-buffer-name)
3698 (when scroll-to-top
3699 (goto-char (point-min))))
3700 (when (eq window-mode t) ;; *svn-info* buffer
3701 (svn-info-mode))
3702 (other-window 1))
3703 (svn-status-show-process-buffer-internal scroll-to-top)))))
3704
3705(defun svn-status-svn-log-switches (arg)
3706 (cond ((eq arg 0) '())
3707 ((or (eq arg -1) (eq arg '-)) '("-q"))
3708 (arg '("-v"))
3709 (t svn-status-default-log-arguments)))
3710
3711(defun svn-status-show-svn-log (arg)
3712 "Run `svn log' on selected files.
3713The output is put into the *svn-log* buffer
3714The optional prefix argument ARG determines which switches are passed to `svn log':
3715 no prefix --- use whatever is in the list `svn-status-default-log-arguments'
3716 prefix argument of -1: --- use the -q switch (quiet)
3717 prefix argument of 0 --- use no arguments
3718 other prefix arguments: --- use the -v switch (verbose)
3719
3720See `svn-status-marked-files' for what counts as selected."
3721 (interactive "P")
3722 (let ((switches (svn-status-svn-log-switches arg))
3723 (svn-status-get-line-information-for-file t))
3724 ;; (message "svn-status-show-svn-log %S" arg)
3725 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3726 (svn-run t t 'log "log" "--targets" svn-status-temp-arg-file switches)))
3727
3728(defun svn-status-version ()
3729 "Show the version numbers for psvn.el and the svn command line client.
3730The version number of the client is cached in `svn-client-version'."
3731 (interactive)
3732 (let ((window-conf (current-window-configuration))
3733 (version-string))
3734 (if (or (interactive-p) (not svn-status-cached-version-string))
3735 (progn
3736 (svn-run nil t 'version "--version")
3737 (when (interactive-p)
3738 (svn-status-show-process-output 'info t))
3739 (with-current-buffer svn-status-last-output-buffer-name
3740 (goto-char (point-min))
3741 (setq svn-client-version
3742 (when (re-search-forward "svn, version \\([0-9\.]+\\) " nil t)
3743 (mapcar 'string-to-number (split-string (match-string 1) "\\."))))
3744 (let ((buffer-read-only nil))
3745 (goto-char (point-min))
3746 (insert (format "psvn.el revision: %s\n\n" svn-psvn-revision)))
3747 (setq version-string (buffer-substring-no-properties (point-min) (point-max))))
3748 (setq svn-status-cached-version-string version-string))
3749 (setq version-string svn-status-cached-version-string)
3750 (unless (interactive-p)
3751 (set-window-configuration window-conf)
3752 version-string))))
3753
3754(defun svn-status-info ()
3755 "Run `svn info' on all selected files.
3756See `svn-status-marked-files' for what counts as selected."
3757 (interactive)
3758 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
3759 (svn-run t t 'info "info" "--targets" svn-status-temp-arg-file))
3760
3761(defun svn-status-info-for-path (path)
3762 "Run svn info on the given PATH.
3763Return some interesting parts of the resulting output.
3764At the moment a list containing the last changed author is returned."
3765 (let ((svn-process-buffer-name "*svn-info-output*")
3766 (last-changed-author))
3767 (svn-run nil t 'info "info" path)
3768 (with-current-buffer svn-process-buffer-name
3769 (goto-char (point-min))
3770 (when (search-forward "last changed author: " nil t)
3771 (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol)))))
3772 (svn-status-message 7 "last-changed-author for '%s': %s" path last-changed-author)
3773 (list last-changed-author)))
3774
3775(defun svn-status-blame (revision &optional file-name)
3776 "Run `svn blame' on the current file.
3777When called with a prefix argument, ask the user for the REVISION to use.
3778When called from a file buffer, go to the current line in the resulting blame output."
3779 (interactive "P")
3780 (when current-prefix-arg
3781 (setq revision (svn-status-read-revision-string "Blame for version: " "BASE")))
3782 (unless revision (setq revision "BASE"))
3783 (setq svn-status-blame-revision revision)
3784 (setq svn-status-blame-file-name (if file-name
3785 file-name
3786 (svn-status-line-info->filename (svn-status-get-file-information))))
3787 (svn-run t t 'blame "blame" svn-status-default-blame-arguments "-r" revision svn-status-blame-file-name))
3788
3789(defun svn-blame-blame-again (arg)
3790 "Run svn blame again, using the revision before the change at point.
3791When point is at revision 3472, run it with 3471."
3792 (interactive "P")
3793 (let ((rev (svn-blame-rev-at-point)))
3794 (setq rev (number-to-string (- (string-to-number rev) 1)))
3795 (when current-prefix-arg
3796 (setq rev (svn-status-read-revision-string (format "Svn blame for rev#? ") rev)))
3797 (svn-status-blame rev svn-status-blame-file-name)))
3798
3799(defun svn-status-show-svn-diff (arg)
3800 "Run `svn diff' on the current file.
3801If the current file is a directory, compare it recursively.
3802If there is a newer revision in the repository, the diff is done against HEAD,
3803otherwise compare the working copy with BASE.
3804If ARG then prompt for revision to diff against (unless arg is '-)
3805When called with a negative prefix argument, do a non recursive diff."
3806 (interactive "P")
3807 (let ((non-recursive (or (and (numberp arg) (< arg 0)) (eq arg '-)))
3808 (revision (if (and (not (eq arg '-)) arg) :ask :auto)))
3809 (svn-status-ensure-cursor-on-file)
3810 (svn-status-show-svn-diff-internal (list (svn-status-get-line-information)) (not non-recursive)
3811 revision)))
3812
3813(defun svn-file-show-svn-diff (arg)
3814 "Run `svn diff' on the current file.
3815If there is a newer revision in the repository, the diff is done against HEAD,
3816otherwise compare the working copy with BASE.
3817If ARG then prompt for revision to diff against."
3818 (interactive "P")
3819 (svn-status-show-svn-diff-internal (list (svn-status-make-line-info buffer-file-name)) nil
3820 (if arg :ask :auto)))
3821
3822(defun svn-status-show-svn-diff-for-marked-files (arg)
3823 "Run `svn diff' on all selected files.
3824If some files have been marked, compare those non-recursively;
3825this is because marking a directory with \\[svn-status-set-user-mark]
3826normally marks all of its files as well.
3827If no files have been marked, compare recursively the file at point.
3828If ARG then prompt for revision to diff against, else compare working copy with BASE."
3829 (interactive "P")
3830 (svn-status-show-svn-diff-internal (svn-status-marked-files)
3831 (not (svn-status-some-files-marked-p))
3832 (if arg :ask "BASE")))
3833
3834(defun svn-status-diff-show-changeset (rev &optional user-confirmation rev-against)
3835 "Show the changeset for a given log entry.
3836When called with a prefix argument, ask the user for the revision."
3837 (let* ((upper-rev (if rev-against rev-against rev))
3838 (lower-rev (if rev-against rev (number-to-string (- (string-to-number upper-rev) 1))))
3839 (rev-arg (concat lower-rev ":" upper-rev)))
3840 (when user-confirmation
3841 (setq rev-arg (read-string "Revision for changeset: " rev-arg)))
3842 (svn-run nil t 'diff "diff" svn-status-default-diff-arguments (concat "-r" rev-arg))
3843 (svn-status-activate-diff-mode)))
3844
3845(defun svn-status-show-svn-diff-internal (line-infos recursive revision)
3846 ;; REVISION must be one of:
3847 ;; - a string: whatever the -r option allows.
3848 ;; - `:ask': asks the user to specify the revision, which then becomes
3849 ;; saved in `minibuffer-history' rather than in `command-history'.
3850 ;; - `:auto': use "HEAD" if an update is known to exist, "BASE" otherwise.
3851 ;; In the future, `nil' might mean omit the -r option entirely;
3852 ;; but that currently seems to imply "BASE", so we just use that.
3853 (when (eq revision :ask)
3854 (setq revision (svn-status-read-revision-string
3855 "Diff with files for version: " "PREV")))
3856
3857 (setq svn-status-last-diff-options (list line-infos recursive revision))
3858
3859 (let ((clear-buf t)
3860 (beginning nil))
3861 (dolist (line-info line-infos)
3862 (svn-run nil clear-buf 'diff "diff" svn-status-default-diff-arguments
3863 "-r" (if (eq revision :auto)
3864 (if (svn-status-line-info->update-available line-info)
3865 "HEAD" "BASE")
3866 revision)
3867 (unless recursive "--non-recursive")
3868 (svn-status-line-info->filename line-info))
3869 (setq clear-buf nil)
3870
3871 ;; "svn diff --non-recursive" skips only subdirectories, not files.
3872 ;; But a non-recursive diff via psvn should skip files too, because
3873 ;; the user would have marked them if he wanted them to be compared.
3874 ;; So we'll look for the "Index: foo" line that marks the first file
3875 ;; in the diff output, and delete it and everything that follows.
3876 ;; This is made more complicated by the fact that `svn-status-activate-diff-mode'
3877 ;; expects the output to be left in the *svn-process* buffer.
3878 (unless recursive
3879 ;; Check `directory-p' relative to the `default-directory' of the
3880 ;; "*svn-status*" buffer, not that of the svn-process-buffer-name buffer.
3881 (let ((directory-p (svn-status-line-info->directory-p line-info)))
3882 (with-current-buffer svn-process-buffer-name
3883 (when directory-p
3884 (goto-char (or beginning (point-min)))
3885 (when (re-search-forward "^Index: " nil t)
3886 (delete-region (match-beginning 0) (point-max))))
3887 (goto-char (setq beginning (point-max))))))))
3888 (svn-status-activate-diff-mode))
3889
3890(defun svn-status-diff-save-current-defun-as-kill ()
3891 "Copy the function name for the change at point to the kill-ring.
3892That function uses `add-log-current-defun'"
3893 (interactive)
3894 (let ((func-name (add-log-current-defun)))
3895 (if func-name
3896 (progn
3897 (kill-new func-name)
3898 (message "Copied %S" func-name))
3899 (message "No current defun detected."))))
3900
3901(defun svn-status-diff-pop-to-commit-buffer ()
3902 "Temporary switch to the `svn-status-buffer-name' buffer and start a commit from there."
3903 (interactive)
3904 (let ((window-conf (current-window-configuration)))
3905 (svn-status-switch-to-status-buffer)
3906 (svn-status-commit)
3907 (set-window-configuration window-conf)
3908 (setq svn-status-pre-commit-window-configuration window-conf)
3909 (pop-to-buffer svn-log-edit-buffer-name)))
3910
3911(defun svn-status-activate-diff-mode ()
3912 "Show the `svn-process-buffer-name' buffer, using the diff-mode."
3913 (svn-status-show-process-output 'diff t)
3914 (let ((working-directory default-directory))
3915 (save-excursion
3916 (set-buffer svn-status-last-output-buffer-name)
3917 (setq default-directory working-directory)
3918 (svn-status-diff-mode)
3919 (setq buffer-read-only t))))
3920
3921(define-derived-mode svn-status-diff-mode fundamental-mode "svn-diff"
3922 "Major mode to display svn diffs. Derives from `diff-mode'.
3923
3924Commands:
3925\\{svn-status-diff-mode-map}
3926"
3927 (let ((diff-mode-shared-map (copy-keymap svn-status-diff-mode-map))
3928 major-mode mode-name)
3929 (diff-mode)
3930 (set (make-local-variable 'revert-buffer-function) 'svn-status-diff-update)))
3931
3932(defun svn-status-diff-update (arg noconfirm)
3933 "Rerun the last svn diff command and update the *svn-diff* buffer."
3934 (interactive)
3935 (svn-status-save-some-buffers)
3936 (save-window-excursion
3937 (apply 'svn-status-show-svn-diff-internal svn-status-last-diff-options)))
3938
3939(defun svn-status-show-process-buffer ()
3940 "Show the content of the `svn-process-buffer-name' buffer"
3941 (interactive)
3942 (svn-status-show-process-output nil))
3943
3944(defun svn-status-pop-to-partner-buffer ()
3945 "Pop to the `svn-status-partner-buffer' if that variable is set."
3946 (interactive)
3947 (when svn-status-partner-buffer
3948 (let ((cur-buf (current-buffer)))
3949 (pop-to-buffer svn-status-partner-buffer)
3950 (setq svn-status-partner-buffer cur-buf))))
3951
3952(defun svn-status-pop-to-new-partner-buffer (buffer)
3953 "Call `pop-to-buffer' and register the current buffer as partner buffer for BUFFER."
3954 (let ((cur-buf (current-buffer)))
3955 (pop-to-buffer buffer)
3956 (setq svn-status-partner-buffer cur-buf)))
3957
3958(defun svn-status-add-file-recursively (arg)
3959 "Run `svn add' on all selected files.
3960When a directory is added, add files recursively.
3961See `svn-status-marked-files' for what counts as selected.
3962When this function is called with a prefix argument, use the actual file instead."
3963 (interactive "P")
3964 (message "adding: %S" (svn-status-get-file-list-names (not arg)))
3965 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
3966 (svn-run t t 'add "add" "--targets" svn-status-temp-arg-file))
3967
3968(defun svn-status-add-file (arg)
3969 "Run `svn add' on all selected files.
3970When a directory is added, don't add the files of the directory
3971 (svn add --non-recursive <file-list> is called).
3972See `svn-status-marked-files' for what counts as selected.
3973When this function is called with a prefix argument, use the actual file instead."
3974 (interactive "P")
3975 (message "adding: %S" (svn-status-get-file-list-names (not arg)))
3976 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
3977 (svn-run t t 'add "add" "--non-recursive" "--targets" svn-status-temp-arg-file))
3978
3979(defun svn-status-lock (arg)
3980 "Run `svn lock' on all selected files.
3981See `svn-status-marked-files' for what counts as selected."
3982 (interactive "P")
3983 (message "locking: %S" (svn-status-get-file-list-names t))
3984 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
3985 (svn-run t t 'lock "lock" "--targets" svn-status-temp-arg-file))
3986
3987(defun svn-status-unlock (arg)
3988 "Run `svn unlock' on all selected files.
3989See `svn-status-marked-files' for what counts as selected."
3990 (interactive "P")
3991 (message "unlocking: %S" (svn-status-get-file-list-names t))
3992 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
3993 (svn-run t t 'unlock "unlock" "--targets" svn-status-temp-arg-file))
3994
3995(defun svn-status-make-directory (dir)
3996 "Run `svn mkdir DIR'."
3997 ;; TODO: Allow entering a URI interactively.
3998 ;; Currently, `read-file-name' corrupts it.
3999 (interactive (list (read-file-name "Make directory: "
4000 (svn-status-directory-containing-point t))))
4001 (unless (string-match "^[^:/]+://" dir) ; Is it a URI?
4002 (setq dir (file-relative-name dir)))
4003 (svn-run t t 'mkdir "mkdir" "--" dir))
4004
4005(defun svn-status-mv ()
4006 "Prompt for a destination, and `svn mv' selected files there.
4007See `svn-status-marked-files' for what counts as `selected'.
4008
4009If one file was selected then the destination DEST should be a
4010filename to rename the selected file to, or a directory to move the
4011file into; if multiple files were selected then DEST should be a
4012directory to move the selected files into.
4013
4014The default DEST is the directory containing point.
4015
4016BUG: If we've marked some directory containging a file as well as the
4017file itself, then we should just mv the directory, but this implementation
4018doesn't check for that.
4019SOLUTION: for each dir, umark all its contents (but not the dir
4020itself) before running mv."
4021 (interactive)
4022 (svn-status-mv-cp "mv" "Rename" "Move" "mv"))
4023
4024(defun svn-status-cp ()
4025 "See `svn-status-mv'"
4026 (interactive)
4027 (svn-status-mv-cp "cp" "Copy" "Copy" "cp"))
4028
4029(defun svn-status-mv-cp (command singleprompt manyprompt fallback)
4030 "Run svn COMMAND on marked files, prompting for destination
4031
4032This function acts on `svn-status-marked-files': at the prompt the
4033user can enter a new file name, or an existing directory: this is used as the argument for svn COMMAND.
4034 COMMAND --- string saying what to do: \"mv\" or \"cp\"
4035 SINGLEPROMPT --- string at start of prompt when one file marked
4036 MANYPROMPT --- string at start of prompt when multiple files marked
4037 FALLBACK --- If any marked file is unversioned, use this instead of 'svn COMMAND'"
4038 (let* ((marked-files (svn-status-marked-files))
4039 (num-of-files (length marked-files))
4040 dest)
4041 (if (= 1 num-of-files)
4042 ;; one file to act on: new name, or directory to hold results
4043 (setq dest (read-file-name
4044 (format "%s %s to: " singleprompt
4045 (svn-status-line-info->filename (car marked-files)))
4046 (svn-status-directory-containing-point t)
4047 (svn-status-line-info->full-path (car marked-files))))
4048 ;;TODO: (when file-exists-p but-no-dir-p dest (error "%s already exists" dest))
4049 ;;multiple files selected, so prompt for existing directory to mv them into.
4050 (setq dest (svn-read-directory-name
4051 (format "%s %d files to directory: " manyprompt num-of-files)
4052 (svn-status-directory-containing-point t) nil t))
4053 (unless (file-directory-p dest)
4054 (error "%s is not a directory" dest)))
4055 (when (string= dest "")
4056 (error "No destination entered"))
4057 (unless (string-match "^[^:/]+://" dest) ; Is it a URI?
4058 (setq dest (file-relative-name dest)))
4059
4060 ;;do the move: svn mv only lets us move things once at a time, so
4061 ;;we need to run svn mv once for each file (hence second arg to
4062 ;;svn-run is nil.)
4063
4064 ;;TODO: before doing any moving, For every marked directory,
4065 ;;ensure none of its contents are also marked, since we dont want
4066 ;;to move both file *and* its parent...
4067 ;; what about elided files? what if user marks a dir+contents, then presses `_' ?
4068;; ;one solution:
4069;; (dolist (original marked-files)
4070;; (when (svn-status-line-info->directory-p original)
4071;; ;; run svn-status-goto-file-name to move point to line of file
4072;; ;; run svn-status-unset-user-mark to unmark dir+all contents
4073;; ;; run svn-status-set-user-mark to remark dir
4074;; ;; maybe check for local mods here, and unmark if user does't say --force?
4075;; ))
4076 (dolist (original marked-files)
4077 (let ((original-name (svn-status-line-info->filename original))
4078 (original-filemarks (svn-status-line-info->filemark original))
4079 (original-propmarks (svn-status-line-info->propmark original))
4080 (moved nil))
4081 (cond
4082 ((or (eq original-filemarks ?M) ;local mods: maybe do `svn mv --force'
4083 (eq original-propmarks ?M)) ;local prop mods: maybe do `svn mv --force'
4084 (if (yes-or-no-p
4085 (format "%s has local modifications; use `--force' to really move it? " original-name))
4086 (progn
4087 (svn-status-run-mv-cp command original-name dest t)
4088 (setq moved t))
4089 (message "Not acting on %s" original-name)))
4090 ((eq original-filemarks ??) ;original is unversioned: use fallback
4091 (if (yes-or-no-p (format "%s is unversioned. Use `%s -i -- %s %s'? "
4092 original-name fallback original-name dest))
4093 ;; TODO: consider svn-call-process-function here also...
4094 (progn (call-process fallback nil (get-buffer-create svn-process-buffer-name) nil
4095 "-i" "--" original-name dest)
4096 (setq moved t))
4097 ;;new files created by fallback are not in *svn-status* now,
4098 ;;TODO: so call (svn-status-update) here?
4099 (message "Not acting on %s" original-name)))
4100
4101 ((eq original-filemarks ?A) ;;`A' (`svn add'ed, but not committed)
4102 (message "Not acting on %s (commit it first)" original-name))
4103
4104 ((eq original-filemarks ? ) ;original is unmodified: can proceed
4105 (svn-status-run-mv-cp command original-name dest)
4106 (setq moved t))
4107
4108 ;;file has some other mark (eg conflicted)
4109 (t
4110 (if (yes-or-no-p
4111 (format "The status of %s looks scary. Risk moving it anyway? "
4112 original-name))
4113 (progn
4114 (svn-status-run-mv-cp command original-name dest)
4115 (setq moved t))
4116 (message "Not acting on %s" original-name))))
4117 (when moved
4118 (message "psvn: did '%s' from %s to %s" command original-name dest)
4119 ;; Silently rename the visited file of any buffer visiting this file.
4120 (when (get-file-buffer original-name)
4121 (with-current-buffer (get-file-buffer original-name)
4122 (set-visited-file-name dest nil t))))))
4123 (svn-status-update)))
4124
4125(defun svn-status-run-mv-cp (command original destination &optional force)
4126 "Actually run svn mv or svn cp.
4127This is just to prevent duplication in `svn-status-prompt-and-act-on-files'"
4128 (if force
4129 (svn-run nil t (intern command) command "--force" "--" original destination)
4130 (svn-run nil t (intern command) command "--" original destination))
4131;;;TODO: use something like the following instead of calling svn-status-update
4132;;; at the end of svn-status-mv-cp.
4133;; (let ((output (svn-status-parse-ar-output))
4134;; newfile
4135;; buffer-read-only) ; otherwise insert-line-in-status-buffer fails
4136;; (dolist (new-file output)
4137;; (when (eq (cadr new-file) 'added-wc)
4138;; ;; files with 'wc-added action do not exist in *svn-status*
4139;; ;; buffer yet, so give each of them their own line-info
4140;; ;; 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?]
4141
4142;; (svn-insert-line-in-status-buffer
4143;; (svn-status-make-line-info (car new-file)))))
4144;; (svn-status-update-with-command-list output))
4145 )
4146
4147(defun svn-status-revert ()
4148 "Run `svn revert' on all selected files.
4149See `svn-status-marked-files' for what counts as selected."
4150 (interactive)
4151 (let* ((marked-files (svn-status-marked-files))
4152 (num-of-files (length marked-files)))
4153 (when (yes-or-no-p
4154 (if (= 1 num-of-files)
4155 (format "Revert %s? " (svn-status-line-info->filename (car marked-files)))
4156 (format "Revert %d files? " num-of-files)))
4157 (message "reverting: %S" (svn-status-marked-file-names))
4158 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
4159 (svn-run t t 'revert "revert" "--targets" svn-status-temp-arg-file))))
4160
4161(defun svn-file-revert ()
4162 "Run `svn revert' on the current file."
4163 (interactive)
4164 (when (y-or-n-p (format "Revert %s? " buffer-file-name))
4165 (svn-run t t 'revert "revert" buffer-file-name)))
4166
4167(defun svn-status-rm (force)
4168 "Run `svn rm' on all selected files.
4169See `svn-status-marked-files' for what counts as selected.
4170When called with a prefix argument add the command line switch --force.
4171
4172Forcing the deletion can also be used to delete files not under svn control."
4173 (interactive "P")
4174 (let* ((marked-files (svn-status-marked-files))
4175 (num-of-files (length marked-files)))
4176 (when (yes-or-no-p
4177 (if (= 1 num-of-files)
4178 (format "%sRemove %s? " (if force "Force " "") (svn-status-line-info->filename (car marked-files)))
4179 (format "%sRemove %d files? " (if force "Force " "") num-of-files)))
4180 (message "removing: %S" (svn-status-marked-file-names))
4181 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
4182 (if force
4183 (save-excursion
4184 (svn-run t t 'rm "rm" "--force" "--targets" svn-status-temp-arg-file)
4185 (dolist (to-delete (svn-status-marked-files))
4186 (when (eq (svn-status-line-info->filemark to-delete) ??)
4187 (svn-status-goto-file-name (svn-status-line-info->filename to-delete))
4188 (let ((buffer-read-only nil))
4189 (delete-region (svn-point-at-bol) (+ 1 (svn-point-at-eol)))
4190 (delete to-delete svn-status-info)))))
4191 (svn-run t t 'rm "rm" "--targets" svn-status-temp-arg-file)))))
4192
4193(defun svn-status-update-cmd (arg)
4194 "Run svn update.
4195When called with a prefix argument, ask the user for the revision to update to.
4196When called with a negative prefix argument, only update the selected files."
4197 (interactive "P")
4198 (let* ((selective-update (or (and (numberp arg) (< arg 0)) (eq arg '-)))
4199 (update-extra-arg)
4200 (rev (when arg (svn-status-read-revision-string
4201 (if selective-update
4202 (format "Selected entries: Run svn update -r ")
4203 (format "Directory: %s: Run svn update -r " default-directory))
4204 (if selective-update "HEAD" nil)))))
4205 (unless svn-client-version
4206 (svn-status-version))
4207 (if (and (<= (car svn-client-version) 1) (< (cadr svn-client-version) 5))
4208 (setq update-extra-arg (list "--non-interactive")) ;; svn version < 1.5
4209 (setq update-extra-arg (list "--accept" "postpone"))) ;; svn version >= 1.5
4210 (if selective-update
4211 (progn
4212 (message "Running svn-update for %s" (svn-status-marked-file-names))
4213 (svn-run t t 'update "update"
4214 (when rev (list "-r" rev))
4215 update-extra-arg
4216 (svn-status-marked-file-names)))
4217 (message "Running svn-update for %s" default-directory)
4218 (svn-run t t 'update "update"
4219 (when rev (list "-r" rev))
4220 update-extra-arg
4221 (svn-local-filename-for-remote-access (expand-file-name default-directory))))))
4222
4223(defun svn-status-commit ()
4224 "Commit selected files.
4225If some files have been marked, commit those non-recursively;
4226this is because marking a directory with \\[svn-status-set-user-mark]
4227normally marks all of its files as well.
4228If no files have been marked, commit recursively the file at point."
4229 (interactive)
4230 (svn-status-save-some-buffers)
4231 (let* ((selected-files (svn-status-marked-files)))
4232 (setq svn-status-files-to-commit selected-files
4233 svn-status-recursive-commit (not (svn-status-only-dirs-or-nothing-marked-p)))
4234 (svn-log-edit-show-files-to-commit)
4235 (svn-status-pop-to-commit-buffer)
4236 (when svn-log-edit-insert-files-to-commit
4237 (svn-log-edit-insert-files-to-commit))
4238 (when svn-log-edit-show-diff-for-commit
4239 (svn-log-edit-svn-diff nil))))
4240
4241(defun svn-status-pop-to-commit-buffer ()
4242 "Pop to the svn commit buffer.
4243If a saved log message exists in `svn-log-edit-file-name' insert it in the buffer."
4244 (interactive)
4245 (setq svn-status-pre-commit-window-configuration (current-window-configuration))
4246 (let* ((use-existing-buffer (get-buffer svn-log-edit-buffer-name))
4247 (commit-buffer (get-buffer-create svn-log-edit-buffer-name))
4248 (dir default-directory)
4249 (log-edit-file-name))
4250 (pop-to-buffer commit-buffer)
4251 (setq default-directory dir)
4252 (setq log-edit-file-name (svn-log-edit-file-name))
4253 (unless use-existing-buffer
4254 (when (and log-edit-file-name (file-readable-p log-edit-file-name))
4255 (insert-file-contents log-edit-file-name)))
4256 (svn-log-edit-mode)))
4257
4258(defun svn-status-switch-to-status-buffer ()
4259 "Switch to the `svn-status-buffer-name' buffer."
4260 (interactive)
4261 (switch-to-buffer svn-status-buffer-name))
4262
4263(defun svn-status-pop-to-status-buffer ()
4264 "Pop to the `svn-status-buffer-name' buffer."
4265 (interactive)
4266 (pop-to-buffer svn-status-buffer-name))
4267
4268(defun svn-status-via-bookmark (bookmark)
4269 "Allows a quick selection of a bookmark in `svn-bookmark-list'.
4270Run `svn-status' on the selected bookmark."
4271 (interactive
4272 (list
4273 (let ((completion-ignore-case t))
4274 (funcall svn-status-completing-read-function "SVN status bookmark: " svn-bookmark-list))))
4275 (unless bookmark
4276 (error "No bookmark specified"))
4277 (let ((directory (cdr (assoc bookmark svn-bookmark-list))))
4278 (if (file-directory-p directory)
4279 (svn-status directory)
4280 (error "%s is not a directory" directory))))
4281
4282(defun svn-status-export ()
4283 "Run `svn export' for the current working copy.
4284Ask the user for the destination path.
4285`svn-status-default-export-directory' is suggested as export directory."
4286 (interactive)
4287 (let* ((src default-directory)
4288 (dir1-name (nth 1 (nreverse (split-string src "/"))))
4289 (dest (read-file-name (format "Export %s to " src) (concat svn-status-default-export-directory dir1-name))))
4290 (svn-run t t 'export "export" (expand-file-name src) (expand-file-name dest))
4291 (message "svn-status-export %s %s" src dest)))
4292
4293(defun svn-status-cleanup (arg)
4294 "Run `svn cleanup' on all selected files.
4295See `svn-status-marked-files' for what counts as selected.
4296When this function is called with a prefix argument, use the actual file instead."
4297 (interactive "P")
4298 (let ((file-names (svn-status-get-file-list-names (not arg))))
4299 (if file-names
4300 (progn
4301 (message "svn-status-cleanup %S" file-names)
4302 (svn-run t t 'cleanup (append (list "cleanup") file-names)))
4303 (message "No valid file selected - No status cleanup possible"))))
4304
4305(defun svn-status-resolved ()
4306 "Run `svn resolved' on all selected files.
4307See `svn-status-marked-files' for what counts as selected."
4308 (interactive)
4309 (let* ((marked-files (svn-status-marked-files))
4310 (num-of-files (length marked-files)))
4311 (when (yes-or-no-p
4312 (if (= 1 num-of-files)
4313 (format "Resolve %s? " (svn-status-line-info->filename (car marked-files)))
4314 (format "Resolve %d files? " num-of-files)))
4315 (message "resolving: %S" (svn-status-marked-file-names))
4316 (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
4317 (svn-run t t 'resolved "resolved" "--targets" svn-status-temp-arg-file))))
4318
4319
4320(defun svn-status-svnversion ()
4321 "Run svnversion on the directory that contains the file at point."
4322 (interactive)
4323 (svn-status-ensure-cursor-on-file)
4324 (let ((simple-path (svn-status-line-info->filename (svn-status-get-line-information)))
4325 (full-path (svn-status-line-info->full-path (svn-status-get-line-information)))
4326 (version))
4327 (unless (file-directory-p simple-path)
4328 (setq simple-path (or (file-name-directory simple-path) "."))
4329 (setq full-path (file-name-directory full-path)))
4330 (setq version (shell-command-to-string (concat "svnversion -n " full-path)))
4331 (message "svnversion for '%s': %s" simple-path version)
4332 version))
4333
4334;; --------------------------------------------------------------------------------
4335;; Update the `svn-status-buffer-name' buffer, when a file is saved
4336;; --------------------------------------------------------------------------------
4337
4338(defvar svn-status-file-modified-after-save-flag ?m
4339 "Flag shown whenever a file is modified and saved in Emacs.
4340The flag is shown in the `svn-status-buffer-name' buffer.
4341Recommended values are ?m or ?M.")
4342(defun svn-status-after-save-hook ()
4343 "Set a modified indication, when a file is saved from a svn working copy."
4344 (let* ((svn-dir (car-safe svn-status-directory-history))
4345 (svn-dir (when svn-dir (expand-file-name svn-dir)))
4346 (file-dir (file-name-directory (buffer-file-name)))
4347 (svn-dir-len (length (or svn-dir "")))
4348 (file-dir-len (length file-dir))
4349 (file-name))
4350 (when (and (get-buffer svn-status-buffer-name)
4351 svn-dir
4352 (>= file-dir-len svn-dir-len)
4353 (string= (substring file-dir 0 svn-dir-len) svn-dir))
4354 (setq file-name (substring (buffer-file-name) svn-dir-len))
4355 ;;(message "In svn-status directory %S" file-name)
4356 (let ((st-info svn-status-info)
4357 (i-fname))
4358 (while st-info
4359 (setq i-fname (svn-status-line-info->filename (car st-info)))
4360 ;;(message "i-fname=%S" i-fname)
4361 (when (and (string= file-name i-fname)
4362 (not (eq (svn-status-line-info->filemark (car st-info)) ??)))
4363 (svn-status-line-info->set-filemark (car st-info)
4364 svn-status-file-modified-after-save-flag)
4365 (save-window-excursion
4366 (set-buffer svn-status-buffer-name)
4367 (save-excursion
4368 (let ((buffer-read-only nil)
4369 (pos (svn-status-get-file-name-buffer-position i-fname)))
4370 (if pos
4371 (progn
4372 (goto-char pos)
4373 (delete-region (svn-point-at-bol) (svn-point-at-eol))
4374 (svn-insert-line-in-status-buffer (car st-info))
4375 (delete-char 1))
4376 (svn-status-message 3 "psvn: file %s not found, updating %s buffer content..."
4377 i-fname svn-status-buffer-name)
4378 (svn-status-update-buffer))))))
4379 (setq st-info (cdr st-info))))))
4380 nil)
4381
4382(add-hook 'after-save-hook 'svn-status-after-save-hook)
4383
4384;; --------------------------------------------------------------------------------
4385;; vc-svn integration
4386;; --------------------------------------------------------------------------------
4387(defvar svn-status-state-mark-modeline t) ; modeline mark display or not
4388(defvar svn-status-state-mark-tooltip nil) ; modeline tooltip display
4389
4390(defun svn-status-state-mark-modeline-dot (color)
4391 (propertize " "
4392 'help-echo 'svn-status-state-mark-tooltip
4393 'display
4394 `(image :type xpm
4395 :data ,(format "/* XPM */
4396static char * data[] = {
4397\"18 13 3 1\",
4398\" c None\",
4399\"+ c #000000\",
4400\". c %s\",
4401\" \",
4402\" +++++ \",
4403\" +.....+ \",
4404\" +.......+ \",
4405\" +.........+ \",
4406\" +.........+ \",
4407\" +.........+ \",
4408\" +.........+ \",
4409\" +.........+ \",
4410\" +.......+ \",
4411\" +.....+ \",
4412\" +++++ \",
4413\" \"};"
4414 color)
4415 :ascent center)))
4416
4417(defun svn-status-install-state-mark-modeline (color)
4418 (push `(svn-status-state-mark-modeline
4419 ,(svn-status-state-mark-modeline-dot color))
4420 mode-line-format)
4421 (force-mode-line-update t))
4422
4423(defun svn-status-uninstall-state-mark-modeline ()
4424 (setq mode-line-format
4425 (remove-if #'(lambda (mode) (eq (car-safe mode)
4426 'svn-status-state-mark-modeline))
4427 mode-line-format))
4428 (force-mode-line-update t))
4429
4430(defun svn-status-update-state-mark-tooltip (tooltip)
4431 (setq svn-status-state-mark-tooltip tooltip))
4432
4433(defun svn-status-update-state-mark (color)
4434 (svn-status-uninstall-state-mark-modeline)
4435 (svn-status-install-state-mark-modeline color))
4436
4437(defsubst svn-status-in-vc-mode? ()
4438 "Is vc-svn active?"
4439 (cond
4440 ((fboundp 'vc-backend)
4441 (eq 'SVN (vc-backend buffer-file-name)))
4442 ((and (boundp 'vc-mode) vc-mode)
4443 (string-match "^ SVN" (svn-substring-no-properties vc-mode)))))
4444
4445(when svn-status-fancy-file-state-in-modeline
4446 (defadvice vc-find-file-hook (after svn-status-vc-svn-find-file-hook activate)
4447 "vc-find-file-hook advice for synchronizing psvn with vc-svn interface"
4448 (when (svn-status-in-vc-mode?) (svn-status-update-modeline)))
4449
4450 (defadvice vc-after-save (after svn-status-vc-svn-after-save activate)
4451 "vc-after-save advice for synchronizing psvn when saving buffer"
4452 (when (svn-status-in-vc-mode?) (svn-status-update-modeline)))
4453
4454 (defadvice ediff-refresh-mode-lines
4455 (around svn-modeline-ediff-fixup activate compile)
4456 "Fixup svn file status in the modeline when using ediff"
4457 (ediff-with-current-buffer ediff-buffer-A
4458 (svn-status-uninstall-state-mark-modeline))
4459 (ediff-with-current-buffer ediff-buffer-B
4460 (svn-status-uninstall-state-mark-modeline))
4461 ad-do-it
4462 (ediff-with-current-buffer ediff-buffer-A
4463 (svn-status-update-modeline))
4464 (ediff-with-current-buffer ediff-buffer-B
4465 (svn-status-update-modeline))))
4466
4467(defun svn-status-update-modeline ()
4468 "Update modeline state dot mark properly"
4469 (when (and buffer-file-name (svn-status-in-vc-mode?))
4470 (svn-status-update-state-mark
4471 (svn-status-interprete-state-mode-color
4472 (vc-svn-state buffer-file-name)))))
4473
4474(defsubst svn-status-interprete-state-mode-color (stat)
4475 "Interpret vc-svn-state symbol to mode line color"
4476 (case stat
4477 ('edited "tomato" )
4478 ('up-to-date "GreenYellow" )
4479 ;; what is missing here??
4480 ;; ('unknown "gray" )
4481 ;; ('added "blue" )
4482 ;; ('deleted "red" )
4483 ;; ('unmerged "purple" )
4484 (t "red")))
4485
4486;; --------------------------------------------------------------------------------
4487;; Getting older revisions
4488;; --------------------------------------------------------------------------------
4489
4490(defun svn-status-get-specific-revision (arg)
4491 "Retrieve older revisions.
4492The older revisions are stored in backup files named F.~REVISION~.
4493
4494When the function is called without a prefix argument: get all marked files.
4495With a prefix argument: get only the actual file."
4496 (interactive "P")
4497 (svn-status-get-specific-revision-internal
4498 (svn-status-get-file-list (not arg)) :ask t))
4499
4500(defun svn-status-get-specific-revision-internal (line-infos revision handle-relative-svn-status-dir)
4501 "Retrieve older revisions of files.
4502LINE-INFOS is a list of line-info structures (see
4503`svn-status-get-line-information').
4504REVISION is one of:
4505- a string: whatever the -r option allows.
4506- `:ask': asks the user to specify the revision, which then becomes
4507 saved in `minibuffer-history' rather than in `command-history'.
4508- `:auto': Use \"HEAD\" if an update is known to exist, \"BASE\" otherwise.
4509
4510After the call, `svn-status-get-revision-file-info' will be an alist
4511\((WORKING-FILE-NAME . RETRIEVED-REVISION-FILE-NAME) ...). These file
4512names are relative to the directory where `svn-status' was run."
4513 ;; In `svn-status-show-svn-diff-internal', there is a comment
4514 ;; that REVISION `nil' might mean omitting the -r option entirely.
4515 ;; That doesn't seem like a good idea with svn cat.
4516
4517 ;; (message "svn-status-get-specific-revision-internal: %S %S" line-infos revision)
4518
4519 (when (eq revision :ask)
4520 (setq revision (svn-status-read-revision-string
4521 "Get files for version: " "PREV")))
4522
4523 (let ((count (length line-infos)))
4524 (if (= count 1)
4525 (let ((line-info (car line-infos)))
4526 (message "Getting revision %s of %s"
4527 (if (eq revision :auto)
4528 (if (svn-status-line-info->update-available line-info)
4529 "HEAD" "BASE")
4530 revision)
4531 (svn-status-line-info->filename line-info)))
4532 ;; We could compute "Getting HEAD of 8 files and BASE of 11 files"
4533 ;; but that'd be more bloat than it's worth.
4534 (message "Getting revision %s of %d files"
4535 (if (eq revision :auto) "HEAD or BASE" revision)
4536 count)))
4537
4538 (let ((svn-status-get-specific-revision-file-info '()))
4539 (dolist (line-info line-infos)
4540 (let* ((revision (if (eq revision :auto)
4541 (if (svn-status-line-info->update-available line-info)
4542 "HEAD" "BASE")
4543 revision)) ;must be a string by this point
4544 (file-name (svn-status-line-info->filename line-info))
4545 ;; If REVISION is e.g. "HEAD", should we find out the actual
4546 ;; revision number and save "foo.~123~" rather than "foo.~HEAD~"?
4547 ;; OTOH, `auto-mode-alist' already ignores ".~HEAD~" suffixes,
4548 ;; and if users often want to know the revision numbers of such
4549 ;; files, they can use svn:keywords.
4550 (file-name-with-revision (concat (file-name-nondirectory file-name) ".~" revision "~"))
4551 (default-directory (concat (svn-status-base-dir)
4552 (if handle-relative-svn-status-dir
4553 (file-relative-name default-directory (svn-status-base-dir))
4554 "")
4555 (file-name-directory file-name))))
4556 ;; `add-to-list' would unnecessarily check for duplicates.
4557 (push (cons file-name (concat (file-name-directory file-name) file-name-with-revision))
4558 svn-status-get-specific-revision-file-info)
4559 (svn-status-message 3 "svn-status-get-specific-revision-internal: file: %s, default-directory: %s"
4560 file-name default-directory)
4561 (svn-status-message 3 "svn-status-get-specific-revision-internal: file-name-with-revision: %s %S"
4562 file-name-with-revision (file-exists-p file-name-with-revision))
4563 (save-excursion
4564 (if (or (not (file-exists-p file-name-with-revision)) ;; file does not exist
4565 (not (string= (number-to-string (string-to-number revision)) revision))) ;; revision is not a number
4566 (progn
4567 (message "Getting revision %s of %s, target: %s" revision file-name
4568 (expand-file-name(concat default-directory file-name-with-revision)))
4569 (let ((content
4570 (with-temp-buffer
4571 (if (string= revision "BASE")
4572 (insert-file-contents (concat (svn-wc-adm-dir-name)
4573 "/text-base/"
4574 (file-name-nondirectory file-name)
4575 ".svn-base"))
4576 (progn
4577 (svn-run nil t 'cat "cat" "-r" revision
4578 (concat default-directory (file-name-nondirectory file-name)))
4579 ;;todo: error processing
4580 ;;svn: Filesystem has no item
4581 ;;svn: file not found: revision `15', path `/trunk/file.txt'
4582 (insert-buffer-substring svn-process-buffer-name)))
4583 (buffer-string))))
4584 (find-file file-name-with-revision)
4585 (setq buffer-read-only nil)
4586 (erase-buffer) ;Widen, because we'll save the whole buffer.
4587 (insert content)
4588 (goto-char (point-min))
4589 (let ((write-file-functions nil)
4590 (require-final-newline nil))
4591 (save-buffer))))
4592 (find-file file-name-with-revision)))))
4593 ;;(message "default-directory: %s revision-file-info: %S" default-directory svn-status-get-specific-revision-file-info)
4594 (nreverse svn-status-get-specific-revision-file-info)))
4595
4596(defun svn-status-ediff-with-revision (arg)
4597 "Run ediff on the current file with a different revision.
4598If there is a newer revision in the repository, the diff is done against HEAD,
4599otherwise compare the working copy with BASE.
4600If ARG then prompt for revision to diff against."
4601 (interactive "P")
4602 (let* ((svn-status-get-specific-revision-file-info
4603 (svn-status-get-specific-revision-internal
4604 (list (svn-status-make-line-info
4605 (file-relative-name
4606 (svn-status-line-info->full-path (svn-status-get-line-information))
4607 (svn-status-base-dir))
4608 nil nil nil nil nil nil
4609 (svn-status-line-info->update-available (svn-status-get-line-information))))
4610 (if arg :ask :auto)
4611 nil))
4612 (ediff-after-quit-destination-buffer (current-buffer))
4613 (default-directory (svn-status-base-dir))
4614 (my-buffer (find-file-noselect (caar svn-status-get-specific-revision-file-info)))
4615 (base-buff (find-file-noselect (cdar svn-status-get-specific-revision-file-info)))
4616 (svn-transient-buffers (list my-buffer base-buff))
4617 (startup-hook '(svn-ediff-startup-hook)))
4618 (ediff-buffers base-buff my-buffer startup-hook)))
4619
4620(defun svn-ediff-startup-hook ()
4621 ;; (message "svn-ediff-startup-hook: ediff-after-quit-hook-internal: %S" ediff-after-quit-hook-internal)
4622 (add-hook 'ediff-after-quit-hook-internal
4623 `(lambda ()
4624 (svn-ediff-exit-hook
4625 ',ediff-after-quit-destination-buffer ',svn-transient-buffers))
4626 nil 'local))
4627
4628(defun svn-ediff-exit-hook (svn-buf tmp-bufs)
4629 ;; (message "svn-ediff-exit-hook: svn-buf: %s, tmp-bufs: %s" svn-buf tmp-bufs)
4630 ;; kill the temp buffers (and their associated windows)
4631 (dolist (tb tmp-bufs)
4632 (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
4633 (let* ((win (get-buffer-window tb t))
4634 (file-name (buffer-file-name tb))
4635 (is-temp-file (numberp (string-match "~\\([0-9]+\\|BASE\\)~" file-name))))
4636 ;; (message "svn-ediff-exit-hook - is-temp-file: %s, temp-buf:: %s - %s " is-temp-file (current-buffer) file-name)
4637 (when (and win (> (count-windows) 1)
4638 (delete-window win)))
4639 (kill-buffer tb)
4640 (when (and is-temp-file svn-status-ediff-delete-temporary-files)
4641 (when (or (eq svn-status-ediff-delete-temporary-files t)
4642 (y-or-n-p (format "Delete File '%s' ? " file-name)))
4643 (delete-file file-name))))))
4644 ;; switch back to the *svn* buffer
4645 (when (and svn-buf (buffer-live-p svn-buf)
4646 (not (get-buffer-window svn-buf t)))
4647 (ignore-errors (switch-to-buffer svn-buf))))
4648
4649
4650(defun svn-status-read-revision-string (prompt &optional default-value)
4651 "Prompt the user for a svn revision number."
4652 (interactive)
4653 (read-string prompt default-value))
4654
4655(defun svn-file-show-svn-ediff (arg)
4656 "Run ediff on the current file with a previous revision.
4657If ARG then prompt for revision to diff against."
4658 (interactive "P")
4659 (let ((svn-status-get-line-information-for-file 'relative)
4660 (default-directory (svn-status-base-dir)))
4661 (svn-status-ediff-with-revision arg)))
4662
4663;; --------------------------------------------------------------------------------
4664;; SVN process handling
4665;; --------------------------------------------------------------------------------
4666
4667(defun svn-process-kill ()
4668 "Kill the current running svn process."
4669 (interactive)
4670 (let ((process (get-process "svn")))
4671 (if process
4672 (delete-process process)
4673 (message "No running svn process"))))
4674
4675(defun svn-process-send-string (string &optional send-passwd)
4676 "Send a string to the running svn process.
4677This is useful, if the running svn process asks the user a question.
4678Note: use C-q C-j to send a line termination character."
4679 (interactive "sSend string to svn process: ")
4680 (save-excursion
4681 (set-buffer svn-process-buffer-name)
4682 (goto-char (point-max))
4683 (let ((buffer-read-only nil))
4684 (insert (if send-passwd (make-string (length string) ?.) string)))
4685 (set-marker (process-mark (get-process "svn")) (point)))
4686 (process-send-string "svn" string))
4687
4688(defun svn-process-send-string-and-newline (string &optional send-passwd)
4689 "Send a string to the running svn process.
4690Just call `svn-process-send-string' with STRING and an end of line termination.
4691When called with a prefix argument, read the data from user as password."
4692 (interactive (let* ((use-passwd current-prefix-arg)
4693 (s (if use-passwd
4694 (read-passwd "Send secret line to svn process: ")
4695 (read-string "Send line to svn process: "))))
4696 (list s use-passwd)))
4697 (svn-process-send-string (concat string "\n") send-passwd))
4698
4699;; --------------------------------------------------------------------------------
4700;; Search interface
4701;; --------------------------------------------------------------------------------
4702
4703(defun svn-status-grep-files (regexp)
4704 "Run grep on selected file(s).
4705See `svn-status-marked-files' for what counts as selected."
4706 (interactive "sGrep files for: ")
4707 (unless grep-command
4708 (grep-compute-defaults))
4709 (grep (format "%s %s %s" grep-command (shell-quote-argument regexp)
4710 (mapconcat 'identity (svn-status-marked-file-names) " "))))
4711
4712(defun svn-status-search-files (search-string)
4713 "Search selected file(s) for a fixed SEARCH-STRING.
4714See `svn-status-marked-files' for what counts as selected."
4715 (interactive "sSearch files for: ")
4716 (svn-status-grep-files (regexp-quote search-string)))
4717
4718;; --------------------------------------------------------------------------------
4719;; Property List stuff
4720;; --------------------------------------------------------------------------------
4721
4722(defun svn-status-property-list ()
4723 (interactive)
4724 (let ((file-names (svn-status-marked-file-names)))
4725 (if file-names
4726 (progn
4727 (svn-run t t 'proplist (append (list "proplist" "-v") file-names)))
4728 (message "No valid file selected - No property listing possible"))))
4729
4730(defun svn-status-proplist-start ()
4731 (svn-status-ensure-cursor-on-file)
4732 (svn-run t t 'proplist-parse "proplist" (svn-status-line-info->filename
4733 (svn-status-get-line-information))))
4734(defun svn-status-property-edit-one-entry (arg)
4735 "Edit a property.
4736When called with a prefix argument, it is possible to enter a new property."
4737 (interactive "P")
4738 (setq svn-status-property-edit-must-match-flag (not arg))
4739 (svn-status-proplist-start))
4740
4741(defun svn-status-property-set ()
4742 (interactive)
4743 (setq svn-status-property-edit-must-match-flag nil)
4744 (svn-status-proplist-start))
4745
4746(defun svn-status-property-delete ()
4747 (interactive)
4748 (setq svn-status-property-edit-must-match-flag t)
4749 (svn-status-proplist-start))
4750
4751(defun svn-status-property-parse-property-names ()
4752 ;(svn-status-show-process-buffer-internal t)
4753 (message "svn-status-property-parse-property-names")
4754 (let ((pl)
4755 (prop-name)
4756 (prop-value))
4757 (save-excursion
4758 (set-buffer svn-process-buffer-name)
4759 (goto-char (point-min))
4760 (forward-line 1)
4761 (while (looking-at " \\(.+\\)")
4762 (setq pl (append pl (list (match-string 1))))
4763 (forward-line 1)))
4764 ;(cond last-command: svn-status-property-set, svn-status-property-edit-one-entry
4765 (cond ((eq last-command 'svn-status-property-edit-one-entry)
4766 ;;(message "svn-status-property-edit-one-entry")
4767 (setq prop-name
4768 (completing-read "Set Property - Name: " (mapcar 'list pl)
4769 nil svn-status-property-edit-must-match-flag))
4770 (unless (string= prop-name "")
4771 (save-excursion
4772 (set-buffer svn-status-buffer-name)
4773 (svn-status-property-edit (list (svn-status-get-line-information))
4774 prop-name))))
4775 ((eq last-command 'svn-status-property-set)
4776 (message "svn-status-property-set")
4777 (setq prop-name
4778 (completing-read "Set Property - Name: " (mapcar 'list pl) nil nil))
4779 (setq prop-value (read-from-minibuffer "Property value: "))
4780 (unless (string= prop-name "")
4781 (save-excursion
4782 (set-buffer svn-status-buffer-name)
4783 (message "Setting property %s := %s for %S" prop-name prop-value
4784 (svn-status-marked-file-names))
4785 (let ((file-names (svn-status-marked-file-names)))
4786 (when file-names
4787 (svn-run nil t 'propset
4788 (append (list "propset" prop-name prop-value) file-names))
4789 )
4790 )
4791 (message "propset finished.")
4792 )))
4793 ((eq last-command 'svn-status-property-delete)
4794 (setq prop-name
4795 (completing-read "Delete Property - Name: " (mapcar 'list pl) nil t))
4796 (unless (string= prop-name "")
4797 (save-excursion
4798 (set-buffer svn-status-buffer-name)
4799 (let ((file-names (svn-status-marked-file-names)))
4800 (when file-names
4801 (message "Going to delete prop %s for %s" prop-name file-names)
4802 (svn-run t t 'propdel
4803 (append (list "propdel" prop-name) file-names))))))))))
4804
4805(defun svn-status-property-edit (file-info-list prop-name &optional new-prop-value remove-values)
4806 (let* ((commit-buffer (get-buffer-create "*svn-property-edit*"))
4807 (dir default-directory)
4808 ;; now only one file is implemented ...
4809 (file-name (svn-status-line-info->filename (car file-info-list)))
4810 (prop-value))
4811 (message "Edit property %s for file %s" prop-name file-name)
4812 (svn-run nil t 'propget-parse "propget" prop-name file-name)
4813 (save-excursion
4814 (set-buffer svn-process-buffer-name)
4815 (setq prop-value (if (> (point-max) 1)
4816 (buffer-substring (point-min) (- (point-max) 1))
4817 "")))
4818 (setq svn-status-propedit-property-name prop-name)
4819 (setq svn-status-propedit-file-list file-info-list)
4820 (setq svn-status-pre-propedit-window-configuration (current-window-configuration))
4821 (pop-to-buffer commit-buffer)
4822 ;; If the buffer has been narrowed, `svn-prop-edit-done' will use
4823 ;; only the accessible part. So we need not erase the rest here.
4824 (delete-region (point-min) (point-max))
4825 (setq default-directory dir)
4826 (insert prop-value)
4827 (svn-status-remove-control-M)
4828 (when new-prop-value
4829 (when (listp new-prop-value)
4830 (if remove-values
4831 (message "Remove prop values %S " new-prop-value)
4832 (message "Adding new prop values %S " new-prop-value))
4833 (while new-prop-value
4834 (goto-char (point-min))
4835 (if (re-search-forward (concat "^" (regexp-quote (car new-prop-value)) "$") nil t)
4836 (when remove-values
4837 (kill-whole-line 1))
4838 (unless remove-values
4839 (goto-char (point-max))
4840 (when (> (current-column) 0) (insert "\n"))
4841 (insert (car new-prop-value))))
4842 (setq new-prop-value (cdr new-prop-value)))))
4843 (svn-prop-edit-mode)))
4844
4845(defun svn-status-property-set-property (file-info-list prop-name prop-value)
4846 "Set a property on a given file list."
4847 (save-excursion
4848 (set-buffer (get-buffer-create "*svn-property-edit*"))
4849 ;; If the buffer has been narrowed, `svn-prop-edit-do-it' will use
4850 ;; only the accessible part. So we need not erase the rest here.
4851 (delete-region (point-min) (point-max))
4852 (insert prop-value))
4853 (setq svn-status-propedit-file-list (svn-status-marked-files))
4854 (setq svn-status-propedit-property-name prop-name)
4855 (svn-prop-edit-do-it nil)
4856 (svn-status-update))
4857
4858
4859(defun svn-status-get-directory (line-info)
4860 (let* ((file-name (svn-status-line-info->filename line-info))
4861 (file-dir (file-name-directory file-name)))
4862 ;;(message "file-dir: %S" file-dir)
4863 (if file-dir
4864 (substring file-dir 0 (- (length file-dir) 1))
4865 ".")))
4866
4867(defun svn-status-get-file-list-per-directory (files)
4868 ;;(message "%S" files)
4869 (let ((dir-list nil)
4870 (i files)
4871 (j)
4872 (dir))
4873 (while i
4874 (setq dir (svn-status-get-directory (car i)))
4875 (setq j (assoc dir dir-list))
4876 (if j
4877 (progn
4878 ;;(message "dir already present %S %s" j dir)
4879 (setcdr j (append (cdr j) (list (car i)))))
4880 (setq dir-list (append dir-list (list (list dir (car i))))))
4881 (setq i (cdr i)))
4882 ;;(message "svn-status-get-file-list-per-directory: %S" dir-list)
4883 dir-list))
4884
4885(defun svn-status-property-ignore-file ()
4886 (interactive)
4887 (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
4888 (dir)
4889 (f-info)
4890 (ext-list))
4891 (while d-list
4892 (setq dir (caar d-list))
4893 (setq f-info (cdar d-list))
4894 (setq ext-list (mapcar '(lambda (i)
4895 (svn-status-line-info->filename-nondirectory i)) f-info))
4896 ;;(message "ignore in dir %s: %S" dir f-info)
4897 (save-window-excursion
4898 (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
4899 (svn-status-property-edit
4900 (list (svn-status-find-info-for-file-name dir)) "svn:ignore" ext-list)
4901 (svn-prop-edit-do-it nil))) ; synchronous
4902 (setq d-list (cdr d-list)))
4903 (svn-status-update)))
4904
4905(defun svn-status-property-ignore-file-extension ()
4906 (interactive)
4907 (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
4908 (dir)
4909 (f-info)
4910 (ext-list))
4911 (while d-list
4912 (setq dir (caar d-list))
4913 (setq f-info (cdar d-list))
4914 ;;(message "ignore in dir %s: %S" dir f-info)
4915 (setq ext-list nil)
4916 (while f-info
4917 (add-to-list 'ext-list (concat "*."
4918 (file-name-extension
4919 (svn-status-line-info->filename (car f-info)))))
4920 (setq f-info (cdr f-info)))
4921 ;;(message "%S" ext-list)
4922 (save-window-excursion
4923 (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
4924 (svn-status-property-edit
4925 (list (svn-status-find-info-for-file-name dir)) "svn:ignore"
4926 ext-list)
4927 (svn-prop-edit-do-it nil)))
4928 (setq d-list (cdr d-list)))
4929 (svn-status-update)))
4930
4931(defun svn-status-property-edit-svn-ignore ()
4932 (interactive)
4933 (let* ((line-info (svn-status-get-line-information))
4934 (dir (if (svn-status-line-info->directory-p line-info)
4935 (svn-status-line-info->filename line-info)
4936 (svn-status-get-directory line-info))))
4937 (svn-status-property-edit
4938 (list (svn-status-find-info-for-file-name dir)) "svn:ignore")
4939 (message "Edit svn:ignore on %s" dir)))
4940
4941
4942(defun svn-status-property-edit-svn-externals ()
4943 (interactive)
4944 (let* ((line-info (svn-status-get-line-information))
4945 (dir (if (svn-status-line-info->directory-p line-info)
4946 (svn-status-line-info->filename line-info)
4947 (svn-status-get-directory line-info))))
4948 (svn-status-property-edit
4949 (list (svn-status-find-info-for-file-name dir)) "svn:externals")
4950 (message "Edit svn:externals on %s" dir)))
4951
4952
4953(defun svn-status-property-set-keyword-list ()
4954 "Edit the svn:keywords property on the marked files."
4955 (interactive)
4956 ;;(message "Set svn:keywords for %S" (svn-status-marked-file-names))
4957 (svn-status-property-edit (svn-status-marked-files) "svn:keywords"))
4958
4959(defun svn-status-property-set-keyword-id (arg)
4960 "Set/Remove Id from the svn:keywords property.
4961Normally Id is added to the svn:keywords property.
4962
4963When called with the prefix arg -, remove Id from the svn:keywords property."
4964 (interactive "P")
4965 (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Id") (eq arg '-))
4966 (svn-prop-edit-do-it nil))
4967
4968(defun svn-status-property-set-keyword-date (arg)
4969 "Set/Remove Date from the svn:keywords property.
4970Normally Date is added to the svn:keywords property.
4971
4972When called with the prefix arg -, remove Date from the svn:keywords property."
4973 (interactive "P")
4974 (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Date") (eq arg '-))
4975 (svn-prop-edit-do-it nil))
4976
4977
4978(defun svn-status-property-set-eol-style ()
4979 "Edit the svn:eol-style property on the marked files."
4980 (interactive)
4981 (svn-status-property-set-property
4982 (svn-status-marked-files) "svn:eol-style"
4983 (completing-read "Set svn:eol-style for the marked files: "
4984 (mapcar 'list '("native" "CRLF" "LF" "CR"))
4985 nil t)))
4986
4987(defun svn-status-property-set-executable (&optional unset)
4988 "Set the svn:executable property on the marked files.
4989When called with a prefix argument: unset the svn:executable property."
4990 (interactive "P")
4991 (if unset
4992 (progn
4993 (svn-run nil t 'propdel (append (list "propdel" "svn:executable") (svn-status-marked-file-names)))
4994 (message "Unset the svn:executable property for %s" (svn-status-marked-file-names))
4995 (svn-status-update))
4996 (svn-status-property-set-property (svn-status-marked-files) "svn:executable" "*")))
4997
4998(defun svn-status-property-set-mime-type ()
4999 "Set the svn:mime-type property on the marked files."
5000 (interactive)
5001 (require 'mailcap nil t)
5002 (let ((completion-ignore-case t)
5003 (mime-types (when (fboundp 'mailcap-mime-types)
5004 (mailcap-mime-types))))
5005 (svn-status-property-set-property
5006 (svn-status-marked-files) "svn:mime-type"
5007 (funcall svn-status-completing-read-function "Set svn:mime-type for the marked files: "
5008 (mapcar (lambda (x) (cons x x)) ; for Emacs 21
5009 (sort mime-types 'string<))))))
5010
5011;; --------------------------------------------------------------------------------
5012;; svn-prop-edit-mode:
5013;; --------------------------------------------------------------------------------
5014
5015(defvar svn-prop-edit-mode-map () "Keymap used in `svn-prop-edit-mode' buffers.")
5016(put 'svn-prop-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
5017
5018(when (not svn-prop-edit-mode-map)
5019 (setq svn-prop-edit-mode-map (make-sparse-keymap))
5020 (define-key svn-prop-edit-mode-map [(control ?c) (control ?c)] 'svn-prop-edit-done)
5021 (define-key svn-prop-edit-mode-map [(control ?c) (control ?d)] 'svn-prop-edit-svn-diff)
5022 (define-key svn-prop-edit-mode-map [(control ?c) (control ?s)] 'svn-prop-edit-svn-status)
5023 (define-key svn-prop-edit-mode-map [(control ?c) (control ?l)] 'svn-prop-edit-svn-log)
5024 (define-key svn-prop-edit-mode-map [(control ?c) (control ?q)] 'svn-prop-edit-abort))
5025
5026(easy-menu-define svn-prop-edit-mode-menu svn-prop-edit-mode-map
5027"'svn-prop-edit-mode' menu"
5028 '("SVN-PropEdit"
5029 ["Commit" svn-prop-edit-done t]
5030 ["Show Diff" svn-prop-edit-svn-diff t]
5031 ["Show Status" svn-prop-edit-svn-status t]
5032 ["Show Log" svn-prop-edit-svn-log t]
5033 ["Abort" svn-prop-edit-abort t]))
5034
5035(defun svn-prop-edit-mode ()
5036 "Major Mode to edit file properties of files under svn control.
5037Commands:
5038\\{svn-prop-edit-mode-map}"
5039 (interactive)
5040 (kill-all-local-variables)
5041 (use-local-map svn-prop-edit-mode-map)
5042 (easy-menu-add svn-prop-edit-mode-menu)
5043 (setq major-mode 'svn-prop-edit-mode)
5044 (setq mode-name "svn-prop-edit"))
5045
5046(defun svn-prop-edit-abort ()
5047 (interactive)
5048 (bury-buffer)
5049 (set-window-configuration svn-status-pre-propedit-window-configuration))
5050
5051(defun svn-prop-edit-done ()
5052 (interactive)
5053 (svn-prop-edit-do-it t))
5054
5055(defun svn-prop-edit-do-it (async)
5056 "Run svn propset `svn-status-propedit-property-name' with the content of the
5057*svn-property-edit* buffer."
5058 (message "svn propset %s on %s"
5059 svn-status-propedit-property-name
5060 (mapcar 'svn-status-line-info->filename svn-status-propedit-file-list))
5061 (save-excursion
5062 (set-buffer (get-buffer "*svn-property-edit*"))
5063 (when (fboundp 'set-buffer-file-coding-system)
5064 (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
5065 (let ((svn-propedit-file-name (concat svn-status-temp-dir "svn-prop-edit.txt" svn-temp-suffix)))
5066 (setq svn-status-temp-file-to-remove (svn-expand-filename-for-remote-access svn-propedit-file-name))
5067 (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1)
5068 (when svn-status-propedit-file-list ; there are files to change properties
5069 (svn-status-create-arg-file svn-status-temp-arg-file ""
5070 svn-status-propedit-file-list "")
5071 (setq svn-status-propedit-file-list nil)
5072 (svn-run async t 'propset "propset"
5073 svn-status-propedit-property-name
5074 "--targets" svn-status-temp-arg-file
5075 (when (eq svn-status-svn-file-coding-system 'utf-8)
5076 '("--encoding" "UTF-8"))
5077 "-F" svn-propedit-file-name)
5078 (unless async (svn-status-remove-temp-file-maybe)))
5079 (when svn-status-pre-propedit-window-configuration
5080 (set-window-configuration svn-status-pre-propedit-window-configuration)))))
5081
5082(defun svn-prop-edit-svn-diff (arg)
5083 (interactive "P")
5084 (set-buffer svn-status-buffer-name)
5085 ;; Because propedit is not recursive in our use, neither is this diff.
5086 (svn-status-show-svn-diff-internal svn-status-propedit-file-list nil
5087 (if arg :ask "BASE")))
5088
5089(defun svn-prop-edit-svn-log (arg)
5090 (interactive "P")
5091 (set-buffer svn-status-buffer-name)
5092 (svn-status-show-svn-log arg))
5093
5094(defun svn-prop-edit-svn-status ()
5095 (interactive)
5096 (pop-to-buffer svn-status-buffer-name)
5097 (other-window 1))
5098
5099;; --------------------------------------------------------------------------------
5100;; svn-log-edit-mode:
5101;; --------------------------------------------------------------------------------
5102
5103(defvar svn-log-edit-mode-map () "Keymap used in `svn-log-edit-mode' buffers.")
5104(put 'svn-log-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
5105
5106(defvar svn-log-edit-mode-menu) ;really defined with `easy-menu-define' below.
5107
5108(defun svn-log-edit-common-setup ()
5109 (set (make-local-variable 'paragraph-start) svn-log-edit-paragraph-start)
5110 (set (make-local-variable 'paragraph-separate) svn-log-edit-paragraph-separate))
5111
5112(if svn-log-edit-use-log-edit-mode
5113 (define-derived-mode svn-log-edit-mode log-edit-mode "svn-log-edit"
5114 "Wrapper around `log-edit-mode' for psvn.el"
5115 (easy-menu-add svn-log-edit-mode-menu)
5116 (setq svn-log-edit-update-log-entry nil)
5117 (set (make-local-variable 'log-edit-callback) 'svn-log-edit-done)
5118 (set (make-local-variable 'log-edit-listfun) 'svn-log-edit-files-to-commit)
5119 (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
5120 (svn-log-edit-common-setup)
5121 (message "Press %s when you are done editing."
5122 (substitute-command-keys "\\[log-edit-done]"))
5123 )
5124 (defun svn-log-edit-mode ()
5125 "Major Mode to edit svn log messages.
5126Commands:
5127\\{svn-log-edit-mode-map}"
5128 (interactive)
5129 (kill-all-local-variables)
5130 (use-local-map svn-log-edit-mode-map)
5131 (easy-menu-add svn-log-edit-mode-menu)
5132 (setq major-mode 'svn-log-edit-mode)
5133 (setq mode-name "svn-log-edit")
5134 (setq svn-log-edit-update-log-entry nil)
5135 (svn-log-edit-common-setup)
5136 (run-hooks 'svn-log-edit-mode-hook)))
5137
5138(when (not svn-log-edit-mode-map)
5139 (setq svn-log-edit-mode-map (make-sparse-keymap))
5140 (unless svn-log-edit-use-log-edit-mode
5141 (define-key svn-log-edit-mode-map (kbd "C-c C-c") 'svn-log-edit-done))
5142 (define-key svn-log-edit-mode-map (kbd "C-c C-d") 'svn-log-edit-svn-diff)
5143 (define-key svn-log-edit-mode-map (kbd "C-c C-s") 'svn-log-edit-save-message)
5144 (define-key svn-log-edit-mode-map (kbd "C-c C-i") 'svn-log-edit-svn-status)
5145 (define-key svn-log-edit-mode-map (kbd "C-c C-l") 'svn-log-edit-svn-log)
5146 (define-key svn-log-edit-mode-map (kbd "C-c C-?") 'svn-log-edit-show-files-to-commit)
5147 (define-key svn-log-edit-mode-map (kbd "C-c C-z") 'svn-log-edit-erase-edit-buffer)
5148 (define-key svn-log-edit-mode-map (kbd "C-c C-q") 'svn-log-edit-abort))
5149
5150(easy-menu-define svn-log-edit-mode-menu svn-log-edit-mode-map
5151"'svn-log-edit-mode' menu"
5152 '("SVN-Log"
5153 ["Save to disk" svn-log-edit-save-message t]
5154 ["Commit" svn-log-edit-done t]
5155 ["Show Diff" svn-log-edit-svn-diff t]
5156 ["Show Status" svn-log-edit-svn-status t]
5157 ["Show Log" svn-log-edit-svn-log t]
5158 ["Show files to commit" svn-log-edit-show-files-to-commit t]
5159 ["Erase buffer" svn-log-edit-erase-edit-buffer]
5160 ["Abort" svn-log-edit-abort t]))
5161(put 'svn-log-edit-mode-menu 'risky-local-variable t)
5162
5163(defun svn-log-edit-abort ()
5164 (interactive)
5165 (bury-buffer)
5166 (set-window-configuration svn-status-pre-commit-window-configuration))
5167
5168(defun svn-log-edit-done ()
5169 "Finish editing the log message and run svn commit."
5170 (interactive)
5171 (svn-status-save-some-buffers)
5172 (let ((svn-logedit-file-name))
5173 (save-excursion
5174 (set-buffer (get-buffer svn-log-edit-buffer-name))
5175 (when svn-log-edit-insert-files-to-commit
5176 (svn-log-edit-remove-comment-lines))
5177 (when (fboundp 'set-buffer-file-coding-system)
5178 (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
5179 (when (or svn-log-edit-update-log-entry svn-status-files-to-commit)
5180 (setq svn-log-edit-file-name (concat svn-status-temp-dir "svn-log-edit.txt" svn-temp-suffix))
5181 (setq svn-status-temp-file-to-remove (svn-expand-filename-for-remote-access svn-log-edit-file-name))
5182 (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1))
5183 (bury-buffer))
5184 (if svn-log-edit-update-log-entry
5185 (when (y-or-n-p "Update the log entry? ")
5186 ;; svn propset svn:log --revprop -r11672 -F file
5187 (svn-run nil t 'propset "propset" "svn:log" "--revprop"
5188 (concat "-r" svn-log-edit-update-log-entry)
5189 "-F" svn-log-edit-file-name)
5190 (save-excursion
5191 (set-buffer svn-process-buffer-name)
5192 (message "%s" (buffer-substring (point-min) (- (point-max) 1)))))
5193 (when svn-status-files-to-commit ; there are files to commit
5194 (setq svn-status-operated-on-dot
5195 (and (= 1 (length svn-status-files-to-commit))
5196 (string= "." (svn-status-line-info->filename (car svn-status-files-to-commit)))))
5197 (svn-status-create-arg-file svn-status-temp-arg-file "" svn-status-files-to-commit "")
5198 (svn-run t t 'commit "commit"
5199 (unless svn-status-recursive-commit "--non-recursive")
5200 "--targets" svn-status-temp-arg-file
5201 "-F" svn-log-edit-file-name
5202 (when (eq svn-status-svn-file-coding-system 'utf-8)
5203 '("--encoding" "UTF-8"))
5204 svn-status-default-commit-arguments))
5205 (set-window-configuration svn-status-pre-commit-window-configuration)
5206 (message "svn-log editing done"))))
5207
5208(defun svn-log-edit-svn-diff (arg)
5209 "Show the diff we are about to commit.
5210If ARG then show diff between some other version of the selected files."
5211 (interactive "P")
5212 (set-buffer svn-status-buffer-name) ; TODO: is this necessary?
5213 ;; This call is very much like `svn-status-show-svn-diff-for-marked-files'
5214 ;; but uses commit-specific variables instead of the current marks.
5215 (svn-status-show-svn-diff-internal svn-status-files-to-commit
5216 svn-status-recursive-commit
5217 (if arg :ask "BASE")))
5218
5219(defun svn-log-edit-svn-log (arg)
5220 (interactive "P")
5221 (set-buffer svn-status-buffer-name)
5222 (svn-status-show-svn-log arg))
5223
5224(defun svn-log-edit-svn-status ()
5225 (interactive)
5226 (pop-to-buffer svn-status-buffer-name)
5227 (other-window 1))
5228
5229(defun svn-log-edit-files-to-commit ()
5230 (mapcar 'svn-status-line-info->filename svn-status-files-to-commit))
5231
5232(defun svn-log-edit-show-files-to-commit ()
5233 (interactive)
5234 (message "Files to commit%s: %S"
5235 (if svn-status-recursive-commit " recursively" "")
5236 (svn-log-edit-files-to-commit)))
5237
5238(defun svn-log-edit-save-message ()
5239 "Save the current log message to the file `svn-log-edit-file-name'."
5240 (interactive)
5241 (let ((log-edit-file-name (svn-log-edit-file-name)))
5242 (if (string= buffer-file-name log-edit-file-name)
5243 (save-buffer)
5244 (write-region (point-min) (point-max) log-edit-file-name))))
5245
5246(defun svn-log-edit-erase-edit-buffer ()
5247 "Delete everything in the `svn-log-edit-buffer-name' buffer."
5248 (interactive)
5249 (set-buffer svn-log-edit-buffer-name)
5250 (erase-buffer))
5251
5252(defun svn-log-edit-insert-files-to-commit ()
5253 (interactive)
5254 (svn-log-edit-remove-comment-lines)
5255 (let ((buf-size (- (point-max) (point-min))))
5256 (save-excursion
5257 (goto-char (point-min))
5258 (insert svn-log-edit-header)
5259 (insert "## File(s) to commit"
5260 (if svn-status-recursive-commit " recursively" "") ":\n")
5261 (let ((file-list svn-status-files-to-commit))
5262 (while file-list
5263 (insert (concat "## " (svn-status-line-info->filename (car file-list)) "\n"))
5264 (setq file-list (cdr file-list)))))
5265 (when (= 0 buf-size)
5266 (goto-char (point-max)))))
5267
5268(defun svn-log-edit-remove-comment-lines ()
5269 (interactive)
5270 (save-excursion
5271 (goto-char (point-min))
5272 (flush-lines "^## .*")))
5273
5274(defun svn-file-add-to-changelog (prefix-arg)
5275 "Create a changelog entry for the function at point.
5276The variable `svn-status-changelog-style' allows to select the used changlog style"
5277 (interactive "P")
5278 (cond ((eq svn-status-changelog-style 'changelog)
5279 (svn-file-add-to-log-changelog-style prefix-arg))
5280 ((eq svn-status-changelog-style 'svn-dev)
5281 (svn-file-add-to-log-svn-dev-style prefix-arg))
5282 ((fboundp svn-status-changelog-style)
5283 (funcall svn-status-changelog-style prefix-arg))
5284 (t
5285 (error "Invalid setting for `svn-status-changelog-style'"))))
5286
5287(defun svn-file-add-to-log-changelog-style (curdir)
5288 "Create a changelog entry for the function at point.
5289`add-change-log-entry-other-window' creates the header information.
5290If CURDIR, save the log file in the current directory, otherwise in the base directory of this working copy."
5291 (interactive "P")
5292 (add-change-log-entry-other-window nil (svn-log-edit-file-name curdir))
5293 (svn-log-edit-mode))
5294
5295;; taken from svn-dev.el: svn-log-path-derive
5296(defun svn-dev-log-path-derive (path)
5297 "Derive a relative directory path for absolute PATH, for a log entry."
5298 (save-match-data
5299 (let ((base (file-name-nondirectory path))
5300 (chop-spot (string-match
5301 "\\(code/\\)\\|\\(src/\\)\\|\\(projects/\\)"
5302 path)))
5303 (if chop-spot
5304 (progn
5305 (setq path (substring path (match-end 0)))
5306 ;; Kluge for Subversion developers.
5307 (if (string-match "subversion/" path)
5308 (substring path (+ (match-beginning 0) 11))
5309 path))
5310 (string-match (expand-file-name "~/") path)
5311 (substring path (match-end 0))))))
5312
5313;; taken from svn-dev.el: svn-log-message
5314(defun svn-file-add-to-log-svn-dev-style (prefix-arg)
5315 "Add to an in-progress log message, based on context around point.
5316If PREFIX-ARG is negative, then use basenames only in
5317log messages, otherwise use full paths. The current defun name is
5318always used.
5319
5320If PREFIX-ARG is a list (e.g. by using C-u), save the log file in
5321the current directory, otherwise in the base directory of this
5322working copy.
5323
5324If the log message already contains material about this defun, then put
5325point there, so adding to that material is easy.
5326
5327Else if the log message already contains material about this file, put
5328point there, and push onto the kill ring the defun name with log
5329message dressing around it, plus the raw defun name, so yank and
5330yank-next are both useful.
5331
5332Else if there is no material about this defun nor file anywhere in the
5333log message, then put point at the end of the message and insert a new
5334entry for file with defun.
5335"
5336 (interactive "P")
5337 (let* ((short-file-names (and (numberp prefix-arg) (< prefix-arg 0)))
5338 (curdir (listp prefix-arg))
5339 (this-file (if short-file-names
5340 (file-name-nondirectory buffer-file-name)
5341 (svn-dev-log-path-derive buffer-file-name)))
5342 (this-defun (or (add-log-current-defun)
5343 (save-excursion
5344 (save-match-data
5345 (if (eq major-mode 'c-mode)
5346 (progn
5347 (if (fboundp 'c-beginning-of-statement-1)
5348 (c-beginning-of-statement-1)
5349 (c-beginning-of-statement))
5350 (search-forward "(" nil t)
5351 (forward-char -1)
5352 (forward-sexp -1)
5353 (buffer-substring
5354 (point)
5355 (progn (forward-sexp 1) (point)))))))))
5356 (log-file (svn-log-edit-file-name curdir)))
5357 (find-file log-file)
5358 (goto-char (point-min))
5359 ;; Strip text properties from strings
5360 (set-text-properties 0 (length this-file) nil this-file)
5361 (set-text-properties 0 (length this-defun) nil this-defun)
5362 ;; If log message for defun already in progress, add to it
5363 (if (and
5364 this-defun ;; we have a defun to work with
5365 (search-forward this-defun nil t) ;; it's in the log msg already
5366 (save-excursion ;; and it's about the same file
5367 (save-match-data
5368 (if (re-search-backward ; Ick, I want a real filename regexp!
5369 "^\\*\\s-+\\([a-zA-Z0-9-_.@=+^$/%!?(){}<>]+\\)" nil t)
5370 (string-equal (match-string 1) this-file)
5371 t))))
5372 (if (re-search-forward ":" nil t)
5373 (if (looking-at " ") (forward-char 1)))
5374 ;; Else no log message for this defun in progress...
5375 (goto-char (point-min))
5376 ;; But if log message for file already in progress, add to it.
5377 (if (search-forward this-file nil t)
5378 (progn
5379 (if this-defun (progn
5380 (kill-new (format "(%s): " this-defun))
5381 (kill-new this-defun)))
5382 (search-forward ")" nil t)
5383 (if (looking-at " ") (forward-char 1)))
5384 ;; Found neither defun nor its file, so create new entry.
5385 (goto-char (point-max))
5386 (if (not (bolp)) (insert "\n"))
5387 (insert (format "\n* %s (%s): " this-file (or this-defun "")))
5388 ;; Finally, if no derived defun, put point where the user can
5389 ;; type it themselves.
5390 (if (not this-defun) (forward-char -3))))))
5391
5392;; --------------------------------------------------------------------------------
5393;; svn-log-view-mode:
5394;; --------------------------------------------------------------------------------
5395
5396(defvar svn-log-view-mode-map () "Keymap used in `svn-log-view-mode' buffers.")
5397(put 'svn-log-view-mode-map 'risky-local-variable t) ;for Emacs 20.7
5398
5399(when (not svn-log-view-mode-map)
5400 (setq svn-log-view-mode-map (make-sparse-keymap))
5401 (suppress-keymap svn-log-view-mode-map)
5402 (define-key svn-log-view-mode-map (kbd "p") 'svn-log-view-prev)
5403 (define-key svn-log-view-mode-map (kbd "n") 'svn-log-view-next)
5404 (define-key svn-log-view-mode-map (kbd "~") 'svn-log-get-specific-revision)
5405 (define-key svn-log-view-mode-map (kbd "f") 'svn-log-get-specific-revision)
5406 (define-key svn-log-view-mode-map (kbd "E") 'svn-log-ediff-specific-revision)
5407 (define-key svn-log-view-mode-map (kbd "=") 'svn-log-view-diff)
5408 (define-key svn-log-view-mode-map (kbd "#") 'svn-log-mark-partner-revision)
5409 (define-key svn-log-view-mode-map (kbd "x") 'svn-log-exchange-partner-mark-with-point)
5410 (define-key svn-log-view-mode-map (kbd "TAB") 'svn-log-next-link)
5411 (define-key svn-log-view-mode-map [backtab] 'svn-log-prev-link)
5412 (define-key svn-log-view-mode-map (kbd "RET") 'svn-log-find-file-at-point)
5413 (define-key svn-log-view-mode-map (kbd "e") 'svn-log-edit-log-entry)
5414 (define-key svn-log-view-mode-map (kbd "q") 'bury-buffer))
5415
5416(defvar svn-log-view-popup-menu-map ()
5417 "Keymap used to show popup menu in `svn-log-view-mode' buffers.")
5418(put 'svn-log-view-popup-menu-map 'risky-local-variable t) ;for Emacs 20.7
5419(when (not svn-log-view-popup-menu-map)
5420 (setq svn-log-view-popup-menu-map (make-sparse-keymap))
5421 (suppress-keymap svn-log-view-popup-menu-map)
5422 (define-key svn-log-view-popup-menu-map [down-mouse-3] 'svn-log-view-popup-menu))
5423
5424(easy-menu-define svn-log-view-mode-menu svn-log-view-mode-map
5425"'svn-log-view-mode' menu"
5426 '("SVN-LogView"
5427 ["Show Changeset" svn-log-view-diff t]
5428 ["Ediff file at point" svn-log-ediff-specific-revision t]
5429 ["Find file at point" svn-log-find-file-at-point t]
5430 ["Mark as diff against revision" svn-log-mark-partner-revision t]
5431 ["Get older revision for file at point" svn-log-get-specific-revision t]
5432 ["Edit log message" svn-log-edit-log-entry t]))
5433
5434(defun svn-log-view-popup-menu (event)
5435 (interactive "e")
5436 (mouse-set-point event)
5437 (let* ((rev (svn-log-revision-at-point)))
5438 (when rev
5439 (svn-status-face-set-temporary-during-popup
5440 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
5441 svn-log-view-mode-menu))))
5442
5443(defvar svn-log-view-font-lock-basic-keywords
5444 '(("^r[0-9]+ .+" (0 `(face font-lock-keyword-face
5445 mouse-face highlight
5446 keymap ,svn-log-view-popup-menu-map))))
5447 "Basic keywords in `svn-log-view-mode'.")
5448(put 'svn-log-view-font-basic-lock-keywords 'risky-local-variable t) ;for Emacs 20.7
5449
5450(defvar svn-log-view-font-lock-keywords)
5451(define-derived-mode svn-log-view-mode fundamental-mode "svn-log-view"
5452 "Major Mode to show the output from svn log.
5453Commands:
5454\\{svn-log-view-mode-map}
5455"
5456 (use-local-map svn-log-view-mode-map)
5457 (easy-menu-add svn-log-view-mode-menu)
5458 (set (make-local-variable 'svn-log-view-font-lock-keywords) svn-log-view-font-lock-basic-keywords)
5459 (dolist (lh svn-log-link-handlers)
5460 (add-to-list 'svn-log-view-font-lock-keywords (gethash lh svn-log-registered-link-handlers)))
5461 (set (make-local-variable 'font-lock-defaults) '(svn-log-view-font-lock-keywords t)))
5462
5463(defun svn-log-view-next ()
5464 (interactive)
5465 (when (re-search-forward "^r[0-9]+" nil t)
5466 (beginning-of-line 2)
5467 (unless (looking-at "Changed paths:")
5468 (beginning-of-line 1))))
5469
5470(defun svn-log-view-prev ()
5471 (interactive)
5472 (when (re-search-backward "^r[0-9]+" nil t 2)
5473 (beginning-of-line 2)
5474 (unless (looking-at "Changed paths:")
5475 (beginning-of-line 1))))
5476
5477(defun svn-log-mark-partner-revision ()
5478 "Mark the revision at point to be used as diff against revision."
5479 (interactive)
5480 (let ((start-pos)
5481 (point-at-partner-rev)
5482 (overlay))
5483 (dolist (ov (overlays-in (point-min) (point-max)))
5484 (when (overlay-get ov 'svn-log-partner-revision)
5485 (setq point-at-partner-rev (and (>= (point) (overlay-start ov))
5486 (<= (point) (overlay-end ov))))
5487 (delete-overlay ov)))
5488 (unless point-at-partner-rev
5489 (save-excursion
5490 (when (re-search-backward "^r[0-9]+" nil t 1)
5491 (setq start-pos (point))
5492 (re-search-forward "^---------------")
5493 (setq overlay (make-overlay start-pos (line-beginning-position 0)))
5494 (overlay-put overlay 'face 'svn-log-partner-highlight-face)
5495 (overlay-put overlay 'svn-log-partner-revision t))))))
5496
5497(defun svn-log-exchange-partner-mark-with-point ()
5498 (interactive)
5499 (let ((cur-pos (point))
5500 (dest-pos))
5501 (dolist (ov (overlays-in (point-min) (point-max)))
5502 (when (overlay-get ov 'svn-log-partner-revision)
5503 (setq dest-pos (overlay-start ov))))
5504 (when dest-pos
5505 (svn-log-mark-partner-revision)
5506 (goto-char dest-pos)
5507 (forward-line 3)
5508 (svn-log-view-prev)
5509 (svn-log-view-next))))
5510
5511(defun svn-log-revision-for-diff ()
5512 (let ((rev))
5513 (dolist (ov (overlays-in (point-min) (point-max)))
5514 (when (overlay-get ov 'svn-log-partner-revision)
5515 (save-excursion
5516 (unless (and (>= (point) (overlay-start ov))
5517 (<= (point) (overlay-end ov)))
5518 (goto-char (overlay-start ov))
5519 (setq rev (svn-log-revision-at-point))))))
5520 rev))
5521
5522(defun svn-log-revision-at-point ()
5523 (save-excursion
5524 (end-of-line)
5525 (re-search-backward "^r\\([0-9]+\\)")
5526 (svn-match-string-no-properties 1)))
5527
5528(defun svn-log-file-name-at-point (respect-checkout-prefix-path)
5529 (let ((full-file-name)
5530 (file-name)
5531 (checkout-prefix-path (if respect-checkout-prefix-path
5532 (url-unhex-string
5533 (svn-status-checkout-prefix-path))
5534 "")))
5535 (save-excursion
5536 (beginning-of-line)
5537 (when (looking-at " [MA] /\\(.+\\)$")
5538 (setq full-file-name (svn-match-string-no-properties 1))))
5539 (when (string= checkout-prefix-path "")
5540 (setq checkout-prefix-path "/"))
5541 (if (null full-file-name)
5542 (progn
5543 (message "No file at point")
5544 nil)
5545 (setq file-name
5546 (if (eq (string-match (regexp-quote (substring checkout-prefix-path 1)) full-file-name) 0)
5547 (substring full-file-name (- (length checkout-prefix-path) (if (string= checkout-prefix-path "/") 1 0)))
5548 full-file-name))
5549 ;; (message "svn-log-file-name-at-point %s prefix: '%s', full-file-name: %s" file-name checkout-prefix-path full-file-name)
5550 file-name)))
5551
5552(defun svn-log-find-file-at-point ()
5553 (interactive)
5554 (let ((file-name (svn-log-file-name-at-point t)))
5555 (when file-name
5556 (let ((default-directory (svn-status-base-dir)))
5557 ;;(message "svn-log-file-name-at-point: %s, default-directory: %s" file-name default-directory)
5558 (find-file file-name)))))
5559
5560(defun svn-log-next-link ()
5561 "Jump to the next external link in this buffer"
5562 (interactive)
5563 (let ((start-pos (if (get-text-property (point) 'link-handler)
5564 (next-single-property-change (point) 'link-handler)
5565 (point))))
5566 (goto-char (or (next-single-property-change start-pos 'link-handler) (point)))))
5567
5568(defun svn-log-prev-link ()
5569 "Jump to the previous external link in this buffer"
5570 (interactive)
5571 (let ((start-pos (if (get-text-property (point) 'link-handler)
5572 (previous-single-property-change (point) 'link-handler)
5573 (point))))
5574 (goto-char (or (previous-single-property-change (or start-pos (point)) 'link-handler) (point)))))
5575
5576(defun svn-log-view-diff (arg)
5577 "Show the changeset for a given log entry.
5578When called with a prefix argument, ask the user for the revision."
5579 (interactive "P")
5580 (svn-status-diff-show-changeset (svn-log-revision-at-point) arg (svn-log-revision-for-diff)))
5581
5582(defun svn-log-get-specific-revision ()
5583 "Get an older revision of the file at point via svn cat."
5584 (interactive)
5585 ;; (message "%S" (svn-status-make-line-info (svn-log-file-name-at-point t)))
5586 (let ((default-directory (svn-status-base-dir))
5587 (file-name (svn-log-file-name-at-point t)))
5588 (if file-name
5589 (svn-status-get-specific-revision-internal
5590 (list (svn-status-make-line-info file-name))
5591 (svn-log-revision-at-point)
5592 nil)
5593 (message "No file at point"))))
5594
5595(defun svn-log-ediff-specific-revision (&optional user-confirmation)
5596 "Call ediff for the file at point to view a changeset.
5597When called with a prefix argument, ask the user for the revision."
5598 (interactive "P")
5599 ;; (message "svn-log-ediff-specific-revision: %s" (svn-log-file-name-at-point t))
5600 (let* ((cur-buf (current-buffer))
5601 (diff-rev (svn-log-revision-for-diff))
5602 (upper-rev (if diff-rev
5603 diff-rev
5604 (svn-log-revision-at-point)))
5605 (lower-rev (if diff-rev
5606 (svn-log-revision-at-point)
5607 (number-to-string (- (string-to-number upper-rev) 1))))
5608 (file-name (svn-log-file-name-at-point t))
5609 (default-directory (svn-status-base-dir))
5610 (upper-rev-file-name)
5611 (lower-rev-file-name)
5612 (rev-arg))
5613 (when user-confirmation
5614 (setq rev-arg (read-string "Revision for changeset: " (concat lower-rev ":" upper-rev)))
5615 (setq lower-rev (car (split-string rev-arg ":")))
5616 (setq upper-rev (cadr (split-string rev-arg ":"))))
5617 ;;(message "lower-rev: %s, upper-rev: %s" lower-rev upper-rev)
5618 (setq upper-rev-file-name (when file-name
5619 (cdar (svn-status-get-specific-revision-internal
5620 (list (svn-status-make-line-info file-name)) upper-rev nil))))
5621 (setq lower-rev-file-name (when file-name
5622 (cdar (svn-status-get-specific-revision-internal
5623 (list (svn-status-make-line-info file-name)) lower-rev nil))))
5624 ;;(message "%S %S" upper-rev-file-name lower-rev-file-name)
5625 (if file-name
5626 (let* ((ediff-after-quit-destination-buffer cur-buf)
5627 (newer-buffer (find-file-noselect upper-rev-file-name))
5628 (base-buff (find-file-noselect lower-rev-file-name))
5629 (svn-transient-buffers (list base-buff newer-buffer))
5630 (startup-hook '(svn-ediff-startup-hook)))
5631 (ediff-buffers base-buff newer-buffer startup-hook))
5632 (message "No file at point"))))
5633
5634(defun svn-log-edit-log-entry ()
5635 "Edit the given log entry."
5636 (interactive)
5637 (let ((rev (svn-log-revision-at-point))
5638 (log-message))
5639 (svn-run nil t 'propget-parse "propget" "--revprop" (concat "-r" rev) "svn:log")
5640 (save-excursion
5641 (set-buffer svn-process-buffer-name)
5642 (setq log-message (if (> (point-max) 1)
5643 (buffer-substring (point-min) (- (point-max) 1))
5644 "")))
5645 (svn-status-pop-to-commit-buffer)
5646 ;; If the buffer has been narrowed, `svn-log-edit-done' will use
5647 ;; only the accessible part. So we need not erase the rest here.
5648 (delete-region (point-min) (point-max))
5649 (insert log-message)
5650 (goto-char (point-min))
5651 (setq svn-log-edit-update-log-entry rev)))
5652
5653
5654;; allow additional hyperlinks in log view buffers
5655(defvar svn-log-link-keymap ()
5656 "Keymap used to resolve links `svn-log-view-mode' buffers.")
5657(put 'svn-log-link-keymap 'risky-local-variable t) ;for Emacs 20.7
5658(when (not svn-log-link-keymap)
5659 (setq svn-log-link-keymap (make-sparse-keymap))
5660 (suppress-keymap svn-log-link-keymap)
5661 (define-key svn-log-link-keymap [mouse-2] 'svn-log-resolve-mouse-link)
5662 (define-key svn-log-link-keymap (kbd "RET") 'svn-log-resolve-link))
5663
5664(defun svn-log-resolve-mouse-link (event)
5665 (interactive "e")
5666 (mouse-set-point event)
5667 (svn-log-resolve-link))
5668
5669(defun svn-log-resolve-link ()
5670 (interactive)
5671 (let* ((point-adjustment (if (not (get-text-property (- (point) 1) 'link-handler)) 1
5672 (if (not (get-text-property (+ (point) 1) 'link-handler)) -1 0)))
5673 (link-name (buffer-substring-no-properties (previous-single-property-change (+ (point) point-adjustment) 'link-handler)
5674 (next-single-property-change (+ (point) point-adjustment) 'link-handler))))
5675 ;; (message "svn-log-resolve-link '%s'" link-name)
5676 (funcall (get-text-property (point) 'link-handler) link-name)))
5677
5678(defun svn-log-register-link-handler (handler-id link-regexp handler-function)
5679 "Register a link handler for external links in *svn-log* buffers
5680HANDLER-ID is a symbolic name for this handler. The link handler is active when HANDLER-ID
5681is registered in `svn-log-link-handlers'.
5682LINK-REGEXP specifies a regular expression that matches the external link.
5683HANDLER-FUNCTION is called with the match of LINK-REGEXP when the user clicks at the external link."
5684 (let ((font-lock-desc (list link-regexp '(0 `(face font-lock-function-name-face
5685 mouse-face highlight
5686 link-handler invalid-handler-function
5687 keymap ,svn-log-link-keymap)))))
5688 ;; no idea, how to use handler-function in invalid-handler-function above, so set it here
5689 (setcar (nthcdr 5 (nth 1 (nth 1 (nth 1 font-lock-desc)))) handler-function)
5690 (svn-puthash handler-id font-lock-desc svn-log-registered-link-handlers)))
5691
5692;; example: add support for ditrack links and handle them via svn-log-resolve-ditrack
5693;;(svn-log-register-link-handler 'ditrack-issue "i#[0-9]+" 'svn-log-resolve-ditrack)
5694;;(defun svn-log-resolve-ditrack (link-name)
5695;; (interactive)
5696;; (message "svn-log-resolve-ditrack %s" link-name))
5697
5698
5699(defun svn-log-resolve-trac-ticket-short (link-name)
5700 "Show the trac ticket specified by LINK-NAME via `svn-trac-browse-ticket'."
5701 (interactive)
5702 (let ((ticket-nr (string-to-number (svn-substring-no-properties link-name 1))))
5703 (svn-trac-browse-ticket ticket-nr)))
5704
5705;; register the out of the box provided link handlers
5706(svn-log-register-link-handler 'trac-ticket-short "#[0-9]+" 'svn-log-resolve-trac-ticket-short)
5707
5708;; the actually used link handlers are specified in svn-log-link-handlers
5709
5710;; --------------------------------------------------------------------------------
5711;; svn-info-mode
5712;; --------------------------------------------------------------------------------
5713(defvar svn-info-mode-map () "Keymap used in `svn-info-mode' buffers.")
5714(put 'svn-info-mode-map 'risky-local-variable t) ;for Emacs 20.7
5715
5716(when (not svn-info-mode-map)
5717 (setq svn-info-mode-map (make-sparse-keymap))
5718 (define-key svn-info-mode-map [?s] 'svn-status-pop-to-status-buffer)
5719 (define-key svn-info-mode-map (kbd "h") 'svn-status-pop-to-partner-buffer)
5720 (define-key svn-info-mode-map (kbd "n") 'next-line)
5721 (define-key svn-info-mode-map (kbd "p") 'previous-line)
5722 (define-key svn-info-mode-map (kbd "RET") 'svn-info-show-context)
5723 (define-key svn-info-mode-map [?q] 'bury-buffer))
5724
5725(defun svn-info-mode ()
5726 "Major Mode to view informative output from svn."
5727 (interactive)
5728 (kill-all-local-variables)
5729 (use-local-map svn-info-mode-map)
5730 (setq major-mode 'svn-info-mode)
5731 (setq mode-name "svn-info")
5732 (toggle-read-only 1))
5733
5734(defun svn-info-show-context ()
5735 "Show the context for a line in the info buffer.
5736Currently is the output from the svn update command known."
5737 (interactive)
5738 (cond ((save-excursion
5739 (goto-char (point-max))
5740 (forward-line -1)
5741 (beginning-of-line)
5742 (looking-at "Updated to revision"))
5743 ;; svn-info contains info from an svn update
5744 (let ((cur-pos (point))
5745 (file-name (buffer-substring-no-properties
5746 (progn (beginning-of-line) (re-search-forward ".. +") (point))
5747 (line-end-position)))
5748 (pos))
5749 (when (eq system-type 'windows-nt)
5750 (setq file-name (replace-regexp-in-string "\\\\" "/" file-name)))
5751 (goto-char cur-pos)
5752 (with-current-buffer svn-status-buffer-name
5753 (setq pos (svn-status-get-file-name-buffer-position file-name)))
5754 (when pos
5755 (svn-status-pop-to-new-partner-buffer svn-status-buffer-name)
5756 (goto-char pos))))))
5757
5758;; --------------------------------------------------------------------------------
5759;; svn blame minor mode
5760;; --------------------------------------------------------------------------------
5761
5762(unless (assq 'svn-blame-mode minor-mode-alist)
5763 (setq minor-mode-alist
5764 (cons (list 'svn-blame-mode " SvnBlame")
5765 minor-mode-alist)))
5766
5767(defvar svn-blame-mode-map () "Keymap used in `svn-blame-mode' buffers.")
5768(put 'svn-blame-mode-map 'risky-local-variable t) ;for Emacs 20.7
5769
5770(when (not svn-blame-mode-map)
5771 (setq svn-blame-mode-map (make-sparse-keymap))
5772 (define-key svn-blame-mode-map [?s] 'svn-status-pop-to-status-buffer)
5773 (define-key svn-blame-mode-map (kbd "n") 'next-line)
5774 (define-key svn-blame-mode-map (kbd "p") 'previous-line)
5775 (define-key svn-blame-mode-map (kbd "RET") 'svn-blame-open-source-file)
5776 (define-key svn-blame-mode-map (kbd "a") 'svn-blame-highlight-author)
5777 (define-key svn-blame-mode-map (kbd "r") 'svn-blame-highlight-revision)
5778 (define-key svn-blame-mode-map (kbd "=") 'svn-blame-show-changeset)
5779 (define-key svn-blame-mode-map (kbd "l") 'svn-blame-show-log)
5780 (define-key svn-blame-mode-map (kbd "b") 'svn-blame-blame-again)
5781 (define-key svn-blame-mode-map (kbd "s") 'svn-blame-show-statistics)
5782 (define-key svn-blame-mode-map [?q] 'bury-buffer))
5783
5784(easy-menu-define svn-blame-mode-menu svn-blame-mode-map
5785"svn blame minor mode menu"
5786 '("SvnBlame"
5787 ["Jump to source location" svn-blame-open-source-file t]
5788 ["Show changeset" svn-blame-show-changeset t]
5789 ["Show log" svn-blame-show-log t]
5790 ["Show blame again" svn-blame-blame-again t]
5791 ["Show statistics" svn-blame-show-statistics t]
5792 ["Highlight by author" svn-blame-highlight-author t]
5793 ["Highlight by revision" svn-blame-highlight-revision t]))
5794
5795(or (assq 'svn-blame-mode minor-mode-map-alist)
5796 (setq minor-mode-map-alist
5797 (cons (cons 'svn-blame-mode svn-blame-mode-map) minor-mode-map-alist)))
5798
5799(make-variable-buffer-local 'svn-blame-mode)
5800
5801(defun svn-blame-mode (&optional arg)
5802 "Toggle svn blame minor mode.
5803With ARG, turn svn blame minor mode on if ARG is positive, off otherwise.
5804
5805Note: This mode does not yet work on XEmacs...
5806It is probably because the revisions are in 'before-string properties of overlays
5807
5808Key bindings:
5809\\{svn-blame-mode-map}"
5810 (interactive "P")
5811 (setq svn-blame-mode (if (null arg)
5812 (not svn-blame-mode)
5813 (> (prefix-numeric-value arg) 0)))
5814 (if svn-blame-mode
5815 (progn
5816 (easy-menu-add svn-blame-mode-menu)
5817 (toggle-read-only 1))
5818 (easy-menu-remove svn-blame-mode-menu))
5819 (force-mode-line-update))
5820
5821(defun svn-status-activate-blame-mode ()
5822 "Activate the svn blame minor in the current buffer.
5823The current buffer must contain a valid output from svn blame"
5824 (save-excursion
5825 (goto-char (point-min))
5826 (let ((buffer-read-only nil)
5827 (line (svn-line-number-at-pos))
5828 (limit (point-max))
5829 (info-end-col (save-excursion (forward-word 2) (+ (current-column) 1)))
5830 (s)
5831 ov)
5832 ;; remove the old overlays (only for testing)
5833 ;; (dolist (ov (overlays-in (point) limit))
5834 ;; (when (overlay-get ov 'svn-blame-line-info)
5835 ;; (delete-overlay ov)))
5836 (while (and (not (eobp)) (< (point) limit))
5837 (setq ov (make-overlay (point) (point)))
5838 (overlay-put ov 'svn-blame-line-info t)
5839 (setq s (buffer-substring-no-properties (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col)))
5840 (overlay-put ov 'before-string (propertize s 'face 'svn-status-blame-rev-number-face))
5841 (overlay-put ov 'rev-info (delete "" (split-string s " ")))
5842 (delete-region (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col))
5843 (forward-line)
5844 (setq line (1+ line)))))
5845 (let* ((buf-name (format "*svn-blame: %s <%s>*"
5846 (file-relative-name svn-status-blame-file-name)
5847 svn-status-blame-revision))
5848 (buffer (get-buffer buf-name)))
5849 (when buffer
5850 (kill-buffer buffer))
5851 (rename-buffer buf-name))
5852 ;; use the correct mode for the displayed blame output
5853 (let ((buffer-file-name svn-status-blame-file-name))
5854 (normal-mode)
5855 (set (make-local-variable 'svn-status-blame-file-name) svn-status-blame-file-name))
5856 (font-lock-fontify-buffer)
5857 (svn-blame-mode 1))
5858
5859(defun svn-blame-open-source-file ()
5860 "Jump to the source file location for the current position in the svn blame buffer"
5861 (interactive)
5862 (let ((src-line-number (svn-line-number-at-pos))
5863 (src-line-col (current-column)))
5864 (find-file-other-window svn-status-blame-file-name)
5865 (goto-line src-line-number)
5866 (forward-char src-line-col)))
5867
5868(defun svn-blame-rev-at-point ()
5869 (let ((rev))
5870 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5871 (when (overlay-get ov 'svn-blame-line-info)
5872 (setq rev (car (overlay-get ov 'rev-info)))))
5873 rev))
5874
5875(defun svn-blame-show-changeset (arg)
5876 "Show a diff for the revision at point.
5877When called with a prefix argument, allow the user to edit the revision."
5878 (interactive "P")
5879 (svn-status-diff-show-changeset (svn-blame-rev-at-point) arg))
5880
5881(defun svn-blame-show-log (arg)
5882 "Show the log for the revision at point.
5883The output is put into the *svn-log* buffer
5884The optional prefix argument ARG determines which switches are passed to `svn log':
5885 no prefix --- use whatever is in the list `svn-status-default-log-arguments'
5886 prefix argument of -1: --- use the -q switch (quiet)
5887 prefix argument of 0 --- use no arguments
5888 other prefix arguments: --- use the -v switch (verbose)"
5889 (interactive "P")
5890 (let ((switches (svn-status-svn-log-switches arg))
5891 (rev (svn-blame-rev-at-point)))
5892 (svn-run t t 'log "log" "--revision" rev switches)))
5893
5894(defun svn-blame-highlight-line-maybe (compare-func)
5895 (let ((reference-value)
5896 (is-highlighted)
5897 (consider-this-line)
5898 (hl-ov))
5899 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5900 (when (overlay-get ov 'svn-blame-line-info)
5901 (setq reference-value (funcall compare-func ov)))
5902 (when (overlay-get ov 'svn-blame-highlighted)
5903 (setq is-highlighted t)))
5904 (save-excursion
5905 (goto-char (point-min))
5906 (while (not (eobp))
5907 (setq consider-this-line nil)
5908 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5909 (when (overlay-get ov 'svn-blame-line-info)
5910 (when (string= reference-value (funcall compare-func ov))
5911 (setq consider-this-line t))))
5912 (when consider-this-line
5913 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5914 (when (and (overlay-get ov 'svn-blame-highlighted) is-highlighted)
5915 (delete-overlay ov))
5916 (unless is-highlighted
5917 (setq hl-ov (make-overlay (svn-point-at-bol) (line-end-position)))
5918 (overlay-put hl-ov 'svn-blame-highlighted t)
5919 (overlay-put hl-ov 'face 'svn-status-blame-highlight-face))))
5920 (forward-line)))))
5921
5922(defun svn-blame-show-statistics ()
5923 "Show statistics for the current blame buffer."
5924 (interactive)
5925 (let ((author-map (make-hash-table :test 'equal))
5926 (revision-map (make-hash-table :test 'equal))
5927 (rev-info)
5928 (author-list)
5929 (author)
5930 (revision-list)
5931 (revision))
5932 (save-excursion
5933 (goto-char (point-min))
5934 (while (not (eobp))
5935 (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
5936 (when (overlay-get ov 'svn-blame-line-info)
5937 (setq rev-info (overlay-get ov 'rev-info))
5938 (setq author (cadr rev-info))
5939 (setq revision (string-to-number (car rev-info)))
5940 (svn-puthash author (+ (gethash author author-map 0) 1) author-map)
5941 (svn-puthash revision (+ (gethash revision revision-map 0) 1) revision-map)))
5942 (forward-line))
5943 (maphash '(lambda (key value) (add-to-list 'author-list (list key value))) author-map)
5944 (maphash '(lambda (key value) (add-to-list 'revision-list (list key value))) revision-map)
5945 (pop-to-buffer (get-buffer-create (replace-regexp-in-string "svn-blame:" "svn-blame-statistics:" (buffer-name))))
5946 (erase-buffer)
5947 (insert (propertize "Authors:\n" 'face 'font-lock-function-name-face))
5948 (dolist (line (sort author-list '(lambda (v1 v2) (> (cadr v1) (cadr v2)))))
5949 (insert (format "%s: %s line%s\n" (car line) (cadr line) (if (eq (cadr line) 1) "" "s"))))
5950 (insert (propertize "\nRevisions:\n" 'face 'font-lock-function-name-face))
5951 (dolist (line (sort revision-list '(lambda (v1 v2) (< (car v1) (car v2)))))
5952 (insert (format "%s: %s line%s\n" (car line) (cadr line) (if (eq (cadr line) 1) "" "s"))))
5953 (goto-char (point-min)))))
5954
5955(defun svn-blame-highlight-author-field (ov)
5956 (cadr (overlay-get ov 'rev-info)))
5957
5958(defun svn-blame-highlight-author ()
5959 "(Un)Highlight all lines with the same author."
5960 (interactive)
5961 (svn-blame-highlight-line-maybe 'svn-blame-highlight-author-field))
5962
5963(defun svn-blame-highlight-revision-field (ov)
5964 (car (overlay-get ov 'rev-info)))
5965
5966(defun svn-blame-highlight-revision ()
5967 "(Un)Highlight all lines with the same revision."
5968 (interactive)
5969 (svn-blame-highlight-line-maybe 'svn-blame-highlight-revision-field))
5970
5971;; --------------------------------------------------------------------------------
5972;; svn-process-mode
5973;; --------------------------------------------------------------------------------
5974(defvar svn-process-mode-map () "Keymap used in `svn-process-mode' buffers.")
5975(put 'svn-process-mode-map 'risky-local-variable t) ;for Emacs 20.7
5976
5977(when (not svn-process-mode-map)
5978 (setq svn-process-mode-map (make-sparse-keymap))
5979 (define-key svn-process-mode-map (kbd "RET") 'svn-process-send-string-and-newline)
5980 (define-key svn-process-mode-map [?s] 'svn-process-send-string)
5981 (define-key svn-process-mode-map [?q] 'bury-buffer))
5982
5983(easy-menu-define svn-process-mode-menu svn-process-mode-map
5984"'svn-process-mode' menu"
5985 '("SvnProcess"
5986 ["Send line to process" svn-process-send-string-and-newline t]
5987 ["Send raw string to process" svn-process-send-string t]
5988 ["Bury process buffer" bury-buffer t]))
5989
5990(defun svn-process-mode ()
5991 "Major Mode to view process output from svn.
5992
5993You can send a new line terminated string to the process via \\[svn-process-send-string-and-newline]
5994You can send raw data to the process via \\[svn-process-send-string]."
5995 (interactive)
5996 (kill-all-local-variables)
5997 (use-local-map svn-process-mode-map)
5998 (easy-menu-add svn-log-view-mode-menu)
5999 (setq major-mode 'svn-process-mode)
6000 (setq mode-name "svn-process"))
6001
6002;; --------------------------------------------------------------------------------
6003;; svn status persistent options
6004;; --------------------------------------------------------------------------------
6005
6006(defun svn-status-repo-for-path (directory)
6007 "Find the repository root for DIRECTORY."
6008 (let ((old-process-default-dir))
6009 (with-current-buffer (get-buffer-create svn-process-buffer-name)
6010 (setq old-process-default-dir default-directory)
6011 (setq default-directory directory)) ;; update the default-directory for the *svn-process* buffer
6012 (svn-run nil t 'parse-info "info" ".")
6013 (with-current-buffer svn-process-buffer-name
6014 ;; (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)
6015 (setq default-directory old-process-default-dir)
6016 (goto-char (point-min))
6017 (let ((case-fold-search t))
6018 (if (search-forward "repository root: " nil t)
6019 (buffer-substring-no-properties (point) (svn-point-at-eol))
6020 (when (search-forward "repository uuid: " nil t)
6021 (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."
6022 default-directory)
6023 (concat "Svn Repo UUID: " (buffer-substring-no-properties (point) (svn-point-at-eol)))))))))
6024
6025(defun svn-status-base-dir (&optional start-directory)
6026 "Find the svn root directory for the current working copy.
6027Return nil, if not in a svn working copy."
6028 (let* ((start-dir (expand-file-name (or start-directory default-directory)))
6029 (base-dir (gethash start-dir svn-status-base-dir-cache 'not-found)))
6030 ;;(message "svn-status-base-dir: %S %S" start-dir base-dir)
6031 (if (not (eq base-dir 'not-found))
6032 base-dir
6033 ;; (message "calculating base-dir for %s" start-dir)
6034 (unless svn-client-version
6035 (svn-status-version))
6036 (let* ((base-dir start-dir)
6037 (repository-root (svn-status-repo-for-path base-dir))
6038 (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
6039 (in-tree (and repository-root (file-exists-p dot-svn-dir)))
6040 (dir-below (expand-file-name base-dir)))
6041 ;; (message "repository-root: %s start-dir: %s" repository-root start-dir)
6042 (if (and (<= (car svn-client-version) 1) (< (cadr svn-client-version) 3))
6043 (setq base-dir (svn-status-base-dir-for-ancient-svn-client start-dir)) ;; svn version < 1.3
6044 (while (when (and dir-below (file-exists-p dot-svn-dir))
6045 (setq base-dir (file-name-directory dot-svn-dir))
6046 (string-match "\\(.+/\\).+/" dir-below)
6047 (setq dir-below
6048 (and (string-match "\\(.*/\\)[^/]+/" dir-below)
6049 (match-string 1 dir-below)))
6050 ;; (message "base-dir: %s, dir-below: %s, dot-svn-dir: %s in-tree: %s" base-dir dir-below dot-svn-dir in-tree)
6051 (when dir-below
6052 (if (string= (svn-status-repo-for-path dir-below) repository-root)
6053 (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))
6054 (setq dir-below nil)))))
6055 (setq base-dir (and in-tree base-dir)))
6056 (svn-puthash start-dir base-dir svn-status-base-dir-cache)
6057 (svn-status-message 7 "svn-status-base-dir %s => %s" start-dir base-dir)
6058 base-dir))))
6059
6060(defun svn-status-base-dir-for-ancient-svn-client (&optional start-directory)
6061 "Find the svn root directory for the current working copy.
6062Return nil, if not in a svn working copy.
6063This function is used for svn clients version 1.2 and below."
6064 (let* ((base-dir (expand-file-name (or start-directory default-directory)))
6065 (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
6066 (in-tree (file-exists-p dot-svn-dir))
6067 (dir-below (expand-file-name default-directory)))
6068 (while (when (and dir-below (file-exists-p dot-svn-dir))
6069 (setq base-dir (file-name-directory dot-svn-dir))
6070 (string-match "\\(.+/\\).+/" dir-below)
6071 (setq dir-below
6072 (and (string-match "\\(.*/\\)[^/]+/" dir-below)
6073 (match-string 1 dir-below)))
6074 (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))))
6075 (and in-tree base-dir)))
6076
6077(defun svn-status-save-state ()
6078 "Save psvn persistent options for this working copy to a file."
6079 (interactive)
6080 (let ((buf (find-file (concat (svn-status-base-dir) "++psvn.state"))))
6081 (erase-buffer) ;Widen, because we'll save the whole buffer.
6082 ;; TO CHECK: why is svn-status-options a global variable??
6083 (setq svn-status-options
6084 (list
6085 (list "svn-trac-project-root" svn-trac-project-root)
6086 (list "sort-status-buffer" svn-status-sort-status-buffer)
6087 (list "elide-list" svn-status-elided-list)
6088 (list "module-name" svn-status-module-name)
6089 (list "branch-list" svn-status-branch-list)
6090 (list "changelog-style" svn-status-changelog-style)
6091 ))
6092 (insert (pp-to-string svn-status-options))
6093 (save-buffer)
6094 (kill-buffer buf)))
6095
6096(defun svn-status-load-state (&optional no-error)
6097 "Load psvn persistent options for this working copy from a file."
6098 (interactive)
6099 (let ((file (concat (svn-status-base-dir) "++psvn.state")))
6100 (if (file-readable-p file)
6101 (with-temp-buffer
6102 (insert-file-contents file)
6103 (setq svn-status-options (read (current-buffer)))
6104 (setq svn-status-sort-status-buffer
6105 (nth 1 (assoc "sort-status-buffer" svn-status-options)))
6106 (setq svn-trac-project-root
6107 (nth 1 (assoc "svn-trac-project-root" svn-status-options)))
6108 (setq svn-status-elided-list
6109 (nth 1 (assoc "elide-list" svn-status-options)))
6110 (setq svn-status-module-name
6111 (nth 1 (assoc "module-name" svn-status-options)))
6112 (setq svn-status-branch-list
6113 (nth 1 (assoc "branch-list" svn-status-options)))
6114 (setq svn-status-changelog-style
6115 (nth 1 (assoc "changelog-style" svn-status-options)))
6116 (when (and (interactive-p) svn-status-elided-list (svn-status-apply-elide-list)))
6117 (message "psvn.el: loaded %s" file))
6118 (if no-error
6119 (setq svn-trac-project-root nil
6120 svn-status-elided-list nil
6121 svn-status-module-name nil
6122 svn-status-branch-list nil
6123 svn-status-changelog-style 'changelog)
6124 (error "psvn.el: %s is not readable." file)))))
6125
6126(defun svn-status-toggle-sort-status-buffer ()
6127 "Toggle sorting of the *svn-status* buffer.
6128
6129If you turn off sorting, you can speed up \\[svn-status]. However,
6130the buffer is not correctly sorted then. This function will be
6131removed again, when a faster parsing and display routine for
6132`svn-status' is available."
6133 (interactive)
6134 (setq svn-status-sort-status-buffer (not svn-status-sort-status-buffer))
6135 (message "The %s buffer will %sbe sorted." svn-status-buffer-name
6136 (if svn-status-sort-status-buffer "" "not ")))
6137
6138(defun svn-status-toggle-svn-verbose-flag ()
6139 "Toggle `svn-status-verbose'. "
6140 (interactive)
6141 (setq svn-status-verbose (not svn-status-verbose))
6142 (message "svn status calls will %suse the -v flag." (if svn-status-verbose "" "not ")))
6143
6144(defun svn-status-toggle-display-full-path ()
6145 "Toggle displaying the full path in the `svn-status-buffer-name' buffer"
6146 (interactive)
6147 (setq svn-status-display-full-path (not svn-status-display-full-path))
6148 (message "The %s buffer will%s use full path names." svn-status-buffer-name
6149 (if svn-status-display-full-path "" " not"))
6150 (svn-status-update-buffer))
6151
6152(defun svn-status-set-trac-project-root ()
6153 (interactive)
6154 (setq svn-trac-project-root
6155 (read-string "Trac project root (e.g.: http://projects.edgewall.com/trac/): "
6156 svn-trac-project-root))
6157 (when (yes-or-no-p "Save the new setting for svn-trac-project-root to disk? ")
6158 (svn-status-save-state)))
6159
6160(defun svn-status-set-module-name ()
6161 "Interactively set `svn-status-module-name'."
6162 (interactive)
6163 (setq svn-status-module-name
6164 (read-string "Short Unit Name (e.g.: MyProject): "
6165 svn-status-module-name))
6166 (when (yes-or-no-p "Save the new setting for svn-status-module-name to disk? ")
6167 (svn-status-save-state)))
6168
6169(defun svn-status-set-changelog-style ()
6170 "Interactively set `svn-status-changelog-style'."
6171 (interactive)
6172 (setq svn-status-changelog-style
6173 (intern (funcall svn-status-completing-read-function "svn-status on directory: " '("changelog" "svn-dev" "other"))))
6174 (when (string= svn-status-changelog-style 'other)
6175 (setq svn-status-changelog-style (car (find-function-read))))
6176 (when (yes-or-no-p "Save the new setting for svn-status-changelog-style to disk? ")
6177 (svn-status-save-state)))
6178
6179(defun svn-status-set-branch-list ()
6180 "Interactively set `svn-status-branch-list'."
6181 (interactive)
6182 (setq svn-status-branch-list
6183 (split-string (read-string "Branch list: "
6184 (mapconcat 'identity svn-status-branch-list " "))))
6185 (when (yes-or-no-p "Save the new setting for svn-status-branch-list to disk? ")
6186 (svn-status-save-state)))
6187
6188(defun svn-browse-url (url)
6189 "Call `browse-url', using `svn-browse-url-function'."
6190 (let ((browse-url-browser-function (or svn-browse-url-function
6191 browse-url-browser-function)))
6192 (browse-url url)))
6193
6194;; --------------------------------------------------------------------------------
6195;; svn status trac integration
6196;; --------------------------------------------------------------------------------
6197(defun svn-trac-browse-wiki ()
6198 "Open the trac wiki view for the current svn repository."
6199 (interactive)
6200 (unless svn-trac-project-root
6201 (svn-status-set-trac-project-root))
6202 (svn-browse-url (concat svn-trac-project-root "wiki")))
6203
6204(defun svn-trac-browse-timeline ()
6205 "Open the trac timeline view for the current svn repository."
6206 (interactive)
6207 (unless svn-trac-project-root
6208 (svn-status-set-trac-project-root))
6209 (svn-browse-url (concat svn-trac-project-root "timeline")))
6210
6211(defun svn-trac-browse-roadmap ()
6212 "Open the trac roadmap view for the current svn repository."
6213 (interactive)
6214 (unless svn-trac-project-root
6215 (svn-status-set-trac-project-root))
6216 (svn-browse-url (concat svn-trac-project-root "roadmap")))
6217
6218(defun svn-trac-browse-source ()
6219 "Open the trac source browser for the current svn repository."
6220 (interactive)
6221 (unless svn-trac-project-root
6222 (svn-status-set-trac-project-root))
6223 (svn-browse-url (concat svn-trac-project-root "browser")))
6224
6225(defun svn-trac-browse-report (arg)
6226 "Open the trac report view for the current svn repository.
6227When called with a prefix argument, display the given report number."
6228 (interactive "P")
6229 (unless svn-trac-project-root
6230 (svn-status-set-trac-project-root))
6231 (svn-browse-url (concat svn-trac-project-root "report" (if (numberp arg) (format "/%s" arg) ""))))
6232
6233(defun svn-trac-browse-changeset (changeset-nr)
6234 "Show a changeset in the trac issue tracker."
6235 (interactive (list (read-number "Browse changeset number: " (number-at-point))))
6236 (unless svn-trac-project-root
6237 (svn-status-set-trac-project-root))
6238 (svn-browse-url (concat svn-trac-project-root "changeset/" (number-to-string changeset-nr))))
6239
6240(defun svn-trac-browse-ticket (ticket-nr)
6241 "Show a ticket in the trac issue tracker."
6242 (interactive (list (read-number "Browse ticket number: " (number-at-point))))
6243 (unless svn-trac-project-root
6244 (svn-status-set-trac-project-root))
6245 (svn-browse-url (concat svn-trac-project-root "ticket/" (number-to-string ticket-nr))))
6246
6247;;;------------------------------------------------------------
6248;;; resolve conflicts using ediff
6249;;;------------------------------------------------------------
6250(defun svn-resolve-conflicts-ediff (&optional name-A name-B)
6251 "Invoke ediff to resolve conflicts in the current buffer.
6252The conflicts must be marked with rcsmerge conflict markers."
6253 (interactive)
6254 (let* ((found nil)
6255 (file-name (file-name-nondirectory buffer-file-name))
6256 (your-buffer (generate-new-buffer
6257 (concat "*" file-name
6258 " " (or name-A "WORKFILE") "*")))
6259 (other-buffer (generate-new-buffer
6260 (concat "*" file-name
6261 " " (or name-B "CHECKED-IN") "*")))
6262 (result-buffer (current-buffer)))
6263 (save-excursion
6264 (set-buffer your-buffer)
6265 (erase-buffer)
6266 (insert-buffer-substring result-buffer)
6267 (goto-char (point-min))
6268 (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
6269 (setq found t)
6270 (replace-match "")
6271 (if (not (re-search-forward "^=======\n" nil t))
6272 (error "Malformed conflict marker"))
6273 (replace-match "")
6274 (let ((start (point)))
6275 (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
6276 (error "Malformed conflict marker"))
6277 (delete-region start (point))))
6278 (if (not found)
6279 (progn
6280 (kill-buffer your-buffer)
6281 (kill-buffer other-buffer)
6282 (error "No conflict markers found")))
6283 (set-buffer other-buffer)
6284 (erase-buffer)
6285 (insert-buffer-substring result-buffer)
6286 (goto-char (point-min))
6287 (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
6288 (let ((start (match-beginning 0)))
6289 (if (not (re-search-forward "^=======\n" nil t))
6290 (error "Malformed conflict marker"))
6291 (delete-region start (point))
6292 (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
6293 (error "Malformed conflict marker"))
6294 (replace-match "")))
6295 (let ((config (current-window-configuration))
6296 (ediff-default-variant 'default-B))
6297
6298 ;; Fire up ediff.
6299
6300 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
6301
6302 ;; Ediff is now set up, and we are in the control buffer.
6303 ;; Do a few further adjustments and take precautions for exit.
6304
6305 (make-local-variable 'svn-ediff-windows)
6306 (setq svn-ediff-windows config)
6307 (make-local-variable 'svn-ediff-result)
6308 (setq svn-ediff-result result-buffer)
6309 (make-local-variable 'ediff-quit-hook)
6310 (setq ediff-quit-hook
6311 (lambda ()
6312 (let ((buffer-A ediff-buffer-A)
6313 (buffer-B ediff-buffer-B)
6314 (buffer-C ediff-buffer-C)
6315 (result svn-ediff-result)
6316 (windows svn-ediff-windows))
6317 (ediff-cleanup-mess)
6318 (set-buffer result)
6319 (erase-buffer)
6320 (insert-buffer-substring buffer-C)
6321 (kill-buffer buffer-A)
6322 (kill-buffer buffer-B)
6323 (kill-buffer buffer-C)
6324 (set-window-configuration windows)
6325 (message "Conflict resolution finished; you may save the buffer"))))
6326 (message "Please resolve conflicts now; exit ediff when done")
6327 nil))))
6328
6329(defun svn-resolve-conflicts (filename)
6330 (let ((buff (find-file-noselect filename)))
6331 (if buff
6332 (progn (switch-to-buffer buff)
6333 (svn-resolve-conflicts-ediff))
6334 (error "can not open file %s" filename))))
6335
6336(defun svn-status-resolve-conflicts ()
6337 "Resolve conflict in the selected file"
6338 (interactive)
6339 (let ((file-info (svn-status-get-line-information)))
6340 (or (and file-info
6341 (= ?C (svn-status-line-info->filemark file-info))
6342 (svn-resolve-conflicts
6343 (svn-status-line-info->full-path file-info)))
6344 (error "can not resolve conflicts at this point"))))
6345
6346
6347;; --------------------------------------------------------------------------------
6348;; Working with branches
6349;; --------------------------------------------------------------------------------
6350
6351(defun svn-branch-select (&optional prompt)
6352 "Select a branch interactively from `svn-status-branch-list'"
6353 (interactive)
6354 (unless prompt
6355 (setq prompt "Select branch: "))
6356 (let* ((branch (funcall svn-status-completing-read-function prompt svn-status-branch-list))
6357 (directory)
6358 (base-url))
6359 (when (string-match "#\\(1#\\)?\\(.+\\)" branch)
6360 (setq directory (match-string 2 branch))
6361 (setq base-url (concat (svn-status-base-info->repository-root) "/" directory))
6362 (save-match-data
6363 (svn-status-parse-info t))
6364 (if (eq (length (match-string 1 branch)) 0)
6365 (setq branch base-url)
6366 (let ((svn-status-branch-list (svn-status-ls base-url t)))
6367 (setq branch (concat (svn-status-base-info->repository-root) "/"
6368 directory "/"
6369 (svn-branch-select (format "Select branch from '%s': " directory)))))))
6370 branch))
6371
6372(defun svn-branch-diff (branch1 branch2)
6373 "Show the diff between two svn repository urls.
6374When called interactively, use `svn-branch-select' to choose two branches from `svn-status-branch-list'."
6375 (interactive
6376 (let* ((branch1 (svn-branch-select "svn diff branch1: "))
6377 (branch2 (svn-branch-select (format "svn diff %s against: " branch1))))
6378 (list branch1 branch2)))
6379 (svn-run t t 'diff "diff" svn-status-default-diff-arguments branch1 branch2))
6380
6381;; --------------------------------------------------------------------------------
6382;; svnadmin interface
6383;; --------------------------------------------------------------------------------
6384(defun svn-admin-create (dir)
6385 "Run svnadmin create DIR."
6386 (interactive (list (expand-file-name
6387 (svn-read-directory-name "Create a svn repository at: "
6388 svn-admin-default-create-directory nil nil))))
6389 (shell-command-to-string (concat "svnadmin create " dir))
6390 (setq svn-admin-last-repository-dir (concat "file://" dir))
6391 (message "Svn repository created at %s" dir)
6392 (run-hooks 'svn-admin-create-hook))
6393
6394;; - Import an empty directory
6395;; cd to an empty directory
6396;; svn import -m "Initial import" . file:///home/stefan/svn_repos/WaldiConfig/trunk
6397(defun svn-admin-create-trunk-directory ()
6398 "Import an empty trunk directory to `svn-admin-last-repository-dir'.
6399Set `svn-admin-last-repository-dir' to the new created trunk url."
6400 (interactive)
6401 (let ((empty-temp-dir-name (make-temp-name svn-status-temp-dir)))
6402 (make-directory empty-temp-dir-name t)
6403 (setq svn-admin-last-repository-dir (concat svn-admin-last-repository-dir "/trunk"))
6404 (svn-run nil t 'import "import" "-m" "Created trunk directory"
6405 empty-temp-dir-name svn-admin-last-repository-dir)
6406 (delete-directory empty-temp-dir-name)))
6407
6408(defun svn-admin-start-import ()
6409 "Start to import the current working directory in a subversion repository.
6410The user is asked to perform the following two steps:
64111. Create a local repository
64122. Add a trunk directory to that repository
6413
6414After that step the empty base directory (either the root directory or
6415the trunk directory of the selected repository) is checked out in the current
6416working directory."
6417 (interactive)
6418 (if (y-or-n-p "Create local repository? ")
6419 (progn
6420 (call-interactively 'svn-admin-create)
6421 (when (y-or-n-p "Add a trunk directory? ")
6422 (svn-admin-create-trunk-directory)))
6423 (setq svn-admin-last-repository-dir (read-string "Repository Url: ")))
6424 (svn-checkout svn-admin-last-repository-dir "."))
6425
6426;; --------------------------------------------------------------------------------
6427;; svn status profiling
6428;; --------------------------------------------------------------------------------
6429;;; Note about profiling psvn:
6430;; (load-library "elp")
6431;; M-x elp-reset-all
6432;; (elp-instrument-package "svn-")
6433;; M-x svn-status
6434;; M-x elp-results
6435
6436(defun svn-status-elp-init ()
6437 (interactive)
6438 (require 'elp)
6439 (elp-reset-all)
6440 (elp-instrument-package "svn-")
6441 (message "Run the desired svn command (e.g. M-x svn-status), then use M-x elp-results."))
6442
6443(defun svn-status-last-commands (&optional string-prefix)
6444 "Return a string with the last executed svn commands"
6445 (interactive)
6446 (unless string-prefix
6447 (setq string-prefix ""))
6448 (with-output-to-string
6449 (dolist (e (ring-elements svn-last-cmd-ring))
6450 (princ (format "%s%s: svn %s <%s>\n" string-prefix (nth 0 e) (mapconcat 'concat (nth 1 e) " ") (nth 2 e))))))
6451
6452;; --------------------------------------------------------------------------------
6453;; reporting bugs
6454;; --------------------------------------------------------------------------------
6455(defun svn-insert-indented-lines (text)
6456 "Helper function to insert TEXT, indented by two characters."
6457 (dolist (line (split-string text "\n"))
6458 (insert (format " %s\n" line))))
6459
6460(defun svn-prepare-bug-report ()
6461 "Create the buffer *psvn-bug-report*. This buffer can be useful to debug problems with psvn.el"
6462 (interactive)
6463 (let* ((last-output-buffer-name (or svn-status-last-output-buffer-name svn-process-buffer-name))
6464 (last-svn-cmd-output (with-current-buffer last-output-buffer-name
6465 (buffer-substring-no-properties (point-min) (point-max)))))
6466 (switch-to-buffer "*psvn-bug-report*")
6467 (delete-region (point-min) (point-max))
6468 (insert "This buffer holds some debug informations for psvn.el\n")
6469 (insert "Please enter a description of the observed and the wanted behaviour\n")
6470 (insert "and send it to the author (stefan@xsteve.at) to allow easier debugging\n\n")
6471 (insert "Revisions:\n")
6472 (svn-insert-indented-lines (svn-status-version))
6473 (insert "Language environment:\n")
6474 (dolist (elem (svn-process-environment))
6475 (when (member (car (split-string elem "=")) '("LC_MESSAGES" "LC_ALL" "LANG"))
6476 (insert (format " %s\n" elem))))
6477 (insert "\nLast svn commands:\n")
6478 (svn-insert-indented-lines (svn-status-last-commands))
6479 (insert (format "\nContent of the <%s> buffer:\n" last-output-buffer-name))
6480 (svn-insert-indented-lines last-svn-cmd-output)
6481 (goto-char (point-min))))
6482
6483;; --------------------------------------------------------------------------------
6484;; Make it easier to reload psvn, if a distribution has an older version
6485;; Just add the following to your .emacs:
6486;; (svn-prepare-for-reload)
6487;; (load "/path/to/psvn.el")
6488
6489;; Note the above will only work, if the loaded psvn.el has already the
6490;; function svn-prepare-for-reload
6491;; If this is not the case, do the following:
6492;; (load "/path/to/psvn.el");;make svn-prepare-for-reload available
6493;; (svn-prepare-for-reload)
6494;; (load "/path/to/psvn.el");; update the keybindings
6495;; --------------------------------------------------------------------------------
6496
6497(defvar svn-prepare-for-reload-dont-touch-list '() "A list of variables that should not be touched by `svn-prepare-for-reload'")
6498(defvar svn-prepare-for-reload-variables-list '(svn-global-keymap svn-status-diff-mode-map svn-global-trac-map svn-status-mode-map
6499 svn-status-mode-property-map svn-status-mode-extension-map
6500 svn-status-mode-options-map svn-status-mode-trac-map svn-status-mode-branch-map
6501 svn-log-edit-mode-map svn-log-view-mode-map
6502 svn-log-view-popup-menu-map svn-info-mode-map svn-blame-mode-map svn-process-mode-map)
6503 "A list of variables that should be set to nil via M-x `svn-prepare-for-reload'")
6504(defun svn-prepare-for-reload ()
6505 "This function resets some psvn.el variables to nil.
6506It makes reloading a newer version of psvn.el easier, if for example the used
6507GNU/Linux distribution uses an older version.
6508
6509The variables specified in `svn-prepare-for-reload-variables-list' will be reseted by this function.
6510
6511A variable will keep its value, if it is specified in `svn-prepare-for-reload-dont-touch-list'."
6512 (interactive)
6513 (dolist (var svn-prepare-for-reload-variables-list)
6514 (unless (member var svn-prepare-for-reload-dont-touch-list)
6515 (message (format "Resetting value of %s to nil" var)))
6516 (set var nil)))
6517
6518(provide 'psvn)
6519
6520;; Local Variables:
6521;; indent-tabs-mode: nil
6522;; End:
6523;;; psvn.el ends here