Fossil SCM
In the merge engine, make sure V1 is always used for the local copy and V2 is used for the merge-in.
Commit
873b364b925d88d2fcd12e469084ee63b995ca6519cb206f2164409725548c72
Parent
adf2269602f11f6…
2 files changed
+15
-15
+6
-5
+15
-15
| --- src/merge.c | ||
| +++ src/merge.c | ||
| @@ -165,31 +165,31 @@ | ||
| 165 | 165 | rid = db_column_int(&q, 1); |
| 166 | 166 | content_get(rid, &pivot); |
| 167 | 167 | } |
| 168 | 168 | mb.pPivot = &pivot; |
| 169 | 169 | |
| 170 | - /* Set up the merge-in as V1 */ | |
| 170 | + /* Set up the merge-in as V2 */ | |
| 171 | 171 | zFN = db_column_text(&q, 5); |
| 172 | 172 | if( zFN==0 ){ |
| 173 | 173 | /* 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); | |
| 176 | 176 | }else{ |
| 177 | - mb.zV1 = mprintf("%s (merge-in)", file_tail(zFN)); | |
| 177 | + mb.zV2 = mprintf("%s (merge-in)", file_tail(zFN)); | |
| 178 | 178 | rid = db_column_int(&q, 6); |
| 179 | - content_get(rid, &v1); | |
| 179 | + content_get(rid, &v2); | |
| 180 | 180 | } |
| 181 | - mb.pV1 = &v1; | |
| 181 | + mb.pV2 = &v2; | |
| 182 | 182 | |
| 183 | - /* Set up the local content as V2 */ | |
| 183 | + /* Set up the local content as V1 */ | |
| 184 | 184 | zFN = db_column_text(&q, 2); |
| 185 | 185 | if( zFN==0 ){ |
| 186 | 186 | /* File added by merge */ |
| 187 | - mb.zV2 = "(no original)"; | |
| 188 | - blob_zero(&v2); | |
| 187 | + mb.zV1 = "(no original)"; | |
| 188 | + blob_zero(&v1); | |
| 189 | 189 | }else{ |
| 190 | - mb.zV2 = mprintf("%s (local)", file_tail(zFN)); | |
| 190 | + mb.zV1 = mprintf("%s (local)", file_tail(zFN)); | |
| 191 | 191 | rid = db_column_int(&q, 3); |
| 192 | 192 | sz = db_column_int(&q, 4); |
| 193 | 193 | if( rid==0 && sz>0 ){ |
| 194 | 194 | /* The origin file had been edited so we'll have to pull its |
| 195 | 195 | ** original content out of the undo buffer */ |
| @@ -197,23 +197,23 @@ | ||
| 197 | 197 | db_prepare(&q2, |
| 198 | 198 | "SELECT content FROM undo" |
| 199 | 199 | " WHERE pathname=%Q AND octet_length(content)=%d", |
| 200 | 200 | zFN, sz |
| 201 | 201 | ); |
| 202 | - blob_zero(&v2); | |
| 202 | + blob_zero(&v1); | |
| 203 | 203 | if( db_step(&q2)==SQLITE_ROW ){ |
| 204 | - db_column_blob(&q, 0, &v2); | |
| 204 | + db_column_blob(&q, 0, &v1); | |
| 205 | 205 | }else{ |
| 206 | - mb.zV2 = "(local content missing)"; | |
| 206 | + mb.zV1 = "(local content missing)"; | |
| 207 | 207 | } |
| 208 | 208 | db_finalize(&q2); |
| 209 | 209 | }else{ |
| 210 | 210 | /* The origin file was unchanged when the merge first occurred */ |
| 211 | - content_get(rid, &v2); | |
| 211 | + content_get(rid, &v1); | |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | - mb.pV2 = &v2; | |
| 214 | + mb.pV1 = &v1; | |
| 215 | 215 | |
| 216 | 216 | /* Set up the output */ |
| 217 | 217 | zFN = db_column_text(&q, 7); |
| 218 | 218 | if( zFN==0 ){ |
| 219 | 219 | mb.zOut = "(Merge Result)"; |
| 220 | 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 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 @@ | ||
| 151 | 151 | const char *zPivot; /* Label or name for the pivot */ |
| 152 | 152 | const char *zV1; /* Label or name for the V1 file */ |
| 153 | 153 | const char *zV2; /* Label or name for the V2 file */ |
| 154 | 154 | const char *zOut; /* Label or name for the output */ |
| 155 | 155 | 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) */ | |
| 158 | 158 | Blob *pOut; /* Write merge results here */ |
| 159 | 159 | int useCrLf; /* Use CRLF line endings */ |
| 160 | 160 | int nContext; /* Size of unchanged line boundaries */ |
| 161 | 161 | unsigned int mxPivot; /* Number of lines in the pivot */ |
| 162 | 162 | unsigned int mxV1; /* Number of lines in V1 */ |
| @@ -298,11 +298,12 @@ | ||
| 298 | 298 | MergeBuilder *p, |
| 299 | 299 | unsigned int nPivot, |
| 300 | 300 | unsigned int nV1, |
| 301 | 301 | unsigned int nV2 |
| 302 | 302 | ){ |
| 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); | |
| 304 | 305 | p->pPivot->iCursor += nPivot; |
| 305 | 306 | p->pV1->iCursor += nV1; |
| 306 | 307 | p->pV2->iCursor += nV2; |
| 307 | 308 | } |
| 308 | 309 | static void mergebuilder_init_token(MergeBuilder *p){ |
| @@ -406,11 +407,11 @@ | ||
| 406 | 407 | |
| 407 | 408 | append_merge_mark(p->pOut, 0, p->lnV1+1, p->useCrLf); |
| 408 | 409 | blob_copy_lines(p->pOut, p->pV1, nV1); p->lnV1 += nV1; |
| 409 | 410 | |
| 410 | 411 | if( nRes>0 ){ |
| 411 | - append_merge_mark(p->pOut, 1, 10000+nRes, p->useCrLf); | |
| 412 | + append_merge_mark(p->pOut, 1, 0, p->useCrLf); | |
| 412 | 413 | blob_copy_lines(p->pOut, &res, nRes); |
| 413 | 414 | } |
| 414 | 415 | |
| 415 | 416 | append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf); |
| 416 | 417 | blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot; |
| @@ -658,11 +659,11 @@ | ||
| 658 | 659 | tclLineOfText(p->pOut, &res, 'X'); |
| 659 | 660 | blob_append_char(p->pOut, '\n'); |
| 660 | 661 | }else{ |
| 661 | 662 | blob_append(p->pOut, " .\n", 3); |
| 662 | 663 | } |
| 663 | - if( i==nRes-1 ){ | |
| 664 | + if( i==mx-1 ){ | |
| 664 | 665 | blob_appendf(p->pOut, "\"S0 0 0 %d\" . . .\n", nPivot+nV1+3); |
| 665 | 666 | } |
| 666 | 667 | } |
| 667 | 668 | blob_reset(&res); |
| 668 | 669 | p->lnPivot += nPivot; |
| 669 | 670 |
| --- 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 |