THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
930 B

  1. #include "cache.h"
  2. #include "sha1-array.h"
  3. static void print_sha1(const unsigned char sha1[20], void *data)
  4. {
  5. puts(sha1_to_hex(sha1));
  6. }
  7. int main(int argc, char **argv)
  8. {
  9. struct sha1_array array = SHA1_ARRAY_INIT;
  10. struct strbuf line = STRBUF_INIT;
  11. while (strbuf_getline(&line, stdin) != EOF) {
  12. const char *arg;
  13. unsigned char sha1[20];
  14. if (skip_prefix(line.buf, "append ", &arg)) {
  15. if (get_sha1_hex(arg, sha1))
  16. die("not a hexadecimal SHA1: %s", arg);
  17. sha1_array_append(&array, sha1);
  18. } else if (skip_prefix(line.buf, "lookup ", &arg)) {
  19. if (get_sha1_hex(arg, sha1))
  20. die("not a hexadecimal SHA1: %s", arg);
  21. printf("%d\n", sha1_array_lookup(&array, sha1));
  22. } else if (!strcmp(line.buf, "clear"))
  23. sha1_array_clear(&array);
  24. else if (!strcmp(line.buf, "for_each_unique"))
  25. sha1_array_for_each_unique(&array, print_sha1, NULL);
  26. else
  27. die("unknown command: %s", line.buf);
  28. }
  29. return 0;
  30. }