-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpjb-cvs.el
776 lines (660 loc) · 27.5 KB
/
pjb-cvs.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
;;;; -*- mode:emacs-lisp;coding:utf-8 -*-
;;;;****************************************************************************
;;;;FILE: pjb-cvs.el
;;;;LANGUAGE: emacs lisp
;;;;SYSTEM: emacs
;;;;USER-INTERFACE: emacs
;;;;DESCRIPTION
;;;;
;;;; This module exports an application that analyses CVS revision graphs.
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal J. Bourguignon
;;;;MODIFICATIONS
;;;; 2002-04-06 <PJB> Creation.
;;;;BUGS
;;;;LEGAL
;;;; LGPL
;;;;
;;;; Copyright Pascal J. Bourguignon 2002 - 2011
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 2 of the License, or (at your option) any later version.
;;;;
;;;; This library 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
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;;;
;;;;****************************************************************************
(require 'pjb-object)
(require 'pjb-graph)
(require 'pjb-dot)
(provide 'pjb-cvs)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; revision = (file,version)
;; file = { revision=(file,*) }
;; tag = { {file_i,version_j), k!=l ==> file_k!=file_l }
;;
;; arc_file ( (file,v1),(file,v2) ) si v2 succède v1 (+branches)
;; arc_tag ( (tag1,tag) si existe arc_file(n1,n2) avec n1 dans tag1
;; et n2 dans tag2 )
;; poind(arc_tag(tag1,tag2)) = cardinal { arc_file(n1,n2) avec n1 dans tag1
;; et n2 dans tag2 }
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass CvsAttributedMixin ()
((attributes-plist
:initform nil
:initarg :attributes-plist
:accessor attributes-plist
:type list
:documentation
"A plist of attributes."))
(:documentation
"A mixin to store attributes as a plist."))
(defmethod* setAttribute ((self CvsAttributedMixin)
(attrName (or symbol string)) (attrValue string))
"
POST: (string-equal attrValue (getAttribute self attrName))
"
(when (stringp attrName)
(setq attrName (intern attrName)))
(setf (slot-value self 'attributes-plist)
(plist-put (attributes-plist self) attrName attrValue)))
(defmethod* getAttribute ((self CvsAttributedMixin)
(attrName (or symbol string)))
"
RETURN: The value of the attribute attrName.
"
(when (stringp attrName)
(setq attrName (intern attrName)))
(plist-get (attributes-plist self) attrName))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Some functions to manipulate revision strings ("1.2.3.1"...)
;; We convert them to vectors [1 2 3 1] instead...
(defun string-to-revision (rev-string)
"
RETURN: A vector containing the revision in binary form.
"
(let* ( (rev-list (split-string rev-string "\\."))
(rev-vector (make-vector (length rev-list) 0))
(i 0)
)
(dolist (value rev-list)
(aset rev-vector i (string-to-number value))
(setq i (1+ i)))
rev-vector))
(defun revision-to-string (rev)
"
RETURN: A string containing the numbers in the rev.
"
(unsplit-string (mapcar 'number-to-string rev) "."))
(defun revision-less-p (rev-a rev-b)
(let ((i 0)
(len-a (length rev-a))
(len-b (length rev-b))
)
(while (and (< i len-a) (< i len-b) (= (aref rev-a i) (aref rev-b i)))
(setq i (1+ i)))
(or (and (= i len-a) (< i len-b))
(and (< i len-a) (< i len-b) (< (aref rev-a i) (aref rev-b i))))))
(defun revision-magic-p (rev)
"
RETURN: Whether the revision rev is a CVS magic revision, ie. its length is odd
or the number before the last is 0.
"
(or (oddp (length rev)) (= 0 (aref rev (- (length rev) 2)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass CvsFile (PjbElement CvsAttributedMixin)
((name
:initform nil
:initarg :name
:accessor name
:type (or null string)
:documentation "RCS file name.")
(revisions
:initform (lambda () (make-instance 'PjbSet))
:initarg :revisions
:accessor revisions
:type PjbSet
:documentation "A set of CvsRevision of this file.")
(revision-graph
:initform (lambda () (make-instance 'PjbGraph :edge-class PjbDirectedEdge))
:initarg :revision-graph
:accessor revision-graph
:type PjbGraph
:documentation
"The graph of the revisions of this file.
The edges denotes the derivation order of the revisions.
Note however that merges can't be known from the file revision numbers alone."))
(:documentation
"A CVS File (RCS file)."))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass CvsRevision (PjbElement CvsAttributedMixin)
((file
:initform nil
:initarg :file
:accessor file
:type (or null CvsFile)
:documentation
"The CVS file of which this is a revision.")
(file-version
:initform "1.0"
:initarg :file-version
:accessor file-version
:type string
:documentation "The CVS version of this revision.")
(tags
:initform (lambda () (make-instance 'PjbSet))
:initarg :tags
:accessor tags
:type PjbSet
:documentation
"The tags that include this revision.")
(name
:initform nil
:accessor cached-name
:type (or null string)
:documentation "Derived name."))
(:documentation
"A CVS File (RCS file)."))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CvsFile methods:
(defmethod* description ((self CvsFile))
"
RETURN: A string describing this element.
"
(format "<A %s named %S with %d revisions>"
(class-name (class-of self))
(name self)
(cardinal (revisions self))))
(defmethod* setName ((self CvsFile) (newName string))
"
POST: (string-equal name (name self))
"
(setf (slot-value self 'name) newName))
(defmethod* addRevision ((self CvsFile) (newRevision CvsRevision))
"
PRE: (eq (file newRevision) self)
DO: Add the newRevision to the list of revisions of this file.
"
(when (eq (file newRevision) self)
(addElement (revisions self) newRevision)))
(defmethod* revisionWithVersion ((self CvsFile) (aVersion string))
"
RETURN: The revision with the version.
"
(let ( (rev (selectElements
(revisions self)
(lambda (element)
(string-equal aVersion (file-version element))))) )
(if rev (car rev) nil)))
(defmethod* addRootRevisionIfMissing ((self CvsFile))
"
DO: If there's no revision 1.1, then add one.
RETURN: The root revision (ie. the revision 1.1).
"
(let ((result (revisionWithVersion self "1.1")))
(unless result
(setq result (make-instance 'CvsRevision :file self :file-version "1.1"))
(addRevision self result))
result))
(defun pjb-cvs$$eat-revision (revision-root revision-list eat-revision-add-edge)
"
PRIVATE. Used by `computeRevisionGraph'.
"
(let ((current (car revision-list)))
(while (and revision-list
(<= (length (car revision-root)) (length (car current))))
;;(show revision-list)
(while (and revision-list
(= (length (car revision-root)) (length (car current))))
(funcall eat-revision-add-edge revision-root current)
(setq revision-root current)
(setq revision-list (cdr revision-list))
(setq current (car revision-list)))
(when (and revision-list
(< (length (car revision-root)) (length (car current))))
(funcall eat-revision-add-edge revision-root current)
(setq revision-list (pjb-cvs$$eat-revision current (cdr revision-list)
eat-revision-add-edge))
(setq current (car revision-list)))))
revision-list)
(defmethod* computeRevisionGraph ((self CvsFile))
"
DO: Compute the revision graph from the revision numbers of this file.
POST: (revision-graph self) is a directed tree (directed cycleless graph).
RETURN: (revision-graph self)
"
(let* ((sorted-revisions
(sort
(mapElements (revisions self)
(lambda (element)
(cons (string-to-revision (file-version element))
element)))
(lambda (vra vrb) (revision-less-p (car vra) (car vrb)))))
(graph (make-instance 'PjbGraph
:nodes (revisions self)
:edge-class PjbDirectedEdge))
(eat-revision-add-edge
(lambda (from to)
(addEdgeBetweenNodes graph (cdr from) (cdr to)))) )
(pjb-cvs$$eat-revision (car sorted-revisions) (cdr sorted-revisions)
eat-revision-add-edge)
(setf (slot-value self 'revision-graph) graph)
(revision-graph self)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CvsRevision methods:
(defmethod* description ((self CvsRevision))
"
RETURN: A string describing this element.
"
(format "<A %s of file %S, version %s>"
(class-name (class-of self))
(name (file self))
(file-version self)))
(defmethod* name ((self CvsRevision))
"
RETURN: A name for this revision instance.
"
(unless (cached-name self)
(setf (slot-value self 'name)
(format "%s-%s" (name (file self)) (file-version self))) )
(cached-name self))
;; (defmethod* identicalTo ((self CvsRevision) (other PjbElement))
;; "
;; RETURN: Whether self and other are identical, that is, if they have the
;; same file and their versions are equal.
;; "
;; (or (eq self other)
;; (and (is-kind-of other CvsRevision)
;; (eq (file self) (file other))
;; (string-equal (file-version self) (file-version other))))
;; )
(defmethod* isMagicBranchRevision ((self CvsRevision))
"
RETURN: Whether this revision file-version is a magic branch revision number.
"
;;elispism:
(string-match "^.*\.0\.[0-9]+$" (file-version self)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass CvsTag (PjbSet)
;; ------------------------------------------------------------ ;;
;; ------------ CvsTag is a PjbSet of CvsRevision ------------- ;;
;; ------------------------------------------------------------ ;;
((name
:initform nil
:initarg :name
:accessor name
:type symbol
:documentation "symbolic name of the tag.")
(date
:initform nil
:accessor cached-date
:type (or null string)
:documentation "Derived date, from revisions."))
(:documentation
"A tag is a named set of revisions. Its name identifies it."))
(defmethod* addTag ((self CvsRevision) (tag CvsTag))
"
POST: (containsElement (tags self) tag)
"
(addElement (tags self) tag))
(defmethod* description ((self CvsTag))
"
RETURN: A string describing this element.
"
(format "<A %s named %S>"
(class-name (class-of self))
(name self)))
;; (defmethod* identicalTo ((self CvsTag) (other PjbElement))
;; "
;; RETURN: Whether self and other are identical, that is,
;; if they have the same name.
;; "
;; (or (eq self other)
;; (and (is-kind-of other CvsTag)
;; (eq (name self) (name other))))
;; )
(defmethod* setName ((self CvsTag) (newName (or string symbol)))
"
POST: (eq (intern newName) (name self))
"
(when (stringp newName)
(setq newName (intern newName)))
(setf (slot-value self 'name) newName))
(defun getRevisionList-dates (tag)
"
RETURN: A list containing the dates of the revisions of tag.
"
;; (declare (tag CvsTag))
(mapcar (lambda (revision) (getAttribute revision "date"))
(elements tag)))
(defmethod* date ((self CvsTag))
"
RETURN: The date of the youngest revision in this tag.
"
(unless (cached-date self)
(setf (slot-value self 'date)
(car (sort
(mapcar (lambda (revision) (getAttribute revision "date"))
(elements self))
'string> ))))
(cached-date self))
(defmethod* revisionForFile ((self CvsTag) (file CvsFile))
"
RETURN: The revision of the file `file' in this tag.
"
(car (selectElements self (lambda (revision) (eq file (file revision))))))
(defmethod* isBranchTagForFile ((self CvsTag) (file CvsFile))
"
RETURN: Whether this tag is a branch tag for the given `file', that is,
the penultimian number of the version number of the file's revision
in this tag is 0.
"
(let ( (revision (revisionForFile self file)) )
(if revision (isMagicBranchRevision revision) nil)))
(defmethod* getRevisionList ((self CvsTag))
"
RETURN: A list containing the file revisions in the form of conses
(file-name . version) of this tag.
"
(mapcar (lambda (revision) (cons (name (file revision))
(file-version revision)))
(elements self)))
(defun pjb-cvs%find-tag-named (tag-set tag-name)
"
RETURN: The tag named `tag-name' in the set of CvsTag `tags'.
"
;; (declare (tag-set PjbSet) (tag-name symbol))
(car (selectElements tag-set (lambda (node) (eq (name node) tag-name)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generating dot files
(defmethod* generate-dot ((self CvsRevision))
"
RETURN: A string containing the dot file data for this CvsRevision node.
"
(format
"%S [ style=filled color=black fillcolor=LightYellow label=\"%s\\n%s\" ];\n"
(name self)
(let* ((got nil)
(tag (selectElements
(tags self) (lambda (elem) (if got nil (setq got t)))))
)
(if (car tag) (name (car tag)) ""))
(file-version self)))
(defmethod* generate-dot ((self CvsTag))
"
RETURN: A string containing the dot file data for this CvsTag node.
"
(let ((sn (cl:string (name self))))
(format "%S [ style=filled color=Black fillcolor=SkyBlue label=\"%s\\n%s\" ];\n"
sn sn (date self))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar pjb-cvs%*ignore-descriptions* t
"set to nil to keep the descriptions from cvs log. They tend to be big.")
(defun pjb-cvs%parse-log (cvs-log-output)
(let ((files (make-instance 'PjbSet))
(tags (make-instance 'PjbSet)))
(dolist (file-data (split-string cvs-log-output "^=============================================================================\n"))
;; processing one file
(let* ((file-revs-l (split-string file-data
"^----------------------------\n"))
(file-lines (split-string (car file-revs-l) "\n"))
(revs-l (cdr file-revs-l))
(file (make-instance 'CvsFile))
(symbolic-names nil)
line value tag)
;; ---------------------
;; 1- file header
(while file-lines
(setq line (car file-lines))
(setq file-lines (cdr file-lines))
(cond
((string-equal line "description:")
(unless pjb-cvs%*ignore-descriptions*
;; end of attributes, the rest of lines are description.
(when file-lines
(setAttribute file "description"
(unsplit-string file-lines "\n"))
(setq file-lines nil))))
((setq value (chop-prefix line "RCS file:"))
(setName file (chop-spaces value)))
((setq value (chop-prefix line "cvs server:"))
;; ignore
)
((setq value (chop-prefix line "? "))
;; ignore
)
((setq value (chop-prefix line "symbolic names:"))
;; nop; the tags follow.
)
((setq value (chop-prefix line "\t"))
;; tag (symbolic names)
(setq symbolic-names (cons value symbolic-names)))
((setq value (chop-prefix line "total revisions:"))
;; we must split
(let ((rsr (split-string value "[;:][\t ]*")))
(setAttribute file "total revisions" (car rsr))
(setAttribute file (nth 1 rsr) (nth 2 rsr))))
(t
(setq line (split-string line ": *"))
(when (not (string-equal (cadr line) ""))
(setAttribute file (car line) (cadr line))))))
;; ---------------------
;; 2- revisions
(dolist (rev revs-l)
(let* ((rev-lines (split-string rev "\n"))
(rev-num (chop-prefix (car rev-lines) "revision "))
(attributes (split-string (nth 1 rev-lines) "[:;][ \t]+"))
(description)
(revision (make-instance 'CvsRevision
:file file
:file-version rev-num)))
(unless pjb-cvs%*ignore-descriptions*
(setq description (unsplit-string (cddr rev-lines) "\n"))
(setAttribute revision "description" description))
(while attributes
(setAttribute revision (car attributes) (cadr attributes))
(setq attributes (cddr attributes)))
(addRevision file revision)))
;; ---------------------
;; 3- tag symbolic names
(dolist (sn symbolic-names)
(let* ((tag-revision (split-string sn ": "))
(tag-name (intern (car tag-revision)))
(version (cadr tag-revision))
(tag (selectElements
tags (lambda (elem) (eq (name elem) tag-name))))
(revision))
(if tag
(setq tag (car tag))
(setq tag (make-instance 'CvsTag :name tag-name)))
(setq revision (revisionWithVersion file version))
(unless revision
(setq revision (make-instance 'CvsRevision
:file file :file-version version))
(addRevision file revision))
(addElement tag revision)
(addTag revision tag)
(addElement tags tag)))
(addElement files file)))
(cons files tags)))
(defun pjb-cvs%computeTagGraph-2 (files tags)
"
DO: Compute the tag graph containing as nodes the tags, and edges
deduced from the revision graphs of the files.
RETURN: The computed graph.
"
(let ((graph (make-instance 'PjbGraph
:nodes tags
:edges (make-instance PjbHashedSet)
:edge-class PjbWeightedDirectedEdge)))
;; check if an INIT tag exists (tag with all revisions 1.1)
;; if not, create it.
;;
;; for each file in files,...
(performWithElements
files
(lambda (file)
;; We need to do a walk of the revision tree,
;; starting from the root "1.1",
;; collecting a "pre-tag" node and a "cur-tag" such as:
;; (not (isMagicBranchRevision pre-rev))
;; (not (isMagicBranchRevision cur-rev))
;; there is a pre-tag in (tags pre-rev)
;; there is a cur-tag in (tags cur-rev)
;; cur-rev is the first successor of pre-rev
;; matching the previous conditions.
(let ((rev-graph (revision-graph file))
(rev-stack '()) ; stack of walked revisions: ((rev suc...)...)
(tev-stack '()) ; stack of tagged revisions.
cur-item cur-rev cur-suc cur-sucs newEdge edge)
(setq cur-rev (revisionWithVersion file "1.1"))
(setq cur-sucs (successorNodes rev-graph cur-rev))
(push (cons cur-rev cur-sucs) rev-stack)
(when (and (not (isMagicBranchRevision cur-rev))
(< 0 (cardinal (tags cur-rev))))
(push cur-rev tev-stack))
(while rev-stack
;;(printf "\nrev-stack=%S\ntev-stack=%S\n"
;; (mapcar (lambda (item) (mapcar 'name item)) rev-stack)
;; (mapcar 'name tev-stack))
(setq cur-item (pop rev-stack))
(setq cur-rev (car cur-item))
(setq cur-sucs (cdr cur-item))
(if (null cur-sucs)
;; no more successors, let's pop.
(if (eq (car tev-stack) cur-rev)
(pop tev-stack))
(progn
(setq cur-suc (car cur-sucs))
;; We need to push even when there's no other successor
;; to be able to pop when needed.
(push (cons cur-rev (cdr cur-sucs)) rev-stack)
(if (and (not (isMagicBranchRevision cur-suc))
(< 0 (cardinal (tags cur-suc))))
(progn
;; got an edge.
;;; (printf "%-16s -> %-16s %-16S => %S\n"
;;; (name cur-rev) (name cur-suc)
;;; (mapcar 'name (elements (tags (car tev-stack))))
;;; (mapcar 'name (elements (tags cur-suc))))
(if (car tev-stack)
(dolist (ftag (elements (tags (car tev-stack))))
(dolist (ttag (elements (tags cur-suc)))
(setq edge
(car (edgesBetweenNodes graph ftag ttag)))
;; There should be only one edge from ftag to ttag.
(if edge
(setWeight edge (1+ (weight edge)))
(addEdgeBetweenNodes graph ftag ttag)))))
(push cur-suc tev-stack))
;;(printf "%-16s -> %-16s\n" (name cur-rev) (name cur-suc))
)
(setq cur-rev cur-suc)
(setq cur-sucs (successorNodes rev-graph cur-rev))
(push (cons cur-rev cur-sucs) rev-stack)))))))
graph))
(defun pjb-cvs%computeTagGraph (files tags)
(let ((graph (make-instance 'PjbGraph
:nodes tags
:edges (make-instance PjbHashedSet)
:edge-class PjbWeightedDirectedEdge)))
;; for each tag
;; for each revision in tag (Files of revisions are unique)
;; for each successor of revision
;; find tags where successor belongs
;; (if there's no tag, get successor's successor's).
;; add and edge from current tag to these successor tags
;; or increment existing edge weight.
(performWithElements
tags
(lambda (tag)
(printf "%s\n" (name tag))
(performWithElements
tag;; is a set of revision.
(lambda (revision)
(message "%-20s %-47s %s"
(name tag) (name (file revision)) (file-version revision))
;;(message "cardinal(edges)=%d" (cardinal (edges graph)))
;; successors are in the file's revision graph.
(let* ( (rev-graph (revision-graph (file revision)))
(successors (successorNodes rev-graph revision))
(checked '())
successor succ-tags edge newEdge)
(printf "file=%S\nrevision=%S successors=%S\n\n" (name (file revision)) (file-version revision) (mapcar (lambda (s) (file-version s)) successors))
;;(message "cardinal(successors)=%d" (length successors))
(while successors
(setq successor (car successors)
successors (cdr successors)
succ-tags (tags successor))
(unless (memq successor checked)
(push successor checked)
;;(message "cardinal(tags successor)=%d" (if succ-tags (cardinal succ-tags) 0))
(if (null succ-tags)
;; let's look the successor's successors.
(dolist (new-succ (successorNodes rev-graph successor))
(unless (or (memq new-succ checked)
(memq new-succ successors))
(push new-succ successors)))
;; let's add edges or increment the existing edges' weight.
(performWithElements
(tags successor)
(lambda (to-tag)
(setq newEdge (make-instance PjbWeightedDirectedEdge
:from tag :to to-tag))
(setq edge (containsElement (edges graph) newEdge))
;; There should be only one edge from tag to to-tag.
(if edge
(setWeight edge (1+ (weight edge)))
(addEdge graph newEdge))))))))))))
graph))
(defun pjb-cvs%get-tag-graph-from-cvs-in-dir (dir-path &optional file-list)
"
NOTE: When file-list is given, then only cvs log those files
(relative from dir-path).
RETURN: A (list tag-graph files tags) containing the tag-graph (PjbGraph),
the files (PjbSet of CvsFile) and the tags (PjbSet of CvsTag).
"
(let* ((cvs-log-out-fname (format "/tmp/%s" (gensym "cvs-log-output-")))
(cmd (format "cd %s ; cvs log %s > %s 2> /dev/null"
(shell-quote-argument dir-path)
(if file-list
(unsplit-string file-list " ")
"")
(shell-quote-argument cvs-log-out-fname)))
(cvs-log-out (progn (shell-command cmd nil nil)
(string-from-file-literally cvs-log-out-fname)))
(pjb-cvs%*ignore-descriptions* t)
(files-tags (pjb-cvs%parse-log cvs-log-out))
(files (car files-tags))
(tags (cdr files-tags))
tag-graph)
(delete-file cvs-log-out-fname)
(message "Got %d files, and %d tags." (cardinal files) (cardinal tags))
(performWithElements files
(lambda (file)
(addRootRevisionIfMissing file)
(computeRevisionGraph file)))
;; (setq tag-graph (pjb-cvs%computeTagGraph-2 files tags))
(list tag-graph files tags)))
(defun pjb-cvs%order-edges-chronologically (graph)
"
PRE: graph is a graph of CvsTag.
DO: All edges such as (STRING> (date (from edge)) (date (to edge)))
are reversed (ie. their from and to nodes are exchanged).
"
(performWithElements
(edges graph)
(lambda (edge)
(when (STRING> (date (from edge)) (date (to edge)))
(setNodes edge (to edge) (from edge))))))
;;;; THE END ;;;;