Fossil SCM
Add the "hash-digits" setting for controling the number of digits of the SHA1 hash to display in output intended for humans. The minimum is 6 and the default is 10. Compile-time option FOSSIL_HASH_DIGITS can set a different default. URLs use at least 6 more digits than human output. Compile-time option FOSSIL_HASH_DIGITS_URL sets a lower-bound on the number of hash digits in URLs.
Commit
cc94bd078e322b6544cc8078957fae6997062656
Parent
8fdb68226f27b15…
2 files changed
+4
+33
-10
M
src/db.c
+4
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -2389,10 +2389,11 @@ | ||
| 2389 | 2389 | { "editor", 0, 32, 0, 0, "" }, |
| 2390 | 2390 | { "empty-dirs", 0, 40, 1, 0, "" }, |
| 2391 | 2391 | { "encoding-glob", 0, 40, 1, 0, "" }, |
| 2392 | 2392 | { "gdiff-command", 0, 40, 0, 0, "gdiff" }, |
| 2393 | 2393 | { "gmerge-command", 0, 40, 0, 0, "" }, |
| 2394 | + { "hash-digits", 0, 5, 0, 0, "10" }, | |
| 2394 | 2395 | { "http-port", 0, 16, 0, 0, "8080" }, |
| 2395 | 2396 | { "https-login", 0, 0, 0, 0, "off" }, |
| 2396 | 2397 | { "ignore-glob", 0, 40, 1, 0, "" }, |
| 2397 | 2398 | { "keep-glob", 0, 40, 1, 0, "" }, |
| 2398 | 2399 | { "localauth", 0, 0, 0, 0, "off" }, |
| @@ -2565,10 +2566,13 @@ | ||
| 2565 | 2566 | ** gmerge-command A graphical merge conflict resolver command operating |
| 2566 | 2567 | ** on four files. |
| 2567 | 2568 | ** Ex: kdiff3 "%baseline" "%original" "%merge" -o "%output" |
| 2568 | 2569 | ** Ex: xxdiff "%original" "%baseline" "%merge" -M "%output" |
| 2569 | 2570 | ** Ex: meld "%baseline" "%original" "%merge" "%output" |
| 2571 | +** | |
| 2572 | +** hash-digits The number of hexadecimal digits of the SHA1 hash to | |
| 2573 | +** display. (Default: 10; Minimum: 6) | |
| 2570 | 2574 | ** |
| 2571 | 2575 | ** http-port The TCP/IP port number to use by the "server" |
| 2572 | 2576 | ** and "ui" commands. Default: 8080 |
| 2573 | 2577 | ** |
| 2574 | 2578 | ** https-login Send login credentials using HTTPS instead of HTTP |
| 2575 | 2579 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -2389,10 +2389,11 @@ | |
| 2389 | { "editor", 0, 32, 0, 0, "" }, |
| 2390 | { "empty-dirs", 0, 40, 1, 0, "" }, |
| 2391 | { "encoding-glob", 0, 40, 1, 0, "" }, |
| 2392 | { "gdiff-command", 0, 40, 0, 0, "gdiff" }, |
| 2393 | { "gmerge-command", 0, 40, 0, 0, "" }, |
| 2394 | { "http-port", 0, 16, 0, 0, "8080" }, |
| 2395 | { "https-login", 0, 0, 0, 0, "off" }, |
| 2396 | { "ignore-glob", 0, 40, 1, 0, "" }, |
| 2397 | { "keep-glob", 0, 40, 1, 0, "" }, |
| 2398 | { "localauth", 0, 0, 0, 0, "off" }, |
| @@ -2565,10 +2566,13 @@ | |
| 2565 | ** gmerge-command A graphical merge conflict resolver command operating |
| 2566 | ** on four files. |
| 2567 | ** Ex: kdiff3 "%baseline" "%original" "%merge" -o "%output" |
| 2568 | ** Ex: xxdiff "%original" "%baseline" "%merge" -M "%output" |
| 2569 | ** Ex: meld "%baseline" "%original" "%merge" "%output" |
| 2570 | ** |
| 2571 | ** http-port The TCP/IP port number to use by the "server" |
| 2572 | ** and "ui" commands. Default: 8080 |
| 2573 | ** |
| 2574 | ** https-login Send login credentials using HTTPS instead of HTTP |
| 2575 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -2389,10 +2389,11 @@ | |
| 2389 | { "editor", 0, 32, 0, 0, "" }, |
| 2390 | { "empty-dirs", 0, 40, 1, 0, "" }, |
| 2391 | { "encoding-glob", 0, 40, 1, 0, "" }, |
| 2392 | { "gdiff-command", 0, 40, 0, 0, "gdiff" }, |
| 2393 | { "gmerge-command", 0, 40, 0, 0, "" }, |
| 2394 | { "hash-digits", 0, 5, 0, 0, "10" }, |
| 2395 | { "http-port", 0, 16, 0, 0, "8080" }, |
| 2396 | { "https-login", 0, 0, 0, 0, "off" }, |
| 2397 | { "ignore-glob", 0, 40, 1, 0, "" }, |
| 2398 | { "keep-glob", 0, 40, 1, 0, "" }, |
| 2399 | { "localauth", 0, 0, 0, 0, "off" }, |
| @@ -2565,10 +2566,13 @@ | |
| 2566 | ** gmerge-command A graphical merge conflict resolver command operating |
| 2567 | ** on four files. |
| 2568 | ** Ex: kdiff3 "%baseline" "%original" "%merge" -o "%output" |
| 2569 | ** Ex: xxdiff "%original" "%baseline" "%merge" -M "%output" |
| 2570 | ** Ex: meld "%baseline" "%original" "%merge" "%output" |
| 2571 | ** |
| 2572 | ** hash-digits The number of hexadecimal digits of the SHA1 hash to |
| 2573 | ** display. (Default: 10; Minimum: 6) |
| 2574 | ** |
| 2575 | ** http-port The TCP/IP port number to use by the "server" |
| 2576 | ** and "ui" commands. Default: 8080 |
| 2577 | ** |
| 2578 | ** https-login Send login credentials using HTTPS instead of HTTP |
| 2579 |
+33
-10
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -29,18 +29,42 @@ | ||
| 29 | 29 | /* Two custom conversions are used to show a prefix of SHA1 hashes: |
| 30 | 30 | ** |
| 31 | 31 | ** %!S Prefix of a length appropriate for URLs |
| 32 | 32 | ** %S Prefix of a length appropriate for human display |
| 33 | 33 | ** |
| 34 | -** The following macros determine those lengths. | |
| 35 | -*/ | |
| 36 | -#ifndef FOSSIL_SHA1_PREFIX_LEN | |
| 37 | -# define FOSSIL_SHA1_PREFIX_LEN 10 /* For %S (human display) */ | |
| 38 | -#endif | |
| 39 | -#ifndef FOSSIL_SHA1_URLPREFIX_LEN | |
| 40 | -# define FOSSIL_SHA1_URLPREFIX_LEN 16 /* For %!S (embedded in URLs) */ | |
| 41 | -#endif | |
| 34 | +** The following macros help determine those lengths. FOSSIL_HASH_DIGITS | |
| 35 | +** is the default number of digits to display to humans. This value can | |
| 36 | +** be overridden using the hash-digits setting. FOSSIL_HASH_DIGITS_URL | |
| 37 | +** is the minimum number of digits to be used in URLs. The number used | |
| 38 | +** will always be at least 6 more than the number used for human output, | |
| 39 | +** or 40 if the number of digits in human output is 34 or more. | |
| 40 | +*/ | |
| 41 | +#ifndef FOSSIL_HASH_DIGITS | |
| 42 | +# define FOSSIL_HASH_DIGITS 10 /* For %S (human display) */ | |
| 43 | +#endif | |
| 44 | +#ifndef FOSSIL_HASH_DIGITS_URL | |
| 45 | +# define FOSSIL_HASH_DIGITS_URL 16 /* For %!S (embedded in URLs) */ | |
| 46 | +#endif | |
| 47 | + | |
| 48 | +/* | |
| 49 | +** Return the number of SHA1 hash digits to display. The number is for | |
| 50 | +** human output if the bForUrl is false and is destined for a URL if | |
| 51 | +** bForUrl is false. | |
| 52 | +*/ | |
| 53 | +static int hashDigits(int bForUrl){ | |
| 54 | + static int nDigitHuman = 0; | |
| 55 | + static int nDigitUrl = 0; | |
| 56 | + if( nDigitHuman==0 ){ | |
| 57 | + nDigitHuman = db_get_int("hash-digits", FOSSIL_HASH_DIGITS); | |
| 58 | + if( nDigitHuman < 6 ) nDigitHuman = 6; | |
| 59 | + if( nDigitHuman > 40 ) nDigitHuman = 40; | |
| 60 | + nDigitUrl = nDigitHuman + 6; | |
| 61 | + if( nDigitUrl < FOSSIL_HASH_DIGITS_URL ) nDigitUrl = FOSSIL_HASH_DIGITS_URL; | |
| 62 | + if( nDigitUrl > 40 ) nDigitUrl = 40; | |
| 63 | + } | |
| 64 | + return bForUrl ? nDigitUrl : nDigitHuman; | |
| 65 | +} | |
| 42 | 66 | |
| 43 | 67 | /* |
| 44 | 68 | ** Conversion types fall into various categories as defined by the |
| 45 | 69 | ** following enumeration. |
| 46 | 70 | */ |
| @@ -634,12 +658,11 @@ | ||
| 634 | 658 | if( bufpt==0 ){ |
| 635 | 659 | bufpt = ""; |
| 636 | 660 | }else if( xtype==etDYNSTRING ){ |
| 637 | 661 | zExtra = bufpt; |
| 638 | 662 | }else if( xtype==etSTRINGID ){ |
| 639 | - precision = flag_altform2 ? FOSSIL_SHA1_URLPREFIX_LEN : | |
| 640 | - FOSSIL_SHA1_PREFIX_LEN; | |
| 663 | + precision = hashDigits(flag_altform2); | |
| 641 | 664 | } |
| 642 | 665 | length = StrNLen32(bufpt, limit); |
| 643 | 666 | if( precision>=0 && precision<length ) length = precision; |
| 644 | 667 | break; |
| 645 | 668 | } |
| 646 | 669 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -29,18 +29,42 @@ | |
| 29 | /* Two custom conversions are used to show a prefix of SHA1 hashes: |
| 30 | ** |
| 31 | ** %!S Prefix of a length appropriate for URLs |
| 32 | ** %S Prefix of a length appropriate for human display |
| 33 | ** |
| 34 | ** The following macros determine those lengths. |
| 35 | */ |
| 36 | #ifndef FOSSIL_SHA1_PREFIX_LEN |
| 37 | # define FOSSIL_SHA1_PREFIX_LEN 10 /* For %S (human display) */ |
| 38 | #endif |
| 39 | #ifndef FOSSIL_SHA1_URLPREFIX_LEN |
| 40 | # define FOSSIL_SHA1_URLPREFIX_LEN 16 /* For %!S (embedded in URLs) */ |
| 41 | #endif |
| 42 | |
| 43 | /* |
| 44 | ** Conversion types fall into various categories as defined by the |
| 45 | ** following enumeration. |
| 46 | */ |
| @@ -634,12 +658,11 @@ | |
| 634 | if( bufpt==0 ){ |
| 635 | bufpt = ""; |
| 636 | }else if( xtype==etDYNSTRING ){ |
| 637 | zExtra = bufpt; |
| 638 | }else if( xtype==etSTRINGID ){ |
| 639 | precision = flag_altform2 ? FOSSIL_SHA1_URLPREFIX_LEN : |
| 640 | FOSSIL_SHA1_PREFIX_LEN; |
| 641 | } |
| 642 | length = StrNLen32(bufpt, limit); |
| 643 | if( precision>=0 && precision<length ) length = precision; |
| 644 | break; |
| 645 | } |
| 646 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -29,18 +29,42 @@ | |
| 29 | /* Two custom conversions are used to show a prefix of SHA1 hashes: |
| 30 | ** |
| 31 | ** %!S Prefix of a length appropriate for URLs |
| 32 | ** %S Prefix of a length appropriate for human display |
| 33 | ** |
| 34 | ** The following macros help determine those lengths. FOSSIL_HASH_DIGITS |
| 35 | ** is the default number of digits to display to humans. This value can |
| 36 | ** be overridden using the hash-digits setting. FOSSIL_HASH_DIGITS_URL |
| 37 | ** is the minimum number of digits to be used in URLs. The number used |
| 38 | ** will always be at least 6 more than the number used for human output, |
| 39 | ** or 40 if the number of digits in human output is 34 or more. |
| 40 | */ |
| 41 | #ifndef FOSSIL_HASH_DIGITS |
| 42 | # define FOSSIL_HASH_DIGITS 10 /* For %S (human display) */ |
| 43 | #endif |
| 44 | #ifndef FOSSIL_HASH_DIGITS_URL |
| 45 | # define FOSSIL_HASH_DIGITS_URL 16 /* For %!S (embedded in URLs) */ |
| 46 | #endif |
| 47 | |
| 48 | /* |
| 49 | ** Return the number of SHA1 hash digits to display. The number is for |
| 50 | ** human output if the bForUrl is false and is destined for a URL if |
| 51 | ** bForUrl is false. |
| 52 | */ |
| 53 | static int hashDigits(int bForUrl){ |
| 54 | static int nDigitHuman = 0; |
| 55 | static int nDigitUrl = 0; |
| 56 | if( nDigitHuman==0 ){ |
| 57 | nDigitHuman = db_get_int("hash-digits", FOSSIL_HASH_DIGITS); |
| 58 | if( nDigitHuman < 6 ) nDigitHuman = 6; |
| 59 | if( nDigitHuman > 40 ) nDigitHuman = 40; |
| 60 | nDigitUrl = nDigitHuman + 6; |
| 61 | if( nDigitUrl < FOSSIL_HASH_DIGITS_URL ) nDigitUrl = FOSSIL_HASH_DIGITS_URL; |
| 62 | if( nDigitUrl > 40 ) nDigitUrl = 40; |
| 63 | } |
| 64 | return bForUrl ? nDigitUrl : nDigitHuman; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | ** Conversion types fall into various categories as defined by the |
| 69 | ** following enumeration. |
| 70 | */ |
| @@ -634,12 +658,11 @@ | |
| 658 | if( bufpt==0 ){ |
| 659 | bufpt = ""; |
| 660 | }else if( xtype==etDYNSTRING ){ |
| 661 | zExtra = bufpt; |
| 662 | }else if( xtype==etSTRINGID ){ |
| 663 | precision = hashDigits(flag_altform2); |
| 664 | } |
| 665 | length = StrNLen32(bufpt, limit); |
| 666 | if( precision>=0 && precision<length ) length = precision; |
| 667 | break; |
| 668 | } |
| 669 |