Fossil SCM
Add a test command to infer the hash policy from the length of path names on reconstruct (disabled by preprocessor directive).
Commit
8d1ed47cc6893493473b747a0f5743498b58c7c81294d7ad96ea7b354b4ee47b
Parent
c47adb914857622…
1 file changed
+60
+60
| --- src/rebuild.c | ||
| +++ src/rebuild.c | ||
| @@ -1074,10 +1074,70 @@ | ||
| 1074 | 1074 | g.eHashPolicy = saved_eHashPolicy; |
| 1075 | 1075 | saved_eHashPolicy = -1; |
| 1076 | 1076 | } |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | +#if 0 | |
| 1080 | +/* | |
| 1081 | +** COMMAND: test-hash-from-path* | |
| 1082 | +** | |
| 1083 | +** Usage: %fossil test-hash-from-path ?OPTIONS? DESTINATION UUID | |
| 1084 | +** | |
| 1085 | +** Generate a sample path name from DESTINATION and UUID, as the `deconstruct' | |
| 1086 | +** command would do. Then try to guess the hash policy from the path name, as | |
| 1087 | +** the `reconstruct' command would do. | |
| 1088 | +** | |
| 1089 | +** No files or directories will be created. | |
| 1090 | +** | |
| 1091 | +** Options: | |
| 1092 | +** -L|--prefixlength N Set the length of the names of the DESTINATION | |
| 1093 | +** subdirectories to N. | |
| 1094 | +*/ | |
| 1095 | +void test_hash_from_path_cmd(void) { | |
| 1096 | + char *zDest; | |
| 1097 | + char *zUuid; | |
| 1098 | + char *zFile; | |
| 1099 | + const char *zHashPolicy = "unknown"; | |
| 1100 | + const char *zPrefixOpt = find_option("prefixlength","L",1); | |
| 1101 | + int iPrefixLength; | |
| 1102 | + if( !zPrefixOpt ){ | |
| 1103 | + iPrefixLength = 2; | |
| 1104 | + }else{ | |
| 1105 | + iPrefixLength = atoi(zPrefixOpt); | |
| 1106 | + if( iPrefixLength<0 || iPrefixLength>9 ){ | |
| 1107 | + fossil_fatal("N(%s) is not a valid prefix length!",zPrefixOpt); | |
| 1108 | + } | |
| 1109 | + } | |
| 1110 | + if( g.argc!=4 ){ | |
| 1111 | + usage ("?OPTIONS? DESTINATION UUID"); | |
| 1112 | + } | |
| 1113 | + zDest = g.argv[2]; | |
| 1114 | + zUuid = g.argv[3]; | |
| 1115 | + if( iPrefixLength ){ | |
| 1116 | + zFNameFormat = mprintf("%s/%%.%ds/%%s",zDest,iPrefixLength); | |
| 1117 | + }else{ | |
| 1118 | + zFNameFormat = mprintf("%s/%%s",zDest); | |
| 1119 | + } | |
| 1120 | + cchFNamePrefix = strlen(zDest); | |
| 1121 | + zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/, | |
| 1122 | + zUuid, zUuid+iPrefixLength); | |
| 1123 | + recon_set_hash_policy(cchFNamePrefix,zFile); | |
| 1124 | + if( saved_eHashPolicy!=-1 ){ | |
| 1125 | + zHashPolicy = hpolicy_name(); | |
| 1126 | + } | |
| 1127 | + recon_restore_hash_policy(); | |
| 1128 | + fossil_print( | |
| 1129 | + "\nPath Name: %s" | |
| 1130 | + "\nHash Policy: %s\n", | |
| 1131 | + zFile,zHashPolicy); | |
| 1132 | + free(zFile); | |
| 1133 | + free(zFNameFormat); | |
| 1134 | + zFNameFormat = 0; | |
| 1135 | + cchFNamePrefix = 0; | |
| 1136 | +} | |
| 1137 | +#endif | |
| 1138 | + | |
| 1079 | 1139 | /* |
| 1080 | 1140 | ** COMMAND: reconstruct* |
| 1081 | 1141 | ** |
| 1082 | 1142 | ** Usage: %fossil reconstruct ?OPTIONS? FILENAME DIRECTORY |
| 1083 | 1143 | ** |
| 1084 | 1144 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -1074,10 +1074,70 @@ | |
| 1074 | g.eHashPolicy = saved_eHashPolicy; |
| 1075 | saved_eHashPolicy = -1; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | ** COMMAND: reconstruct* |
| 1081 | ** |
| 1082 | ** Usage: %fossil reconstruct ?OPTIONS? FILENAME DIRECTORY |
| 1083 | ** |
| 1084 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -1074,10 +1074,70 @@ | |
| 1074 | g.eHashPolicy = saved_eHashPolicy; |
| 1075 | saved_eHashPolicy = -1; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | #if 0 |
| 1080 | /* |
| 1081 | ** COMMAND: test-hash-from-path* |
| 1082 | ** |
| 1083 | ** Usage: %fossil test-hash-from-path ?OPTIONS? DESTINATION UUID |
| 1084 | ** |
| 1085 | ** Generate a sample path name from DESTINATION and UUID, as the `deconstruct' |
| 1086 | ** command would do. Then try to guess the hash policy from the path name, as |
| 1087 | ** the `reconstruct' command would do. |
| 1088 | ** |
| 1089 | ** No files or directories will be created. |
| 1090 | ** |
| 1091 | ** Options: |
| 1092 | ** -L|--prefixlength N Set the length of the names of the DESTINATION |
| 1093 | ** subdirectories to N. |
| 1094 | */ |
| 1095 | void test_hash_from_path_cmd(void) { |
| 1096 | char *zDest; |
| 1097 | char *zUuid; |
| 1098 | char *zFile; |
| 1099 | const char *zHashPolicy = "unknown"; |
| 1100 | const char *zPrefixOpt = find_option("prefixlength","L",1); |
| 1101 | int iPrefixLength; |
| 1102 | if( !zPrefixOpt ){ |
| 1103 | iPrefixLength = 2; |
| 1104 | }else{ |
| 1105 | iPrefixLength = atoi(zPrefixOpt); |
| 1106 | if( iPrefixLength<0 || iPrefixLength>9 ){ |
| 1107 | fossil_fatal("N(%s) is not a valid prefix length!",zPrefixOpt); |
| 1108 | } |
| 1109 | } |
| 1110 | if( g.argc!=4 ){ |
| 1111 | usage ("?OPTIONS? DESTINATION UUID"); |
| 1112 | } |
| 1113 | zDest = g.argv[2]; |
| 1114 | zUuid = g.argv[3]; |
| 1115 | if( iPrefixLength ){ |
| 1116 | zFNameFormat = mprintf("%s/%%.%ds/%%s",zDest,iPrefixLength); |
| 1117 | }else{ |
| 1118 | zFNameFormat = mprintf("%s/%%s",zDest); |
| 1119 | } |
| 1120 | cchFNamePrefix = strlen(zDest); |
| 1121 | zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/, |
| 1122 | zUuid, zUuid+iPrefixLength); |
| 1123 | recon_set_hash_policy(cchFNamePrefix,zFile); |
| 1124 | if( saved_eHashPolicy!=-1 ){ |
| 1125 | zHashPolicy = hpolicy_name(); |
| 1126 | } |
| 1127 | recon_restore_hash_policy(); |
| 1128 | fossil_print( |
| 1129 | "\nPath Name: %s" |
| 1130 | "\nHash Policy: %s\n", |
| 1131 | zFile,zHashPolicy); |
| 1132 | free(zFile); |
| 1133 | free(zFNameFormat); |
| 1134 | zFNameFormat = 0; |
| 1135 | cchFNamePrefix = 0; |
| 1136 | } |
| 1137 | #endif |
| 1138 | |
| 1139 | /* |
| 1140 | ** COMMAND: reconstruct* |
| 1141 | ** |
| 1142 | ** Usage: %fossil reconstruct ?OPTIONS? FILENAME DIRECTORY |
| 1143 | ** |
| 1144 |