diff options
author | Jim Keniston <jkenisto@us.ibm.com> | 2009-03-31 11:06:58 -0700 |
---|---|---|
committer | Jim Keniston <jkenisto@us.ibm.com> | 2009-03-31 11:06:58 -0700 |
commit | 2020af07c2a7f58538874ce652b52a6883f7ada0 (patch) | |
tree | 25c9ae36d86a27963d52cdb5a780e4b90c5967f4 /util.cxx | |
parent | 1cd9c3ad40595180123083109e5b7d1230095f54 (diff) | |
parent | c5746f91b1ba8f374b4230e16cb33e1b9206ca2b (diff) | |
download | systemtap-steved-2020af07c2a7f58538874ce652b52a6883f7ada0.tar.gz systemtap-steved-2020af07c2a7f58538874ce652b52a6883f7ada0.tar.xz systemtap-steved-2020af07c2a7f58538874ce652b52a6883f7ada0.zip |
Merge branch 'master' of ssh://kenistoj@sources.redhat.com/git/systemtap
Diffstat (limited to 'util.cxx')
-rw-r--r-- | util.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -248,4 +248,31 @@ const string cmdstr_quoted(const string& cmd) return quoted_cmd; } + +string +git_revision(const string& path) +{ + string revision = "(not-a-git-repository)"; + string git_dir = path + "/.git/"; + + struct stat st; + if (stat(git_dir.c_str(), &st) == 0) + { + string command = "git --git-dir=\"" + git_dir + + "\" rev-parse HEAD 2>/dev/null"; + + char buf[50]; + FILE *fp = popen(command.c_str(), "r"); + if (fp != NULL) + { + char *bufp = fgets(buf, sizeof(buf), fp); + int rc = pclose(fp); + if (bufp != NULL && rc == 0) + revision = buf; + } + } + + return revision; +} + /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |