MCPcopy Create free account
hub / github.com/git/git / refs_for_each_ref_ext

Function refs_for_each_ref_ext

refs.c:1875–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1873}
1874
1875int refs_for_each_ref_ext(struct ref_store *refs,
1876 refs_for_each_cb cb, void *cb_data,
1877 const struct refs_for_each_ref_options *opts)
1878{
1879 struct strvec namespaced_exclude_patterns = STRVEC_INIT;
1880 struct strbuf namespaced_prefix = STRBUF_INIT;
1881 struct strbuf real_pattern = STRBUF_INIT;
1882 struct for_each_ref_filter filter;
1883 struct ref_iterator *iter;
1884 size_t trim_prefix = opts->trim_prefix;
1885 const char **exclude_patterns;
1886 const char *prefix;
1887 int ret;
1888
1889 if (!refs)
1890 BUG("no ref store passed");
1891
1892 if (opts->trim_prefix) {
1893 size_t prefix_len;
1894
1895 if (!opts->prefix)
1896 BUG("trimming only allowed with a prefix");
1897
1898 prefix_len = strlen(opts->prefix);
1899 if (prefix_len == opts->trim_prefix && opts->prefix[prefix_len - 1] != '/')
1900 BUG("ref pattern must end in a trailing slash when trimming");
1901 }
1902
1903 if (opts->pattern) {
1904 if (!opts->prefix && !starts_with(opts->pattern, "refs/"))
1905 strbuf_addstr(&real_pattern, "refs/");
1906 else if (opts->prefix)
1907 strbuf_addstr(&real_pattern, opts->prefix);
1908 strbuf_addstr(&real_pattern, opts->pattern);
1909
1910 if (!has_glob_specials(opts->pattern)) {
1911 /* Append implied '/' '*' if not present. */
1912 strbuf_complete(&real_pattern, '/');
1913 /* No need to check for '*', there is none. */
1914 strbuf_addch(&real_pattern, '*');
1915 }
1916
1917 filter.pattern = real_pattern.buf;
1918 filter.trim_prefix = opts->trim_prefix;
1919 filter.fn = cb;
1920 filter.cb_data = cb_data;
1921
1922 /*
1923 * We need to trim the prefix in the callback function as the
1924 * pattern is expected to match on the full refname.
1925 */
1926 trim_prefix = 0;
1927
1928 cb = for_each_filter_refs;
1929 cb_data = &filter;
1930 }
1931
1932 if (opts->namespace) {

Callers 15

mark_tipsFunction · 0.85
for_each_bisect_refFunction · 0.85
refs_for_each_tag_refFunction · 0.85
refs_for_each_branch_refFunction · 0.85
refs_for_each_remote_refFunction · 0.85
refs_for_each_refFunction · 0.85

Calls 10

starts_withFunction · 0.85
strbuf_addstrFunction · 0.85
has_glob_specialsFunction · 0.85
strbuf_completeFunction · 0.85
strbuf_addchFunction · 0.85
refs_ref_iterator_beginFunction · 0.85
do_for_each_ref_iteratorFunction · 0.85
strvec_clearFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by 2

cmd_for_each_refFunction · 0.68