From 04e0835f29b6d21e8491ba6f35092f1ab860263d Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sun, 18 Feb 2024 10:00:47 -0500 Subject: Extract git repository information * First pass; this will eventually be used to rewite exact commit refs in YAML delivery files --- src/utils.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 12cf22c..d8cf929 100644 --- a/src/utils.c +++ b/src/utils.c @@ -377,7 +377,27 @@ char *git_describe(const char *path) { pushd(path); static char version[NAME_MAX]; FILE *pp; - pp = popen("git describe --always --tags", "r"); + pp = popen("git describe --first-parent --always --tags", "r"); + memset(version, 0, sizeof(version)); + fgets(version, sizeof(version) - 1, pp); + strip(version); + pclose(pp); + popd(); + return version; +} + +char *git_rev_parse(const char *path, char *args) { + pushd(path); + static char version[NAME_MAX]; + char cmd[PATH_MAX]; + FILE *pp; + + if (isempty(args)) { + fprintf(stderr, "git_rev_parse args cannot be empty"); + return NULL; + } + sprintf(cmd, "git rev-parse %s", args); + pp = popen(cmd, "r"); memset(version, 0, sizeof(version)); fgets(version, sizeof(version) - 1, pp); strip(version); -- cgit