diff options
author | Jay Soffian <jaysoffian@gmail.com> | 2009-11-10 00:03:31 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-11-10 01:01:22 -0800 |
commit | f2ef6075c9d248523bf658d82065b46d892b5601 (patch) | |
tree | 7524f95071bc2ec11b2bc8a02e698714af17947e /remote.c | |
parent | e2d41c64bfbea592daeb3a065f1aa3900a03e07f (diff) | |
download | git-f2ef6075c9d248523bf658d82065b46d892b5601.tar.gz |
remote: refactor some logic into get_stale_heads()
Move the logic in builtin-remote.c which determines which local heads are stale
to remote.c so it can be used by other builtins.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -6,6 +6,7 @@ #include "revision.h" #include "dir.h" #include "tag.h" +#include "string-list.h" static struct refspec s_tag_refspec = { 0, @@ -1587,3 +1588,42 @@ struct ref *guess_remote_head(const struct ref *head, return list; } + +struct stale_heads_info { + struct remote *remote; + struct string_list *ref_names; + struct ref **stale_refs_tail; +}; + +static int get_stale_heads_cb(const char *refname, + const unsigned char *sha1, int flags, void *cb_data) +{ + struct stale_heads_info *info = cb_data; + struct refspec refspec; + memset(&refspec, 0, sizeof(refspec)); + refspec.dst = (char *)refname; + if (!remote_find_tracking(info->remote, &refspec)) { + if (!((flags & REF_ISSYMREF) || + string_list_has_string(info->ref_names, refspec.src))) { + struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail); + hashcpy(ref->new_sha1, sha1); + } + } + return 0; +} + +struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map) +{ + struct ref *ref, *stale_refs = NULL; + struct string_list ref_names = { NULL, 0, 0, 0 }; + struct stale_heads_info info; + info.remote = remote; + info.ref_names = &ref_names; + info.stale_refs_tail = &stale_refs; + for (ref = fetch_map; ref; ref = ref->next) + string_list_append(ref->name, &ref_names); + sort_string_list(&ref_names); + for_each_ref(get_stale_heads_cb, &info); + string_list_clear(&ref_names, 0); + return stale_refs; +} |