summaryrefslogtreecommitdiff
path: root/builtin-for-each-ref.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-11-01 08:48:50 -0800
committerJunio C Hamano <junkio@cox.net>2006-11-01 08:48:50 -0800
commit58a1e0e83bcdbf063fb708ee9a8a563c0aa14f87 (patch)
treee3534fae05b865abb5d686c191cdbde9b9cbf3d0 /builtin-for-each-ref.c
parentec1e46897329317d7a9996264d7e999f9a68e307 (diff)
parent2e6d8f181dd77d40a1148549d4f33cdf2877fb19 (diff)
downloadgit-58a1e0e83bcdbf063fb708ee9a8a563c0aa14f87.tar.gz
Merge branch 'lj/refs'
* lj/refs: (63 commits) Fix show-ref usagestring t3200: git-branch testsuite update sha1_name.c: avoid compilation warnings. Make git-branch a builtin ref-log: fix D/F conflict coming from deleted refs. git-revert with conflicts to behave as git-merge with conflicts core.logallrefupdates thinko-fix git-pack-refs --all core.logallrefupdates create new log file only for branch heads. Remove bashism from t3210-pack-refs.sh ref-log: allow ref@{count} syntax. pack-refs: call fflush before fsync. pack-refs: use lockfile as everybody else does. git-fetch: do not look into $GIT_DIR/refs to see if a tag exists. lock_ref_sha1_basic does not remove empty directories on BSD Do not create tag leading directories since git update-ref does it. Check that a tag exists using show-ref instead of looking for the ref file. Use git-update-ref to delete a tag instead of rm()ing the ref file. Fix refs.c;:repack_without_ref() clean-up path Clean up "git-branch.sh" and add remove recursive dir test cases. ...
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r--builtin-for-each-ref.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 698618b798..93d3d7eef0 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -585,24 +585,27 @@ static void get_value(struct refinfo *ref, int atom, struct atom_value **v)
*v = &ref->value[atom];
}
-static struct refinfo **grab_array;
-static const char **grab_pattern;
-static int *grab_cnt;
+struct grab_ref_cbdata {
+ struct refinfo **grab_array;
+ const char **grab_pattern;
+ int grab_cnt;
+};
/*
* A call-back given to for_each_ref(). It is unfortunate that we
* need to use global variables to pass extra information to this
* function.
*/
-static int grab_single_ref(const char *refname, const unsigned char *sha1)
+static int grab_single_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
+ struct grab_ref_cbdata *cb = cb_data;
struct refinfo *ref;
int cnt;
- if (*grab_pattern) {
+ if (*cb->grab_pattern) {
const char **pattern;
int namelen = strlen(refname);
- for (pattern = grab_pattern; *pattern; pattern++) {
+ for (pattern = cb->grab_pattern; *pattern; pattern++) {
const char *p = *pattern;
int plen = strlen(p);
@@ -626,25 +629,14 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1)
ref->refname = xstrdup(refname);
hashcpy(ref->objectname, sha1);
- cnt = *grab_cnt;
- grab_array = xrealloc(grab_array, sizeof(*grab_array) * (cnt + 1));
- grab_array[cnt++] = ref;
- *grab_cnt = cnt;
+ cnt = cb->grab_cnt;
+ cb->grab_array = xrealloc(cb->grab_array,
+ sizeof(*cb->grab_array) * (cnt + 1));
+ cb->grab_array[cnt++] = ref;
+ cb->grab_cnt = cnt;
return 0;
}
-static struct refinfo **grab_refs(const char **pattern, int *cnt)
-{
- /* Sheesh, we really should make for-each-ref to take
- * callback data.
- */
- *cnt = 0;
- grab_pattern = pattern;
- grab_cnt = cnt;
- for_each_ref(grab_single_ref);
- return grab_array;
-}
-
static int cmp_ref_sort(struct ref_sort *s, struct refinfo *a, struct refinfo *b)
{
struct atom_value *va, *vb;
@@ -784,6 +776,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)
int maxcount = 0;
int quote_style = -1; /* unspecified yet */
struct refinfo **refs;
+ struct grab_ref_cbdata cbdata;
for (i = 1; i < ac; i++) {
const char *arg = av[i];
@@ -855,7 +848,11 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)
verify_format(format);
- refs = grab_refs(av + i, &num_refs);
+ memset(&cbdata, 0, sizeof(cbdata));
+ cbdata.grab_pattern = av + i;
+ for_each_ref(grab_single_ref, &cbdata);
+ refs = cbdata.grab_array;
+ num_refs = cbdata.grab_cnt;
for (i = 0; i < used_atom_cnt; i++) {
if (used_atom[i][0] == '*') {