Fossil SCM

Add button to annotate/blame pages. Also minor bug fix for annotate/blame pages url rendering.

andybradford 2014-03-05 06:14 UTC pending-review
Commit f1e99a5a408c42a70e9c811f35f6ad8e459bdbc6
1 file changed +29 -10
+29 -10
--- src/diff.c
+++ src/diff.c
@@ -1994,16 +1994,16 @@
19941994
/*
19951995
** Initialize the annotation process by specifying the file that is
19961996
** to be annotated. The annotator takes control of the input Blob and
19971997
** will release it when it is finished with it.
19981998
*/
1999
-static int annotation_start(Annotator *p, Blob *pInput){
1999
+static int annotation_start(Annotator *p, Blob *pInput, u64 diffFlags){
20002000
int i;
20012001
20022002
memset(p, 0, sizeof(*p));
20032003
p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
2004
- DIFF_IGNORE_SOLWS|DIFF_IGNORE_EOLWS);
2004
+ diffFlags);
20052005
if( p->c.aTo==0 ){
20062006
return 1;
20072007
}
20082008
p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
20092009
for(i=0; i<p->c.nTo; i++){
@@ -2020,17 +2020,17 @@
20202020
** being annotated. Do another step of the annotation. Return true
20212021
** if additional annotation is required. zPName is the tag to insert
20222022
** on each line of the file being annotated that was contributed by
20232023
** pParent. Memory to hold zPName is leaked.
20242024
*/
2025
-static int annotation_step(Annotator *p, Blob *pParent, int iVers){
2025
+static int annotation_step(Annotator *p, Blob *pParent, int iVers, u64 diffFlags){
20262026
int i, j;
20272027
int lnTo;
20282028
20292029
/* Prepare the parent file to be diffed */
20302030
p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
2031
- &p->c.nFrom, DIFF_IGNORE_SOLWS|DIFF_IGNORE_EOLWS);
2031
+ &p->c.nFrom, diffFlags);
20322032
if( p->c.aFrom==0 ){
20332033
return 1;
20342034
}
20352035
20362036
/* Compute the differences going from pParent to the file being
@@ -2077,11 +2077,12 @@
20772077
static void annotate_file(
20782078
Annotator *p, /* The annotator */
20792079
int fnid, /* The name of the file to be annotated */
20802080
int mid, /* Use the version of the file in this check-in */
20812081
int iLimit, /* Limit the number of levels if greater than zero */
2082
- int annFlags /* Flags to alter the annotation */
2082
+ int annFlags, /* Flags to alter the annotation */
2083
+ u64 diffFlags /* Flags to alter the whitespace handling */
20832084
){
20842085
Blob toAnnotate; /* Text of the final (mid) version of the file */
20852086
Blob step; /* Text of previous revision */
20862087
int rid; /* Artifact ID of the file being annotated */
20872088
Stmt q; /* Query returning all ancestor versions */
@@ -2095,11 +2096,11 @@
20952096
}
20962097
if( !content_get(rid, &toAnnotate) ){
20972098
fossil_fatal("unable to retrieve content of artifact #%d", rid);
20982099
}
20992100
if( iLimit<=0 ) iLimit = 1000000000;
2100
- annotation_start(p, &toAnnotate);
2101
+ annotation_start(p, &toAnnotate, diffFlags);
21012102
db_begin_transaction();
21022103
db_multi_exec(
21032104
"CREATE TEMP TABLE IF NOT EXISTS vseen(rid INTEGER PRIMARY KEY);"
21042105
"DELETE FROM vseen;"
21052106
);
@@ -2129,11 +2130,11 @@
21292130
p->aVers[p->nVers].zMUuid = fossil_strdup(db_column_text(&q, 1));
21302131
p->aVers[p->nVers].zDate = fossil_strdup(db_column_text(&q, 2));
21312132
p->aVers[p->nVers].zUser = fossil_strdup(db_column_text(&q, 3));
21322133
if( p->nVers ){
21332134
content_get(rid, &step);
2134
- annotation_step(p, &step, p->nVers-1);
2135
+ annotation_step(p, &step, p->nVers-1, diffFlags);
21352136
blob_reset(&step);
21362137
}
21372138
p->nVers++;
21382139
db_bind_int(&ins, ":rid", rid);
21392140
db_step(&ins);
@@ -2185,10 +2186,12 @@
21852186
int fnid;
21862187
int i;
21872188
int iLimit; /* Depth limit */
21882189
int annFlags = ANN_FILE_ANCEST;
21892190
int showLog = 0; /* True to display the log */
2191
+ int ignoreWs = 0; /* Ignore whitespace */
2192
+ u64 diffFlags = 0; /* diff flags for ignore whitespace */
21902193
const char *zFilename; /* Name of file to annotate */
21912194
const char *zCI; /* The check-in containing zFilename */
21922195
Annotator ann;
21932196
HQuery url;
21942197
struct AnnVers *p;
@@ -2204,26 +2207,40 @@
22042207
zFilename = P("filename");
22052208
fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
22062209
if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
22072210
iLimit = atoi(PD("limit","20"));
22082211
if( P("filevers") ) annFlags |= ANN_FILE_VERS;
2212
+ ignoreWs = atoi(PD("w","0"))!=0;
2213
+ if( ignoreWs ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS);
22092214
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
22102215
fossil_redirect_home();
22112216
}
22122217
22132218
/* compute the annotation */
22142219
compute_direct_ancestors(mid, 10000000);
2215
- annotate_file(&ann, fnid, mid, iLimit, annFlags);
2220
+ annotate_file(&ann, fnid, mid, iLimit, annFlags, diffFlags);
22162221
zCI = ann.aVers[0].zMUuid;
22172222
22182223
/* generate the web page */
22192224
style_header("Annotation For %h", zFilename);
2220
- url_initialize(&url, "annotate");
2225
+ if( bBlame ){
2226
+ url_initialize(&url, "blame");
2227
+ }else{
2228
+ url_initialize(&url, "annotate");
2229
+ }
22212230
url_add_parameter(&url, "checkin", P("checkin"));
22222231
url_add_parameter(&url, "filename", zFilename);
22232232
if( iLimit!=20 ){
22242233
url_add_parameter(&url, "limit", sqlite3_mprintf("%d", iLimit));
2234
+ }
2235
+ url_add_parameter(&url, "w", ignoreWs ? "1" : "0");
2236
+ if( ignoreWs ){
2237
+ style_submenu_element("Show Whitespace Changes", "Show Whitespace Changes",
2238
+ "%s", url_render(&url, "w", "0", 0, 0));
2239
+ }else{
2240
+ style_submenu_element("Ignore Whitespace", "Ignore Whitespace",
2241
+ "%s", url_render(&url, "w", "1", 0, 0));
22252242
}
22262243
url_add_parameter(&url, "log", showLog ? "1" : "0");
22272244
if( showLog ){
22282245
style_submenu_element("Hide Log", "Hide Log",
22292246
"%s", url_render(&url, "log", "0", 0, 0));
@@ -2361,19 +2378,21 @@
23612378
Annotator ann; /* The annotation of the file */
23622379
int i; /* Loop counter */
23632380
const char *zLimit; /* The value to the -n|--limit option */
23642381
int iLimit; /* How far back in time to look */
23652382
int showLog; /* True to show the log */
2383
+ u64 diffFlags = 0;/* Flags to control whitespace handling */
23662384
int fileVers; /* Show file version instead of check-in versions */
23672385
int annFlags = 0; /* Flags to control annotation properties */
23682386
int bBlame = 0; /* True for BLAME output. False for ANNOTATE. */
23692387
23702388
bBlame = g.argv[1][0]=='b';
23712389
zLimit = find_option("limit","n",1);
23722390
if( zLimit==0 || zLimit[0]==0 ) zLimit = "-1";
23732391
iLimit = atoi(zLimit);
23742392
showLog = find_option("log","l",0)!=0;
2393
+ if( find_option("w",0,0)!=0 ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS);
23752394
fileVers = find_option("filevers",0,0)!=0;
23762395
db_must_be_within_tree();
23772396
if( g.argc<3 ) {
23782397
usage("FILENAME");
23792398
}
@@ -2399,11 +2418,11 @@
23992418
fid, fnid);
24002419
if( mid==0 ){
24012420
fossil_fatal("unable to find manifest");
24022421
}
24032422
annFlags |= ANN_FILE_ANCEST;
2404
- annotate_file(&ann, fnid, mid, iLimit, annFlags);
2423
+ annotate_file(&ann, fnid, mid, iLimit, annFlags, diffFlags);
24052424
if( showLog ){
24062425
struct AnnVers *p;
24072426
for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
24082427
fossil_print("version %3d: %s %.10s file %.10s\n",
24092428
i+1, p->zDate, p->zMUuid, p->zFUuid);
24102429
--- src/diff.c
+++ src/diff.c
@@ -1994,16 +1994,16 @@
1994 /*
1995 ** Initialize the annotation process by specifying the file that is
1996 ** to be annotated. The annotator takes control of the input Blob and
1997 ** will release it when it is finished with it.
1998 */
1999 static int annotation_start(Annotator *p, Blob *pInput){
2000 int i;
2001
2002 memset(p, 0, sizeof(*p));
2003 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
2004 DIFF_IGNORE_SOLWS|DIFF_IGNORE_EOLWS);
2005 if( p->c.aTo==0 ){
2006 return 1;
2007 }
2008 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2009 for(i=0; i<p->c.nTo; i++){
@@ -2020,17 +2020,17 @@
2020 ** being annotated. Do another step of the annotation. Return true
2021 ** if additional annotation is required. zPName is the tag to insert
2022 ** on each line of the file being annotated that was contributed by
2023 ** pParent. Memory to hold zPName is leaked.
2024 */
2025 static int annotation_step(Annotator *p, Blob *pParent, int iVers){
2026 int i, j;
2027 int lnTo;
2028
2029 /* Prepare the parent file to be diffed */
2030 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
2031 &p->c.nFrom, DIFF_IGNORE_SOLWS|DIFF_IGNORE_EOLWS);
2032 if( p->c.aFrom==0 ){
2033 return 1;
2034 }
2035
2036 /* Compute the differences going from pParent to the file being
@@ -2077,11 +2077,12 @@
2077 static void annotate_file(
2078 Annotator *p, /* The annotator */
2079 int fnid, /* The name of the file to be annotated */
2080 int mid, /* Use the version of the file in this check-in */
2081 int iLimit, /* Limit the number of levels if greater than zero */
2082 int annFlags /* Flags to alter the annotation */
 
2083 ){
2084 Blob toAnnotate; /* Text of the final (mid) version of the file */
2085 Blob step; /* Text of previous revision */
2086 int rid; /* Artifact ID of the file being annotated */
2087 Stmt q; /* Query returning all ancestor versions */
@@ -2095,11 +2096,11 @@
2095 }
2096 if( !content_get(rid, &toAnnotate) ){
2097 fossil_fatal("unable to retrieve content of artifact #%d", rid);
2098 }
2099 if( iLimit<=0 ) iLimit = 1000000000;
2100 annotation_start(p, &toAnnotate);
2101 db_begin_transaction();
2102 db_multi_exec(
2103 "CREATE TEMP TABLE IF NOT EXISTS vseen(rid INTEGER PRIMARY KEY);"
2104 "DELETE FROM vseen;"
2105 );
@@ -2129,11 +2130,11 @@
2129 p->aVers[p->nVers].zMUuid = fossil_strdup(db_column_text(&q, 1));
2130 p->aVers[p->nVers].zDate = fossil_strdup(db_column_text(&q, 2));
2131 p->aVers[p->nVers].zUser = fossil_strdup(db_column_text(&q, 3));
2132 if( p->nVers ){
2133 content_get(rid, &step);
2134 annotation_step(p, &step, p->nVers-1);
2135 blob_reset(&step);
2136 }
2137 p->nVers++;
2138 db_bind_int(&ins, ":rid", rid);
2139 db_step(&ins);
@@ -2185,10 +2186,12 @@
2185 int fnid;
2186 int i;
2187 int iLimit; /* Depth limit */
2188 int annFlags = ANN_FILE_ANCEST;
2189 int showLog = 0; /* True to display the log */
 
 
2190 const char *zFilename; /* Name of file to annotate */
2191 const char *zCI; /* The check-in containing zFilename */
2192 Annotator ann;
2193 HQuery url;
2194 struct AnnVers *p;
@@ -2204,26 +2207,40 @@
2204 zFilename = P("filename");
2205 fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
2206 if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
2207 iLimit = atoi(PD("limit","20"));
2208 if( P("filevers") ) annFlags |= ANN_FILE_VERS;
 
 
2209 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
2210 fossil_redirect_home();
2211 }
2212
2213 /* compute the annotation */
2214 compute_direct_ancestors(mid, 10000000);
2215 annotate_file(&ann, fnid, mid, iLimit, annFlags);
2216 zCI = ann.aVers[0].zMUuid;
2217
2218 /* generate the web page */
2219 style_header("Annotation For %h", zFilename);
2220 url_initialize(&url, "annotate");
 
 
 
 
2221 url_add_parameter(&url, "checkin", P("checkin"));
2222 url_add_parameter(&url, "filename", zFilename);
2223 if( iLimit!=20 ){
2224 url_add_parameter(&url, "limit", sqlite3_mprintf("%d", iLimit));
 
 
 
 
 
 
 
 
2225 }
2226 url_add_parameter(&url, "log", showLog ? "1" : "0");
2227 if( showLog ){
2228 style_submenu_element("Hide Log", "Hide Log",
2229 "%s", url_render(&url, "log", "0", 0, 0));
@@ -2361,19 +2378,21 @@
2361 Annotator ann; /* The annotation of the file */
2362 int i; /* Loop counter */
2363 const char *zLimit; /* The value to the -n|--limit option */
2364 int iLimit; /* How far back in time to look */
2365 int showLog; /* True to show the log */
 
2366 int fileVers; /* Show file version instead of check-in versions */
2367 int annFlags = 0; /* Flags to control annotation properties */
2368 int bBlame = 0; /* True for BLAME output. False for ANNOTATE. */
2369
2370 bBlame = g.argv[1][0]=='b';
2371 zLimit = find_option("limit","n",1);
2372 if( zLimit==0 || zLimit[0]==0 ) zLimit = "-1";
2373 iLimit = atoi(zLimit);
2374 showLog = find_option("log","l",0)!=0;
 
2375 fileVers = find_option("filevers",0,0)!=0;
2376 db_must_be_within_tree();
2377 if( g.argc<3 ) {
2378 usage("FILENAME");
2379 }
@@ -2399,11 +2418,11 @@
2399 fid, fnid);
2400 if( mid==0 ){
2401 fossil_fatal("unable to find manifest");
2402 }
2403 annFlags |= ANN_FILE_ANCEST;
2404 annotate_file(&ann, fnid, mid, iLimit, annFlags);
2405 if( showLog ){
2406 struct AnnVers *p;
2407 for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
2408 fossil_print("version %3d: %s %.10s file %.10s\n",
2409 i+1, p->zDate, p->zMUuid, p->zFUuid);
2410
--- src/diff.c
+++ src/diff.c
@@ -1994,16 +1994,16 @@
1994 /*
1995 ** Initialize the annotation process by specifying the file that is
1996 ** to be annotated. The annotator takes control of the input Blob and
1997 ** will release it when it is finished with it.
1998 */
1999 static int annotation_start(Annotator *p, Blob *pInput, u64 diffFlags){
2000 int i;
2001
2002 memset(p, 0, sizeof(*p));
2003 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
2004 diffFlags);
2005 if( p->c.aTo==0 ){
2006 return 1;
2007 }
2008 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2009 for(i=0; i<p->c.nTo; i++){
@@ -2020,17 +2020,17 @@
2020 ** being annotated. Do another step of the annotation. Return true
2021 ** if additional annotation is required. zPName is the tag to insert
2022 ** on each line of the file being annotated that was contributed by
2023 ** pParent. Memory to hold zPName is leaked.
2024 */
2025 static int annotation_step(Annotator *p, Blob *pParent, int iVers, u64 diffFlags){
2026 int i, j;
2027 int lnTo;
2028
2029 /* Prepare the parent file to be diffed */
2030 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
2031 &p->c.nFrom, diffFlags);
2032 if( p->c.aFrom==0 ){
2033 return 1;
2034 }
2035
2036 /* Compute the differences going from pParent to the file being
@@ -2077,11 +2077,12 @@
2077 static void annotate_file(
2078 Annotator *p, /* The annotator */
2079 int fnid, /* The name of the file to be annotated */
2080 int mid, /* Use the version of the file in this check-in */
2081 int iLimit, /* Limit the number of levels if greater than zero */
2082 int annFlags, /* Flags to alter the annotation */
2083 u64 diffFlags /* Flags to alter the whitespace handling */
2084 ){
2085 Blob toAnnotate; /* Text of the final (mid) version of the file */
2086 Blob step; /* Text of previous revision */
2087 int rid; /* Artifact ID of the file being annotated */
2088 Stmt q; /* Query returning all ancestor versions */
@@ -2095,11 +2096,11 @@
2096 }
2097 if( !content_get(rid, &toAnnotate) ){
2098 fossil_fatal("unable to retrieve content of artifact #%d", rid);
2099 }
2100 if( iLimit<=0 ) iLimit = 1000000000;
2101 annotation_start(p, &toAnnotate, diffFlags);
2102 db_begin_transaction();
2103 db_multi_exec(
2104 "CREATE TEMP TABLE IF NOT EXISTS vseen(rid INTEGER PRIMARY KEY);"
2105 "DELETE FROM vseen;"
2106 );
@@ -2129,11 +2130,11 @@
2130 p->aVers[p->nVers].zMUuid = fossil_strdup(db_column_text(&q, 1));
2131 p->aVers[p->nVers].zDate = fossil_strdup(db_column_text(&q, 2));
2132 p->aVers[p->nVers].zUser = fossil_strdup(db_column_text(&q, 3));
2133 if( p->nVers ){
2134 content_get(rid, &step);
2135 annotation_step(p, &step, p->nVers-1, diffFlags);
2136 blob_reset(&step);
2137 }
2138 p->nVers++;
2139 db_bind_int(&ins, ":rid", rid);
2140 db_step(&ins);
@@ -2185,10 +2186,12 @@
2186 int fnid;
2187 int i;
2188 int iLimit; /* Depth limit */
2189 int annFlags = ANN_FILE_ANCEST;
2190 int showLog = 0; /* True to display the log */
2191 int ignoreWs = 0; /* Ignore whitespace */
2192 u64 diffFlags = 0; /* diff flags for ignore whitespace */
2193 const char *zFilename; /* Name of file to annotate */
2194 const char *zCI; /* The check-in containing zFilename */
2195 Annotator ann;
2196 HQuery url;
2197 struct AnnVers *p;
@@ -2204,26 +2207,40 @@
2207 zFilename = P("filename");
2208 fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
2209 if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
2210 iLimit = atoi(PD("limit","20"));
2211 if( P("filevers") ) annFlags |= ANN_FILE_VERS;
2212 ignoreWs = atoi(PD("w","0"))!=0;
2213 if( ignoreWs ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS);
2214 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
2215 fossil_redirect_home();
2216 }
2217
2218 /* compute the annotation */
2219 compute_direct_ancestors(mid, 10000000);
2220 annotate_file(&ann, fnid, mid, iLimit, annFlags, diffFlags);
2221 zCI = ann.aVers[0].zMUuid;
2222
2223 /* generate the web page */
2224 style_header("Annotation For %h", zFilename);
2225 if( bBlame ){
2226 url_initialize(&url, "blame");
2227 }else{
2228 url_initialize(&url, "annotate");
2229 }
2230 url_add_parameter(&url, "checkin", P("checkin"));
2231 url_add_parameter(&url, "filename", zFilename);
2232 if( iLimit!=20 ){
2233 url_add_parameter(&url, "limit", sqlite3_mprintf("%d", iLimit));
2234 }
2235 url_add_parameter(&url, "w", ignoreWs ? "1" : "0");
2236 if( ignoreWs ){
2237 style_submenu_element("Show Whitespace Changes", "Show Whitespace Changes",
2238 "%s", url_render(&url, "w", "0", 0, 0));
2239 }else{
2240 style_submenu_element("Ignore Whitespace", "Ignore Whitespace",
2241 "%s", url_render(&url, "w", "1", 0, 0));
2242 }
2243 url_add_parameter(&url, "log", showLog ? "1" : "0");
2244 if( showLog ){
2245 style_submenu_element("Hide Log", "Hide Log",
2246 "%s", url_render(&url, "log", "0", 0, 0));
@@ -2361,19 +2378,21 @@
2378 Annotator ann; /* The annotation of the file */
2379 int i; /* Loop counter */
2380 const char *zLimit; /* The value to the -n|--limit option */
2381 int iLimit; /* How far back in time to look */
2382 int showLog; /* True to show the log */
2383 u64 diffFlags = 0;/* Flags to control whitespace handling */
2384 int fileVers; /* Show file version instead of check-in versions */
2385 int annFlags = 0; /* Flags to control annotation properties */
2386 int bBlame = 0; /* True for BLAME output. False for ANNOTATE. */
2387
2388 bBlame = g.argv[1][0]=='b';
2389 zLimit = find_option("limit","n",1);
2390 if( zLimit==0 || zLimit[0]==0 ) zLimit = "-1";
2391 iLimit = atoi(zLimit);
2392 showLog = find_option("log","l",0)!=0;
2393 if( find_option("w",0,0)!=0 ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS);
2394 fileVers = find_option("filevers",0,0)!=0;
2395 db_must_be_within_tree();
2396 if( g.argc<3 ) {
2397 usage("FILENAME");
2398 }
@@ -2399,11 +2418,11 @@
2418 fid, fnid);
2419 if( mid==0 ){
2420 fossil_fatal("unable to find manifest");
2421 }
2422 annFlags |= ANN_FILE_ANCEST;
2423 annotate_file(&ann, fnid, mid, iLimit, annFlags, diffFlags);
2424 if( showLog ){
2425 struct AnnVers *p;
2426 for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
2427 fossil_print("version %3d: %s %.10s file %.10s\n",
2428 i+1, p->zDate, p->zMUuid, p->zFUuid);
2429

Keyboard Shortcuts

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