Fossil SCM

In the merge engine, make sure V1 is always used for the local copy and V2 is used for the merge-in.

drh 2024-12-05 17:13 better-merge
Commit 873b364b925d88d2fcd12e469084ee63b995ca6519cb206f2164409725548c72
2 files changed +15 -15 +6 -5
+15 -15
--- src/merge.c
+++ src/merge.c
@@ -165,31 +165,31 @@
165165
rid = db_column_int(&q, 1);
166166
content_get(rid, &pivot);
167167
}
168168
mb.pPivot = &pivot;
169169
170
- /* Set up the merge-in as V1 */
170
+ /* Set up the merge-in as V2 */
171171
zFN = db_column_text(&q, 5);
172172
if( zFN==0 ){
173173
/* File deleted in the merged-in branch */
174
- mb.zV1 = "(deleted file)";
175
- blob_zero(&v1);
174
+ mb.zV2 = "(deleted file)";
175
+ blob_zero(&v2);
176176
}else{
177
- mb.zV1 = mprintf("%s (merge-in)", file_tail(zFN));
177
+ mb.zV2 = mprintf("%s (merge-in)", file_tail(zFN));
178178
rid = db_column_int(&q, 6);
179
- content_get(rid, &v1);
179
+ content_get(rid, &v2);
180180
}
181
- mb.pV1 = &v1;
181
+ mb.pV2 = &v2;
182182
183
- /* Set up the local content as V2 */
183
+ /* Set up the local content as V1 */
184184
zFN = db_column_text(&q, 2);
185185
if( zFN==0 ){
186186
/* File added by merge */
187
- mb.zV2 = "(no original)";
188
- blob_zero(&v2);
187
+ mb.zV1 = "(no original)";
188
+ blob_zero(&v1);
189189
}else{
190
- mb.zV2 = mprintf("%s (local)", file_tail(zFN));
190
+ mb.zV1 = mprintf("%s (local)", file_tail(zFN));
191191
rid = db_column_int(&q, 3);
192192
sz = db_column_int(&q, 4);
193193
if( rid==0 && sz>0 ){
194194
/* The origin file had been edited so we'll have to pull its
195195
** original content out of the undo buffer */
@@ -197,23 +197,23 @@
197197
db_prepare(&q2,
198198
"SELECT content FROM undo"
199199
" WHERE pathname=%Q AND octet_length(content)=%d",
200200
zFN, sz
201201
);
202
- blob_zero(&v2);
202
+ blob_zero(&v1);
203203
if( db_step(&q2)==SQLITE_ROW ){
204
- db_column_blob(&q, 0, &v2);
204
+ db_column_blob(&q, 0, &v1);
205205
}else{
206
- mb.zV2 = "(local content missing)";
206
+ mb.zV1 = "(local content missing)";
207207
}
208208
db_finalize(&q2);
209209
}else{
210210
/* The origin file was unchanged when the merge first occurred */
211
- content_get(rid, &v2);
211
+ content_get(rid, &v1);
212212
}
213213
}
214
- mb.pV2 = &v2;
214
+ mb.pV1 = &v1;
215215
216216
/* Set up the output */
217217
zFN = db_column_text(&q, 7);
218218
if( zFN==0 ){
219219
mb.zOut = "(Merge Result)";
220220
--- src/merge.c
+++ src/merge.c
@@ -165,31 +165,31 @@
165 rid = db_column_int(&q, 1);
166 content_get(rid, &pivot);
167 }
168 mb.pPivot = &pivot;
169
170 /* Set up the merge-in as V1 */
171 zFN = db_column_text(&q, 5);
172 if( zFN==0 ){
173 /* File deleted in the merged-in branch */
174 mb.zV1 = "(deleted file)";
175 blob_zero(&v1);
176 }else{
177 mb.zV1 = mprintf("%s (merge-in)", file_tail(zFN));
178 rid = db_column_int(&q, 6);
179 content_get(rid, &v1);
180 }
181 mb.pV1 = &v1;
182
183 /* Set up the local content as V2 */
184 zFN = db_column_text(&q, 2);
185 if( zFN==0 ){
186 /* File added by merge */
187 mb.zV2 = "(no original)";
188 blob_zero(&v2);
189 }else{
190 mb.zV2 = mprintf("%s (local)", file_tail(zFN));
191 rid = db_column_int(&q, 3);
192 sz = db_column_int(&q, 4);
193 if( rid==0 && sz>0 ){
194 /* The origin file had been edited so we'll have to pull its
195 ** original content out of the undo buffer */
@@ -197,23 +197,23 @@
197 db_prepare(&q2,
198 "SELECT content FROM undo"
199 " WHERE pathname=%Q AND octet_length(content)=%d",
200 zFN, sz
201 );
202 blob_zero(&v2);
203 if( db_step(&q2)==SQLITE_ROW ){
204 db_column_blob(&q, 0, &v2);
205 }else{
206 mb.zV2 = "(local content missing)";
207 }
208 db_finalize(&q2);
209 }else{
210 /* The origin file was unchanged when the merge first occurred */
211 content_get(rid, &v2);
212 }
213 }
214 mb.pV2 = &v2;
215
216 /* Set up the output */
217 zFN = db_column_text(&q, 7);
218 if( zFN==0 ){
219 mb.zOut = "(Merge Result)";
220
--- src/merge.c
+++ src/merge.c
@@ -165,31 +165,31 @@
165 rid = db_column_int(&q, 1);
166 content_get(rid, &pivot);
167 }
168 mb.pPivot = &pivot;
169
170 /* Set up the merge-in as V2 */
171 zFN = db_column_text(&q, 5);
172 if( zFN==0 ){
173 /* File deleted in the merged-in branch */
174 mb.zV2 = "(deleted file)";
175 blob_zero(&v2);
176 }else{
177 mb.zV2 = mprintf("%s (merge-in)", file_tail(zFN));
178 rid = db_column_int(&q, 6);
179 content_get(rid, &v2);
180 }
181 mb.pV2 = &v2;
182
183 /* Set up the local content as V1 */
184 zFN = db_column_text(&q, 2);
185 if( zFN==0 ){
186 /* File added by merge */
187 mb.zV1 = "(no original)";
188 blob_zero(&v1);
189 }else{
190 mb.zV1 = mprintf("%s (local)", file_tail(zFN));
191 rid = db_column_int(&q, 3);
192 sz = db_column_int(&q, 4);
193 if( rid==0 && sz>0 ){
194 /* The origin file had been edited so we'll have to pull its
195 ** original content out of the undo buffer */
@@ -197,23 +197,23 @@
197 db_prepare(&q2,
198 "SELECT content FROM undo"
199 " WHERE pathname=%Q AND octet_length(content)=%d",
200 zFN, sz
201 );
202 blob_zero(&v1);
203 if( db_step(&q2)==SQLITE_ROW ){
204 db_column_blob(&q, 0, &v1);
205 }else{
206 mb.zV1 = "(local content missing)";
207 }
208 db_finalize(&q2);
209 }else{
210 /* The origin file was unchanged when the merge first occurred */
211 content_get(rid, &v1);
212 }
213 }
214 mb.pV1 = &v1;
215
216 /* Set up the output */
217 zFN = db_column_text(&q, 7);
218 if( zFN==0 ){
219 mb.zOut = "(Merge Result)";
220
+6 -5
--- src/merge3.c
+++ src/merge3.c
@@ -151,12 +151,12 @@
151151
const char *zPivot; /* Label or name for the pivot */
152152
const char *zV1; /* Label or name for the V1 file */
153153
const char *zV2; /* Label or name for the V2 file */
154154
const char *zOut; /* Label or name for the output */
155155
Blob *pPivot; /* The common ancestor */
156
- Blob *pV1; /* First variant */
157
- Blob *pV2; /* Second variant */
156
+ Blob *pV1; /* First variant (local copy) */
157
+ Blob *pV2; /* Second variant (merged in) */
158158
Blob *pOut; /* Write merge results here */
159159
int useCrLf; /* Use CRLF line endings */
160160
int nContext; /* Size of unchanged line boundaries */
161161
unsigned int mxPivot; /* Number of lines in the pivot */
162162
unsigned int mxV1; /* Number of lines in V1 */
@@ -298,11 +298,12 @@
298298
MergeBuilder *p,
299299
unsigned int nPivot,
300300
unsigned int nV1,
301301
unsigned int nV2
302302
){
303
- blob_append(p->pOut, p->pV1->aData+p->pV1->iCursor, nV1);
303
+ /* For a token-merge conflict, use the text from the merge-in */
304
+ blob_append(p->pOut, p->pV2->aData+p->pV2->iCursor, nV2);
304305
p->pPivot->iCursor += nPivot;
305306
p->pV1->iCursor += nV1;
306307
p->pV2->iCursor += nV2;
307308
}
308309
static void mergebuilder_init_token(MergeBuilder *p){
@@ -406,11 +407,11 @@
406407
407408
append_merge_mark(p->pOut, 0, p->lnV1+1, p->useCrLf);
408409
blob_copy_lines(p->pOut, p->pV1, nV1); p->lnV1 += nV1;
409410
410411
if( nRes>0 ){
411
- append_merge_mark(p->pOut, 1, 10000+nRes, p->useCrLf);
412
+ append_merge_mark(p->pOut, 1, 0, p->useCrLf);
412413
blob_copy_lines(p->pOut, &res, nRes);
413414
}
414415
415416
append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
416417
blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
@@ -658,11 +659,11 @@
658659
tclLineOfText(p->pOut, &res, 'X');
659660
blob_append_char(p->pOut, '\n');
660661
}else{
661662
blob_append(p->pOut, " .\n", 3);
662663
}
663
- if( i==nRes-1 ){
664
+ if( i==mx-1 ){
664665
blob_appendf(p->pOut, "\"S0 0 0 %d\" . . .\n", nPivot+nV1+3);
665666
}
666667
}
667668
blob_reset(&res);
668669
p->lnPivot += nPivot;
669670
--- src/merge3.c
+++ src/merge3.c
@@ -151,12 +151,12 @@
151 const char *zPivot; /* Label or name for the pivot */
152 const char *zV1; /* Label or name for the V1 file */
153 const char *zV2; /* Label or name for the V2 file */
154 const char *zOut; /* Label or name for the output */
155 Blob *pPivot; /* The common ancestor */
156 Blob *pV1; /* First variant */
157 Blob *pV2; /* Second variant */
158 Blob *pOut; /* Write merge results here */
159 int useCrLf; /* Use CRLF line endings */
160 int nContext; /* Size of unchanged line boundaries */
161 unsigned int mxPivot; /* Number of lines in the pivot */
162 unsigned int mxV1; /* Number of lines in V1 */
@@ -298,11 +298,12 @@
298 MergeBuilder *p,
299 unsigned int nPivot,
300 unsigned int nV1,
301 unsigned int nV2
302 ){
303 blob_append(p->pOut, p->pV1->aData+p->pV1->iCursor, nV1);
 
304 p->pPivot->iCursor += nPivot;
305 p->pV1->iCursor += nV1;
306 p->pV2->iCursor += nV2;
307 }
308 static void mergebuilder_init_token(MergeBuilder *p){
@@ -406,11 +407,11 @@
406
407 append_merge_mark(p->pOut, 0, p->lnV1+1, p->useCrLf);
408 blob_copy_lines(p->pOut, p->pV1, nV1); p->lnV1 += nV1;
409
410 if( nRes>0 ){
411 append_merge_mark(p->pOut, 1, 10000+nRes, p->useCrLf);
412 blob_copy_lines(p->pOut, &res, nRes);
413 }
414
415 append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
416 blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
@@ -658,11 +659,11 @@
658 tclLineOfText(p->pOut, &res, 'X');
659 blob_append_char(p->pOut, '\n');
660 }else{
661 blob_append(p->pOut, " .\n", 3);
662 }
663 if( i==nRes-1 ){
664 blob_appendf(p->pOut, "\"S0 0 0 %d\" . . .\n", nPivot+nV1+3);
665 }
666 }
667 blob_reset(&res);
668 p->lnPivot += nPivot;
669
--- src/merge3.c
+++ src/merge3.c
@@ -151,12 +151,12 @@
151 const char *zPivot; /* Label or name for the pivot */
152 const char *zV1; /* Label or name for the V1 file */
153 const char *zV2; /* Label or name for the V2 file */
154 const char *zOut; /* Label or name for the output */
155 Blob *pPivot; /* The common ancestor */
156 Blob *pV1; /* First variant (local copy) */
157 Blob *pV2; /* Second variant (merged in) */
158 Blob *pOut; /* Write merge results here */
159 int useCrLf; /* Use CRLF line endings */
160 int nContext; /* Size of unchanged line boundaries */
161 unsigned int mxPivot; /* Number of lines in the pivot */
162 unsigned int mxV1; /* Number of lines in V1 */
@@ -298,11 +298,12 @@
298 MergeBuilder *p,
299 unsigned int nPivot,
300 unsigned int nV1,
301 unsigned int nV2
302 ){
303 /* For a token-merge conflict, use the text from the merge-in */
304 blob_append(p->pOut, p->pV2->aData+p->pV2->iCursor, nV2);
305 p->pPivot->iCursor += nPivot;
306 p->pV1->iCursor += nV1;
307 p->pV2->iCursor += nV2;
308 }
309 static void mergebuilder_init_token(MergeBuilder *p){
@@ -406,11 +407,11 @@
407
408 append_merge_mark(p->pOut, 0, p->lnV1+1, p->useCrLf);
409 blob_copy_lines(p->pOut, p->pV1, nV1); p->lnV1 += nV1;
410
411 if( nRes>0 ){
412 append_merge_mark(p->pOut, 1, 0, p->useCrLf);
413 blob_copy_lines(p->pOut, &res, nRes);
414 }
415
416 append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
417 blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
@@ -658,11 +659,11 @@
659 tclLineOfText(p->pOut, &res, 'X');
660 blob_append_char(p->pOut, '\n');
661 }else{
662 blob_append(p->pOut, " .\n", 3);
663 }
664 if( i==mx-1 ){
665 blob_appendf(p->pOut, "\"S0 0 0 %d\" . . .\n", nPivot+nV1+3);
666 }
667 }
668 blob_reset(&res);
669 p->lnPivot += nPivot;
670

Keyboard Shortcuts

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