-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsvn.el
1918 lines (1739 loc) · 66.4 KB
/
dsvn.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; dsvn.el --- Subversion interface
;; Copyright 2006-2007 Virtutech AB
;; Author: David Kågedal <[email protected]>
;; Mattias Engdegård <[email protected]>
;; Maintainer: David Kågedal <[email protected]>
;; Created: 27 Jan 2006
;; Version: 1.5
;; Keywords: docs
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
;; License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA
;;; Commentary:
;;
;; This is an interface for managing Subversion working copies. It
;; can show you an up-to-date view of the current status, and commit
;; changes. If also helps you do other tasks such as updating,
;; switching, diffing and more.
;;
;; To get you started, add this line to your startup file:
;;
;; (autoload 'svn-status "dsvn" "Run `svn status'." t)
;; (autoload 'svn-update "dsvn" "Run `svn update'." t)
;;
;; This file integrates well with vc-svn, so you might want to do this
;; as well:
;;
;; (require 'vc-svn)
;;
;; To get the status view, type
;;
;; M-x svn-status
;;
;; and select a directory where you have a checked-out Subversion
;; working copy. A buffer will be created that shows what files you
;; have modified, and any unknown files. The file list corresponds
;; closely to that produced by "svn status", only slightly
;; reformatted.
;;
;; Navigate through the file list using "n" and "p", for next and
;; previous file, respectively.
;;
;; You can get a summary of available commands by typing "?".
;;
;; Some commands operate on files, and can either operate on the file
;; under point, or on a group of files that have been marked. The
;; commands used for marking a file are the following:
;;
;; m mark and go down
;; DEL unmark and go up
;; u unmark and go down
;; SPC toggle mark
;; M-DEL unmark all
;;
;; The commands that operate on files are:
;;
;; f Visit the file under point (does not use marks)
;; o Visit the file under point in another window (does not use marks)
;; = Show diff of uncommitted changes. This does not use marks
;; unless you give a prefix argument (C-u)
;; c Commit files
;; a Add files
;; r Remove files
;; R Resolve conflicts
;; M Rename/move files
;; U Revert files
;; P View or edit properties of the file or directory under point
;; (does not use marks)
;;
;; These commands update what is shown in the status buffer:
;;
;; g Rerun "svn status" to update the list. Use a prefix
;; argument (C-u) to clear the list first to make sure that
;; it is correct.
;; s Update status of selected files
;; S Show status of specific file or directory
;; x Expunge unchanged files from the list
;;
;; To update the working copy:
;;
;; M-u Run "svn update". If a prefix argument is given (C-u),
;; you will be prompted for a revision to update to.
;; M-s Switch working copy to another branch.
;; M-m Merge in changes using "svn merge".
;;
;; To view the Subversion log type "M-x svn-log".
;;
;; Bugs and missing features:
;;
;; - Annotate (blame).
;; - Log, with a useful log mode where the user can easily view any revision
;; as a diff or visit a revision of a file in a buffer.
;; - Integration with ediff or similar to resolve conflicts.
(require 'vc)
(require 'log-edit)
(defconst svn-status-msg-col 1)
(defconst svn-status-flags-col 11)
(defconst svn-status-mark-col 18)
(defconst svn-status-file-col 20)
(defgroup dsvn nil
"Settings for dsvn."
:group 'tools)
(defcustom svn-program "svn"
"*The svn program to run"
:type 'string
:group 'dsvn)
(defun svn-call-process (program buffer &rest args)
"Run svn and wait for it to finish.
Argument PROGRAM is the svn binary to run.
Argument BUFFER is the buffer in which to insert output.
Optional argument ARGS are the arguments to svn."
(let ((proc (apply 'start-process "svn" buffer program args)))
(set-process-coding-system proc 'utf-8)
(set-process-filter proc 'svn-output-filter)
(while (eq (process-status proc) 'run)
(accept-process-output proc 5)
(sit-for 0))))
(defun svn-run-with-output (subcommand &optional args mode)
"Run 'svn' with output to another window.
Argument SUBCOMMAND is the command to execute.
Optional argument ARGS is a list of the arguments to the command.
Optional argument MODE is the major mode to use for the output buffer.
Return non-NIL if there was any output."
(let ((buf (get-buffer-create "*svn output*"))
(dir default-directory)
(inhibit-read-only t))
(save-current-buffer
(set-buffer buf)
(erase-buffer)
(if mode
(funcall mode)
(fundamental-mode))
(setq default-directory dir)
(setq buffer-read-only t)
(let ((cmd `(,svn-program ,subcommand ,@args))
proc)
(setq proc (apply 'start-process "svn" buf cmd))
(set-process-coding-system proc 'utf-8)
(set-process-filter proc 'svn-output-filter)
(while (eq (process-status proc) 'run)
(accept-process-output proc 5)
(sit-for 0)))
(if (= (point-min) (point-max))
nil
(save-selected-window
(select-window (display-buffer buf))
(goto-char (point-min)))
t))))
(defun svn-run-hidden (command args)
"Run 'svn' without showing output.
Argument COMMAND is the command to run.
Optional argument ARGS is a list of arguments."
(let ((buf (get-buffer-create " *svn*"))
(dir default-directory))
(with-current-buffer buf
(erase-buffer)
(setq default-directory dir))
(apply 'call-process svn-program nil buf nil (symbol-name command) args)
buf))
(defun svn-run-predicate (command args)
"Run `svn', discarding output, returning t if it succeeded (exited with
status zero).
Argument COMMAND is the svn subcommand to run.
Optional argument ARGS is a list of arguments."
(zerop
(apply 'call-process svn-program nil nil nil (symbol-name command) args)))
(defun svn-output-filter (proc str)
"Output filter for svn output.
Argument PROC is the process object.
Argument STR is the output string."
(save-excursion
(set-buffer (process-buffer proc))
(goto-char (process-mark proc))
(let ((p (point))
(inhibit-read-only t))
(insert-before-markers str)
(goto-char p)
(while (search-forward "\r" (process-mark proc) t)
(save-excursion
(beginning-of-line)
(delete-region (point) (match-beginning 0))))
(goto-char p))))
(defvar svn-status-buffer nil
"svn-status buffer describing the files that a commit operation applies to")
(make-variable-buffer-local 'svn-status-buffer)
(defvar svn-todo-queue '()
"A queue of commands to run when the current command finishes.")
(make-variable-buffer-local 'svn-todo-queue)
(defun svn-current-url ()
"Get the repository URL."
(with-current-buffer (svn-run-hidden 'info ())
(if (re-search-backward "^URL: \\(.*\\)$" nil t)
(match-string 1)
(error "Couldn't find the current URL"))))
(defun svn-run (command args &optional description)
"Run subversion command COMMAND with ARGS.
Optional third argument DESCRIPTION is a string used in the status
buffer to describe what is going on."
;; Clean up old output
(let ((inhibit-read-only t))
(delete-region svn-output-marker (point-max)))
(let* ((command-s (symbol-name command))
(filter-func (intern (concat "svn-" command-s "-filter")))
(sentinel-func (intern (concat "svn-" command-s "-sentinel")))
proc)
;; The command status-v is interpreted as status -v
(when (eq command 'status-v)
(setq command-s "status"
args (cons "-v" args)))
(setq proc (apply 'start-process "svn" (current-buffer)
svn-program command-s args))
(if (fboundp filter-func)
(set-process-filter proc filter-func)
(set-process-filter proc 'svn-default-filter))
(if (fboundp sentinel-func)
(set-process-sentinel proc sentinel-func)
(set-process-sentinel proc 'svn-default-sentinel))
(setq svn-running (list description proc))
(set-svn-process-status 'running)
proc))
(defun svn-check-running ()
(when (and svn-running
(eq (process-status (cadr svn-running)) 'run))
(error "Can't run two svn processes from the same buffer")))
(defun svn-run-async (command args &optional file-filter)
"Run subversion command COMMAND with ARGS, possibly at a later time.
Optional third argument FILE-FILTER is the file filter to be in effect
during the run."
(if (and svn-running
(eq (process-status (cadr svn-running)) 'run))
(setq svn-todo-queue
(nconc svn-todo-queue
(list (list command args file-filter))))
(progn
(set (make-local-variable 'svn-file-filter) file-filter)
(svn-run command args))))
;; This could be used to debug filter functions
(defvar svn-output-queue nil)
(defvar svn-in-output-filter nil)
(defun svn-filter-queue (proc str)
(setq svn-output-queue (nconc svn-output-queue (list str)))
(unless svn-in-output-filter
(let ((svn-in-output-filter t))
(while svn-output-queue
(svn-status-filter proc (car svn-output-queue))
(setq svn-output-queue (cdr svn-output-queue))))))
(defun svn-default-filter (proc str)
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t))
(goto-char (point-max))
(insert str))))
(defun svn-default-sentinel (proc reason)
(with-current-buffer (process-buffer proc)
(when (and svn-running
(eq proc (cadr svn-running)))
(setq svn-running nil)
(if (/= (process-exit-status proc) 0)
(set-svn-process-status 'failed)
(set-svn-process-status 'finished))
(move-to-column goal-column))
(when svn-todo-queue
(let ((cmd-info (car svn-todo-queue)))
(setq svn-todo-queue (cdr svn-todo-queue))
(let ((command (car cmd-info))
(args (cadr cmd-info))
(file-filter (caddr cmd-info)))
(set (make-local-variable 'svn-file-filter) file-filter)
(svn-run command args))))))
(defun svn-diff (arg)
"Run `svn diff'.
Argument ARG are the command line arguments."
(interactive "ssvn diff arguments: ")
(svn-run-with-output "diff" (split-string arg) 'diff-mode))
(defun svn-commit ()
"Commit changes to one or more files."
(interactive)
(save-some-buffers)
(let ((status-buf (current-buffer))
(commit-buf (get-buffer-create "*svn commit*")))
(switch-to-buffer-other-window commit-buf)
(log-edit 'svn-confirm-commit)
(setq svn-status-buffer status-buf)))
(defun svn-confirm-commit ()
"Commit changes with the current buffer as commit message."
(interactive)
(let ((files (with-current-buffer svn-status-buffer
(svn-action-files)))
(commit-buf (current-buffer))
(status-buf svn-status-buffer)
;; XEmacs lacks make-temp-file but has make-temp-name + temp-directory
(msg-file (if (fboundp 'make-temp-file)
(make-temp-file "svn-commit")
(make-temp-name (expand-file-name "svn-commit"
(temp-directory))))))
;; Ensure final newline
(goto-char (point-max))
(unless (bolp)
(newline))
(write-region (point-min) (point-max) msg-file)
(when (boundp 'vc-comment-ring)
;; insert message into comment ring, unless identical to the previous
(let ((comment (buffer-string)))
(when (or (ring-empty-p vc-comment-ring)
(not (equal comment (ring-ref vc-comment-ring 0))))
(ring-insert vc-comment-ring comment))))
(kill-buffer commit-buf)
(with-current-buffer status-buf
(make-local-variable 'svn-commit-msg-file)
(make-local-variable 'svn-commit-files)
(setq svn-commit-msg-file msg-file)
(setq svn-commit-files files)
(svn-run 'commit (append (list "-N" "-F" msg-file) files)))))
(defun svn-commit-filter (proc str)
"Output filter function for `svn commit'."
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t)
(nomore))
(goto-char (point-max))
(insert str)
(goto-char svn-output-marker)
(while (not nomore)
(cond ((looking-at
"\\(Sending\\|Adding\\|Transmitting file\\|Deleting\\) .*\n")
;; Ignore these expected and uninteresting messages
(delete-region (match-beginning 0)
(match-end 0)))
((looking-at "Committed revision \\([0-9]+\\).\n")
(svn-update-label svn-revision-label (match-string 1))
(forward-line 1))
((looking-at ".*\n")
;; Unexpected output is left in the buffer
(forward-line 1))
(t
(setq nomore t)))))))
(defun svn-commit-sentinel (proc reason)
"Sentinel function for `svn commit'."
(with-current-buffer (process-buffer proc)
(setq svn-running nil)
(if (/= (process-exit-status proc) 0)
(set-svn-process-status 'failed)
(set-svn-process-status 'finished)
(while svn-commit-files
(let* ((file (car svn-commit-files))
(path (concat default-directory file))
(pos (svn-file-pos file))
(file-buffer (get-file-buffer path))
(inhibit-read-only t))
(when pos
(svn-update-status-flag pos ?\ ?\ )
(svn-update-status-msg pos "Committed"))
(when (and file-buffer (fboundp 'vc-svn-workfile-version))
(with-current-buffer file-buffer
;; Use buffer-file-name instead of path to get the
;; canonical file name used by vc
;; TODO: use the version number written by the commit command
(vc-file-setprop buffer-file-name 'vc-workfile-version
(vc-svn-workfile-version buffer-file-name))
(vc-mode-line buffer-file-name))))
(setq svn-commit-files (cdr svn-commit-files))))
(delete-file svn-commit-msg-file)))
;;; Svn log
(defun svn-log (arg)
"Run `svn log'.
Argument ARG is the command-line arguments, as a string."
(interactive "ssvn log arguments: ")
(svn-run-with-output "log" (split-string arg)
'svn-log-mode))
(defvar svn-log-mode-map nil
"Keymap for `svn-log-mode'.")
(unless svn-log-mode-map
(setq svn-log-mode-map (make-sparse-keymap))
(define-key svn-log-mode-map "\r" 'svn-log-show-diff)
(define-key svn-log-mode-map "n" 'svn-log-next)
(define-key svn-log-mode-map "p" 'svn-log-prev)
)
(defun svn-log-mode ()
"Major mode for viewing Subversion logs."
(interactive)
(kill-all-local-variables)
(setq major-mode 'svn-log-mode
mode-name "Svn log")
(use-local-map svn-log-mode-map)
(setq paragraph-start "^commit"))
(defun svn-log-current-commit ()
(save-excursion
(end-of-line)
(unless (re-search-forward "^r\\([0-9]+\\) |" nil t)
(error "Found no commit"))
(string-to-number (match-string 1))))
(defun svn-log-show-diff ()
"Show the changes introduced by the changeset under point."
(interactive)
(let ((commit-id (svn-log-current-commit))
(diff-buf (get-buffer-create "*svn diff*"))
(dir default-directory)
(inhibit-read-only t))
(display-buffer diff-buf)
(save-current-buffer
(set-buffer diff-buf)
(diff-mode)
(setq buffer-read-only t)
(erase-buffer)
(setq default-directory dir)
(svn-call-process svn-program diff-buf
"diff" "-r"
(format "%d:%d" (1- commit-id) commit-id)))))
(defun svn-log-next ()
"Move to the next changeset in the log."
(interactive)
(end-of-line)
(unless (re-search-forward "^------------------------------------------------------------------------$" nil t)
(error "Found no commit"))
(beginning-of-line)
(svn-log-show-diff))
(defun svn-log-prev ()
"Move to the previous changeset in the log."
(interactive)
(beginning-of-line)
(unless (re-search-backward "^------------------------------------------------------------------------$" nil t)
(error "Found no commit"))
(svn-log-show-diff))
(defun svn-new-label (&optional pos)
(unless pos (setq pos (point)))
(let ((start (make-marker))
(stop (make-marker)))
(set-marker start pos)
(set-marker stop pos)
(list start stop)))
(defun svn-update-label (label str)
(let ((start (car label))
(stop (cadr label))
(inhibit-read-only t))
(delete-region start stop)
(set-marker-insertion-type stop t)
(save-excursion
(goto-char start)
(insert str))))
;;; Svn propedit
(defun svn-propget (file propname)
"Return the Subversion property PROPNAME of FILE."
(with-current-buffer (svn-run-hidden 'propget (list propname file))
(substring (buffer-string) 0 -1))) ; trim final newline added by svn
(defun svn-get-props (file)
"Return an alist containing the properties of FILE"
;; First retrieve the property names, and then the value of each.
;; We can't use proplist -v because is output is ambiguous when values
;; consist of multiple lines.
(unless (svn-run-predicate 'ls (list file))
(error "%s is not under version control" file))
(let (propnames)
(with-current-buffer (svn-run-hidden 'proplist (list file))
(goto-char (point-min))
(when (looking-at "Properties on ")
(forward-line 1)
(while (looking-at " \\(.+\\)$")
(setq propnames (cons (match-string 1) propnames))
(forward-line 1))))
(mapcar (lambda (propname)
(cons propname (svn-propget file propname)))
propnames)))
(defun svn-propedit (file)
"Edit properties of FILE."
(interactive (list (expand-file-name
(or (svn-getprop (point) 'file)
(read-file-name "Edit properties of file: "
default-directory
nil t
(svn-getprop (point) 'dir))))))
(let ((local-file (svn-local-file-name file)))
(when (string-equal local-file "")
(setq local-file ".")
(setq file (file-name-as-directory file)))
(svn-check-running)
(let ((buf-name (format "*propedit %s*" local-file)))
(if (get-buffer buf-name)
(kill-buffer buf-name))
(let ((prop-alist (svn-get-props local-file))
(propedit-buf (get-buffer-create buf-name)))
(switch-to-buffer-other-window propedit-buf)
(svn-propedit-mode)
(insert
"# Properties of " local-file "\n"
"#\n"
"# Lines are on the form PROPNAME: VALUE for single-line values,\n"
"# or just PROPNAME: followed by one or more lines starting with > for\n"
"# multi-line values. Lines starting with # are ignored.\n"
"#\n"
"# Change, add, delete or rename properties just by editing this\n"
"# buffer; then press "
(substitute-command-keys "\\[svn-propedit-done]")
" to save changes.\n\n")
(mapc (lambda (prop)
(let* ((value (cdr prop))
(lines (split-string value "\n")))
;; split-string ignores single leading and trailing
;; delimiters, so add them explicitly
(when (not (equal value ""))
(when (equal (substring value 0 1) "\n")
(setq lines (cons "" lines)))
(when (equal (substring value -1) "\n")
(setq lines (append lines (list "")))))
(insert (car prop) ":")
(if (> (length lines) 1)
(progn
(insert "\n")
(mapc (lambda (line) (insert ">" line "\n"))
lines))
(insert " " (or (car lines) "") "\n"))))
(sort prop-alist #'(lambda (a b) (string< (car a) (car b)))))
(make-local-variable 'svn-propedit-file)
(setq svn-propedit-file file)
(setq default-directory (file-name-directory file))
(message
(substitute-command-keys
"Press \\[svn-propedit-done] when you are done editing."))))))
(defvar svn-propedit-mode-map nil
"Keymap for `svn-propedit-mode'.")
(unless svn-propedit-mode-map
(setq svn-propedit-mode-map (make-sparse-keymap))
(define-key svn-propedit-mode-map "\C-c\C-c" 'svn-propedit-done))
(defun svn-propedit-mode ()
"Major mode for editing Subversion properties."
(interactive)
(kill-all-local-variables)
(setq major-mode 'svn-propedit-mode
mode-name "Svn propedit")
(use-local-map svn-propedit-mode-map)
(setq font-lock-defaults
'((("^#.*$" ;comment
. 'font-lock-comment-face)
("^\\([^ \t\n#>][^ \t\n]*\\):" ;property name
. (1 'bold))
("^[^ \t\n#>][^ \t\n]*: *\\(.*\\)$" ;property value
. (1 'font-lock-function-name-face))
("^>" ;multi-line marker
. 'bold)
("^>\\(.*\\)$" ;property value (continued)
. (1 'font-lock-function-name-face))
)
nil ;keywords-only
nil ;case-fold
;; syntax-alist: don't fontify quotes specially in any way
((?\" . "."))
nil ;syntax-begin
))
(font-lock-mode))
(defun svn-props-from-buffer ()
"Parse the current propedit buffer and return an alist of the properties."
(save-excursion
(let (prop-alist)
(goto-char (point-min))
(while (not (eobp))
(cond ((looking-at "^\\([^ \t\n#>][^ \t\n]*\\): *\\(.*\\)$")
(let ((prop-name (match-string 1))
(value (match-string 2)))
(set-text-properties 0 (length prop-name) nil prop-name)
(set-text-properties 0 (length value) nil value)
(when (assoc prop-name prop-alist)
(error "Duplicated property '%s'" prop-name))
(setq prop-alist (cons (cons prop-name value) prop-alist))))
((looking-at "^>\\(.*\\)$")
(let ((extra-line (match-string 1)))
(set-text-properties 0 (length extra-line) nil extra-line)
(when (null prop-alist)
(error "Continued line not preceded by property name"))
(let ((old-value (cdar prop-alist)))
(setcdr (car prop-alist)
(concat old-value "\n" extra-line))))))
(forward-line 1))
;; Remove the extra leading newline from multi-line values
(mapcar (lambda (prop)
(let ((name (car prop))
(value (cdr prop)))
(if (and (not (equal value ""))
(equal (substring value 0 1) "\n"))
(cons name (substring value 1))
prop)))
prop-alist))))
(defun svn-propdel (file prop-name)
"Delete FILE's property PROP-NAME."
(svn-run-hidden 'propdel (list prop-name file)))
(defun svn-propset (file prop-name prop-value)
"Set FILE's property PROP-NAME to PROP-VALUE."
(svn-run-hidden 'propset (list prop-name prop-value file)))
(defun svn-propedit-done ()
"Apply property changes to the file."
(interactive)
(let ((wc-props (svn-get-props svn-propedit-file))
(new-props (svn-props-from-buffer))
(changes 0))
;; first remove properties that the user deleted from the buffer
(mapc (lambda (wc-prop)
(let ((prop-name (car wc-prop)))
(when (not (assoc prop-name new-props))
(message "Deleting property %s" prop-name)
(svn-propdel svn-propedit-file prop-name)
(setq changes (1+ changes)))))
wc-props)
;; then set the properties that have changed or are new
(mapc (lambda (new-prop)
(let* ((prop-name (car new-prop))
(wc-prop (assoc prop-name wc-props)))
(unless (equal new-prop wc-prop)
(message "Setting property %s" prop-name)
(svn-propset svn-propedit-file prop-name (cdr new-prop))
(setq changes (1+ changes)))))
new-props)
(cond
((> changes 1) (message "Changed %d properties." changes))
((= changes 0) (message "No properties changed."))))
(svn-foreach-svn-buffer
svn-propedit-file
(lambda (local-file-name file-pos)
(svn-refresh-item local-file-name nil)))
(kill-buffer (current-buffer)))
;;; Svn buffer
(defvar svn-files-start nil)
(defvar svn-files-stop nil)
(defvar svn-url-label nil)
(defvar svn-revision-label nil)
(defvar svn-running-label nil)
(defvar svn-output-marker nil)
(defvar svn-running nil)
(defun create-svn-buffer (dir)
"Create a buffer for showing svn status.
Argument DIR is the directory to run svn in."
(let ((status-buf (create-file-buffer (concat dir "*svn*")))
(inhibit-read-only t))
(with-current-buffer status-buf
(svn-status-mode)
(make-local-variable 'svn-url-label)
(make-local-variable 'svn-revision-label)
(make-local-variable 'svn-running-label)
(make-local-variable 'svn-output-marker)
(setq default-directory dir)
(insert "Svn status for " dir) (newline)
(insert "URL: ") (setq svn-url-label (svn-new-label))
(insert " revision " ) (setq svn-revision-label (svn-new-label))
(newline)
(newline)
(insert "---- ") (setq svn-running-label (svn-new-label))
(newline)
(setq svn-files-start (point-marker))
(set-marker-insertion-type svn-files-start nil)
(setq svn-last-inserted-marker (point-marker))
(set-marker-insertion-type svn-last-inserted-marker nil)
(insert "----")
(newline)
(setq svn-output-marker (point-marker))
(set-marker-insertion-type svn-output-marker nil)
;; Do this after inserting stuff
(setq svn-files-stop (copy-marker svn-files-start t))
(setq buffer-read-only t))
status-buf))
(defun switch-to-svn-buffer (dir)
"Switch to a (possibly new) buffer displaying status for DIR"
(setq dir (file-name-as-directory dir))
(let ((buffers (buffer-list)))
(while (and buffers
(not (with-current-buffer (car buffers)
(and (eq major-mode 'svn-status-mode)
(string= default-directory dir)))))
(setq buffers (cdr buffers)))
(switch-to-buffer (if buffers
(car buffers)
(create-svn-buffer dir)))))
(defun svn-in-dir-p (dir file)
"Return non-NIL if FILE is inside DIR"
(let ((l (length dir)))
(and (> (length file) l)
(string= dir (substring file 0 l)))))
;;; Svn status
(defun svn-status (dir)
"Run `svn status'.
Argument DIR is the directory to run svn status in."
(interactive "DDirectory: \n")
(switch-to-svn-buffer dir)
(let ((proc (svn-run 'info ())))
(while (eq (process-status proc) 'run)
(accept-process-output proc 2 10000)))
(svn-refresh)
(message
(substitute-command-keys
"Welcome to dsvn. Press \\[svn-status-help] for keyboard help summary.")))
(defun svn-refresh (&optional clear)
"Run `svn status'.
If optional argument CLEAR is non-NIL, clear the buffer first."
(interactive "P")
(svn-check-running)
(let ((inhibit-read-only t))
(if clear
(delete-region svn-files-start svn-files-stop)
(put-text-property svn-files-start svn-files-stop 'svn-updated nil))
(setq svn-last-inserted-filename nil)
(svn-run 'status '())))
(defun svn-run-status-v (files recursive)
"Run svn status -v on FILES. If not RECURSIVE, only applies to files and
directories explicitly listed in FILES."
;; The command 'svn status -N DIR' will process the immediate contents of
;; DIR as well as DIR itself, but that is not what we want if running
;; non-recursively. To compensate, filter the status output through a list
;; of files and directories we are interested in.
(let ((flag (if recursive nil '("-N")))
(file-filter
(if recursive
nil
(mapcar (lambda (file)
;; trim trailing slash for directory comparison to work
(if (equal (substring file -1) "/")
(substring file 0 -1)
file))
files))))
(svn-run-async 'status-v (append flag files) file-filter)))
(defun svn-refresh-file ()
"Run `svn status' on the selected files."
(interactive)
(svn-check-running)
(let ((actions (svn-actions))
(inhibit-read-only t))
(setq svn-last-inserted-filename nil)
(put-text-property svn-files-start svn-files-stop 'svn-updated t)
(mapc (lambda (pos)
(svn-setprop pos 'updated nil))
(mapcar 'cadr actions))
(svn-run-status-v (mapcar 'car actions) t))
(svn-next-file 1))
(defun svn-local-file-name (file)
"Return file name relative the current directory, or raise an error if
outside."
(if (file-directory-p file)
(setq file (file-name-as-directory file)))
(let ((exp-default-dir (expand-file-name default-directory)))
(if (file-name-absolute-p file)
(let ((ddl (length exp-default-dir)))
(if (or (< (length file) ddl)
(not (string= (substring file 0 ddl)
exp-default-dir)))
(error "Outside working copy")
(substring file ddl)))
file)))
(defun svn-refresh-item (file recursive)
"Refresh status for FILE. If RECURSIVE, do it recursively (for directories)."
(svn-check-running)
(let ((inhibit-read-only t))
(setq svn-last-inserted-filename nil)
(let ((local-file (svn-local-file-name file)))
(svn-run-status-v (list local-file) recursive))))
(defun svn-refresh-one (file)
"Run `svn status' on FILE."
(interactive (list (expand-file-name
(read-file-name "Svn status on file: "
default-directory
nil t
(or (svn-getprop (point) 'file)
(svn-getprop (point) 'dir))))))
(svn-refresh-item file t))
(defun svn-cleanup-status ()
(save-excursion
(let ((inhibit-read-only t))
(goto-char svn-files-start)
(while (< (point) svn-files-stop)
(if (or (svn-getprop (point) 'dir)
(svn-getprop (point) 'updated))
(forward-line)
(svn-update-status-flag (point) ?\ ?\ )
(svn-update-status-msg (point) "")
(forward-line))))))
(defun svn-status-filter (proc str)
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t))
(goto-char (point-max))
(insert str)
(goto-char svn-output-marker)
(while (looking-at
"\\([ ACDGIMRX?!~][ CM][ L][ +][ S][ KOTB]\\) \\(.*\\)\n")
(let ((status (match-string 1))
(filename (match-string 2)))
(delete-region (match-beginning 0)
(match-end 0))
(svn-insert-file filename status))))))
(defun svn-status-sentinel (proc reason)
(with-current-buffer (process-buffer proc)
(svn-cleanup-status)
(svn-insert-dirs))
(svn-default-sentinel proc reason))
(defun svn-status-v-filter (proc str)
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t))
(goto-char (point-max))
(insert str)
(goto-char svn-output-marker)
(while (looking-at
"\\([ ACDGIMRX?!~][ CM][ L][ +][ S][ KOTB]\\) \\([\\* ]\\) \\(........\\) \\(........\\) \\(............\\) \\(.*\\)\n")
(let ((status (match-string 1))
(filename (match-string 6)))
(delete-region (match-beginning 0)
(match-end 0))
(when (or (not svn-file-filter)
(member filename svn-file-filter))
(svn-insert-file filename status)))))))
(defun svn-status-v-sentinel (proc reason)
(with-current-buffer (process-buffer proc)
(svn-cleanup-status))
(svn-default-sentinel proc reason))
;; info
(defun svn-info-filter (proc str)
"Output filter function for `svn info'."
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t)
(nomore))
(goto-char (point-max))
(insert str)
(goto-char svn-output-marker)
(while (not nomore)
(cond ((looking-at "URL: \\(.*\\)\n")
(svn-update-label svn-url-label (match-string 1))
(forward-line 1))
((looking-at "Revision: \\([0-9]+\\)\n")
(svn-update-label svn-revision-label (match-string 1))
(forward-line 1))
((looking-at ".*\n")
;; Unexpected output is left in the buffer
(forward-line 1))
(t
(setq nomore t)))))))
(defun svn-info-sentinel (proc reason)
(svn-default-sentinel proc reason))
;; update
(defun svn-update (dir)
"Run `svn update'.
Argument DIR is the directory to run svn status in."
(interactive "DDirectory: \n")
(switch-to-svn-buffer dir)
(svn-update-current))
(defun svn-update-current (&optional revision)
"Run `svn update' in the current buffer.
Update to REVISION, which defaults to HEAD.
With prefix arg, prompt for REVISION."
(interactive (list
(if current-prefix-arg
(read-string "update to revision (HEAD): "
nil nil "HEAD")
nil)))
(svn-check-running)
(make-local-variable 'svn-updated-files)
(setq svn-updated-files nil)
(let ((args (if revision
(list "-r" revision)
'())))
(svn-run 'update args "Updating")))
(defconst svn-update-flag-name
'((?A . "Added")
(?D . "Deleted")
(?U . "Updated")
(?G . "Merged")
(?C . "Conflict")))
(defvar svn-merging nil)
(defun svn-remap-update-to-status (status-char)
"Map a status character from the svn update command to the resulting status."
(if svn-merging
(cond ((memq status-char '(?U ?G))
?M)
(t
status-char))
(cond ((memq status-char '(?A ?D ?U))
?\ )
((eq status-char ?G)
?M)
(t
status-char))))
(defun svn-update-filter (proc str)
(save-excursion
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t)
nomore)
(goto-char (point-max))
(insert str)
(goto-char svn-output-marker)
(while (not nomore)
(cond ((looking-at
"\\([ ADUCG][ ADUCG][ B]\\) \\(.*\\)\n")
(let* ((status (match-string 1))
(file-status (elt status 0))
(prop-status (elt status 1))
(filename (match-string 2)))
(delete-region (match-beginning 0)
(match-end 0))
(svn-insert-file
filename
;; Remap A and U to unmodified in file and prop status
(format "%c%c...."
(svn-remap-update-to-status file-status)
(svn-remap-update-to-status prop-status))
;; Optimize for some common cases
(cond ((= prop-status ?\ )
(cdr (assq file-status svn-update-flag-name)))