Fossil SCM
Allow comment_print() to handle lines >400 characters. Add parameter "width" to print_timeline() function.
Commit
b2455507cb732c11da44dac6c3260000ea26ba8c
Parent
8e7edc60fa0ec8c…
6 files changed
+8
-3
+1
-1
+1
-1
+1
-1
+3
-3
+1
-1
+8
-3
| --- src/comformat.c | ||
| +++ src/comformat.c | ||
| @@ -26,28 +26,33 @@ | ||
| 26 | 26 | ** Given a comment string zText, format that string for printing |
| 27 | 27 | ** on a TTY. Assume that the output cursors is indent spaces from |
| 28 | 28 | ** the left margin and that a single line can contain no more than |
| 29 | 29 | ** lineLength characters. Indent all subsequent lines by indent. |
| 30 | 30 | ** |
| 31 | -** lineLength must be less than 400. | |
| 32 | -** | |
| 33 | 31 | ** Return the number of newlines that are output. |
| 34 | 32 | */ |
| 35 | 33 | int comment_print(const char *zText, int indent, int lineLength){ |
| 36 | 34 | int tlen = lineLength - indent; |
| 37 | 35 | int si, sk, i, k; |
| 38 | 36 | int doIndent = 0; |
| 39 | - char zBuf[400]; | |
| 37 | + char *zBuf; | |
| 38 | + char zBuffer[400]; | |
| 40 | 39 | int lineCnt = 0; |
| 41 | 40 | |
| 41 | + if( lineLength > sizeof(zBuffer) ){ | |
| 42 | + zBuf = fossil_malloc(lineLength); | |
| 43 | + }else{ | |
| 44 | + zBuf = zBuffer; | |
| 45 | + } | |
| 42 | 46 | for(;;){ |
| 43 | 47 | while( fossil_isspace(zText[0]) ){ zText++; } |
| 44 | 48 | if( zText[0]==0 ){ |
| 45 | 49 | if( doIndent==0 ){ |
| 46 | 50 | fossil_print("\n"); |
| 47 | 51 | lineCnt = 1; |
| 48 | 52 | } |
| 53 | + if( zBuf!=zBuffer) fossil_free(zBuf); | |
| 49 | 54 | return lineCnt; |
| 50 | 55 | } |
| 51 | 56 | for(sk=si=i=k=0; zText[i] && k<tlen; i++){ |
| 52 | 57 | char c = zText[i]; |
| 53 | 58 | if( fossil_isspace(c) ){ |
| 54 | 59 |
| --- 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 |
+1
-1
| --- src/descendants.c | ||
| +++ src/descendants.c | ||
| @@ -329,11 +329,11 @@ | ||
| 329 | 329 | "%s" |
| 330 | 330 | " AND event.objid IN (SELECT rid FROM leaves)" |
| 331 | 331 | " ORDER BY event.mtime DESC", |
| 332 | 332 | timeline_query_for_tty() |
| 333 | 333 | ); |
| 334 | - print_timeline(&q, 20, 0); | |
| 334 | + print_timeline(&q, 20, 79, 0); | |
| 335 | 335 | db_finalize(&q); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /* |
| 339 | 339 | ** COMMAND: leaves* |
| 340 | 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 |
| --- 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 @@ | ||
| 225 | 225 | if(nLimit>0){ |
| 226 | 226 | blob_appendf(&sql, "LIMIT %d", nLimit); |
| 227 | 227 | } |
| 228 | 228 | db_prepare(&q, blob_str(&sql)); |
| 229 | 229 | blob_reset(&sql); |
| 230 | - print_timeline(&q, 1000, 0); | |
| 230 | + print_timeline(&q, 1000, 79, 0); | |
| 231 | 231 | db_finalize(&q); |
| 232 | 232 | } |
| 233 | 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, 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 @@ | ||
| 472 | 472 | if(nFindLimit>0){ |
| 473 | 473 | blob_appendf(&sql, " LIMIT %d", nFindLimit); |
| 474 | 474 | } |
| 475 | 475 | db_prepare(&q, "%s", blob_str(&sql)); |
| 476 | 476 | blob_reset(&sql); |
| 477 | - print_timeline(&q, 2000, 0); | |
| 477 | + print_timeline(&q, 2000, 79, 0); | |
| 478 | 478 | db_finalize(&q); |
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | }else |
| 482 | 482 | |
| 483 | 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, 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 @@ | ||
| 1510 | 1510 | ** 4. Number of non-merge children |
| 1511 | 1511 | ** 5. Number of parents |
| 1512 | 1512 | ** 6. mtime |
| 1513 | 1513 | ** 7. branch |
| 1514 | 1514 | */ |
| 1515 | -void print_timeline(Stmt *q, int mxLine, int verboseFlag){ | |
| 1515 | +void print_timeline(Stmt *q, int mxLine, int width, int verboseFlag){ | |
| 1516 | 1516 | int nLine = 0; |
| 1517 | 1517 | char zPrevDate[20]; |
| 1518 | 1518 | const char *zCurrentUuid=0; |
| 1519 | 1519 | int fchngQueryInit = 0; /* True if fchngQuery is initialized */ |
| 1520 | 1520 | Stmt fchngQuery; /* Query for file changes on check-ins */ |
| @@ -1563,11 +1563,11 @@ | ||
| 1563 | 1563 | if( fossil_strcmp(zCurrentUuid,zId)==0 ){ |
| 1564 | 1564 | sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* "); |
| 1565 | 1565 | n += strlen(zPrefix); |
| 1566 | 1566 | } |
| 1567 | 1567 | 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 */ | |
| 1569 | 1569 | sqlite3_free(zFree); |
| 1570 | 1570 | |
| 1571 | 1571 | if(verboseFlag){ |
| 1572 | 1572 | if( !fchngQueryInit ){ |
| 1573 | 1573 | db_prepare(&fchngQuery, |
| @@ -1780,11 +1780,11 @@ | ||
| 1780 | 1780 | blob_appendf(&sql, " AND event.type=%Q ", zType); |
| 1781 | 1781 | } |
| 1782 | 1782 | blob_appendf(&sql, " ORDER BY event.mtime DESC"); |
| 1783 | 1783 | db_prepare(&q, blob_str(&sql)); |
| 1784 | 1784 | blob_reset(&sql); |
| 1785 | - print_timeline(&q, n, verboseFlag); | |
| 1785 | + print_timeline(&q, n, 79, verboseFlag); | |
| 1786 | 1786 | db_finalize(&q); |
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | 1789 | /* |
| 1790 | 1790 | ** This is a version of the "localtime()" function from the standard |
| 1791 | 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 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 @@ | ||
| 188 | 188 | "%s " |
| 189 | 189 | " AND event.objid IN leaves" |
| 190 | 190 | " ORDER BY event.mtime DESC", |
| 191 | 191 | timeline_query_for_tty() |
| 192 | 192 | ); |
| 193 | - print_timeline(&q, 100, 0); | |
| 193 | + print_timeline(&q, 100, 79, 0); | |
| 194 | 194 | db_finalize(&q); |
| 195 | 195 | fossil_fatal("Multiple descendants"); |
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | tid = db_int(0, "SELECT rid FROM leaves, event" |
| 199 | 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 |
| --- 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 |