Fossil SCM

Merge timeline entry/line limit improvements from the v2 branch.

mistachkin 2013-10-18 03:15 UTC timeline_cmd_dash_n_fix merge
Commit 9cc75945be86cfc470de6749ad9096aaae905f1c
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329329
"%s"
330330
" AND event.objid IN (SELECT rid FROM leaves)"
331331
" ORDER BY event.mtime DESC",
332332
timeline_query_for_tty()
333333
);
334
- print_timeline(&q, 20, 0);
334
+ print_timeline(&q, -20, 0);
335335
db_finalize(&q);
336336
}
337337
338338
/*
339339
** COMMAND: leaves*
340340
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329 "%s"
330 " AND event.objid IN (SELECT rid FROM leaves)"
331 " ORDER BY event.mtime DESC",
332 timeline_query_for_tty()
333 );
334 print_timeline(&q, 20, 0);
335 db_finalize(&q);
336 }
337
338 /*
339 ** COMMAND: leaves*
340
--- src/descendants.c
+++ src/descendants.c
@@ -329,11 +329,11 @@
329 "%s"
330 " AND event.objid IN (SELECT rid FROM leaves)"
331 " ORDER BY event.mtime DESC",
332 timeline_query_for_tty()
333 );
334 print_timeline(&q, -20, 0);
335 db_finalize(&q);
336 }
337
338 /*
339 ** COMMAND: leaves*
340
+3 -3
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189189
int iBest;
190190
char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191191
off the end of the
192192
results. */
193193
char const * zLimit = find_option("limit","n",1);
194
- int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries
195
- to list */
194
+ int const nLimit = zLimit ? atoi(zLimit) : 0; /* Max number of matching
195
+ lines/entries to list */
196196
197197
db_must_be_within_tree();
198198
if( g.argc<2 ) return;
199199
blob_init(&pattern, g.argv[2], -1);
200200
for(i=3; i<g.argc; i++){
@@ -225,8 +225,8 @@
225225
if(nLimit>0){
226226
blob_appendf(&sql, "LIMIT %d", nLimit);
227227
}
228228
db_prepare(&q, blob_str(&sql));
229229
blob_reset(&sql);
230
- print_timeline(&q, 1000, 0);
230
+ print_timeline(&q, nLimit, 0);
231231
db_finalize(&q);
232232
}
233233
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189 int iBest;
190 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191 off the end of the
192 results. */
193 char const * zLimit = find_option("limit","n",1);
194 int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries
195 to list */
196
197 db_must_be_within_tree();
198 if( g.argc<2 ) return;
199 blob_init(&pattern, g.argv[2], -1);
200 for(i=3; i<g.argc; i++){
@@ -225,8 +225,8 @@
225 if(nLimit>0){
226 blob_appendf(&sql, "LIMIT %d", nLimit);
227 }
228 db_prepare(&q, blob_str(&sql));
229 blob_reset(&sql);
230 print_timeline(&q, 1000, 0);
231 db_finalize(&q);
232 }
233
--- src/search.c
+++ src/search.c
@@ -189,12 +189,12 @@
189 int iBest;
190 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
191 off the end of the
192 results. */
193 char const * zLimit = find_option("limit","n",1);
194 int const nLimit = zLimit ? atoi(zLimit) : 0; /* Max number of matching
195 lines/entries to list */
196
197 db_must_be_within_tree();
198 if( g.argc<2 ) return;
199 blob_init(&pattern, g.argv[2], -1);
200 for(i=3; i<g.argc; i++){
@@ -225,8 +225,8 @@
225 if(nLimit>0){
226 blob_appendf(&sql, "LIMIT %d", nLimit);
227 }
228 db_prepare(&q, blob_str(&sql));
229 blob_reset(&sql);
230 print_timeline(&q, nLimit, 0);
231 db_finalize(&q);
232 }
233
+2 -2
--- src/tag.c
+++ src/tag.c
@@ -444,11 +444,11 @@
444444
" WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445445
" AND tagxref.tagtype>0"
446446
" AND blob.rid=tagxref.rid",
447447
g.argv[3]
448448
);
449
- if(nFindLimit>0){
449
+ if( nFindLimit>0 ){
450450
blob_appendf(&sql, " LIMIT %d", nFindLimit);
451451
}
452452
db_prepare(&q, "%s", blob_str(&sql));
453453
blob_reset(&sql);
454454
while( db_step(&q)==SQLITE_ROW ){
@@ -472,11 +472,11 @@
472472
if(nFindLimit>0){
473473
blob_appendf(&sql, " LIMIT %d", nFindLimit);
474474
}
475475
db_prepare(&q, "%s", blob_str(&sql));
476476
blob_reset(&sql);
477
- print_timeline(&q, 2000, 0);
477
+ print_timeline(&q, nFindLimit, 0);
478478
db_finalize(&q);
479479
}
480480
}
481481
}else
482482
483483
--- src/tag.c
+++ src/tag.c
@@ -444,11 +444,11 @@
444 " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445 " AND tagxref.tagtype>0"
446 " AND blob.rid=tagxref.rid",
447 g.argv[3]
448 );
449 if(nFindLimit>0){
450 blob_appendf(&sql, " LIMIT %d", nFindLimit);
451 }
452 db_prepare(&q, "%s", blob_str(&sql));
453 blob_reset(&sql);
454 while( db_step(&q)==SQLITE_ROW ){
@@ -472,11 +472,11 @@
472 if(nFindLimit>0){
473 blob_appendf(&sql, " LIMIT %d", nFindLimit);
474 }
475 db_prepare(&q, "%s", blob_str(&sql));
476 blob_reset(&sql);
477 print_timeline(&q, 2000, 0);
478 db_finalize(&q);
479 }
480 }
481 }else
482
483
--- src/tag.c
+++ src/tag.c
@@ -444,11 +444,11 @@
444 " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
445 " AND tagxref.tagtype>0"
446 " AND blob.rid=tagxref.rid",
447 g.argv[3]
448 );
449 if( nFindLimit>0 ){
450 blob_appendf(&sql, " LIMIT %d", nFindLimit);
451 }
452 db_prepare(&q, "%s", blob_str(&sql));
453 blob_reset(&sql);
454 while( db_step(&q)==SQLITE_ROW ){
@@ -472,11 +472,11 @@
472 if(nFindLimit>0){
473 blob_appendf(&sql, " LIMIT %d", nFindLimit);
474 }
475 db_prepare(&q, "%s", blob_str(&sql));
476 blob_reset(&sql);
477 print_timeline(&q, nFindLimit, 0);
478 db_finalize(&q);
479 }
480 }
481 }else
482
483
+24 -6
--- src/timeline.c
+++ src/timeline.c
@@ -1474,11 +1474,17 @@
14741474
14751475
/*
14761476
** The input query q selects various records. Print a human-readable
14771477
** summary of those records.
14781478
**
1479
-** Limit number of entries printed to N.
1479
+** Limit number of lines or entries printed to nLimit. If nLimit is zero
1480
+** there is no limit. If nLimit is greater than zero, limit the number of
1481
+** complete entries printed. If nLimit is less than zero, attempt to limit
1482
+** the number of lines printed (this is basically the legacy behavior).
1483
+** The line limit, if used, is approximate because it is only checked on a
1484
+** per-entry basis. If verbose mode, the file name details are considered
1485
+** to be part of the entry.
14801486
**
14811487
** The query should return these columns:
14821488
**
14831489
** 0. rid
14841490
** 1. uuid
@@ -1487,11 +1493,13 @@
14871493
** 4. Number of non-merge children
14881494
** 5. Number of parents
14891495
** 6. mtime
14901496
** 7. branch
14911497
*/
1492
-void print_timeline(Stmt *q, int N, int verboseFlag){
1498
+void print_timeline(Stmt *q, int nLimit, int verboseFlag){
1499
+ int nAbsLimit = (nLimit >= 0) ? nLimit : -nLimit;
1500
+ int nLine = 0;
14931501
int nEntry = 0;
14941502
char zPrevDate[20];
14951503
const char *zCurrentUuid=0;
14961504
int fchngQueryInit = 0; /* True if fchngQuery is initialized */
14971505
Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1500,11 +1508,11 @@
15001508
if( g.localOpen ){
15011509
int rid = db_lget_int("checkout", 0);
15021510
zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
15031511
}
15041512
1505
- while( db_step(q)==SQLITE_ROW && nEntry<N){
1513
+ while( db_step(q)==SQLITE_ROW ){
15061514
int rid = db_column_int(q, 0);
15071515
const char *zId = db_column_text(q, 1);
15081516
const char *zDate = db_column_text(q, 2);
15091517
const char *zCom = db_column_text(q, 3);
15101518
int nChild = db_column_int(q, 4);
@@ -1516,10 +1524,11 @@
15161524
15171525
sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
15181526
if( memcmp(zDate, zPrevDate, 10) ){
15191527
fossil_print("=== %.10s ===\n", zDate);
15201528
memcpy(zPrevDate, zDate, 10);
1529
+ nLine++; /* record another line */
15211530
}
15221531
if( zCom==0 ) zCom = "";
15231532
fossil_print("%.8s ", &zDate[11]);
15241533
zPrefix[0] = 0;
15251534
if( nParent>1 ){
@@ -1538,13 +1547,12 @@
15381547
}
15391548
if( fossil_strcmp(zCurrentUuid,zId)==0 ){
15401549
sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
15411550
n += strlen(zPrefix);
15421551
}
1543
- nEntry++;
15441552
zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1545
- comment_print(zFree, 9, 79);
1553
+ nLine += comment_print(zFree, 9, 79); /* record another X lines */
15461554
sqlite3_free(zFree);
15471555
15481556
if(verboseFlag){
15491557
if( !fchngQueryInit ){
15501558
db_prepare(&fchngQuery,
@@ -1564,17 +1572,27 @@
15641572
const char *zFilename = db_column_text(&fchngQuery, 2);
15651573
int isNew = db_column_int(&fchngQuery, 0);
15661574
int isDel = db_column_int(&fchngQuery, 1);
15671575
if( isNew ){
15681576
fossil_print(" ADDED %s\n",zFilename);
1577
+ nLine++; /* record another line */
15691578
}else if( isDel ){
15701579
fossil_print(" DELETED %s\n",zFilename);
1580
+ nLine++; /* record another line */
15711581
}else{
15721582
fossil_print(" EDITED %s\n", zFilename);
1583
+ nLine++; /* record another line */
15731584
}
15741585
}
15751586
db_reset(&fchngQuery);
1587
+ }
1588
+ nEntry++; /* record another complete entry */
1589
+ if( !nAbsLimit ) continue; /* no limit, continue */
1590
+ if( nLimit<0 && nLine>=nAbsLimit ){
1591
+ break; /* line count limit hit, stop. */
1592
+ }else if( nEntry>=nAbsLimit ){
1593
+ break; /* entry count limit hit, stop. */
15761594
}
15771595
}
15781596
if( fchngQueryInit ) db_finalize(&fchngQuery);
15791597
}
15801598
@@ -1677,11 +1695,11 @@
16771695
zLimit = find_option("count",0,1);
16781696
}
16791697
if( zLimit ){
16801698
n = atoi(zLimit);
16811699
}else{
1682
- n = 20;
1700
+ n = -20;
16831701
}
16841702
if( g.argc>=4 ){
16851703
k = strlen(g.argv[2]);
16861704
if( strncmp(g.argv[2],"before",k)==0 ){
16871705
mode = 1;
16881706
--- src/timeline.c
+++ src/timeline.c
@@ -1474,11 +1474,17 @@
1474
1475 /*
1476 ** The input query q selects various records. Print a human-readable
1477 ** summary of those records.
1478 **
1479 ** Limit number of entries printed to N.
 
 
 
 
 
 
1480 **
1481 ** The query should return these columns:
1482 **
1483 ** 0. rid
1484 ** 1. uuid
@@ -1487,11 +1493,13 @@
1487 ** 4. Number of non-merge children
1488 ** 5. Number of parents
1489 ** 6. mtime
1490 ** 7. branch
1491 */
1492 void print_timeline(Stmt *q, int N, int verboseFlag){
 
 
1493 int nEntry = 0;
1494 char zPrevDate[20];
1495 const char *zCurrentUuid=0;
1496 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1497 Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1500,11 +1508,11 @@
1500 if( g.localOpen ){
1501 int rid = db_lget_int("checkout", 0);
1502 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1503 }
1504
1505 while( db_step(q)==SQLITE_ROW && nEntry<N){
1506 int rid = db_column_int(q, 0);
1507 const char *zId = db_column_text(q, 1);
1508 const char *zDate = db_column_text(q, 2);
1509 const char *zCom = db_column_text(q, 3);
1510 int nChild = db_column_int(q, 4);
@@ -1516,10 +1524,11 @@
1516
1517 sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
1518 if( memcmp(zDate, zPrevDate, 10) ){
1519 fossil_print("=== %.10s ===\n", zDate);
1520 memcpy(zPrevDate, zDate, 10);
 
1521 }
1522 if( zCom==0 ) zCom = "";
1523 fossil_print("%.8s ", &zDate[11]);
1524 zPrefix[0] = 0;
1525 if( nParent>1 ){
@@ -1538,13 +1547,12 @@
1538 }
1539 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1540 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1541 n += strlen(zPrefix);
1542 }
1543 nEntry++;
1544 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1545 comment_print(zFree, 9, 79);
1546 sqlite3_free(zFree);
1547
1548 if(verboseFlag){
1549 if( !fchngQueryInit ){
1550 db_prepare(&fchngQuery,
@@ -1564,17 +1572,27 @@
1564 const char *zFilename = db_column_text(&fchngQuery, 2);
1565 int isNew = db_column_int(&fchngQuery, 0);
1566 int isDel = db_column_int(&fchngQuery, 1);
1567 if( isNew ){
1568 fossil_print(" ADDED %s\n",zFilename);
 
1569 }else if( isDel ){
1570 fossil_print(" DELETED %s\n",zFilename);
 
1571 }else{
1572 fossil_print(" EDITED %s\n", zFilename);
 
1573 }
1574 }
1575 db_reset(&fchngQuery);
 
 
 
 
 
 
 
1576 }
1577 }
1578 if( fchngQueryInit ) db_finalize(&fchngQuery);
1579 }
1580
@@ -1677,11 +1695,11 @@
1677 zLimit = find_option("count",0,1);
1678 }
1679 if( zLimit ){
1680 n = atoi(zLimit);
1681 }else{
1682 n = 20;
1683 }
1684 if( g.argc>=4 ){
1685 k = strlen(g.argv[2]);
1686 if( strncmp(g.argv[2],"before",k)==0 ){
1687 mode = 1;
1688
--- src/timeline.c
+++ src/timeline.c
@@ -1474,11 +1474,17 @@
1474
1475 /*
1476 ** The input query q selects various records. Print a human-readable
1477 ** summary of those records.
1478 **
1479 ** Limit number of lines or entries printed to nLimit. If nLimit is zero
1480 ** there is no limit. If nLimit is greater than zero, limit the number of
1481 ** complete entries printed. If nLimit is less than zero, attempt to limit
1482 ** the number of lines printed (this is basically the legacy behavior).
1483 ** The line limit, if used, is approximate because it is only checked on a
1484 ** per-entry basis. If verbose mode, the file name details are considered
1485 ** to be part of the entry.
1486 **
1487 ** The query should return these columns:
1488 **
1489 ** 0. rid
1490 ** 1. uuid
@@ -1487,11 +1493,13 @@
1493 ** 4. Number of non-merge children
1494 ** 5. Number of parents
1495 ** 6. mtime
1496 ** 7. branch
1497 */
1498 void print_timeline(Stmt *q, int nLimit, int verboseFlag){
1499 int nAbsLimit = (nLimit >= 0) ? nLimit : -nLimit;
1500 int nLine = 0;
1501 int nEntry = 0;
1502 char zPrevDate[20];
1503 const char *zCurrentUuid=0;
1504 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1505 Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1500,11 +1508,11 @@
1508 if( g.localOpen ){
1509 int rid = db_lget_int("checkout", 0);
1510 zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1511 }
1512
1513 while( db_step(q)==SQLITE_ROW ){
1514 int rid = db_column_int(q, 0);
1515 const char *zId = db_column_text(q, 1);
1516 const char *zDate = db_column_text(q, 2);
1517 const char *zCom = db_column_text(q, 3);
1518 int nChild = db_column_int(q, 4);
@@ -1516,10 +1524,11 @@
1524
1525 sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
1526 if( memcmp(zDate, zPrevDate, 10) ){
1527 fossil_print("=== %.10s ===\n", zDate);
1528 memcpy(zPrevDate, zDate, 10);
1529 nLine++; /* record another line */
1530 }
1531 if( zCom==0 ) zCom = "";
1532 fossil_print("%.8s ", &zDate[11]);
1533 zPrefix[0] = 0;
1534 if( nParent>1 ){
@@ -1538,13 +1547,12 @@
1547 }
1548 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1549 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1550 n += strlen(zPrefix);
1551 }
 
1552 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1553 nLine += comment_print(zFree, 9, 79); /* record another X lines */
1554 sqlite3_free(zFree);
1555
1556 if(verboseFlag){
1557 if( !fchngQueryInit ){
1558 db_prepare(&fchngQuery,
@@ -1564,17 +1572,27 @@
1572 const char *zFilename = db_column_text(&fchngQuery, 2);
1573 int isNew = db_column_int(&fchngQuery, 0);
1574 int isDel = db_column_int(&fchngQuery, 1);
1575 if( isNew ){
1576 fossil_print(" ADDED %s\n",zFilename);
1577 nLine++; /* record another line */
1578 }else if( isDel ){
1579 fossil_print(" DELETED %s\n",zFilename);
1580 nLine++; /* record another line */
1581 }else{
1582 fossil_print(" EDITED %s\n", zFilename);
1583 nLine++; /* record another line */
1584 }
1585 }
1586 db_reset(&fchngQuery);
1587 }
1588 nEntry++; /* record another complete entry */
1589 if( !nAbsLimit ) continue; /* no limit, continue */
1590 if( nLimit<0 && nLine>=nAbsLimit ){
1591 break; /* line count limit hit, stop. */
1592 }else if( nEntry>=nAbsLimit ){
1593 break; /* entry count limit hit, stop. */
1594 }
1595 }
1596 if( fchngQueryInit ) db_finalize(&fchngQuery);
1597 }
1598
@@ -1677,11 +1695,11 @@
1695 zLimit = find_option("count",0,1);
1696 }
1697 if( zLimit ){
1698 n = atoi(zLimit);
1699 }else{
1700 n = -20;
1701 }
1702 if( g.argc>=4 ){
1703 k = strlen(g.argv[2]);
1704 if( strncmp(g.argv[2],"before",k)==0 ){
1705 mode = 1;
1706
+1 -1
--- src/update.c
+++ src/update.c
@@ -188,11 +188,11 @@
188188
"%s "
189189
" AND event.objid IN leaves"
190190
" ORDER BY event.mtime DESC",
191191
timeline_query_for_tty()
192192
);
193
- print_timeline(&q, 100, 0);
193
+ print_timeline(&q, -100, 0);
194194
db_finalize(&q);
195195
fossil_fatal("Multiple descendants");
196196
}
197197
}
198198
tid = db_int(0, "SELECT rid FROM leaves, event"
199199
--- src/update.c
+++ src/update.c
@@ -188,11 +188,11 @@
188 "%s "
189 " AND event.objid IN leaves"
190 " ORDER BY event.mtime DESC",
191 timeline_query_for_tty()
192 );
193 print_timeline(&q, 100, 0);
194 db_finalize(&q);
195 fossil_fatal("Multiple descendants");
196 }
197 }
198 tid = db_int(0, "SELECT rid FROM leaves, event"
199
--- src/update.c
+++ src/update.c
@@ -188,11 +188,11 @@
188 "%s "
189 " AND event.objid IN leaves"
190 " ORDER BY event.mtime DESC",
191 timeline_query_for_tty()
192 );
193 print_timeline(&q, -100, 0);
194 db_finalize(&q);
195 fossil_fatal("Multiple descendants");
196 }
197 }
198 tid = db_int(0, "SELECT rid FROM leaves, event"
199

Keyboard Shortcuts

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