author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 08 Feb 2013 08:51:42 +0100 | |
branch | jv |
changeset 12406 | 1fbd331e4489 |
parent 12401 | 4714b9640528 |
parent 12405 | 76f9a872362b |
child 12431 | 9f0c59c742d5 |
permissions | -rw-r--r-- |
9346 | 1 |
" |
2 |
COPYRIGHT (c) 2009 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
8933 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
Object subclass:#DiffListUtility |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'DiffCommandTemplate' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Text' |
|
19 |
! |
|
20 |
||
21 |
!DiffListUtility class methodsFor:'documentation'! |
|
22 |
||
9346 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 2009 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
8933 | 37 |
documentation |
38 |
" |
|
39 |
a utility to encapsulate access to the diff command |
|
9494 | 40 |
(may also be a facade to a smalltalk-diff algorithm, eventually) |
8933 | 41 |
|
42 |
[author:] |
|
43 |
cg (cg@CG-PC) |
|
44 |
||
45 |
[instance variables:] |
|
46 |
||
47 |
[class variables:] |
|
48 |
||
49 |
[see also:] |
|
50 |
||
51 |
" |
|
52 |
! ! |
|
53 |
||
12405
76f9a872362b
Merged 3efd83b86c07 and 1206aff1f11 (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
54 |
|
8933 | 55 |
!DiffListUtility class methodsFor:'defaults'! |
56 |
||
57 |
diffCommand |
|
12358 | 58 |
"return the diff-command (with argument placeHolders). |
59 |
By default, diff is used with windows, diff -b with Unix. |
|
60 |
You can change this via the diffCommandTemplate" |
|
8933 | 61 |
|
62 |
DiffCommandTemplate notNil ifTrue:[ ^ DiffCommandTemplate ]. |
|
12358 | 63 |
^ UserPreferences current externalDiffCommandTemplate |
8933 | 64 |
! |
65 |
||
66 |
diffCommandTemplate:aCommandTemplateString |
|
67 |
"set the diff-command template" |
|
68 |
||
69 |
DiffCommandTemplate := aCommandTemplateString |
|
70 |
! ! |
|
71 |
||
12405
76f9a872362b
Merged 3efd83b86c07 and 1206aff1f11 (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
72 |
|
8933 | 73 |
!DiffListUtility class methodsFor:'private'! |
74 |
||
75 |
saveForDiff:text as:filename |
|
76 |
|stream| |
|
77 |
||
78 |
[ |
|
79 |
stream := filename writeStream. |
|
80 |
text do:[:line | |
|
81 |
|lOut i| |
|
82 |
||
83 |
line notEmptyOrNil ifTrue:[ |
|
84 |
lOut := line. |
|
85 |
(line includes:Character return) ifTrue: [ |
|
86 |
(line endsWith:Character return) ifTrue:[ |
|
87 |
lOut := line copyWithoutLast:1. |
|
12384 | 88 |
]. |
89 |
] ifFalse:[ |
|
90 |
(line endsWith:(String crlf)) ifTrue: [ |
|
91 |
lOut := line copyWithoutLast:2. |
|
8933 | 92 |
] |
12384 | 93 |
"/ i := line indexOf:Character return. |
94 |
"/ (line at:i+1) == Character nl ifTrue:[ |
|
95 |
"/ "/ crnl endings |
|
96 |
"/ lOut := line copyReplaceString:(String crlf) withString:(String lf). |
|
97 |
"/ ] ifFalse:[ |
|
98 |
"/ "/ cr endings |
|
99 |
"/ lOut := line copyReplaceAll:(Character return) with:Character nl. |
|
100 |
"/ ]. |
|
101 |
"/ ] |
|
8933 | 102 |
]. |
12082 | 103 |
lOut isWideString ifTrue:[ |
8933 | 104 |
(lOut first = (Character value:16rFEFF)) ifTrue:[ |
12082 | 105 |
lOut := (lOut copyFrom:2) asSingleByteStringReplaceInvalidWith:(Character value:16rFF). |
8933 | 106 |
]. |
107 |
]. |
|
108 |
stream nextPutAll:lOut. |
|
109 |
]. |
|
110 |
stream cr |
|
111 |
]. |
|
112 |
] ensure:[ |
|
113 |
stream close. |
|
114 |
]. |
|
115 |
||
116 |
"Modified: / 22-10-2008 / 17:52:52 / cg" |
|
117 |
! ! |
|
118 |
||
12405
76f9a872362b
Merged 3efd83b86c07 and 1206aff1f11 (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
119 |
|
8933 | 120 |
!DiffListUtility class methodsFor:'utilities'! |
121 |
||
122 |
diffListFor:text1 and:text2 |
|
123 |
"execute DiffCommand to get a list of diffs." |
|
124 |
||
125 |
" |
|
126 |
The returned list is in raw-diff output format, such as: |
|
127 |
1 : '1c1' |
|
128 |
2 : '< hello world' |
|
129 |
3 : '---' |
|
130 |
4 : '> Hello World' |
|
131 |
5 : '2a3' |
|
132 |
6 : '> line2' |
|
133 |
7 : '4d4' |
|
134 |
8 : '< line4' |
|
135 |
" |
|
136 |
||
137 |
|tmpFile1 tmpFile2 stream line |
|
138 |
diffList diffTemplate diffCmd| |
|
139 |
||
140 |
diffTemplate := self diffCommand. |
|
141 |
diffTemplate isNil ifTrue:[ |
|
142 |
"/ self warn:'no diff command available'. |
|
143 |
^ nil |
|
144 |
]. |
|
145 |
||
146 |
text1 = text2 ifTrue:[ |
|
147 |
"no diff" |
|
148 |
^ #() |
|
149 |
]. |
|
150 |
||
151 |
" |
|
152 |
save them texts in two temporary files ... |
|
153 |
" |
|
154 |
[ |
|
155 |
self saveForDiff:text1 as:(tmpFile1 := Filename newTemporary). |
|
156 |
self saveForDiff:text2 as:(tmpFile2 := Filename newTemporary). |
|
157 |
||
158 |
" |
|
159 |
start diff on it ... |
|
160 |
" |
|
161 |
diffCmd := diffTemplate |
|
162 |
bindWith:tmpFile1 asString |
|
163 |
with:tmpFile2 asString. |
|
164 |
||
165 |
stream := PipeStream readingFrom:diffCmd. |
|
166 |
stream isNil ifTrue:[ |
|
12384 | 167 |
stream := PipeStream readingFrom:('support' asFilename / diffCmd). |
8933 | 168 |
stream isNil ifTrue:[ |
169 |
self error:'cannot execute diff' mayProceed:true. |
|
170 |
^ nil. |
|
171 |
] |
|
172 |
]. |
|
173 |
||
174 |
diffList := OrderedCollection new. |
|
175 |
(stream readWaitWithTimeout:10) ifTrue:[ |
|
176 |
"/ timeout |
|
177 |
stream close. |
|
178 |
self error:'cannot execute diff (timeout)' mayProceed:true. |
|
179 |
^ nil. |
|
180 |
]. |
|
181 |
||
182 |
[stream atEnd] whileFalse:[ |
|
183 |
line := stream nextLine. |
|
184 |
line notNil ifTrue:[diffList add:line] |
|
185 |
]. |
|
186 |
stream close. |
|
187 |
] ensure:[ |
|
188 |
tmpFile1 notNil ifTrue:[ tmpFile1 delete ]. |
|
189 |
tmpFile2 notNil ifTrue:[ tmpFile2 delete ]. |
|
190 |
]. |
|
191 |
^ diffList |
|
192 |
||
193 |
" |
|
194 |
self |
|
195 |
diffListFor:#( |
|
196 |
'hello world' |
|
197 |
'line1' |
|
198 |
'line3' |
|
199 |
'line4' |
|
200 |
) |
|
201 |
and: #( |
|
202 |
'Hello World' |
|
203 |
'line1' |
|
204 |
'line2' |
|
205 |
'line3' |
|
206 |
) |
|
207 |
" |
|
208 |
! ! |
|
209 |
||
12405
76f9a872362b
Merged 3efd83b86c07 and 1206aff1f11 (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
210 |
|
8933 | 211 |
!DiffListUtility class methodsFor:'documentation'! |
212 |
||
12384 | 213 |
version |
214 |
^ '$Header: /cvs/stx/stx/libtool/DiffListUtility.st,v 1.6 2013-02-01 15:13:18 cg Exp $' |
|
215 |
! |
|
216 |
||
8933 | 217 |
version_CVS |
12384 | 218 |
^ '$Header: /cvs/stx/stx/libtool/DiffListUtility.st,v 1.6 2013-02-01 15:13:18 cg Exp $' |
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12123
diff
changeset
|
219 |
! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12123
diff
changeset
|
220 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12123
diff
changeset
|
221 |
version_SVN |
12314 | 222 |
^ '$Id: DiffListUtility.st 8083 2013-01-14 11:48:37Z vranyj1 $' |
8933 | 223 |
! ! |
12358 | 224 |