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.

73 lines
1.6KB

  1. #include "cache.h"
  2. #include "oidset.h"
  3. void oidset_init(struct oidset *set, size_t initial_size)
  4. {
  5. memset(&set->set, 0, sizeof(set->set));
  6. if (initial_size)
  7. kh_resize_oid_set(&set->set, initial_size);
  8. }
  9. int oidset_contains(const struct oidset *set, const struct object_id *oid)
  10. {
  11. khiter_t pos = kh_get_oid_set(&set->set, *oid);
  12. return pos != kh_end(&set->set);
  13. }
  14. int oidset_insert(struct oidset *set, const struct object_id *oid)
  15. {
  16. int added;
  17. kh_put_oid_set(&set->set, *oid, &added);
  18. return !added;
  19. }
  20. int oidset_remove(struct oidset *set, const struct object_id *oid)
  21. {
  22. khiter_t pos = kh_get_oid_set(&set->set, *oid);
  23. if (pos == kh_end(&set->set))
  24. return 0;
  25. kh_del_oid_set(&set->set, pos);
  26. return 1;
  27. }
  28. void oidset_clear(struct oidset *set)
  29. {
  30. kh_release_oid_set(&set->set);
  31. oidset_init(set, 0);
  32. }
  33. void oidset_parse_file(struct oidset *set, const char *path)
  34. {
  35. FILE *fp;
  36. struct strbuf sb = STRBUF_INIT;
  37. struct object_id oid;
  38. fp = fopen(path, "r");
  39. if (!fp)
  40. die("could not open object name list: %s", path);
  41. while (!strbuf_getline(&sb, fp)) {
  42. const char *p;
  43. const char *name;
  44. /*
  45. * Allow trailing comments, leading whitespace
  46. * (including before commits), and empty or whitespace
  47. * only lines.
  48. */
  49. name = strchr(sb.buf, '#');
  50. if (name)
  51. strbuf_setlen(&sb, name - sb.buf);
  52. strbuf_trim(&sb);
  53. if (!sb.len)
  54. continue;
  55. if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0')
  56. die("invalid object name: %s", sb.buf);
  57. oidset_insert(set, &oid);
  58. }
  59. if (ferror(fp))
  60. die_errno("Could not read '%s'", path);
  61. fclose(fp);
  62. strbuf_release(&sb);
  63. }