summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cb5d709)
raw | patch | inline | side by side (parent: cb5d709)
author | Junio C Hamano <junkio@cox.net> | |
Thu, 21 Sep 2006 05:02:01 +0000 (22:02 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 21 Sep 2006 05:02:01 +0000 (22:02 -0700) |
This adds a "int *flag" parameter to resolve_ref() and makes
for_each_ref() family to call callback function with an extra
"int flag" parameter. They are used to give two bits of
information (REF_ISSYMREF and REF_ISPACKED) about the ref.
Signed-off-by: Junio C Hamano <junkio@cox.net>
for_each_ref() family to call callback function with an extra
"int flag" parameter. They are used to give two bits of
information (REF_ISSYMREF and REF_ISPACKED) about the ref.
Signed-off-by: Junio C Hamano <junkio@cox.net>
23 files changed:
builtin-fmt-merge-msg.c | patch | blob | history | |
builtin-name-rev.c | patch | blob | history | |
builtin-pack-refs.c | patch | blob | history | |
builtin-prune.c | patch | blob | history | |
builtin-push.c | patch | blob | history | |
builtin-rev-parse.c | patch | blob | history | |
builtin-show-branch.c | patch | blob | history | |
builtin-symbolic-ref.c | patch | blob | history | |
cache.h | patch | blob | history | |
describe.c | patch | blob | history | |
fetch-pack.c | patch | blob | history | |
fetch.c | patch | blob | history | |
fsck-objects.c | patch | blob | history | |
http-push.c | patch | blob | history | |
receive-pack.c | patch | blob | history | |
refs.c | patch | blob | history | |
refs.h | patch | blob | history | |
revision.c | patch | blob | history | |
send-pack.c | patch | blob | history | |
server-info.c | patch | blob | history | |
sha1_name.c | patch | blob | history | |
upload-pack.c | patch | blob | history | |
wt-status.c | patch | blob | history |
index b93c17c2f036b972ed6be3b5029251681acfeec7..3d3097d299d4c964e1acfff7a365501a8bd53587 100644 (file)
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
usage(fmt_merge_msg_usage);
/* get current branch */
- current_branch = resolve_ref("HEAD", head_sha1, 1);
+ current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
if (!strncmp(current_branch, "refs/heads/", 11))
current_branch += 11;
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 9e3e537f38ce18cdfbf64a54852351e4e7c258bf..618aa314d22dd16bb62b0a7deb3be14fda411ebe 100644 (file)
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
}
}
-static int name_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
{
struct object *o = parse_object(sha1);
int tags_only = *(int*)cb_data;
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index b3d5470cc09ad35f7baa79bc618c8dda3be2f324..98710893b04c1747635776eb4f126cc18c860e35 100644 (file)
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
unlink(lock_path);
}
-static int handle_one_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int handle_one_ref(const char *path, const unsigned char *sha1,
+ int flags, void *cb_data)
{
FILE *refs_file = cb_data;
diff --git a/builtin-prune.c b/builtin-prune.c
index e21c29baecfc38bee60253364efc1b173efc280d..e79b515c76d9eac9f1ce8e5d88ba0f7058ca53fb 100644 (file)
--- a/builtin-prune.c
+++ b/builtin-prune.c
}
}
-static int add_one_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *object = parse_object(sha1);
if (!object)
diff --git a/builtin-push.c b/builtin-push.c
index 88fc8e2a3b66bb7b251a1055c040c6c7ca8d2be2..581c44ba8e404b80e6a1c2010b501d9bb0642f0b 100644 (file)
--- a/builtin-push.c
+++ b/builtin-push.c
refspec_nr = nr;
}
-static int expand_one_ref(const char *ref, const unsigned char *sha1, void *cb_data)
+static int expand_one_ref(const char *ref, const unsigned char *sha1, int flag, void *cb_data)
{
/* Ignore the "refs/" at the beginning of the refname */
ref += 5;
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index c7712748bc034ba7ef39bc3b993093bea012d084..3b716fba133ae2f0375ef73d6a50a4d93112b5e4 100644 (file)
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
}
}
-static int show_reference(const char *refname, const unsigned char *sha1, void *cb_data)
+static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
show_rev(NORMAL, sha1, refname);
return 0;
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index b3548ae36fbc55ae6c3875978df2b2e96142a2bd..5d6ce568360629f3844513b81f97e4412002b88b 100644 (file)
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
compare_ref_name);
}
-static int append_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int append_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
int i;
@@ -369,7 +369,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, void *cb_d
return 0;
}
-static int append_head_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
unsigned char tmp[20];
int ofs = 11;
@@ -380,14 +380,14 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, void
*/
if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
ofs = 5;
- return append_ref(refname + ofs, sha1, cb_data);
+ return append_ref(refname + ofs, sha1, flag, cb_data);
}
-static int append_tag_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
if (strncmp(refname, "refs/tags/", 10))
return 0;
- return append_ref(refname + 5, sha1, cb_data);
+ return append_ref(refname + 5, sha1, flag, cb_data);
}
static const char *match_ref_pattern = NULL;
return cnt;
}
-static int append_matching_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int append_matching_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
/* we want to allow pattern hold/<asterisk> to show all
* branches under refs/heads/hold/, and v0.99.9? to show
@@ -417,10 +417,10 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, v
if (fnmatch(match_ref_pattern, tail, 0))
return 0;
if (!strncmp("refs/heads/", refname, 11))
- return append_head_ref(refname, sha1, cb_data);
+ return append_head_ref(refname, sha1, flag, cb_data);
if (!strncmp("refs/tags/", refname, 10))
- return append_tag_ref(refname, sha1, cb_data);
- return append_ref(refname, sha1, cb_data);
+ return append_tag_ref(refname, sha1, flag, cb_data);
+ return append_ref(refname, sha1, flag, cb_data);
}
static void snarf_refs(int head, int tag)
{
unsigned char revkey[20];
if (!get_sha1(av, revkey)) {
- append_ref(av, revkey, NULL);
+ append_ref(av, revkey, 0, NULL);
return;
}
if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
ac--; av++;
}
- head_p = resolve_ref("HEAD", head_sha1, 1);
+ head_p = resolve_ref("HEAD", head_sha1, 1, NULL);
if (head_p) {
head_len = strlen(head_p);
memcpy(head, head_p, head_len + 1);
diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index 13163baa88e87db469ba111b748696c24b5ffd0d..d8be0527f4752131b0a1276ecedcc82714636c28 100644 (file)
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
#include "builtin.h"
#include "cache.h"
+#include "refs.h"
static const char git_symbolic_ref_usage[] =
"git-symbolic-ref name [ref]";
static void check_symref(const char *HEAD)
{
unsigned char sha1[20];
- const char *refs_heads_master = resolve_ref(HEAD, sha1, 0);
+ int flag;
+ const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
if (!refs_heads_master)
die("No such ref: %s", HEAD);
+ else if (!(flag & REF_ISSYMREF))
+ die("ref %s is not a symbolic ref", HEAD);
puts(refs_heads_master);
}
index 282eed6f07b3db18bec06b497678cd272eacad41..6def1551624fffd90044b8154ee78683143e343e 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern int read_ref(const char *filename, unsigned char *sha1);
-extern const char *resolve_ref(const char *path, unsigned char *sha1, int);
+extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
extern int create_symref(const char *ref, const char *refs_heads_master);
extern int validate_symref(const char *ref);
diff --git a/describe.c b/describe.c
index ea0f2ce55bf7e20109f43e41908a580f7fdb6eac..f4029ee74e80305e9ec9e5793d2e12c07096f45a 100644 (file)
--- a/describe.c
+++ b/describe.c
names = ++idx;
}
-static int get_name(const char *path, const unsigned char *sha1, void *cb_data)
+static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
struct object *object;
diff --git a/fetch-pack.c b/fetch-pack.c
index 6264ea1af96c18f381063a4910507e69718cc99f..99ac08b2c2528358d51665ef3f301cd68947409c 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
}
}
-static int rev_list_insert_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int rev_list_insert_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *o = deref_tag(parse_object(sha1), path, 0);
static struct commit_list *complete;
-static int mark_complete(const char *path, const unsigned char *sha1, void *cb_data)
+static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *o = parse_object(sha1);
index 36d1e7668e15bb79dba428034f6cab55acceddd8..a2cbdfba8246a24b7da3ccf7cc0dbc1be2bd52bf 100644 (file)
--- a/fetch.c
+++ b/fetch.c
return -1;
}
-static int mark_complete(const char *path, const unsigned char *sha1, void *cb_data)
+static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
if (commit) {
diff --git a/fsck-objects.c b/fsck-objects.c
index bb0c94e9d3193d19fc687e2b8612a8af55fc55dc..46b628cb94375e3f645f868efb04547ffc20e6e7 100644 (file)
--- a/fsck-objects.c
+++ b/fsck-objects.c
static int default_refs;
-static int fsck_handle_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *obj;
static int fsck_head_link(void)
{
unsigned char sha1[20];
- const char *head_points_at = resolve_ref("HEAD", sha1, 1);
+ int flag;
+ const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag);
- if (!head_points_at)
+ if (!head_points_at || !(flag & REF_ISSYMREF))
return error("HEAD is not a symbolic ref");
if (strncmp(head_points_at, "refs/heads/", 11))
return error("HEAD points to something strange (%s)",
diff --git a/http-push.c b/http-push.c
index 460c9bec100824abd2255d86d2b2255e97474826..ecefdfd4f8c9c17282f5cec10640343359278028 100644 (file)
--- a/http-push.c
+++ b/http-push.c
static struct ref *local_refs, **local_tail;
static struct ref *remote_refs, **remote_tail;
-static int one_local_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct ref *ref;
int len = strlen(refname) + 1;
diff --git a/receive-pack.c b/receive-pack.c
index 7abc9210c5b316e58a097539a2724ef351091644..abbcb6af0b61ba5d31db878ccd78e5d7c9c64971 100644 (file)
--- a/receive-pack.c
+++ b/receive-pack.c
static char capabilities[] = "report-status";
static int capabilities_sent;
-static int show_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
if (capabilities_sent)
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
{
for_each_ref(show_ref, NULL);
if (!capabilities_sent)
- show_ref("capabilities^{}", null_sha1, NULL);
+ show_ref("capabilities^{}", null_sha1, 0, NULL);
}
index 85564f0dc70ffd298daf3a9f2bb84801b6564911..40f16af18562dbe3e32be2dfe7c700c295ed744e 100644 (file)
--- a/refs.c
+++ b/refs.c
struct ref_list {
struct ref_list *next;
+ unsigned char flag; /* ISSYMREF? ISPACKED? */
unsigned char sha1[20];
char name[FLEX_ARRAY];
};
return line;
}
-static struct ref_list *add_ref(const char *name, const unsigned char *sha1, struct ref_list *list)
+static struct ref_list *add_ref(const char *name, const unsigned char *sha1,
+ int flag, struct ref_list *list)
{
int len;
struct ref_list **p = &list, *entry;
entry = xmalloc(sizeof(struct ref_list) + len);
hashcpy(entry->sha1, sha1);
memcpy(entry->name, name, len);
+ entry->flag = flag;
entry->next = *p;
*p = entry;
return list;
const char *name = parse_ref_line(refline, sha1);
if (!name)
continue;
- list = add_ref(name, sha1, list);
+ list = add_ref(name, sha1, REF_ISPACKED, list);
}
fclose(f);
refs = list;
while ((de = readdir(dir)) != NULL) {
unsigned char sha1[20];
struct stat st;
+ int flag;
int namelen;
if (de->d_name[0] == '.')
list = get_ref_dir(ref, list);
continue;
}
- if (read_ref(ref, sha1) < 0) {
+ if (!resolve_ref(ref, sha1, 1, &flag)) {
error("%s points nowhere!", ref);
continue;
}
- list = add_ref(ref, sha1, list);
+ list = add_ref(ref, sha1, flag, list);
}
free(ref);
closedir(dir);
/* We allow "recursive" symbolic refs. Only within reason, though */
#define MAXDEPTH 5
-const char *resolve_ref(const char *ref, unsigned char *sha1, int reading)
+const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
{
int depth = MAXDEPTH, len;
char buffer[256];
static char ref_buffer[256];
+ if (flag)
+ *flag = 0;
+
for (;;) {
const char *path = git_path("%s", ref);
struct stat st;
while (list) {
if (!strcmp(ref, list->name)) {
hashcpy(sha1, list->sha1);
+ if (flag)
+ *flag |= REF_ISPACKED;
return ref;
}
list = list->next;
buffer[len] = 0;
strcpy(ref_buffer, buffer);
ref = ref_buffer;
+ if (flag)
+ *flag |= REF_ISSYMREF;
continue;
}
}
buf[len] = 0;
memcpy(ref_buffer, buf, len + 1);
ref = ref_buffer;
+ if (flag)
+ *flag |= REF_ISSYMREF;
}
if (len < 40 || get_sha1_hex(buffer, sha1))
return NULL;
int read_ref(const char *ref, unsigned char *sha1)
{
- if (resolve_ref(ref, sha1, 1))
+ if (resolve_ref(ref, sha1, 1, NULL))
return 0;
return -1;
}
-static int do_for_each_ref(const char *base, each_ref_fn fn, int trim, void *cb_data)
+static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
+ void *cb_data)
{
int retval;
struct ref_list *packed = get_packed_refs();
@@ -303,7 +317,8 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim, void *cb_
error("%s does not point to a valid object!", entry->name);
continue;
}
- retval = fn(entry->name + trim, entry->sha1, cb_data);
+ retval = fn(entry->name + trim, entry->sha1,
+ entry->flag, cb_data);
if (retval)
return retval;
}
@@ -311,7 +326,8 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim, void *cb_
packed = packed ? packed : loose;
while (packed) {
if (!strncmp(base, packed->name, trim)) {
- retval = fn(packed->name + trim, packed->sha1, cb_data);
+ retval = fn(packed->name + trim, packed->sha1,
+ packed->flag, cb_data);
if (retval)
return retval;
}
@@ -323,8 +339,10 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim, void *cb_
int head_ref(each_ref_fn fn, void *cb_data)
{
unsigned char sha1[20];
- if (!read_ref("HEAD", sha1))
- return fn("HEAD", sha1, cb_data);
+ int flag;
+
+ if (resolve_ref("HEAD", sha1, 1, &flag))
+ return fn("HEAD", sha1, flag, cb_data);
return 0;
}
static struct ref_lock *verify_lock(struct ref_lock *lock,
const unsigned char *old_sha1, int mustexist)
{
- if (!resolve_ref(lock->ref_name, lock->old_sha1, mustexist)) {
+ if (!resolve_ref(lock->ref_name, lock->old_sha1, mustexist, NULL)) {
error("Can't verify ref %s", lock->ref_name);
unlock_ref(lock);
return NULL;
lock = xcalloc(1, sizeof(struct ref_lock));
lock->lock_fd = -1;
- ref = resolve_ref(ref, lock->old_sha1, mustexist);
+ ref = resolve_ref(ref, lock->old_sha1, mustexist, NULL);
if (!ref) {
int last_errno = errno;
error("unable to resolve reference %s: %s",
index 886c857105aefff7a743b796f160b2bc7bb0c178..305d408690cec81bf094702848f52364708c6613 100644 (file)
--- a/refs.h
+++ b/refs.h
* Calls the specified function for each ref file until it returns nonzero,
* and returns the value
*/
-typedef int each_ref_fn(const char *refname, const unsigned char *sha1, void *cb_data);
+#define REF_ISSYMREF 01
+#define REF_ISPACKED 02
+typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
extern int head_ref(each_ref_fn, void *);
extern int for_each_ref(each_ref_fn, void *);
extern int for_each_tag_ref(each_ref_fn, void *);
diff --git a/revision.c b/revision.c
index 0e84b8a0fbea67d8bc7fea37b94faa09ab964469..cb13b90776793dba8d18af4aecefb9e0dde5628b 100644 (file)
--- a/revision.c
+++ b/revision.c
static int all_flags;
static struct rev_info *all_revs;
-static int handle_one_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *object = get_reference(all_revs, path, sha1, all_flags);
add_pending_object(all_revs, object, "");
diff --git a/send-pack.c b/send-pack.c
index ee1309313ff41e23b49380d87cd0077cc2e84a85..fbd792ccf4a55ddb5bb09273ceb9e103d242db0e 100644 (file)
--- a/send-pack.c
+++ b/send-pack.c
static struct ref *local_refs, **local_tail;
static struct ref *remote_refs, **remote_tail;
-static int one_local_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct ref *ref;
int len = strlen(refname) + 1;
diff --git a/server-info.c b/server-info.c
index 7667b412576644ee5f428658df6db32efc37f0c3..6cd38be3291e95e75a7d2348e825d49c8f7ad2af 100644 (file)
--- a/server-info.c
+++ b/server-info.c
/* refs */
static FILE *info_ref_fp;
-static int add_info_ref(const char *path, const unsigned char *sha1, void *cb_data)
+static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *o = parse_object(sha1);
diff --git a/sha1_name.c b/sha1_name.c
index b4975289d5063880f8541d1b43aa92d074b74b8d..84d24c6abf39f395281c7d80476575cbd482e6f0 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
for (p = fmt; *p; p++) {
this_result = refs_found ? sha1_from_ref : sha1;
- ref = resolve_ref(mkpath(*p, len, str), this_result, 1);
+ ref = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL);
if (ref) {
if (!refs_found++)
real_ref = xstrdup(ref);
diff --git a/upload-pack.c b/upload-pack.c
index 10237ebe548a134c52f77668bd74fa1039b2b739..9412a9b2604af161bd8f88c27750e95a24a78097 100644 (file)
--- a/upload-pack.c
+++ b/upload-pack.c
}
}
-static int send_ref(const char *refname, const unsigned char *sha1, void *cb_data)
+static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
static const char *capabilities = "multi_ack thin-pack side-band side-band-64k";
struct object *o = parse_object(sha1);
diff --git a/wt-status.c b/wt-status.c
index 050922df54de483cf7112aeb397fc555e4eb2310..d8e284c311cb480f77085b0ba563cfa999920a43 100644 (file)
--- a/wt-status.c
+++ b/wt-status.c
s->is_initial = get_sha1("HEAD", sha1) ? 1 : 0;
- head = resolve_ref("HEAD", sha1, 0);
+ head = resolve_ref("HEAD", sha1, 0, NULL);
s->branch = head ? xstrdup(head) : NULL;
s->reference = "HEAD";