Fossil SCM
Improvements to the annotation algorithm so that if a line changes from X to Y then back to X, the annotation shows the second X not the first. Ticket [f0f9aff371f26]
Commit
73c38a3add8f0c3261f1ff5d1bc5d9b343329139
Parent
bd36723c3d77111…
1 file changed
+15
-4
+15
-4
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -626,17 +626,19 @@ | ||
| 626 | 626 | ** of the following structure. |
| 627 | 627 | */ |
| 628 | 628 | typedef struct Annotator Annotator; |
| 629 | 629 | struct Annotator { |
| 630 | 630 | DContext c; /* The diff-engine context */ |
| 631 | - struct { /* Lines of the original files... */ | |
| 631 | + struct AnnLine { /* Lines of the original files... */ | |
| 632 | 632 | const char *z; /* The text of the line */ |
| 633 | - int n; /* Number of bytes (omitting trailing space and \n) */ | |
| 633 | + short int n; /* Number of bytes (omitting trailing space and \n) */ | |
| 634 | + short int iLevel; /* Level at which tag was set */ | |
| 634 | 635 | const char *zSrc; /* Tag showing origin of this line */ |
| 635 | 636 | } *aOrig; |
| 636 | 637 | int nOrig; /* Number of elements in aOrig[] */ |
| 637 | 638 | int nNoSrc; /* Number of entries where aOrig[].zSrc==NULL */ |
| 639 | + int iLevel; /* Current level */ | |
| 638 | 640 | int nVers; /* Number of versions analyzed */ |
| 639 | 641 | char **azVers; /* Names of versions analyzed */ |
| 640 | 642 | }; |
| 641 | 643 | |
| 642 | 644 | /* |
| @@ -670,10 +672,12 @@ | ||
| 670 | 672 | ** pParent. Memory to hold zPName is leaked. |
| 671 | 673 | */ |
| 672 | 674 | static int annotation_step(Annotator *p, Blob *pParent, char *zPName){ |
| 673 | 675 | int i, j; |
| 674 | 676 | int lnTo; |
| 677 | + int iPrevLevel; | |
| 678 | + int iThisLevel; | |
| 675 | 679 | |
| 676 | 680 | /* Prepare the parent file to be diffed */ |
| 677 | 681 | p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent), |
| 678 | 682 | &p->c.nFrom, 1); |
| 679 | 683 | if( p->c.aFrom==0 ){ |
| @@ -685,13 +689,20 @@ | ||
| 685 | 689 | diff_all(&p->c); |
| 686 | 690 | |
| 687 | 691 | /* Where new lines are inserted on this difference, record the |
| 688 | 692 | ** zPName as the source of the new line. |
| 689 | 693 | */ |
| 694 | + iPrevLevel = p->iLevel; | |
| 695 | + p->iLevel++; | |
| 696 | + iThisLevel = p->iLevel; | |
| 690 | 697 | for(i=lnTo=0; i<p->c.nEdit; i+=3){ |
| 691 | - for(j=0; j<p->c.aEdit[i]; j++, lnTo++){ | |
| 692 | - p->aOrig[lnTo].zSrc = zPName; | |
| 698 | + struct AnnLine *x = &p->aOrig[lnTo]; | |
| 699 | + for(j=0; j<p->c.aEdit[i]; j++, lnTo++, x++){ | |
| 700 | + if( x->zSrc==0 || x->iLevel==iPrevLevel ){ | |
| 701 | + x->zSrc = zPName; | |
| 702 | + x->iLevel = iThisLevel; | |
| 703 | + } | |
| 693 | 704 | } |
| 694 | 705 | lnTo += p->c.aEdit[i+2]; |
| 695 | 706 | } |
| 696 | 707 | |
| 697 | 708 | /* Clear out the diff results */ |
| 698 | 709 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -626,17 +626,19 @@ | |
| 626 | ** of the following structure. |
| 627 | */ |
| 628 | typedef struct Annotator Annotator; |
| 629 | struct Annotator { |
| 630 | DContext c; /* The diff-engine context */ |
| 631 | struct { /* Lines of the original files... */ |
| 632 | const char *z; /* The text of the line */ |
| 633 | int n; /* Number of bytes (omitting trailing space and \n) */ |
| 634 | const char *zSrc; /* Tag showing origin of this line */ |
| 635 | } *aOrig; |
| 636 | int nOrig; /* Number of elements in aOrig[] */ |
| 637 | int nNoSrc; /* Number of entries where aOrig[].zSrc==NULL */ |
| 638 | int nVers; /* Number of versions analyzed */ |
| 639 | char **azVers; /* Names of versions analyzed */ |
| 640 | }; |
| 641 | |
| 642 | /* |
| @@ -670,10 +672,12 @@ | |
| 670 | ** pParent. Memory to hold zPName is leaked. |
| 671 | */ |
| 672 | static int annotation_step(Annotator *p, Blob *pParent, char *zPName){ |
| 673 | int i, j; |
| 674 | int lnTo; |
| 675 | |
| 676 | /* Prepare the parent file to be diffed */ |
| 677 | p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent), |
| 678 | &p->c.nFrom, 1); |
| 679 | if( p->c.aFrom==0 ){ |
| @@ -685,13 +689,20 @@ | |
| 685 | diff_all(&p->c); |
| 686 | |
| 687 | /* Where new lines are inserted on this difference, record the |
| 688 | ** zPName as the source of the new line. |
| 689 | */ |
| 690 | for(i=lnTo=0; i<p->c.nEdit; i+=3){ |
| 691 | for(j=0; j<p->c.aEdit[i]; j++, lnTo++){ |
| 692 | p->aOrig[lnTo].zSrc = zPName; |
| 693 | } |
| 694 | lnTo += p->c.aEdit[i+2]; |
| 695 | } |
| 696 | |
| 697 | /* Clear out the diff results */ |
| 698 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -626,17 +626,19 @@ | |
| 626 | ** of the following structure. |
| 627 | */ |
| 628 | typedef struct Annotator Annotator; |
| 629 | struct Annotator { |
| 630 | DContext c; /* The diff-engine context */ |
| 631 | struct AnnLine { /* Lines of the original files... */ |
| 632 | const char *z; /* The text of the line */ |
| 633 | short int n; /* Number of bytes (omitting trailing space and \n) */ |
| 634 | short int iLevel; /* Level at which tag was set */ |
| 635 | const char *zSrc; /* Tag showing origin of this line */ |
| 636 | } *aOrig; |
| 637 | int nOrig; /* Number of elements in aOrig[] */ |
| 638 | int nNoSrc; /* Number of entries where aOrig[].zSrc==NULL */ |
| 639 | int iLevel; /* Current level */ |
| 640 | int nVers; /* Number of versions analyzed */ |
| 641 | char **azVers; /* Names of versions analyzed */ |
| 642 | }; |
| 643 | |
| 644 | /* |
| @@ -670,10 +672,12 @@ | |
| 672 | ** pParent. Memory to hold zPName is leaked. |
| 673 | */ |
| 674 | static int annotation_step(Annotator *p, Blob *pParent, char *zPName){ |
| 675 | int i, j; |
| 676 | int lnTo; |
| 677 | int iPrevLevel; |
| 678 | int iThisLevel; |
| 679 | |
| 680 | /* Prepare the parent file to be diffed */ |
| 681 | p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent), |
| 682 | &p->c.nFrom, 1); |
| 683 | if( p->c.aFrom==0 ){ |
| @@ -685,13 +689,20 @@ | |
| 689 | diff_all(&p->c); |
| 690 | |
| 691 | /* Where new lines are inserted on this difference, record the |
| 692 | ** zPName as the source of the new line. |
| 693 | */ |
| 694 | iPrevLevel = p->iLevel; |
| 695 | p->iLevel++; |
| 696 | iThisLevel = p->iLevel; |
| 697 | for(i=lnTo=0; i<p->c.nEdit; i+=3){ |
| 698 | struct AnnLine *x = &p->aOrig[lnTo]; |
| 699 | for(j=0; j<p->c.aEdit[i]; j++, lnTo++, x++){ |
| 700 | if( x->zSrc==0 || x->iLevel==iPrevLevel ){ |
| 701 | x->zSrc = zPName; |
| 702 | x->iLevel = iThisLevel; |
| 703 | } |
| 704 | } |
| 705 | lnTo += p->c.aEdit[i+2]; |
| 706 | } |
| 707 | |
| 708 | /* Clear out the diff results */ |
| 709 |