Fossil SCM
Add the 'test-commit-warning' command.
Commit
de78b73a7eeb27ca1cf329e20dc6d95587836611
Parent
508c67b0880536e…
1 file changed
+85
-18
+85
-18
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -1466,16 +1466,17 @@ | ||
| 1466 | 1466 | ** Return 1 if the user pressed 'c'. In that case, the file will have |
| 1467 | 1467 | ** been converted to UTF-8 (if it was UTF-16) with NL line-endings, |
| 1468 | 1468 | ** and the original file will have been renamed to "<filename>-original". |
| 1469 | 1469 | */ |
| 1470 | 1470 | static int commit_warning( |
| 1471 | - Blob *p, /* The content of the file being committed. */ | |
| 1472 | - int crnlOk, /* Non-zero if CR/NL warnings should be disabled. */ | |
| 1473 | - int binOk, /* Non-zero if binary warnings should be disabled. */ | |
| 1474 | - int encodingOk, /* Non-zero if encoding warnings should be disabled. */ | |
| 1475 | - int noPrompt, /* Non-zero to disable prompts and assume 'No'. */ | |
| 1476 | - const char *zFilename /* The full name of the file being committed. */ | |
| 1471 | + Blob *pContent, /* The content of the file being committed. */ | |
| 1472 | + int crnlOk, /* Non-zero if CR/NL warnings should be disabled. */ | |
| 1473 | + int binOk, /* Non-zero if binary warnings should be disabled. */ | |
| 1474 | + int encodingOk, /* Non-zero if encoding warnings should be disabled. */ | |
| 1475 | + int noPrompt, /* 0 to always prompt, 1 for 'N', 2 for 'Y'. */ | |
| 1476 | + const char *zFilename, /* The full name of the file being committed. */ | |
| 1477 | + Blob *pReason /* Reason for warning, if any (non-fatal only). */ | |
| 1477 | 1478 | ){ |
| 1478 | 1479 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 1479 | 1480 | int fUnicode; /* return value of could_be_utf16() */ |
| 1480 | 1481 | int fBinary; /* does the blob content appear to be binary? */ |
| 1481 | 1482 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| @@ -1486,24 +1487,24 @@ | ||
| 1486 | 1487 | char *zMsg; /* Warning message */ |
| 1487 | 1488 | Blob fname; /* Relative pathname of the file */ |
| 1488 | 1489 | static int allOk = 0; /* Set to true to disable this routine */ |
| 1489 | 1490 | |
| 1490 | 1491 | if( allOk ) return 0; |
| 1491 | - fUnicode = could_be_utf16(p, &bReverse); | |
| 1492 | + fUnicode = could_be_utf16(pContent, &bReverse); | |
| 1492 | 1493 | if( fUnicode ){ |
| 1493 | - lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL); | |
| 1494 | + lookFlags = looks_like_utf16(pContent, bReverse, LOOK_NUL); | |
| 1494 | 1495 | }else{ |
| 1495 | - lookFlags = looks_like_utf8(p, LOOK_NUL); | |
| 1496 | - if( !(lookFlags & LOOK_BINARY) && invalid_utf8(p) ){ | |
| 1496 | + lookFlags = looks_like_utf8(pContent, LOOK_NUL); | |
| 1497 | + if( !(lookFlags & LOOK_BINARY) && invalid_utf8(pContent) ){ | |
| 1497 | 1498 | fHasInvalidUtf8 = 1; |
| 1498 | 1499 | } |
| 1499 | 1500 | } |
| 1500 | 1501 | fHasAnyCr = (lookFlags & LOOK_CR); |
| 1501 | 1502 | fBinary = (lookFlags & LOOK_BINARY); |
| 1502 | 1503 | fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR); |
| 1503 | 1504 | fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF); |
| 1504 | - if( fUnicode || fHasAnyCr || fBinary || fHasInvalidUtf8){ | |
| 1505 | + if( fUnicode || fHasAnyCr || fBinary || fHasInvalidUtf8 ){ | |
| 1505 | 1506 | const char *zWarning; |
| 1506 | 1507 | const char *zDisable; |
| 1507 | 1508 | const char *zConvert = "c=convert/"; |
| 1508 | 1509 | Blob ans; |
| 1509 | 1510 | char cReply; |
| @@ -1563,52 +1564,118 @@ | ||
| 1563 | 1564 | zMsg = mprintf( |
| 1564 | 1565 | "%s contains %s. Use --no-warnings or the %s to" |
| 1565 | 1566 | " disable this warning.\n" |
| 1566 | 1567 | "Commit anyhow (a=all/%sy/N)? ", |
| 1567 | 1568 | blob_str(&fname), zWarning, zDisable, zConvert); |
| 1568 | - if( !noPrompt ){ | |
| 1569 | + if( noPrompt==0 ){ | |
| 1569 | 1570 | prompt_user(zMsg, &ans); |
| 1570 | 1571 | cReply = blob_str(&ans)[0]; |
| 1571 | 1572 | blob_reset(&ans); |
| 1573 | + }else if( noPrompt==2 ){ | |
| 1574 | + cReply = 'Y'; | |
| 1572 | 1575 | }else{ |
| 1573 | 1576 | cReply = 'N'; |
| 1574 | 1577 | } |
| 1575 | 1578 | fossil_free(zMsg); |
| 1576 | 1579 | if( cReply=='a' || cReply=='A' ){ |
| 1577 | 1580 | allOk = 1; |
| 1578 | 1581 | }else if( *zConvert && (cReply=='c' || cReply=='C') ){ |
| 1579 | 1582 | char *zOrig = file_newname(zFilename, "original", 1); |
| 1580 | 1583 | FILE *f; |
| 1581 | - blob_write_to_file(p, zOrig); | |
| 1584 | + blob_write_to_file(pContent, zOrig); | |
| 1582 | 1585 | fossil_free(zOrig); |
| 1583 | 1586 | f = fossil_fopen(zFilename, "wb"); |
| 1584 | 1587 | if( f==0 ){ |
| 1585 | 1588 | fossil_warning("cannot open %s for writing", zFilename); |
| 1586 | 1589 | }else{ |
| 1587 | 1590 | if( fUnicode ){ |
| 1588 | 1591 | int bomSize; |
| 1589 | 1592 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 1590 | 1593 | fwrite(bom, 1, bomSize, f); |
| 1591 | - blob_to_utf8_no_bom(p, 0); | |
| 1594 | + blob_to_utf8_no_bom(pContent, 0); | |
| 1592 | 1595 | }else if( fHasInvalidUtf8 ){ |
| 1593 | - blob_cp1252_to_utf8(p); | |
| 1596 | + blob_cp1252_to_utf8(pContent); | |
| 1594 | 1597 | } |
| 1595 | 1598 | if( fHasAnyCr ){ |
| 1596 | - blob_to_lf_only(p); | |
| 1599 | + blob_to_lf_only(pContent); | |
| 1597 | 1600 | } |
| 1598 | - fwrite(blob_buffer(p), 1, blob_size(p), f); | |
| 1601 | + fwrite(blob_buffer(pContent), 1, blob_size(pContent), f); | |
| 1599 | 1602 | fclose(f); |
| 1600 | 1603 | } |
| 1601 | 1604 | return 1; |
| 1602 | 1605 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1603 | 1606 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1604 | 1607 | zWarning, blob_str(&fname)); |
| 1608 | + }else if( noPrompt==2 ){ | |
| 1609 | + if( pReason ){ | |
| 1610 | + blob_append(pReason, zWarning, -1); | |
| 1611 | + } | |
| 1612 | + return 1; | |
| 1605 | 1613 | } |
| 1606 | 1614 | blob_reset(&fname); |
| 1607 | 1615 | } |
| 1608 | 1616 | return 0; |
| 1609 | 1617 | } |
| 1618 | + | |
| 1619 | +/* | |
| 1620 | +** COMMAND: test-commit-warning | |
| 1621 | +** | |
| 1622 | +** Usage: %fossil test-commit-warning ?OPTIONS? | |
| 1623 | +** | |
| 1624 | +** Check each file in the checkout, including unmodified ones, using all | |
| 1625 | +** the pre-commit checks. | |
| 1626 | +** | |
| 1627 | +** Options: | |
| 1628 | +** --no-settings Do not consider any glob settings. | |
| 1629 | +** -v|--verbose Show per-file results for all pre-commit checks. | |
| 1630 | +** | |
| 1631 | +** See also: commit, extras | |
| 1632 | +*/ | |
| 1633 | +void test_commit_warning(void){ | |
| 1634 | + int rc = 0; | |
| 1635 | + int noSettings = find_option("no-settings", 0, 0)!=0; | |
| 1636 | + int verboseFlag = find_option("verbose", 0, 0)!=0; | |
| 1637 | + Stmt q; | |
| 1638 | + db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); | |
| 1639 | + db_prepare(&q, | |
| 1640 | + "SELECT %Q || pathname, pathname, %s, %s, %s FROM vfile" | |
| 1641 | + " WHERE NOT deleted", | |
| 1642 | + g.zLocalRoot, | |
| 1643 | + glob_expr("pathname", noSettings ? 0 : db_get("crnl-glob","")), | |
| 1644 | + glob_expr("pathname", noSettings ? 0 : db_get("binary-glob","")), | |
| 1645 | + glob_expr("pathname", noSettings ? 0 : db_get("encoding-glob","")) | |
| 1646 | + ); | |
| 1647 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1648 | + const char *zFullname; | |
| 1649 | + const char *zName; | |
| 1650 | + Blob content, reason; | |
| 1651 | + int crnlOk, binOk, encodingOk; | |
| 1652 | + int fileRc; | |
| 1653 | + | |
| 1654 | + zFullname = db_column_text(&q, 0); | |
| 1655 | + zName = db_column_text(&q, 1); | |
| 1656 | + crnlOk = db_column_int(&q, 2); | |
| 1657 | + binOk = db_column_int(&q, 3); | |
| 1658 | + encodingOk = db_column_int(&q, 4); | |
| 1659 | + blob_zero(&content); | |
| 1660 | + if( file_wd_islink(zFullname) ){ | |
| 1661 | + blob_read_link(&content, zFullname); | |
| 1662 | + }else{ | |
| 1663 | + blob_read_from_file(&content, zFullname); | |
| 1664 | + } | |
| 1665 | + blob_zero(&reason); | |
| 1666 | + fileRc = commit_warning(&content, crnlOk, binOk, encodingOk, 2, | |
| 1667 | + zFullname, &reason); | |
| 1668 | + if( fileRc || verboseFlag ){ | |
| 1669 | + fossil_print("%d\t%s\t%s\n", fileRc, zName, blob_str(&reason)); | |
| 1670 | + } | |
| 1671 | + blob_reset(&reason); | |
| 1672 | + rc |= fileRc; | |
| 1673 | + } | |
| 1674 | + db_finalize(&q); | |
| 1675 | + fossil_print("%d\n", rc); | |
| 1676 | +} | |
| 1610 | 1677 | |
| 1611 | 1678 | /* |
| 1612 | 1679 | ** qsort() comparison routine for an array of pointers to strings. |
| 1613 | 1680 | */ |
| 1614 | 1681 | static int tagCmp(const void *a, const void *b){ |
| @@ -2056,11 +2123,11 @@ | ||
| 2056 | 2123 | } |
| 2057 | 2124 | /* Do not emit any warnings when they are disabled. */ |
| 2058 | 2125 | if( !noWarningFlag ){ |
| 2059 | 2126 | abortCommit |= commit_warning(&content, crnlOk, binOk, |
| 2060 | 2127 | encodingOk, noPrompt, |
| 2061 | - zFullname); | |
| 2128 | + zFullname, 0); | |
| 2062 | 2129 | } |
| 2063 | 2130 | if( contains_merge_marker(&content) ){ |
| 2064 | 2131 | Blob fname; /* Relative pathname of the file */ |
| 2065 | 2132 | |
| 2066 | 2133 | nConflict++; |
| 2067 | 2134 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1466,16 +1466,17 @@ | |
| 1466 | ** Return 1 if the user pressed 'c'. In that case, the file will have |
| 1467 | ** been converted to UTF-8 (if it was UTF-16) with NL line-endings, |
| 1468 | ** and the original file will have been renamed to "<filename>-original". |
| 1469 | */ |
| 1470 | static int commit_warning( |
| 1471 | Blob *p, /* The content of the file being committed. */ |
| 1472 | int crnlOk, /* Non-zero if CR/NL warnings should be disabled. */ |
| 1473 | int binOk, /* Non-zero if binary warnings should be disabled. */ |
| 1474 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 1475 | int noPrompt, /* Non-zero to disable prompts and assume 'No'. */ |
| 1476 | const char *zFilename /* The full name of the file being committed. */ |
| 1477 | ){ |
| 1478 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 1479 | int fUnicode; /* return value of could_be_utf16() */ |
| 1480 | int fBinary; /* does the blob content appear to be binary? */ |
| 1481 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| @@ -1486,24 +1487,24 @@ | |
| 1486 | char *zMsg; /* Warning message */ |
| 1487 | Blob fname; /* Relative pathname of the file */ |
| 1488 | static int allOk = 0; /* Set to true to disable this routine */ |
| 1489 | |
| 1490 | if( allOk ) return 0; |
| 1491 | fUnicode = could_be_utf16(p, &bReverse); |
| 1492 | if( fUnicode ){ |
| 1493 | lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL); |
| 1494 | }else{ |
| 1495 | lookFlags = looks_like_utf8(p, LOOK_NUL); |
| 1496 | if( !(lookFlags & LOOK_BINARY) && invalid_utf8(p) ){ |
| 1497 | fHasInvalidUtf8 = 1; |
| 1498 | } |
| 1499 | } |
| 1500 | fHasAnyCr = (lookFlags & LOOK_CR); |
| 1501 | fBinary = (lookFlags & LOOK_BINARY); |
| 1502 | fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR); |
| 1503 | fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF); |
| 1504 | if( fUnicode || fHasAnyCr || fBinary || fHasInvalidUtf8){ |
| 1505 | const char *zWarning; |
| 1506 | const char *zDisable; |
| 1507 | const char *zConvert = "c=convert/"; |
| 1508 | Blob ans; |
| 1509 | char cReply; |
| @@ -1563,52 +1564,118 @@ | |
| 1563 | zMsg = mprintf( |
| 1564 | "%s contains %s. Use --no-warnings or the %s to" |
| 1565 | " disable this warning.\n" |
| 1566 | "Commit anyhow (a=all/%sy/N)? ", |
| 1567 | blob_str(&fname), zWarning, zDisable, zConvert); |
| 1568 | if( !noPrompt ){ |
| 1569 | prompt_user(zMsg, &ans); |
| 1570 | cReply = blob_str(&ans)[0]; |
| 1571 | blob_reset(&ans); |
| 1572 | }else{ |
| 1573 | cReply = 'N'; |
| 1574 | } |
| 1575 | fossil_free(zMsg); |
| 1576 | if( cReply=='a' || cReply=='A' ){ |
| 1577 | allOk = 1; |
| 1578 | }else if( *zConvert && (cReply=='c' || cReply=='C') ){ |
| 1579 | char *zOrig = file_newname(zFilename, "original", 1); |
| 1580 | FILE *f; |
| 1581 | blob_write_to_file(p, zOrig); |
| 1582 | fossil_free(zOrig); |
| 1583 | f = fossil_fopen(zFilename, "wb"); |
| 1584 | if( f==0 ){ |
| 1585 | fossil_warning("cannot open %s for writing", zFilename); |
| 1586 | }else{ |
| 1587 | if( fUnicode ){ |
| 1588 | int bomSize; |
| 1589 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 1590 | fwrite(bom, 1, bomSize, f); |
| 1591 | blob_to_utf8_no_bom(p, 0); |
| 1592 | }else if( fHasInvalidUtf8 ){ |
| 1593 | blob_cp1252_to_utf8(p); |
| 1594 | } |
| 1595 | if( fHasAnyCr ){ |
| 1596 | blob_to_lf_only(p); |
| 1597 | } |
| 1598 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1599 | fclose(f); |
| 1600 | } |
| 1601 | return 1; |
| 1602 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1603 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1604 | zWarning, blob_str(&fname)); |
| 1605 | } |
| 1606 | blob_reset(&fname); |
| 1607 | } |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | /* |
| 1612 | ** qsort() comparison routine for an array of pointers to strings. |
| 1613 | */ |
| 1614 | static int tagCmp(const void *a, const void *b){ |
| @@ -2056,11 +2123,11 @@ | |
| 2056 | } |
| 2057 | /* Do not emit any warnings when they are disabled. */ |
| 2058 | if( !noWarningFlag ){ |
| 2059 | abortCommit |= commit_warning(&content, crnlOk, binOk, |
| 2060 | encodingOk, noPrompt, |
| 2061 | zFullname); |
| 2062 | } |
| 2063 | if( contains_merge_marker(&content) ){ |
| 2064 | Blob fname; /* Relative pathname of the file */ |
| 2065 | |
| 2066 | nConflict++; |
| 2067 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1466,16 +1466,17 @@ | |
| 1466 | ** Return 1 if the user pressed 'c'. In that case, the file will have |
| 1467 | ** been converted to UTF-8 (if it was UTF-16) with NL line-endings, |
| 1468 | ** and the original file will have been renamed to "<filename>-original". |
| 1469 | */ |
| 1470 | static int commit_warning( |
| 1471 | Blob *pContent, /* The content of the file being committed. */ |
| 1472 | int crnlOk, /* Non-zero if CR/NL warnings should be disabled. */ |
| 1473 | int binOk, /* Non-zero if binary warnings should be disabled. */ |
| 1474 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 1475 | int noPrompt, /* 0 to always prompt, 1 for 'N', 2 for 'Y'. */ |
| 1476 | const char *zFilename, /* The full name of the file being committed. */ |
| 1477 | Blob *pReason /* Reason for warning, if any (non-fatal only). */ |
| 1478 | ){ |
| 1479 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 1480 | int fUnicode; /* return value of could_be_utf16() */ |
| 1481 | int fBinary; /* does the blob content appear to be binary? */ |
| 1482 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| @@ -1486,24 +1487,24 @@ | |
| 1487 | char *zMsg; /* Warning message */ |
| 1488 | Blob fname; /* Relative pathname of the file */ |
| 1489 | static int allOk = 0; /* Set to true to disable this routine */ |
| 1490 | |
| 1491 | if( allOk ) return 0; |
| 1492 | fUnicode = could_be_utf16(pContent, &bReverse); |
| 1493 | if( fUnicode ){ |
| 1494 | lookFlags = looks_like_utf16(pContent, bReverse, LOOK_NUL); |
| 1495 | }else{ |
| 1496 | lookFlags = looks_like_utf8(pContent, LOOK_NUL); |
| 1497 | if( !(lookFlags & LOOK_BINARY) && invalid_utf8(pContent) ){ |
| 1498 | fHasInvalidUtf8 = 1; |
| 1499 | } |
| 1500 | } |
| 1501 | fHasAnyCr = (lookFlags & LOOK_CR); |
| 1502 | fBinary = (lookFlags & LOOK_BINARY); |
| 1503 | fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR); |
| 1504 | fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF); |
| 1505 | if( fUnicode || fHasAnyCr || fBinary || fHasInvalidUtf8 ){ |
| 1506 | const char *zWarning; |
| 1507 | const char *zDisable; |
| 1508 | const char *zConvert = "c=convert/"; |
| 1509 | Blob ans; |
| 1510 | char cReply; |
| @@ -1563,52 +1564,118 @@ | |
| 1564 | zMsg = mprintf( |
| 1565 | "%s contains %s. Use --no-warnings or the %s to" |
| 1566 | " disable this warning.\n" |
| 1567 | "Commit anyhow (a=all/%sy/N)? ", |
| 1568 | blob_str(&fname), zWarning, zDisable, zConvert); |
| 1569 | if( noPrompt==0 ){ |
| 1570 | prompt_user(zMsg, &ans); |
| 1571 | cReply = blob_str(&ans)[0]; |
| 1572 | blob_reset(&ans); |
| 1573 | }else if( noPrompt==2 ){ |
| 1574 | cReply = 'Y'; |
| 1575 | }else{ |
| 1576 | cReply = 'N'; |
| 1577 | } |
| 1578 | fossil_free(zMsg); |
| 1579 | if( cReply=='a' || cReply=='A' ){ |
| 1580 | allOk = 1; |
| 1581 | }else if( *zConvert && (cReply=='c' || cReply=='C') ){ |
| 1582 | char *zOrig = file_newname(zFilename, "original", 1); |
| 1583 | FILE *f; |
| 1584 | blob_write_to_file(pContent, zOrig); |
| 1585 | fossil_free(zOrig); |
| 1586 | f = fossil_fopen(zFilename, "wb"); |
| 1587 | if( f==0 ){ |
| 1588 | fossil_warning("cannot open %s for writing", zFilename); |
| 1589 | }else{ |
| 1590 | if( fUnicode ){ |
| 1591 | int bomSize; |
| 1592 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 1593 | fwrite(bom, 1, bomSize, f); |
| 1594 | blob_to_utf8_no_bom(pContent, 0); |
| 1595 | }else if( fHasInvalidUtf8 ){ |
| 1596 | blob_cp1252_to_utf8(pContent); |
| 1597 | } |
| 1598 | if( fHasAnyCr ){ |
| 1599 | blob_to_lf_only(pContent); |
| 1600 | } |
| 1601 | fwrite(blob_buffer(pContent), 1, blob_size(pContent), f); |
| 1602 | fclose(f); |
| 1603 | } |
| 1604 | return 1; |
| 1605 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1606 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1607 | zWarning, blob_str(&fname)); |
| 1608 | }else if( noPrompt==2 ){ |
| 1609 | if( pReason ){ |
| 1610 | blob_append(pReason, zWarning, -1); |
| 1611 | } |
| 1612 | return 1; |
| 1613 | } |
| 1614 | blob_reset(&fname); |
| 1615 | } |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
| 1619 | /* |
| 1620 | ** COMMAND: test-commit-warning |
| 1621 | ** |
| 1622 | ** Usage: %fossil test-commit-warning ?OPTIONS? |
| 1623 | ** |
| 1624 | ** Check each file in the checkout, including unmodified ones, using all |
| 1625 | ** the pre-commit checks. |
| 1626 | ** |
| 1627 | ** Options: |
| 1628 | ** --no-settings Do not consider any glob settings. |
| 1629 | ** -v|--verbose Show per-file results for all pre-commit checks. |
| 1630 | ** |
| 1631 | ** See also: commit, extras |
| 1632 | */ |
| 1633 | void test_commit_warning(void){ |
| 1634 | int rc = 0; |
| 1635 | int noSettings = find_option("no-settings", 0, 0)!=0; |
| 1636 | int verboseFlag = find_option("verbose", 0, 0)!=0; |
| 1637 | Stmt q; |
| 1638 | db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); |
| 1639 | db_prepare(&q, |
| 1640 | "SELECT %Q || pathname, pathname, %s, %s, %s FROM vfile" |
| 1641 | " WHERE NOT deleted", |
| 1642 | g.zLocalRoot, |
| 1643 | glob_expr("pathname", noSettings ? 0 : db_get("crnl-glob","")), |
| 1644 | glob_expr("pathname", noSettings ? 0 : db_get("binary-glob","")), |
| 1645 | glob_expr("pathname", noSettings ? 0 : db_get("encoding-glob","")) |
| 1646 | ); |
| 1647 | while( db_step(&q)==SQLITE_ROW ){ |
| 1648 | const char *zFullname; |
| 1649 | const char *zName; |
| 1650 | Blob content, reason; |
| 1651 | int crnlOk, binOk, encodingOk; |
| 1652 | int fileRc; |
| 1653 | |
| 1654 | zFullname = db_column_text(&q, 0); |
| 1655 | zName = db_column_text(&q, 1); |
| 1656 | crnlOk = db_column_int(&q, 2); |
| 1657 | binOk = db_column_int(&q, 3); |
| 1658 | encodingOk = db_column_int(&q, 4); |
| 1659 | blob_zero(&content); |
| 1660 | if( file_wd_islink(zFullname) ){ |
| 1661 | blob_read_link(&content, zFullname); |
| 1662 | }else{ |
| 1663 | blob_read_from_file(&content, zFullname); |
| 1664 | } |
| 1665 | blob_zero(&reason); |
| 1666 | fileRc = commit_warning(&content, crnlOk, binOk, encodingOk, 2, |
| 1667 | zFullname, &reason); |
| 1668 | if( fileRc || verboseFlag ){ |
| 1669 | fossil_print("%d\t%s\t%s\n", fileRc, zName, blob_str(&reason)); |
| 1670 | } |
| 1671 | blob_reset(&reason); |
| 1672 | rc |= fileRc; |
| 1673 | } |
| 1674 | db_finalize(&q); |
| 1675 | fossil_print("%d\n", rc); |
| 1676 | } |
| 1677 | |
| 1678 | /* |
| 1679 | ** qsort() comparison routine for an array of pointers to strings. |
| 1680 | */ |
| 1681 | static int tagCmp(const void *a, const void *b){ |
| @@ -2056,11 +2123,11 @@ | |
| 2123 | } |
| 2124 | /* Do not emit any warnings when they are disabled. */ |
| 2125 | if( !noWarningFlag ){ |
| 2126 | abortCommit |= commit_warning(&content, crnlOk, binOk, |
| 2127 | encodingOk, noPrompt, |
| 2128 | zFullname, 0); |
| 2129 | } |
| 2130 | if( contains_merge_marker(&content) ){ |
| 2131 | Blob fname; /* Relative pathname of the file */ |
| 2132 | |
| 2133 | nConflict++; |
| 2134 |