Fossil

Check-in [47cdbbf2]
Login

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

Overview
Comment:Added two (local) options to sbsdiff (allow expansion and max columns limit), though they can't be changed in runtime yet. Added some missing error handling.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | jan-sbsdiff
Files: files | file ages | folders
SHA1:47cdbbf2fb82664ce8150edce8a6a39c5738394c
User & Date: jan 2011-10-14 22:21:28
Context
2011-10-15
00:26
Code documentation. check-in: 9b7955b5 user: jan tags: jan-sbsdiff
2011-10-14
22:21
Added two (local) options to sbsdiff (allow expansion and max columns limit), though they can't be changed in runtime yet. Added some missing error handling. check-in: 47cdbbf2 user: jan tags: jan-sbsdiff
22:17
Minor diff view change for the black'n'white skin. check-in: 07714601 user: jan tags: jan-sbsdiff
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/diff.c.

577
578
579
580
581
582
583
















584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601


602
603
604
605
606
607
608
609
610
611
612

613
614


615
616
617
618
619
620
621


622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

644

645


646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
...
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
...
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
...
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
    */
    free(c.aFrom);
    free(c.aTo);
    return c.aEdit;
  }
}


















/*
 * References in the fossil repository:
 * /vdiff?from=080d27a&to=4b0f813&detail=1
 * /vdiff?from=636804745b&to=c1d78e0556&detail=1
 * /vdiff?from=c0b6c28d29&to=25169506b7&detail=1
 * /vdiff?from=e3d022dffa&to=48bcfbd47b&detail=1
 */
int *html_sbsdiff(
  Blob *pA_Blob,   /* FROM file */
  Blob *pB_Blob,   /* TO file */
  int nContext,    /* Amount of context to unified diff */
  int ignoreEolWs  /* Ignore whitespace at the end of lines */
){
  DContext c;
  int i;
  int iFrom, iTo;
  char *linebuf;



  /* Prepare the input files */
  memset(&c, 0, sizeof(c));
  c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
                             &c.nFrom, ignoreEolWs);
  c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
                           &c.nTo, ignoreEolWs);
  if( c.aFrom==0 || c.aTo==0 ){
    free(c.aFrom);
    free(c.aTo);
    /* TODO Error handling */

    return 0;
  }



  /* Compute the difference */
  diff_all(&c);

  linebuf = fossil_malloc(LENGTH_MASK+1);
  if( !linebuf ){
    /* TODO Handle error */


  }

  iFrom=iTo=0;
  i=0;
  while( i<c.nEdit ){
    int j;
    /* Copied lines */
    for( j=0; j<c.aEdit[i]; j++){
      int len;
      int dist;

      /* Hide lines which are copied and are further away from block boundaries
      ** then nConext lines. For each block with hidden lines, show a row
      ** notifying the user about the hidden rows.
      */
      if( j<nContext || j>c.aEdit[i]-nContext-1 ){
        @ <tr>
      }else if( j==nContext && j<c.aEdit[i]-nContext-1 ){
        @ <tr>
        @ <td class="meta" colspan="5" style="white-space: nowrap;">
        @ %d(c.aEdit[i]-2*nContext) hidden line(s).</td>
        @ </tr>

        continue;

      }else{


        @ <tr style="display:none;">
      }

      len = c.aFrom[iFrom+j].h & LENGTH_MASK;
      memcpy(linebuf, c.aFrom[iFrom+j].z, len);
      linebuf[len] = '\0';
      @ <td class="lineno">%d(iFrom+j+1)</td><td>%s(linebuf)</td>

      @ <td> </td>

      len = c.aTo[iTo+j].h & LENGTH_MASK;
      memcpy(linebuf, c.aTo[iTo+j].z, len);
      linebuf[len] = '\0';
      @ <td class="lineno">%d(iTo+j+1)</td><td>%s(linebuf)</td>

      @ </tr>
    }
    iFrom+=c.aEdit[i];
    iTo+=c.aEdit[i];

................................................................................

      /* Assume changed lines */
      for( j=0; j<lim; j++ ){
        int len;
        @ <tr>

        if( j<c.aEdit[i+1] ){
          len = c.aFrom[iFrom+j].h & LENGTH_MASK;
          memcpy(linebuf, c.aFrom[iFrom+j].z, len);
          linebuf[len] = '\0';
          @ <td class="changed lineno">%d(iFrom+j+1)</td>
          @ <td class="changed">%s(linebuf)</td>
        }else{
           @ <td colspan="2"/>
        }

        @ <td class="changed">|</td>

        if( j<c.aEdit[i+2] ){
          len = c.aTo[iTo+j].h & LENGTH_MASK;
          memcpy(linebuf, c.aTo[iTo+j].z, len);
          linebuf[len] = '\0';
          @ <td class="changed lineno">%d(iTo+j+1)</td>
          @ <td class="changed">%s(linebuf)</td>
        }else{
          @ <td colspan="2"/>
        }

        @ </tr>
................................................................................
    }else{

      /* Process deleted lines */
      for( j=0; j<c.aEdit[i+1]; j++ ){
        int len;
        @ <tr>

        len = c.aFrom[iFrom+j].h & LENGTH_MASK;
        memcpy(linebuf, c.aFrom[iFrom+j].z, len);
        linebuf[len] = '\0';
        @ <td class="removed lineno">%d(iFrom+j+1)</td>
        @ <td class="removed">%s(linebuf)</td>

        @ <td>&lt;</td>

        @ <td colspan="2"/>

................................................................................
      for( j=0; j<c.aEdit[i+2]; j++ ){
        int len;
        @ <tr>
        @ <td colspan="2"/>

        @ <td>&gt;</td>

        len = c.aTo[iTo+j].h & LENGTH_MASK;
        memcpy(linebuf, c.aTo[iTo+j].z, len);
        linebuf[len] = '\0';
        @ <td class="added lineno">%d(iTo+j+1)</td>
        @ <td class="added">%s(linebuf)</td>

        @ </tr>
      }
      iTo+=c.aEdit[i+2];
    }
................................................................................
    i+=3;
  }

  free(linebuf);
  free(c.aFrom);
  free(c.aTo);
  free(c.aEdit);
  return 0;
}


/*
** COMMAND: test-rawdiff
*/
void test_rawdiff_cmd(void){







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








|









>
>










|
>


>
>






|
>
>












|







|

>
|
>

>
>



|
<
<




|
<
<







 







|
<
<









|
<
<







 







|
<
<







 







|
<
<







 







|







577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676


677
678
679
680
681


682
683
684
685
686
687
688
...
692
693
694
695
696
697
698
699


700
701
702
703
704
705
706
707
708
709


710
711
712
713
714
715
716
...
720
721
722
723
724
725
726
727


728
729
730
731
732
733
734
...
740
741
742
743
744
745
746
747


748
749
750
751
752
753
754
...
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
    */
    free(c.aFrom);
    free(c.aTo);
    return c.aEdit;
  }
}

/*
** Copy a line with a limit. Used for side-by-side diffs to enforce a maximum
** line length limit.
*/
static char *copylimline(char *out, DLine *dl, int lim){
  int len;
  len = dl->h & LENGTH_MASK;
  if( lim && len > lim ){
    memcpy(out, dl->z, lim-3);
    strcpy(&out[lim-3], "...");
  }else{
    memcpy(out, dl->z, len);
    out[len] = '\0';
  }
  return out;
}

/*
 * References in the fossil repository:
 * /vdiff?from=080d27a&to=4b0f813&detail=1
 * /vdiff?from=636804745b&to=c1d78e0556&detail=1
 * /vdiff?from=c0b6c28d29&to=25169506b7&detail=1
 * /vdiff?from=e3d022dffa&to=48bcfbd47b&detail=1
 */
int html_sbsdiff(
  Blob *pA_Blob,   /* FROM file */
  Blob *pB_Blob,   /* TO file */
  int nContext,    /* Amount of context to unified diff */
  int ignoreEolWs  /* Ignore whitespace at the end of lines */
){
  DContext c;
  int i;
  int iFrom, iTo;
  char *linebuf;
  int collim=0; /* Currently not settable; allows a column limit for diffs */
  int allowExp=0; /* Currently not settable; (dis)allow expansion of rows */

  /* Prepare the input files */
  memset(&c, 0, sizeof(c));
  c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
                             &c.nFrom, ignoreEolWs);
  c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
                           &c.nTo, ignoreEolWs);
  if( c.aFrom==0 || c.aTo==0 ){
    free(c.aFrom);
    free(c.aTo);
    @ <p class="generalError" style="white-space: nowrap">cannot compute
    @ difference between binary files</p>
    return 0;
  }

  collim = collim < 4 ? 0 : collim;

  /* Compute the difference */
  diff_all(&c);

  linebuf = fossil_malloc(LENGTH_MASK+1);
  if( !linebuf ){
    free(c.aFrom);
    free(c.aTo);
    return 0;
  }

  iFrom=iTo=0;
  i=0;
  while( i<c.nEdit ){
    int j;
    /* Copied lines */
    for( j=0; j<c.aEdit[i]; j++){
      int len;
      int dist;

      /* Hide lines which are copied and are further away from block boundaries
      ** than nConext lines. For each block with hidden lines, show a row
      ** notifying the user about the hidden rows.
      */
      if( j<nContext || j>c.aEdit[i]-nContext-1 ){
        @ <tr>
      }else if( j==nContext && j<c.aEdit[i]-nContext-1 ){
        @ <tr>
        @ <td class="meta" colspan="5" style="white-space: nowrap;">
        @ %d(c.aEdit[i]-2*nContext) hidden lines</td>
        @ </tr>
        if( !allowExp )
           continue;
        @ <tr style="display:none;">
      }else{
        if( !allowExp )
           continue;
        @ <tr style="display:none;">
      }

      copylimline(linebuf, &c.aFrom[iFrom+j], collim);


      @ <td class="lineno">%d(iFrom+j+1)</td><td>%s(linebuf)</td>

      @ <td> </td>

      copylimline(linebuf, &c.aTo[iTo+j], collim);


      @ <td class="lineno">%d(iTo+j+1)</td><td>%s(linebuf)</td>

      @ </tr>
    }
    iFrom+=c.aEdit[i];
    iTo+=c.aEdit[i];

................................................................................

      /* Assume changed lines */
      for( j=0; j<lim; j++ ){
        int len;
        @ <tr>

        if( j<c.aEdit[i+1] ){
          copylimline(linebuf, &c.aFrom[iFrom+j], collim);


          @ <td class="changed lineno">%d(iFrom+j+1)</td>
          @ <td class="changed">%s(linebuf)</td>
        }else{
           @ <td colspan="2"/>
        }

        @ <td class="changed">|</td>

        if( j<c.aEdit[i+2] ){
          copylimline(linebuf, &c.aTo[iTo+j], collim);


          @ <td class="changed lineno">%d(iTo+j+1)</td>
          @ <td class="changed">%s(linebuf)</td>
        }else{
          @ <td colspan="2"/>
        }

        @ </tr>
................................................................................
    }else{

      /* Process deleted lines */
      for( j=0; j<c.aEdit[i+1]; j++ ){
        int len;
        @ <tr>

        copylimline(linebuf, &c.aFrom[iFrom+j], collim);


        @ <td class="removed lineno">%d(iFrom+j+1)</td>
        @ <td class="removed">%s(linebuf)</td>

        @ <td>&lt;</td>

        @ <td colspan="2"/>

................................................................................
      for( j=0; j<c.aEdit[i+2]; j++ ){
        int len;
        @ <tr>
        @ <td colspan="2"/>

        @ <td>&gt;</td>

        copylimline(linebuf, &c.aTo[iTo+j], collim);


        @ <td class="added lineno">%d(iTo+j+1)</td>
        @ <td class="added">%s(linebuf)</td>

        @ </tr>
      }
      iTo+=c.aEdit[i+2];
    }
................................................................................
    i+=3;
  }

  free(linebuf);
  free(c.aFrom);
  free(c.aTo);
  free(c.aEdit);
  return 1;
}


/*
** COMMAND: test-rawdiff
*/
void test_rawdiff_cmd(void){

Changes to src/info.c.

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    }else{
      @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
      @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a>
    }
    if( showDiff ){
      if( sideBySide ){
         @ <table class="sbsdiff">
         @ <tr><th colspan="2" class="diffhdr"">Old (%s(zOld))</th><th/>
         @ <th colspan="2" class="diffhdr">New (%s(zNew))</th></tr>
         generate_sbsdiff(zOld, zNew);
         @ </table>
      }else{
        @ <blockquote><pre>
        append_diff(zOld, zNew);
        @ </pre></blockquote>
      }







|
|







356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    }else{
      @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
      @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a>
    }
    if( showDiff ){
      if( sideBySide ){
         @ <table class="sbsdiff">
         @ <tr><th colspan="2" class="diffhdr">Old (%S(zOld))</th><th/>
         @ <th colspan="2" class="diffhdr">New (%S(zNew))</th></tr>
         generate_sbsdiff(zOld, zNew);
         @ </table>
      }else{
        @ <blockquote><pre>
        append_diff(zOld, zNew);
        @ </pre></blockquote>
      }