From: Ronnie Sahlberg Subject: [PATCH v3 17/23] refs.c: move ref iterators to the common code Date: Tue, 19 Aug 2014 09:30:41 -0700 Message-ID: <1408465847-30384-18-git-send-email-sahlberg@google.com> References: <1408465847-30384-1-git-send-email-sahlberg@google.com> Cc: Ronnie Sahlberg To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Aug 19 18:32:38 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XJmKa-0002zZ-P8 for gcvg-git-2@plane.gmane.org; Tue, 19 Aug 2014 18:32:21 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204AbaHSQbc (ORCPT ); Tue, 19 Aug 2014 12:31:32 -0400 Received: from mail-ig0-f201.google.com ([209.85.213.201]:36560 "EHLO mail-ig0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbaHSQaz (ORCPT ); Tue, 19 Aug 2014 12:30:55 -0400 Received: by mail-ig0-f201.google.com with SMTP id h3so1089089igd.4 for ; Tue, 19 Aug 2014 09:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OMrSsP7rpCIh9DDD8hTEh0Vx3Fm1KBrCWVqoRbfJZcA=; b=mgK+LtT19Nk0Qv6DSTg6Ux7jWjh20tR+5rAOPK7qpxQjwwQ1wpwe8kVXC8yP847fkN UqCWNOX7Zj5XPY4O1rVyoUiPTeHUWBQ5O7WFtL42QQdJDAEqiIWWzv3M9iAxdH5achQW Xxv4b5RSSF8xVFLB6Yrvvz3W9nA5Wh71Rmr6qUDJIuF5ty0abaRC/a0+t151AERoZxMu +N8R50yPDAqtAzLGmpd9+NW0nwYJrma07ZsxQRBjDs8cQGe4AwwE0281tjNpmrMLysle H8ig3MU+1CX6zJX7cUhtEtlB1MRjRmCYc4MxBJvqgEObaQLyWKfZLzIlK+kyBk2H1vTP cXig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OMrSsP7rpCIh9DDD8hTEh0Vx3Fm1KBrCWVqoRbfJZcA=; b=esylhdanUTwC6nt3fZi+diR5JyOpjgtKyym8GsSp46AY2X1uo/zS9gybWaBznqANsm 0Kogv7na7mS8wU+m3hVAtXP5l68/LMFTCVsvlUV+/EblNg2zN/5Ju6GnYNgJPlty/u/E C3uzJsyIHaLzineYWvDjbMmmEgyfiO3SlbccTtwks9nFffWEKglDBY9kxmODzwaFn4kp pdSq07Jr/IiwFyDhJoGAM+9Zr78eDova7D5sgyWSopiZVMn/F2/eAUCoVWQlt/0u2AEO IVA/Uu4vFy0pTTOpNTBod3ym2RnmD/ounEdn2+rN7BbaAfS3YjhqH+ITIxKJFXOhAFcH I0hw== X-Gm-Message-State: ALoCoQlokHVMKLr2HurMJBZXQdgI4Zhg2vrrBCYjdp+sbrhifupalwVY5diSIY9O6zyD4pc/Q26K X-Received: by 10.50.153.98 with SMTP id vf2mr3632792igb.5.1408465853708; Tue, 19 Aug 2014 09:30:53 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id o69si329358yhp.6.2014.08.19.09.30.53 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Aug 2014 09:30:53 -0700 (PDT) Received: from sahlberg1.mtv.corp.google.com (sahlberg1.mtv.corp.google.com [172.27.69.52]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 7702631C534; Tue, 19 Aug 2014 09:30:53 -0700 (PDT) Received: by sahlberg1.mtv.corp.google.com (Postfix, from userid 177442) id 209A9E0967; Tue, 19 Aug 2014 09:30:53 -0700 (PDT) X-Mailer: git-send-email 2.0.1.552.g1af257a In-Reply-To: <1408465847-30384-1-git-send-email-sahlberg@google.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Signed-off-by: Ronnie Sahlberg --- refs-be-files.c | 81 --------------------------------------------------------- refs.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/refs-be-files.c b/refs-be-files.c index fb9c614..9aa88ef 100644 --- a/refs-be-files.c +++ b/refs-be-files.c @@ -1377,22 +1377,6 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int fla } } -/* The argument to filter_refs */ -struct ref_filter { - const char *pattern; - each_ref_fn *fn; - void *cb_data; -}; - -static int filter_refs(const char *refname, const unsigned char *sha1, int flags, - void *data) -{ - struct ref_filter *filter = (struct ref_filter *)data; - if (wildmatch(filter->pattern, refname, 0, NULL)) - return 0; - return filter->fn(refname, sha1, flags, filter->cb_data); -} - enum peel_status { /* object was peeled successfully: */ PEEL_PEELED = 0, @@ -1646,36 +1630,6 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix, return do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data); } -int for_each_tag_ref(each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in("refs/tags/", fn, cb_data); -} - -int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data); -} - -int for_each_branch_ref(each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in("refs/heads/", fn, cb_data); -} - -int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data); -} - -int for_each_remote_ref(each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in("refs/remotes/", fn, cb_data); -} - -int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data); -} - int for_each_replace_ref(each_ref_fn fn, void *cb_data) { return do_for_each_ref(&ref_cache, "refs/replace/", fn, 13, 0, cb_data); @@ -1706,41 +1660,6 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data) return ret; } -int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, - const char *prefix, void *cb_data) -{ - struct strbuf real_pattern = STRBUF_INIT; - struct ref_filter filter; - int ret; - - if (!prefix && !starts_with(pattern, "refs/")) - strbuf_addstr(&real_pattern, "refs/"); - else if (prefix) - strbuf_addstr(&real_pattern, prefix); - strbuf_addstr(&real_pattern, pattern); - - if (!has_glob_specials(pattern)) { - /* Append implied '/' '*' if not present. */ - if (real_pattern.buf[real_pattern.len - 1] != '/') - strbuf_addch(&real_pattern, '/'); - /* No need to check for '*', there is none. */ - strbuf_addch(&real_pattern, '*'); - } - - filter.pattern = real_pattern.buf; - filter.fn = fn; - filter.cb_data = cb_data; - ret = for_each_ref(filter_refs, &filter); - - strbuf_release(&real_pattern); - return ret; -} - -int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data) -{ - return for_each_glob_ref_in(fn, pattern, NULL, cb_data); -} - int for_each_rawref(each_ref_fn fn, void *cb_data) { return do_for_each_ref(&ref_cache, "", fn, 0, diff --git a/refs.c b/refs.c index d163e61..964a513 100644 --- a/refs.c +++ b/refs.c @@ -705,3 +705,84 @@ const char *prettify_refname(const char *name) starts_with(name, "refs/remotes/") ? 13 : 0); } + +/* The argument to filter_refs */ +struct ref_filter { + const char *pattern; + each_ref_fn *fn; + void *cb_data; +}; + +static int filter_refs(const char *refname, const unsigned char *sha1, int flags, + void *data) +{ + struct ref_filter *filter = (struct ref_filter *)data; + if (wildmatch(filter->pattern, refname, 0, NULL)) + return 0; + return filter->fn(refname, sha1, flags, filter->cb_data); +} + +int for_each_tag_ref(each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in("refs/tags/", fn, cb_data); +} + +int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data); +} + +int for_each_branch_ref(each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in("refs/heads/", fn, cb_data); +} + +int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data); +} + +int for_each_remote_ref(each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in("refs/remotes/", fn, cb_data); +} + +int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data); +} + +int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, + const char *prefix, void *cb_data) +{ + struct strbuf real_pattern = STRBUF_INIT; + struct ref_filter filter; + int ret; + + if (!prefix && !starts_with(pattern, "refs/")) + strbuf_addstr(&real_pattern, "refs/"); + else if (prefix) + strbuf_addstr(&real_pattern, prefix); + strbuf_addstr(&real_pattern, pattern); + + if (!has_glob_specials(pattern)) { + /* Append implied '/' '*' if not present. */ + if (real_pattern.buf[real_pattern.len - 1] != '/') + strbuf_addch(&real_pattern, '/'); + /* No need to check for '*', there is none. */ + strbuf_addch(&real_pattern, '*'); + } + + filter.pattern = real_pattern.buf; + filter.fn = fn; + filter.cb_data = cb_data; + ret = for_each_ref(filter_refs, &filter); + + strbuf_release(&real_pattern); + return ret; +} + +int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data) +{ + return for_each_glob_ref_in(fn, pattern, NULL, cb_data); +} -- 2.0.1.552.g1af257a