For a branch name, support getting related refs based on configuration. Signed-off-by: Daniel Barkalow <barkalow@xxxxxxxxxxxx> --- sha1_name.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 7df01af..dc5da7a 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -5,6 +5,7 @@ #include "blob.h" #include "tree-walk.h" #include "refs.h" +#include "remote.h" static int find_short_object_filename(int len, const char *name, unsigned char *sha1) { @@ -511,6 +512,51 @@ static int peel_onion(const char *name, int len, unsigned char *sha1) return 0; } +static int lookup_specials(const char *name, int len, unsigned char *sha1) +{ + const char *sp; + + if (len < 5 || name[len - 1] != ']') + return -1; + + for (sp = name + len - 1; name <= sp; sp--) { + int ch = *sp; + if (ch == '[' && name < sp && sp[-1] == '^') + break; + } + + if (sp <= name) + return -1; + + sp++; /* beginning of special name */ + if (!strncmp("merge]", sp, 6)) { + char *word = xstrndup(name, sp - name - 2); + struct branch *branch = branch_get(word); + free(word); + if (branch && branch->merge) { + return get_sha1(branch->merge->dst, sha1); + } + } else if (!strncmp("push]", sp, 5)) { + char *word = xstrndup(name, sp - name - 2); + struct branch *branch = branch_get(word); + struct refspec remote; + struct refspec local; + + if (!branch || !branch->remote) + return -1; + + remote.src = branch->refname; + if (remote_find_push(branch->remote, &remote)) + return -1; + + local.src = remote.dst; + if (remote_find_tracking(branch->remote, &local)) + return -1; + return get_sha1(local.dst, sha1); + } + return -1; +} + static int get_describe_name(const char *name, int len, unsigned char *sha1) { const char *cp; @@ -565,6 +611,10 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1) return get_nth_ancestor(name, len1, sha1, num); } + ret = lookup_specials(name, len, sha1); + if (!ret) + return 0; + ret = peel_onion(name, len, sha1); if (!ret) return 0; -- 1.5.2.901.g27ad4-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html