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.

drh 2015-02-13 02:36 UTC trunk
Commit cc94bd078e322b6544cc8078957fae6997062656
2 files changed +4 +33 -10
+4
--- src/db.c
+++ src/db.c
@@ -2389,10 +2389,11 @@
23892389
{ "editor", 0, 32, 0, 0, "" },
23902390
{ "empty-dirs", 0, 40, 1, 0, "" },
23912391
{ "encoding-glob", 0, 40, 1, 0, "" },
23922392
{ "gdiff-command", 0, 40, 0, 0, "gdiff" },
23932393
{ "gmerge-command", 0, 40, 0, 0, "" },
2394
+ { "hash-digits", 0, 5, 0, 0, "10" },
23942395
{ "http-port", 0, 16, 0, 0, "8080" },
23952396
{ "https-login", 0, 0, 0, 0, "off" },
23962397
{ "ignore-glob", 0, 40, 1, 0, "" },
23972398
{ "keep-glob", 0, 40, 1, 0, "" },
23982399
{ "localauth", 0, 0, 0, 0, "off" },
@@ -2565,10 +2566,13 @@
25652566
** gmerge-command A graphical merge conflict resolver command operating
25662567
** on four files.
25672568
** Ex: kdiff3 "%baseline" "%original" "%merge" -o "%output"
25682569
** Ex: xxdiff "%original" "%baseline" "%merge" -M "%output"
25692570
** 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)
25702574
**
25712575
** http-port The TCP/IP port number to use by the "server"
25722576
** and "ui" commands. Default: 8080
25732577
**
25742578
** https-login Send login credentials using HTTPS instead of HTTP
25752579
--- 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 @@
2929
/* Two custom conversions are used to show a prefix of SHA1 hashes:
3030
**
3131
** %!S Prefix of a length appropriate for URLs
3232
** %S Prefix of a length appropriate for human display
3333
**
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
+}
4266
4367
/*
4468
** Conversion types fall into various categories as defined by the
4569
** following enumeration.
4670
*/
@@ -634,12 +658,11 @@
634658
if( bufpt==0 ){
635659
bufpt = "";
636660
}else if( xtype==etDYNSTRING ){
637661
zExtra = bufpt;
638662
}else if( xtype==etSTRINGID ){
639
- precision = flag_altform2 ? FOSSIL_SHA1_URLPREFIX_LEN :
640
- FOSSIL_SHA1_PREFIX_LEN;
663
+ precision = hashDigits(flag_altform2);
641664
}
642665
length = StrNLen32(bufpt, limit);
643666
if( precision>=0 && precision<length ) length = precision;
644667
break;
645668
}
646669
--- 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

Keyboard Shortcuts

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