Fossil

Check-in [57ae422a37]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Continuing work on the --tk option to the 3-way-merge command.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | merge-enhancements
Files: files | file ages | folders
SHA3-256: 57ae422a377852df2eda874d0041eedd435d012709e146af319c97179aa5482d
User & Date: drh 2024-12-02 21:36:55.237
Context
2024-12-03
01:06
Improvements to the new merge display. check-in: 7002d98d73 user: drh tags: merge-enhancements
2024-12-02
21:36
Continuing work on the --tk option to the 3-way-merge command. check-in: 57ae422a37 user: drh tags: merge-enhancements
2024-11-28
21:54
Preliminary implementation of a --tk option to the 3-way-merge command. Lots of work left to do to get this working well. check-in: bdcacd55be user: drh tags: merge-enhancements
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/merge.tcl.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  TITLE      {Fossil Diff}
  LN_COL_BG  #dddddd
  LN_COL_FG  #444444
  TXT_COL_BG #ffffff
  TXT_COL_FG #000000
  MKR_COL_BG #444444
  MKR_COL_FG #dddddd
  CHNG_BG    #d0d0ff
  ADD_BG     #c0ffc0
  RM_BG      #ffc0c0
  HR_FG      #444444
  HR_PAD_TOP 4
  HR_PAD_BTM 8
  FN_BG      #444444
  FN_FG      #ffffff







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  TITLE      {Fossil Diff}
  LN_COL_BG  #dddddd
  LN_COL_FG  #444444
  TXT_COL_BG #ffffff
  TXT_COL_FG #000000
  MKR_COL_BG #444444
  MKR_COL_FG #dddddd
  CHNG_BG    #d0d070
  ADD_BG     #c0ffc0
  RM_BG      #ffc0c0
  HR_FG      #444444
  HR_PAD_TOP 4
  HR_PAD_BTM 8
  FN_BG      #444444
  FN_FG      #ffffff
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  TITLE      {Fossil Diff}
  LN_COL_BG  #dddddd
  LN_COL_FG  #444444
  TXT_COL_BG #3f3f3f
  TXT_COL_FG #dcdccc
  MKR_COL_BG #444444
  MKR_COL_FG #dddddd
  CHNG_BG    #6a6afc
  ADD_BG     #57934c
  RM_BG      #ef6767
  HR_FG      #444444
  HR_PAD_TOP 4
  HR_PAD_BTM 8
  FN_BG      #5e5e5e
  FN_FG      #ffffff







|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  TITLE      {Fossil Diff}
  LN_COL_BG  #dddddd
  LN_COL_FG  #444444
  TXT_COL_BG #3f3f3f
  TXT_COL_FG #dcdccc
  MKR_COL_BG #444444
  MKR_COL_FG #dddddd
  CHNG_BG    #6a6a00
  ADD_BG     #57934c
  RM_BG      #ef6767
  HR_FG      #444444
  HR_PAD_TOP 4
  HR_PAD_BTM 8
  FN_BG      #5e5e5e
  FN_FG      #ffffff
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
    $c delete 1.0 end
  }
  set lnA 1
  set lnB 1
  set lnC 1
  set lnD 1
  foreach {A B C D} $mergetxt {
    set key [string index $A 0]
    if {$key=="."} {



















      .lnA insert end \n -
      .txtA insert end \n -
    } else {
      .lnA insert end $lnA\n -
      incr lnA
      .txtA insert end [string range $A 1 end]\n -
    }
    set key [string index $B 0]
    if {$key=="."} {
      .lnB insert end \n -
      .txtB insert end \n -
    } else {
      .lnB insert end $lnB\n -
      incr lnB

      if {$key=="1"} {
        .txtB insert end [string range $A 1 end]\n -
      } else {
        .txtB insert end [string range $B 1 end]\n -
      }
    }
    set key [string index $C 0]
    if {$key=="."} {
      .lnC insert end \n -
      .txtC insert end \n -
    } else {
      .lnC insert end $lnC\n -
      incr lnC

      if {$key=="1"} {
        .txtC insert end [string range $A 1 end]\n -
      } elseif {$key=="2"} {
        .txtC insert end [string range $B 1 end]\n -
      } else {
        .txtC insert end [string range $C 1 end]\n -
      }
    }
    set key [string index $D 0]
    if {$key=="."} {
      .lnD insert end \n -
      .txtD insert end \n -
    } else {
      .lnD insert end $lnD\n -
      incr lnD
      if {$key=="1"} {
        .txtD insert end [string range $A 1 end]\n -
      } elseif {$key=="2"} {
        .txtD insert end [string range $B 1 end]\n -
      } elseif {$key=="3"} {
        .txtD insert end [string range $C 1 end]\n -


      } else {
        .txtD insert end [string range $D 1 end]\n -
      }
    }
  }
  foreach c [cols] {
    set type [colType $c]







|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







<
|





>
|
|

|


<
|





>
|
|
|
|

|


<
|





|

|
|
|
|
>
>







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
    $c delete 1.0 end
  }
  set lnA 1
  set lnB 1
  set lnC 1
  set lnD 1
  foreach {A B C D} $mergetxt {
    set key1 [string index $A 0]
    if {$key1=="S"} {
      set N [string range $A 1 end]
      incr lnA $N
      incr lnB $N
      incr lnC $N
      incr lnD $N
      .lnA insert end ...\n hrln
      .txtA insert end [string repeat . 30]\n hrtxt
      .lnB insert end ...\n hrln
      .txtB insert end [string repeat . 30]\n hrtxt
      .lnC insert end ...\n hrln
      .txtC insert end [string repeat . 30]\n hrtxt
      .lnD insert end ...\n hrln
      .txtD insert end [string repeat . 30]\n hrtxt
      continue
    }
    set key2 [string index $B 0]
    set key3 [string index $C 0]
    set key4 [string index $D 0]
    if {$key1=="."} {
      .lnA insert end \n -
      .txtA insert end \n -
    } else {
      .lnA insert end $lnA\n -
      incr lnA
      .txtA insert end [string range $A 1 end]\n -
    }

    if {$key2=="."} {
      .lnB insert end \n -
      .txtB insert end \n -
    } else {
      .lnB insert end $lnB\n -
      incr lnB
      if {$key4=="2"} {set tag chng} {set tag -}
      if {$key2=="1"} {
        .txtB insert end [string range $A 1 end]\n $tag
      } else {
        .txtB insert end [string range $B 1 end]\n $tag
      }
    }

    if {$key3=="."} {
      .lnC insert end \n -
      .txtC insert end \n -
    } else {
      .lnC insert end $lnC\n -
      incr lnC
      if {$key4=="3"} {set tag add} {set tag -}
      if {$key3=="1"} {
        .txtC insert end [string range $A 1 end]\n $tag
      } elseif {$key3=="2"} {
        .txtC insert end [string range $B 1 end]\n $tag
      } else {
        .txtC insert end [string range $C 1 end]\n $tag
      }
    }

    if {$key4=="."} {
      .lnD insert end \n -
      .txtD insert end \n -
    } else {
      .lnD insert end $lnD\n -
      incr lnD
      if {$key4=="1"} {
        .txtD insert end [string range $A 1 end]\n -
      } elseif {$key4=="2"} {
        .txtD insert end [string range $B 1 end]\n chng
      } elseif {$key4=="3"} {
        .txtD insert end [string range $C 1 end]\n add
      } elseif {$key4=="X"} {
        .txtD insert end "     \n" rm
      } else {
        .txtD insert end [string range $D 1 end]\n -
      }
    }
  }
  foreach c [cols] {
    set type [colType $c]
Changes to src/merge3.c.
175
176
177
178
179
180
181

182
183
184
185
186
187
188
  const char *zV2;           /* Label or name for the V2 file */
  const char *zOut;          /* Label or name for the output */
  Blob *pPivot;              /* The common ancestor */
  Blob *pV1;                 /* First variant */
  Blob *pV2;                 /* Second variant */
  Blob *pOut;                /* Write merge results here */
  int useCrLf;               /* Use CRLF line endings */

  unsigned int lnPivot;      /* Lines read from pivot */
  unsigned int lnV1;         /* Lines read from v1 */
  unsigned int lnV2;         /* Lines read from v2 */
  unsigned int lnOut;        /* Lines written to out */
  unsigned int nConflict;    /* Number of conflicts seen */
};








>







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  const char *zV2;           /* Label or name for the V2 file */
  const char *zOut;          /* Label or name for the output */
  Blob *pPivot;              /* The common ancestor */
  Blob *pV1;                 /* First variant */
  Blob *pV2;                 /* Second variant */
  Blob *pOut;                /* Write merge results here */
  int useCrLf;               /* Use CRLF line endings */
  int nContext;              /* Size of unchanged line boundaries */
  unsigned int lnPivot;      /* Lines read from pivot */
  unsigned int lnV1;         /* Lines read from v1 */
  unsigned int lnV2;         /* Lines read from v2 */
  unsigned int lnOut;        /* Lines written to out */
  unsigned int nConflict;    /* Number of conflicts seen */
};

351
352
353
354
355
356
357

358
359
360
361
362
363
364
** respectively.  The first character of each token provides auxiliary
** information:
**
**     .     This line is omitted.
**     T     Literal text follows that should have a \n terminator.
**     R     Literal text follows that needs a \r\n terminator.
**     Z     Literal text without a line terminator.

**     1     Text is a copy of token 1
**     2     Use data from data-token 2
**     3     Use data from data-token 3
*/

/* Copy one line of text from pIn and append to pOut, encoded as TCL */
static void tclLineOfText(Blob *pOut, Blob *pIn){







>







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
** respectively.  The first character of each token provides auxiliary
** information:
**
**     .     This line is omitted.
**     T     Literal text follows that should have a \n terminator.
**     R     Literal text follows that needs a \r\n terminator.
**     Z     Literal text without a line terminator.
**     S     Skipped lines in all 4 files.
**     1     Text is a copy of token 1
**     2     Use data from data-token 2
**     3     Use data from data-token 3
*/

/* Copy one line of text from pIn and append to pOut, encoded as TCL */
static void tclLineOfText(Blob *pOut, Blob *pIn){
394
395
396
397
398
399
400
401

402


403
404

405















406
407
408
409
410
411
412
      blob_append_char(pOut, c);
    }
  }
  pIn->iCursor = i;
  blob_append_char(pOut, '"');
}
static void tclSame(MergeBuilder *p, unsigned int N){
  int i;

  for(i=0; i<N; i++){


    tclLineOfText(p->pOut, p->pPivot);
    blob_append(p->pOut, " 1 1 1\n", 7);

  }















  p->lnPivot += N;
  p->lnV1 += N;
  p->lnV2 += N;
  blob_copy_lines(0, p->pV1, N);
  blob_copy_lines(0, p->pV2, N);
}
static void tclChngV1(MergeBuilder *p, unsigned int nPivot, unsigned int nV1){







|
>
|
>
>
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
      blob_append_char(pOut, c);
    }
  }
  pIn->iCursor = i;
  blob_append_char(pOut, '"');
}
static void tclSame(MergeBuilder *p, unsigned int N){
  int i = 0;
  int nSkip;

  if( p->lnPivot>=2 || p->lnV1>2 || p->lnV2>2 ){
    while( i<N && i<p->nContext ){
      tclLineOfText(p->pOut, p->pPivot);
      blob_append(p->pOut, " 1 1 1\n", 7);
      i++;
    }
    nSkip = N - p->nContext*2;
  }else{
    nSkip = N - p->nContext;
  }
  if( nSkip>0 ){
    blob_appendf(p->pOut, "S%d . . .\n", nSkip);
    blob_copy_lines(0, p->pPivot, nSkip);
    i += nSkip;
  }
  while( i<N ){
    tclLineOfText(p->pOut, p->pPivot);
    blob_append(p->pOut, " 1 1 1\n", 7);
    i++;
  }

  p->lnPivot += N;
  p->lnV1 += N;
  p->lnV2 += N;
  blob_copy_lines(0, p->pV1, N);
  blob_copy_lines(0, p->pV2, N);
}
static void tclChngV1(MergeBuilder *p, unsigned int nPivot, unsigned int nV1){
515
516
517
518
519
520
521

522
523
524
525
526
527
528
static void mergebuilder_init_tcl(MergeBuilder *p){
  mergebuilder_init(p);
  p->xSame = tclSame;
  p->xChngV1 = tclChngV1;
  p->xChngV2 = tclChngV2;
  p->xChngBoth = tclChngBoth;
  p->xConflict = tclConflict;

}
/*****************************************************************************/

/*
** aC[] is an "edit triple" for changes from A to B.  Advance through
** this triple to determine the number of lines to bypass on B in order
** to match an advance of sz lines on A.







>







536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
static void mergebuilder_init_tcl(MergeBuilder *p){
  mergebuilder_init(p);
  p->xSame = tclSame;
  p->xChngV1 = tclChngV1;
  p->xChngV2 = tclChngV2;
  p->xChngBoth = tclChngBoth;
  p->xConflict = tclConflict;
  p->nContext = 6;
}
/*****************************************************************************/

/*
** aC[] is an "edit triple" for changes from A to B.  Advance through
** this triple to determine the number of lines to bypass on B in order
** to match an advance of sz lines on A.
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  if( find_option("debug", 0, 0) ){
    mergebuilder_init(&s);
  }
  if( find_option("tcl", 0, 0) ){
    mergebuilder_init_tcl(&s);
    noWarn = 1;
  }
  flagTk = find_option("tk", 0, 0);
  blob_zero(&pivot); s.pPivot = &pivot;
  blob_zero(&v1);    s.pV1 = &v1;
  blob_zero(&v2);    s.pV2 = &v2;
  blob_zero(&out);   s.pOut = &out;

  /* We should be done with options.. */
  verify_all_options();







|







848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
  if( find_option("debug", 0, 0) ){
    mergebuilder_init(&s);
  }
  if( find_option("tcl", 0, 0) ){
    mergebuilder_init_tcl(&s);
    noWarn = 1;
  }
  flagTk = find_option("tk", 0, 0)!=0;
  blob_zero(&pivot); s.pPivot = &pivot;
  blob_zero(&v1);    s.pV1 = &v1;
  blob_zero(&v2);    s.pV2 = &v2;
  blob_zero(&out);   s.pOut = &out;

  /* We should be done with options.. */
  verify_all_options();