Git fork

refs: introduce missing functions that accept a `struct ref_store`

While most of the functions in "refs.h" have a variant that accepts a
`struct ref_store`, some don't. Callers of these functions are thus
forced to implicitly rely on `the_repository` to figure out the ref
store that is to be used.

Introduce those missing functions to address this shortcoming.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
39a9ef8f d4cc1ec3

+64 -14
+51 -14
refs.c
··· 400 400 void *cb_data; 401 401 }; 402 402 403 - int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags) 403 + int refs_read_ref_full(struct ref_store *refs, const char *refname, 404 + int resolve_flags, struct object_id *oid, int *flags) 404 405 { 405 - struct ref_store *refs = get_main_ref_store(the_repository); 406 - 407 406 if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, 408 407 oid, flags)) 409 408 return 0; 410 409 return -1; 411 410 } 412 411 412 + int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags) 413 + { 414 + return refs_read_ref_full(get_main_ref_store(the_repository), refname, 415 + resolve_flags, oid, flags); 416 + } 417 + 418 + int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid) 419 + { 420 + return refs_read_ref_full(refs, refname, RESOLVE_REF_READING, oid, NULL); 421 + } 422 + 413 423 int read_ref(const char *refname, struct object_id *oid) 414 424 { 415 - return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL); 425 + return refs_read_ref(get_main_ref_store(the_repository), refname, oid); 416 426 } 417 427 418 428 int refs_ref_exists(struct ref_store *refs, const char *refname) ··· 542 552 return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data); 543 553 } 544 554 545 - int head_ref_namespaced(each_ref_fn fn, void *cb_data) 555 + int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_data) 546 556 { 547 557 struct strbuf buf = STRBUF_INIT; 548 558 int ret = 0; ··· 550 560 int flag; 551 561 552 562 strbuf_addf(&buf, "%sHEAD", get_git_namespace()); 553 - if (!read_ref_full(buf.buf, RESOLVE_REF_READING, &oid, &flag)) 563 + if (!refs_read_ref_full(refs, buf.buf, RESOLVE_REF_READING, &oid, &flag)) 554 564 ret = fn(buf.buf, &oid, flag, cb_data); 555 565 strbuf_release(&buf); 556 566 557 567 return ret; 558 568 } 559 569 570 + int head_ref_namespaced(each_ref_fn fn, void *cb_data) 571 + { 572 + return refs_head_ref_namespaced(get_main_ref_store(the_repository), 573 + fn, cb_data); 574 + } 575 + 560 576 void normalize_glob_ref(struct string_list_item *item, const char *prefix, 561 577 const char *pattern) 562 578 { ··· 583 599 strbuf_release(&normalized_pattern); 584 600 } 585 601 586 - int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, 587 - const char *prefix, void *cb_data) 602 + int refs_for_each_glob_ref_in(struct ref_store *refs, each_ref_fn fn, 603 + const char *pattern, const char *prefix, void *cb_data) 588 604 { 589 605 struct strbuf real_pattern = STRBUF_INIT; 590 606 struct for_each_ref_filter filter; ··· 607 623 filter.prefix = prefix; 608 624 filter.fn = fn; 609 625 filter.cb_data = cb_data; 610 - ret = for_each_ref(for_each_filter_refs, &filter); 626 + ret = refs_for_each_ref(refs, for_each_filter_refs, &filter); 611 627 612 628 strbuf_release(&real_pattern); 613 629 return ret; 614 630 } 615 631 632 + int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, 633 + const char *prefix, void *cb_data) 634 + { 635 + return refs_for_each_glob_ref_in(get_main_ref_store(the_repository), 636 + fn, pattern, prefix, cb_data); 637 + } 638 + 639 + int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn, 640 + const char *pattern, void *cb_data) 641 + { 642 + return refs_for_each_glob_ref_in(refs, fn, pattern, NULL, cb_data); 643 + } 644 + 616 645 int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data) 617 646 { 618 - return for_each_glob_ref_in(fn, pattern, NULL, cb_data); 647 + return refs_for_each_glob_ref(get_main_ref_store(the_repository), 648 + fn, pattern, cb_data); 619 649 } 620 650 621 651 const char *prettify_refname(const char *name) ··· 1733 1763 DO_FOR_EACH_INCLUDE_BROKEN, cb_data); 1734 1764 } 1735 1765 1736 - int for_each_namespaced_ref(const char **exclude_patterns, 1737 - each_ref_fn fn, void *cb_data) 1766 + int refs_for_each_namespaced_ref(struct ref_store *refs, 1767 + const char **exclude_patterns, 1768 + each_ref_fn fn, void *cb_data) 1738 1769 { 1739 1770 struct strbuf buf = STRBUF_INIT; 1740 1771 int ret; 1741 1772 strbuf_addf(&buf, "%srefs/", get_git_namespace()); 1742 - ret = do_for_each_ref(get_main_ref_store(the_repository), 1743 - buf.buf, exclude_patterns, fn, 0, 0, cb_data); 1773 + ret = do_for_each_ref(refs, buf.buf, exclude_patterns, fn, 0, 0, cb_data); 1744 1774 strbuf_release(&buf); 1745 1775 return ret; 1776 + } 1777 + 1778 + int for_each_namespaced_ref(const char **exclude_patterns, 1779 + each_ref_fn fn, void *cb_data) 1780 + { 1781 + return refs_for_each_namespaced_ref(get_main_ref_store(the_repository), 1782 + exclude_patterns, fn, cb_data); 1746 1783 } 1747 1784 1748 1785 int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
+13
refs.h
··· 81 81 char *resolve_refdup(const char *refname, int resolve_flags, 82 82 struct object_id *oid, int *flags); 83 83 84 + int refs_read_ref_full(struct ref_store *refs, const char *refname, 85 + int resolve_flags, struct object_id *oid, int *flags); 84 86 int read_ref_full(const char *refname, int resolve_flags, 85 87 struct object_id *oid, int *flags); 88 + 89 + int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid); 86 90 int read_ref(const char *refname, struct object_id *oid); 87 91 88 92 int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname, ··· 375 379 int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data); 376 380 377 381 /* iterates all refs that match the specified glob pattern. */ 382 + int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn, 383 + const char *pattern, void *cb_data); 378 384 int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data); 379 385 386 + int refs_for_each_glob_ref_in(struct ref_store *refs, each_ref_fn fn, 387 + const char *pattern, const char *prefix, void *cb_data); 380 388 int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, 381 389 const char *prefix, void *cb_data); 382 390 391 + int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_data); 383 392 int head_ref_namespaced(each_ref_fn fn, void *cb_data); 393 + 384 394 /* 385 395 * references matching any pattern in "exclude_patterns" are omitted from the 386 396 * result set on a best-effort basis. 387 397 */ 398 + int refs_for_each_namespaced_ref(struct ref_store *refs, 399 + const char **exclude_patterns, 400 + each_ref_fn fn, void *cb_data); 388 401 int for_each_namespaced_ref(const char **exclude_patterns, 389 402 each_ref_fn fn, void *cb_data); 390 403