static void bz_git_make_slug(struct cork_buffer *dest, const char *url, const char *commit) { struct cork_path *path; cork_hash hash; /* First grab the basename of the URL. */ path = cork_path_new(url); cork_path_set_basename(path); cork_buffer_append_string(dest, cork_path_get(path)); cork_path_free(path); /* Then remove any trailing ".git" extension. */ if (dest->size >= 4) { const char *extension = &cork_buffer_char(dest, dest->size - 4); if (strcmp(extension, ".git") == 0) { cork_buffer_truncate(dest, dest->size - 4); } } /* Then calculate the hash of the full URL and commit, and append that to * ensure we have a unique slug. */ hash = 0x48f2a642; /* hash of "git" */ hash = cork_stable_hash_buffer(hash, url, strlen(url)); hash = cork_stable_hash_buffer(hash, commit, strlen(commit)); cork_buffer_append_printf(dest, "-%08" PRIx32, hash); }
int main(int argc, char **argv) { parse_options(argc, argv); if (type == CORK_HASH_BIG) { cork_big_hash result = CORK_BIG_HASH_INIT(); result = cork_big_hash_buffer(result, string, strlen(string)); printf("%016" PRIx64 "%016" PRIx64 "\n", cork_u128_be64(result.u128, 0), cork_u128_be64(result.u128, 1)); } if (type == CORK_HASH_FASTEST) { /* don't include NUL terminator in hash */ cork_hash result = 0; result = cork_hash_buffer(result, string, strlen(string)); printf("0x%08" PRIx32 "\n", result); } if (type == CORK_HASH_STABLE) { /* don't include NUL terminator in hash */ cork_hash result = 0; result = cork_stable_hash_buffer(result, string, strlen(string)); printf("0x%08" PRIx32 "\n", result); } return EXIT_SUCCESS; }