Skip to content

Commit 41da711

Browse files
pcloudsgitster
authored andcommitted
refs: add expand_ref()
This is basically dwim_ref() without @{} support. To be used on the server side where we want to expand abbreviated to full ref names and nothing else. The first user is "git clone/fetch --shallow-exclude". Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d43a0c commit 41da711

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

refs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@ static char *substitute_branch_name(const char **string, int *len)
392392
int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
393393
{
394394
char *last_branch = substitute_branch_name(&str, &len);
395+
int refs_found = expand_ref(str, len, sha1, ref);
396+
free(last_branch);
397+
return refs_found;
398+
}
399+
400+
int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
401+
{
395402
const char **p, *r;
396403
int refs_found = 0;
397404

@@ -417,7 +424,6 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
417424
warning("ignoring broken ref %s.", fullref);
418425
}
419426
}
420-
free(last_branch);
421427
return refs_found;
422428
}
423429

refs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned c
9090
*/
9191
extern int refname_match(const char *abbrev_name, const char *full_name);
9292

93+
extern int expand_ref(const char *str, int len, unsigned char *sha1, char **ref);
9394
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
9495
extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
9596

0 commit comments

Comments
 (0)