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]

drh 2011-05-06 16:32 trunk
Commit 73c38a3add8f0c3261f1ff5d1bc5d9b343329139
1 file changed +15 -4
+15 -4
--- src/diff.c
+++ src/diff.c
@@ -626,17 +626,19 @@
626626
** of the following structure.
627627
*/
628628
typedef struct Annotator Annotator;
629629
struct Annotator {
630630
DContext c; /* The diff-engine context */
631
- struct { /* Lines of the original files... */
631
+ struct AnnLine { /* Lines of the original files... */
632632
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 */
634635
const char *zSrc; /* Tag showing origin of this line */
635636
} *aOrig;
636637
int nOrig; /* Number of elements in aOrig[] */
637638
int nNoSrc; /* Number of entries where aOrig[].zSrc==NULL */
639
+ int iLevel; /* Current level */
638640
int nVers; /* Number of versions analyzed */
639641
char **azVers; /* Names of versions analyzed */
640642
};
641643
642644
/*
@@ -670,10 +672,12 @@
670672
** pParent. Memory to hold zPName is leaked.
671673
*/
672674
static int annotation_step(Annotator *p, Blob *pParent, char *zPName){
673675
int i, j;
674676
int lnTo;
677
+ int iPrevLevel;
678
+ int iThisLevel;
675679
676680
/* Prepare the parent file to be diffed */
677681
p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
678682
&p->c.nFrom, 1);
679683
if( p->c.aFrom==0 ){
@@ -685,13 +689,20 @@
685689
diff_all(&p->c);
686690
687691
/* Where new lines are inserted on this difference, record the
688692
** zPName as the source of the new line.
689693
*/
694
+ iPrevLevel = p->iLevel;
695
+ p->iLevel++;
696
+ iThisLevel = p->iLevel;
690697
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
+ }
693704
}
694705
lnTo += p->c.aEdit[i+2];
695706
}
696707
697708
/* Clear out the diff results */
698709
--- 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

Keyboard Shortcuts

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