Fossil SCM

Allow comment_print() to handle lines >400 characters. Add parameter "width" to print_timeline() function.

jan.nijtmans 2013-10-26 09:06 UTC trunk
Commit b2455507cb732c11da44dac6c3260000ea26ba8c
+8 -3
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,33 @@
2626
** Given a comment string zText, format that string for printing
2727
** on a TTY. Assume that the output cursors is indent spaces from
2828
** the left margin and that a single line can contain no more than
2929
** lineLength characters. Indent all subsequent lines by indent.
3030
**
31
-** lineLength must be less than 400.
32
-**
3331
** Return the number of newlines that are output.
3432
*/
3533
int comment_print(const char *zText, int indent, int lineLength){
3634
int tlen = lineLength - indent;
3735
int si, sk, i, k;
3836
int doIndent = 0;
39
- char zBuf[400];
37
+ char *zBuf;
38
+ char zBuffer[400];
4039
int lineCnt = 0;
4140
41
+ if( lineLength > sizeof(zBuffer) ){
42
+ zBuf = fossil_malloc(lineLength);
43
+ }else{
44
+ zBuf = zBuffer;
45
+ }
4246
for(;;){
4347
while( fossil_isspace(zText[0]) ){ zText++; }
4448
if( zText[0]==0 ){
4549
if( doIndent==0 ){
4650
fossil_print("\n");
4751
lineCnt = 1;
4852
}
53
+ if( zBuf!=zBuffer) fossil_free(zBuf);
4954
return lineCnt;
5055
}
5156
for(sk=si=i=k=0; zText[i] && k<tlen; i++){
5257
char c = zText[i];
5358
if( fossil_isspace(c) ){
5459
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,33 @@
26 ** Given a comment string zText, format that string for printing
27 ** on a TTY. Assume that the output cursors is indent spaces from
28 ** the left margin and that a single line can contain no more than
29 ** lineLength characters. Indent all subsequent lines by indent.
30 **
31 ** lineLength must be less than 400.
32 **
33 ** Return the number of newlines that are output.
34 */
35 int comment_print(const char *zText, int indent, int lineLength){
36 int tlen = lineLength - indent;
37 int si, sk, i, k;
38 int doIndent = 0;
39 char zBuf[400];
 
40 int lineCnt = 0;
41
 
 
 
 
 
42 for(;;){
43 while( fossil_isspace(zText[0]) ){ zText++; }
44 if( zText[0]==0 ){
45 if( doIndent==0 ){
46 fossil_print("\n");
47 lineCnt = 1;
48 }
 
49 return lineCnt;
50 }
51 for(sk=si=i=k=0; zText[i] && k<tlen; i++){
52 char c = zText[i];
53 if( fossil_isspace(c) ){
54
--- src/comformat.c
+++ src/comformat.c
@@ -26,28 +26,33 @@
26 ** Given a comment string zText, format that string for printing
27 ** on a TTY. Assume that the output cursors is indent spaces from
28 ** the left margin and that a single line can contain no more than
29 ** lineLength characters. Indent all subsequent lines by indent.
30 **
 
 
31 ** Return the number of newlines that are output.
32 */
33 int comment_print(const char *zText, int indent, int lineLength){
34 int tlen = lineLength - indent;
35 int si, sk, i, k;
36 int doIndent = 0;
37 char *zBuf;
38 char zBuffer[400];
39 int lineCnt = 0;
40
41 if( lineLength > sizeof(zBuffer) ){
42 zBuf = fossil_malloc(lineLength);
43 }else{
44 zBuf = zBuffer;
45 }
46 for(;;){
47 while( fossil_isspace(zText[0]) ){ zText++; }
48 if( zText[0]==0 ){
49 if( doIndent==0 ){
50 fossil_print("\n");
51 lineCnt = 1;
52 }
53 if( zBuf!=zBuffer) fossil_free(zBuf);
54 return lineCnt;
55 }
56 for(sk=si=i=k=0; zText[i] && k<tlen; i++){
57 char c = zText[i];
58 if( fossil_isspace(c) ){
59
--- 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, 79, 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, 79, 0);
335 db_finalize(&q);
336 }
337
338 /*
339 ** COMMAND: leaves*
340
+1 -1
--- src/search.c
+++ src/search.c
@@ -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, 1000, 79, 0);
231231
db_finalize(&q);
232232
}
233233
--- src/search.c
+++ src/search.c
@@ -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
@@ -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, 79, 0);
231 db_finalize(&q);
232 }
233
+1 -1
--- src/tag.c
+++ src/tag.c
@@ -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, 2000, 79, 0);
478478
db_finalize(&q);
479479
}
480480
}
481481
}else
482482
483483
--- src/tag.c
+++ src/tag.c
@@ -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
@@ -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, 79, 0);
478 db_finalize(&q);
479 }
480 }
481 }else
482
483
+3 -3
--- src/timeline.c
+++ src/timeline.c
@@ -1510,11 +1510,11 @@
15101510
** 4. Number of non-merge children
15111511
** 5. Number of parents
15121512
** 6. mtime
15131513
** 7. branch
15141514
*/
1515
-void print_timeline(Stmt *q, int mxLine, int verboseFlag){
1515
+void print_timeline(Stmt *q, int mxLine, int width, int verboseFlag){
15161516
int nLine = 0;
15171517
char zPrevDate[20];
15181518
const char *zCurrentUuid=0;
15191519
int fchngQueryInit = 0; /* True if fchngQuery is initialized */
15201520
Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1563,11 +1563,11 @@
15631563
if( fossil_strcmp(zCurrentUuid,zId)==0 ){
15641564
sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
15651565
n += strlen(zPrefix);
15661566
}
15671567
zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1568
- nLine += comment_print(zFree, 9, 79); /* record another X lines */
1568
+ nLine += comment_print(zFree, 9, width); /* record another X lines */
15691569
sqlite3_free(zFree);
15701570
15711571
if(verboseFlag){
15721572
if( !fchngQueryInit ){
15731573
db_prepare(&fchngQuery,
@@ -1780,11 +1780,11 @@
17801780
blob_appendf(&sql, " AND event.type=%Q ", zType);
17811781
}
17821782
blob_appendf(&sql, " ORDER BY event.mtime DESC");
17831783
db_prepare(&q, blob_str(&sql));
17841784
blob_reset(&sql);
1785
- print_timeline(&q, n, verboseFlag);
1785
+ print_timeline(&q, n, 79, verboseFlag);
17861786
db_finalize(&q);
17871787
}
17881788
17891789
/*
17901790
** This is a version of the "localtime()" function from the standard
17911791
--- src/timeline.c
+++ src/timeline.c
@@ -1510,11 +1510,11 @@
1510 ** 4. Number of non-merge children
1511 ** 5. Number of parents
1512 ** 6. mtime
1513 ** 7. branch
1514 */
1515 void print_timeline(Stmt *q, int mxLine, int verboseFlag){
1516 int nLine = 0;
1517 char zPrevDate[20];
1518 const char *zCurrentUuid=0;
1519 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1520 Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1563,11 +1563,11 @@
1563 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1564 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1565 n += strlen(zPrefix);
1566 }
1567 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1568 nLine += comment_print(zFree, 9, 79); /* record another X lines */
1569 sqlite3_free(zFree);
1570
1571 if(verboseFlag){
1572 if( !fchngQueryInit ){
1573 db_prepare(&fchngQuery,
@@ -1780,11 +1780,11 @@
1780 blob_appendf(&sql, " AND event.type=%Q ", zType);
1781 }
1782 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1783 db_prepare(&q, blob_str(&sql));
1784 blob_reset(&sql);
1785 print_timeline(&q, n, verboseFlag);
1786 db_finalize(&q);
1787 }
1788
1789 /*
1790 ** This is a version of the "localtime()" function from the standard
1791
--- src/timeline.c
+++ src/timeline.c
@@ -1510,11 +1510,11 @@
1510 ** 4. Number of non-merge children
1511 ** 5. Number of parents
1512 ** 6. mtime
1513 ** 7. branch
1514 */
1515 void print_timeline(Stmt *q, int mxLine, int width, int verboseFlag){
1516 int nLine = 0;
1517 char zPrevDate[20];
1518 const char *zCurrentUuid=0;
1519 int fchngQueryInit = 0; /* True if fchngQuery is initialized */
1520 Stmt fchngQuery; /* Query for file changes on check-ins */
@@ -1563,11 +1563,11 @@
1563 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1564 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1565 n += strlen(zPrefix);
1566 }
1567 zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
1568 nLine += comment_print(zFree, 9, width); /* record another X lines */
1569 sqlite3_free(zFree);
1570
1571 if(verboseFlag){
1572 if( !fchngQueryInit ){
1573 db_prepare(&fchngQuery,
@@ -1780,11 +1780,11 @@
1780 blob_appendf(&sql, " AND event.type=%Q ", zType);
1781 }
1782 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1783 db_prepare(&q, blob_str(&sql));
1784 blob_reset(&sql);
1785 print_timeline(&q, n, 79, verboseFlag);
1786 db_finalize(&q);
1787 }
1788
1789 /*
1790 ** This is a version of the "localtime()" function from the standard
1791
+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, 79, 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, 79, 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