Fossil SCM

Continuing work on the --tk option to the 3-way-merge command.

drh 2024-12-02 21:36 merge-enhancements
Commit 57ae422a377852df2eda874d0041eedd435d012709e146af319c97179aa5482d
2 files changed +43 -23 +25 -3
+43 -23
--- src/merge.tcl
+++ src/merge.tcl
@@ -16,11 +16,11 @@
1616
LN_COL_FG #444444
1717
TXT_COL_BG #ffffff
1818
TXT_COL_FG #000000
1919
MKR_COL_BG #444444
2020
MKR_COL_FG #dddddd
21
- CHNG_BG #d0d0ff
21
+ CHNG_BG #d0d070
2222
ADD_BG #c0ffc0
2323
RM_BG #ffc0c0
2424
HR_FG #444444
2525
HR_PAD_TOP 4
2626
HR_PAD_BTM 8
@@ -40,11 +40,11 @@
4040
LN_COL_FG #444444
4141
TXT_COL_BG #3f3f3f
4242
TXT_COL_FG #dcdccc
4343
MKR_COL_BG #444444
4444
MKR_COL_FG #dddddd
45
- CHNG_BG #6a6afc
45
+ CHNG_BG #6a6a00
4646
ADD_BG #57934c
4747
RM_BG #ef6767
4848
HR_FG #444444
4949
HR_PAD_TOP 4
5050
HR_PAD_BTM 8
@@ -106,60 +106,80 @@
106106
set lnA 1
107107
set lnB 1
108108
set lnC 1
109109
set lnD 1
110110
foreach {A B C D} $mergetxt {
111
- set key [string index $A 0]
112
- if {$key=="."} {
111
+ set key1 [string index $A 0]
112
+ if {$key1=="S"} {
113
+ set N [string range $A 1 end]
114
+ incr lnA $N
115
+ incr lnB $N
116
+ incr lnC $N
117
+ incr lnD $N
118
+ .lnA insert end ...\n hrln
119
+ .txtA insert end [string repeat . 30]\n hrtxt
120
+ .lnB insert end ...\n hrln
121
+ .txtB insert end [string repeat . 30]\n hrtxt
122
+ .lnC insert end ...\n hrln
123
+ .txtC insert end [string repeat . 30]\n hrtxt
124
+ .lnD insert end ...\n hrln
125
+ .txtD insert end [string repeat . 30]\n hrtxt
126
+ continue
127
+ }
128
+ set key2 [string index $B 0]
129
+ set key3 [string index $C 0]
130
+ set key4 [string index $D 0]
131
+ if {$key1=="."} {
113132
.lnA insert end \n -
114133
.txtA insert end \n -
115134
} else {
116135
.lnA insert end $lnA\n -
117136
incr lnA
118137
.txtA insert end [string range $A 1 end]\n -
119138
}
120
- set key [string index $B 0]
121
- if {$key=="."} {
139
+ if {$key2=="."} {
122140
.lnB insert end \n -
123141
.txtB insert end \n -
124142
} else {
125143
.lnB insert end $lnB\n -
126144
incr lnB
127
- if {$key=="1"} {
128
- .txtB insert end [string range $A 1 end]\n -
145
+ if {$key4=="2"} {set tag chng} {set tag -}
146
+ if {$key2=="1"} {
147
+ .txtB insert end [string range $A 1 end]\n $tag
129148
} else {
130
- .txtB insert end [string range $B 1 end]\n -
149
+ .txtB insert end [string range $B 1 end]\n $tag
131150
}
132151
}
133
- set key [string index $C 0]
134
- if {$key=="."} {
152
+ if {$key3=="."} {
135153
.lnC insert end \n -
136154
.txtC insert end \n -
137155
} else {
138156
.lnC insert end $lnC\n -
139157
incr lnC
140
- if {$key=="1"} {
141
- .txtC insert end [string range $A 1 end]\n -
142
- } elseif {$key=="2"} {
143
- .txtC insert end [string range $B 1 end]\n -
158
+ if {$key4=="3"} {set tag add} {set tag -}
159
+ if {$key3=="1"} {
160
+ .txtC insert end [string range $A 1 end]\n $tag
161
+ } elseif {$key3=="2"} {
162
+ .txtC insert end [string range $B 1 end]\n $tag
144163
} else {
145
- .txtC insert end [string range $C 1 end]\n -
164
+ .txtC insert end [string range $C 1 end]\n $tag
146165
}
147166
}
148
- set key [string index $D 0]
149
- if {$key=="."} {
167
+ if {$key4=="."} {
150168
.lnD insert end \n -
151169
.txtD insert end \n -
152170
} else {
153171
.lnD insert end $lnD\n -
154172
incr lnD
155
- if {$key=="1"} {
173
+ if {$key4=="1"} {
156174
.txtD insert end [string range $A 1 end]\n -
157
- } elseif {$key=="2"} {
158
- .txtD insert end [string range $B 1 end]\n -
159
- } elseif {$key=="3"} {
160
- .txtD insert end [string range $C 1 end]\n -
175
+ } elseif {$key4=="2"} {
176
+ .txtD insert end [string range $B 1 end]\n chng
177
+ } elseif {$key4=="3"} {
178
+ .txtD insert end [string range $C 1 end]\n add
179
+ } elseif {$key4=="X"} {
180
+ .txtD insert end " \n" rm
161181
} else {
162182
.txtD insert end [string range $D 1 end]\n -
163183
}
164184
}
165185
}
166186
--- src/merge.tcl
+++ src/merge.tcl
@@ -16,11 +16,11 @@
16 LN_COL_FG #444444
17 TXT_COL_BG #ffffff
18 TXT_COL_FG #000000
19 MKR_COL_BG #444444
20 MKR_COL_FG #dddddd
21 CHNG_BG #d0d0ff
22 ADD_BG #c0ffc0
23 RM_BG #ffc0c0
24 HR_FG #444444
25 HR_PAD_TOP 4
26 HR_PAD_BTM 8
@@ -40,11 +40,11 @@
40 LN_COL_FG #444444
41 TXT_COL_BG #3f3f3f
42 TXT_COL_FG #dcdccc
43 MKR_COL_BG #444444
44 MKR_COL_FG #dddddd
45 CHNG_BG #6a6afc
46 ADD_BG #57934c
47 RM_BG #ef6767
48 HR_FG #444444
49 HR_PAD_TOP 4
50 HR_PAD_BTM 8
@@ -106,60 +106,80 @@
106 set lnA 1
107 set lnB 1
108 set lnC 1
109 set lnD 1
110 foreach {A B C D} $mergetxt {
111 set key [string index $A 0]
112 if {$key=="."} {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113 .lnA insert end \n -
114 .txtA insert end \n -
115 } else {
116 .lnA insert end $lnA\n -
117 incr lnA
118 .txtA insert end [string range $A 1 end]\n -
119 }
120 set key [string index $B 0]
121 if {$key=="."} {
122 .lnB insert end \n -
123 .txtB insert end \n -
124 } else {
125 .lnB insert end $lnB\n -
126 incr lnB
127 if {$key=="1"} {
128 .txtB insert end [string range $A 1 end]\n -
 
129 } else {
130 .txtB insert end [string range $B 1 end]\n -
131 }
132 }
133 set key [string index $C 0]
134 if {$key=="."} {
135 .lnC insert end \n -
136 .txtC insert end \n -
137 } else {
138 .lnC insert end $lnC\n -
139 incr lnC
140 if {$key=="1"} {
141 .txtC insert end [string range $A 1 end]\n -
142 } elseif {$key=="2"} {
143 .txtC insert end [string range $B 1 end]\n -
 
144 } else {
145 .txtC insert end [string range $C 1 end]\n -
146 }
147 }
148 set key [string index $D 0]
149 if {$key=="."} {
150 .lnD insert end \n -
151 .txtD insert end \n -
152 } else {
153 .lnD insert end $lnD\n -
154 incr lnD
155 if {$key=="1"} {
156 .txtD insert end [string range $A 1 end]\n -
157 } elseif {$key=="2"} {
158 .txtD insert end [string range $B 1 end]\n -
159 } elseif {$key=="3"} {
160 .txtD insert end [string range $C 1 end]\n -
 
 
161 } else {
162 .txtD insert end [string range $D 1 end]\n -
163 }
164 }
165 }
166
--- src/merge.tcl
+++ src/merge.tcl
@@ -16,11 +16,11 @@
16 LN_COL_FG #444444
17 TXT_COL_BG #ffffff
18 TXT_COL_FG #000000
19 MKR_COL_BG #444444
20 MKR_COL_FG #dddddd
21 CHNG_BG #d0d070
22 ADD_BG #c0ffc0
23 RM_BG #ffc0c0
24 HR_FG #444444
25 HR_PAD_TOP 4
26 HR_PAD_BTM 8
@@ -40,11 +40,11 @@
40 LN_COL_FG #444444
41 TXT_COL_BG #3f3f3f
42 TXT_COL_FG #dcdccc
43 MKR_COL_BG #444444
44 MKR_COL_FG #dddddd
45 CHNG_BG #6a6a00
46 ADD_BG #57934c
47 RM_BG #ef6767
48 HR_FG #444444
49 HR_PAD_TOP 4
50 HR_PAD_BTM 8
@@ -106,60 +106,80 @@
106 set lnA 1
107 set lnB 1
108 set lnC 1
109 set lnD 1
110 foreach {A B C D} $mergetxt {
111 set key1 [string index $A 0]
112 if {$key1=="S"} {
113 set N [string range $A 1 end]
114 incr lnA $N
115 incr lnB $N
116 incr lnC $N
117 incr lnD $N
118 .lnA insert end ...\n hrln
119 .txtA insert end [string repeat . 30]\n hrtxt
120 .lnB insert end ...\n hrln
121 .txtB insert end [string repeat . 30]\n hrtxt
122 .lnC insert end ...\n hrln
123 .txtC insert end [string repeat . 30]\n hrtxt
124 .lnD insert end ...\n hrln
125 .txtD insert end [string repeat . 30]\n hrtxt
126 continue
127 }
128 set key2 [string index $B 0]
129 set key3 [string index $C 0]
130 set key4 [string index $D 0]
131 if {$key1=="."} {
132 .lnA insert end \n -
133 .txtA insert end \n -
134 } else {
135 .lnA insert end $lnA\n -
136 incr lnA
137 .txtA insert end [string range $A 1 end]\n -
138 }
139 if {$key2=="."} {
 
140 .lnB insert end \n -
141 .txtB insert end \n -
142 } else {
143 .lnB insert end $lnB\n -
144 incr lnB
145 if {$key4=="2"} {set tag chng} {set tag -}
146 if {$key2=="1"} {
147 .txtB insert end [string range $A 1 end]\n $tag
148 } else {
149 .txtB insert end [string range $B 1 end]\n $tag
150 }
151 }
152 if {$key3=="."} {
 
153 .lnC insert end \n -
154 .txtC insert end \n -
155 } else {
156 .lnC insert end $lnC\n -
157 incr lnC
158 if {$key4=="3"} {set tag add} {set tag -}
159 if {$key3=="1"} {
160 .txtC insert end [string range $A 1 end]\n $tag
161 } elseif {$key3=="2"} {
162 .txtC insert end [string range $B 1 end]\n $tag
163 } else {
164 .txtC insert end [string range $C 1 end]\n $tag
165 }
166 }
167 if {$key4=="."} {
 
168 .lnD insert end \n -
169 .txtD insert end \n -
170 } else {
171 .lnD insert end $lnD\n -
172 incr lnD
173 if {$key4=="1"} {
174 .txtD insert end [string range $A 1 end]\n -
175 } elseif {$key4=="2"} {
176 .txtD insert end [string range $B 1 end]\n chng
177 } elseif {$key4=="3"} {
178 .txtD insert end [string range $C 1 end]\n add
179 } elseif {$key4=="X"} {
180 .txtD insert end " \n" rm
181 } else {
182 .txtD insert end [string range $D 1 end]\n -
183 }
184 }
185 }
186
+25 -3
--- src/merge3.c
+++ src/merge3.c
@@ -177,10 +177,11 @@
177177
Blob *pPivot; /* The common ancestor */
178178
Blob *pV1; /* First variant */
179179
Blob *pV2; /* Second variant */
180180
Blob *pOut; /* Write merge results here */
181181
int useCrLf; /* Use CRLF line endings */
182
+ int nContext; /* Size of unchanged line boundaries */
182183
unsigned int lnPivot; /* Lines read from pivot */
183184
unsigned int lnV1; /* Lines read from v1 */
184185
unsigned int lnV2; /* Lines read from v2 */
185186
unsigned int lnOut; /* Lines written to out */
186187
unsigned int nConflict; /* Number of conflicts seen */
@@ -353,10 +354,11 @@
353354
**
354355
** . This line is omitted.
355356
** T Literal text follows that should have a \n terminator.
356357
** R Literal text follows that needs a \r\n terminator.
357358
** Z Literal text without a line terminator.
359
+** S Skipped lines in all 4 files.
358360
** 1 Text is a copy of token 1
359361
** 2 Use data from data-token 2
360362
** 3 Use data from data-token 3
361363
*/
362364
@@ -396,15 +398,34 @@
396398
}
397399
pIn->iCursor = i;
398400
blob_append_char(pOut, '"');
399401
}
400402
static void tclSame(MergeBuilder *p, unsigned int N){
401
- int i;
402
- for(i=0; i<N; i++){
403
+ int i = 0;
404
+ int nSkip;
405
+
406
+ if( p->lnPivot>=2 || p->lnV1>2 || p->lnV2>2 ){
407
+ while( i<N && i<p->nContext ){
408
+ tclLineOfText(p->pOut, p->pPivot);
409
+ blob_append(p->pOut, " 1 1 1\n", 7);
410
+ i++;
411
+ }
412
+ nSkip = N - p->nContext*2;
413
+ }else{
414
+ nSkip = N - p->nContext;
415
+ }
416
+ if( nSkip>0 ){
417
+ blob_appendf(p->pOut, "S%d . . .\n", nSkip);
418
+ blob_copy_lines(0, p->pPivot, nSkip);
419
+ i += nSkip;
420
+ }
421
+ while( i<N ){
403422
tclLineOfText(p->pOut, p->pPivot);
404423
blob_append(p->pOut, " 1 1 1\n", 7);
424
+ i++;
405425
}
426
+
406427
p->lnPivot += N;
407428
p->lnV1 += N;
408429
p->lnV2 += N;
409430
blob_copy_lines(0, p->pV1, N);
410431
blob_copy_lines(0, p->pV2, N);
@@ -517,10 +538,11 @@
517538
p->xSame = tclSame;
518539
p->xChngV1 = tclChngV1;
519540
p->xChngV2 = tclChngV2;
520541
p->xChngBoth = tclChngBoth;
521542
p->xConflict = tclConflict;
543
+ p->nContext = 6;
522544
}
523545
/*****************************************************************************/
524546
525547
/*
526548
** aC[] is an "edit triple" for changes from A to B. Advance through
@@ -828,11 +850,11 @@
828850
}
829851
if( find_option("tcl", 0, 0) ){
830852
mergebuilder_init_tcl(&s);
831853
noWarn = 1;
832854
}
833
- flagTk = find_option("tk", 0, 0);
855
+ flagTk = find_option("tk", 0, 0)!=0;
834856
blob_zero(&pivot); s.pPivot = &pivot;
835857
blob_zero(&v1); s.pV1 = &v1;
836858
blob_zero(&v2); s.pV2 = &v2;
837859
blob_zero(&out); s.pOut = &out;
838860
839861
--- src/merge3.c
+++ src/merge3.c
@@ -177,10 +177,11 @@
177 Blob *pPivot; /* The common ancestor */
178 Blob *pV1; /* First variant */
179 Blob *pV2; /* Second variant */
180 Blob *pOut; /* Write merge results here */
181 int useCrLf; /* Use CRLF line endings */
 
182 unsigned int lnPivot; /* Lines read from pivot */
183 unsigned int lnV1; /* Lines read from v1 */
184 unsigned int lnV2; /* Lines read from v2 */
185 unsigned int lnOut; /* Lines written to out */
186 unsigned int nConflict; /* Number of conflicts seen */
@@ -353,10 +354,11 @@
353 **
354 ** . This line is omitted.
355 ** T Literal text follows that should have a \n terminator.
356 ** R Literal text follows that needs a \r\n terminator.
357 ** Z Literal text without a line terminator.
 
358 ** 1 Text is a copy of token 1
359 ** 2 Use data from data-token 2
360 ** 3 Use data from data-token 3
361 */
362
@@ -396,15 +398,34 @@
396 }
397 pIn->iCursor = i;
398 blob_append_char(pOut, '"');
399 }
400 static void tclSame(MergeBuilder *p, unsigned int N){
401 int i;
402 for(i=0; i<N; i++){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403 tclLineOfText(p->pOut, p->pPivot);
404 blob_append(p->pOut, " 1 1 1\n", 7);
 
405 }
 
406 p->lnPivot += N;
407 p->lnV1 += N;
408 p->lnV2 += N;
409 blob_copy_lines(0, p->pV1, N);
410 blob_copy_lines(0, p->pV2, N);
@@ -517,10 +538,11 @@
517 p->xSame = tclSame;
518 p->xChngV1 = tclChngV1;
519 p->xChngV2 = tclChngV2;
520 p->xChngBoth = tclChngBoth;
521 p->xConflict = tclConflict;
 
522 }
523 /*****************************************************************************/
524
525 /*
526 ** aC[] is an "edit triple" for changes from A to B. Advance through
@@ -828,11 +850,11 @@
828 }
829 if( find_option("tcl", 0, 0) ){
830 mergebuilder_init_tcl(&s);
831 noWarn = 1;
832 }
833 flagTk = find_option("tk", 0, 0);
834 blob_zero(&pivot); s.pPivot = &pivot;
835 blob_zero(&v1); s.pV1 = &v1;
836 blob_zero(&v2); s.pV2 = &v2;
837 blob_zero(&out); s.pOut = &out;
838
839
--- src/merge3.c
+++ src/merge3.c
@@ -177,10 +177,11 @@
177 Blob *pPivot; /* The common ancestor */
178 Blob *pV1; /* First variant */
179 Blob *pV2; /* Second variant */
180 Blob *pOut; /* Write merge results here */
181 int useCrLf; /* Use CRLF line endings */
182 int nContext; /* Size of unchanged line boundaries */
183 unsigned int lnPivot; /* Lines read from pivot */
184 unsigned int lnV1; /* Lines read from v1 */
185 unsigned int lnV2; /* Lines read from v2 */
186 unsigned int lnOut; /* Lines written to out */
187 unsigned int nConflict; /* Number of conflicts seen */
@@ -353,10 +354,11 @@
354 **
355 ** . This line is omitted.
356 ** T Literal text follows that should have a \n terminator.
357 ** R Literal text follows that needs a \r\n terminator.
358 ** Z Literal text without a line terminator.
359 ** S Skipped lines in all 4 files.
360 ** 1 Text is a copy of token 1
361 ** 2 Use data from data-token 2
362 ** 3 Use data from data-token 3
363 */
364
@@ -396,15 +398,34 @@
398 }
399 pIn->iCursor = i;
400 blob_append_char(pOut, '"');
401 }
402 static void tclSame(MergeBuilder *p, unsigned int N){
403 int i = 0;
404 int nSkip;
405
406 if( p->lnPivot>=2 || p->lnV1>2 || p->lnV2>2 ){
407 while( i<N && i<p->nContext ){
408 tclLineOfText(p->pOut, p->pPivot);
409 blob_append(p->pOut, " 1 1 1\n", 7);
410 i++;
411 }
412 nSkip = N - p->nContext*2;
413 }else{
414 nSkip = N - p->nContext;
415 }
416 if( nSkip>0 ){
417 blob_appendf(p->pOut, "S%d . . .\n", nSkip);
418 blob_copy_lines(0, p->pPivot, nSkip);
419 i += nSkip;
420 }
421 while( i<N ){
422 tclLineOfText(p->pOut, p->pPivot);
423 blob_append(p->pOut, " 1 1 1\n", 7);
424 i++;
425 }
426
427 p->lnPivot += N;
428 p->lnV1 += N;
429 p->lnV2 += N;
430 blob_copy_lines(0, p->pV1, N);
431 blob_copy_lines(0, p->pV2, N);
@@ -517,10 +538,11 @@
538 p->xSame = tclSame;
539 p->xChngV1 = tclChngV1;
540 p->xChngV2 = tclChngV2;
541 p->xChngBoth = tclChngBoth;
542 p->xConflict = tclConflict;
543 p->nContext = 6;
544 }
545 /*****************************************************************************/
546
547 /*
548 ** aC[] is an "edit triple" for changes from A to B. Advance through
@@ -828,11 +850,11 @@
850 }
851 if( find_option("tcl", 0, 0) ){
852 mergebuilder_init_tcl(&s);
853 noWarn = 1;
854 }
855 flagTk = find_option("tk", 0, 0)!=0;
856 blob_zero(&pivot); s.pPivot = &pivot;
857 blob_zero(&v1); s.pV1 = &v1;
858 blob_zero(&v2); s.pV2 = &v2;
859 blob_zero(&out); s.pOut = &out;
860
861

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button