diff options
author | Mark Wielaard <mjw@redhat.com> | 2009-04-01 23:04:29 +0200 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2009-04-01 23:04:29 +0200 |
commit | 2c246d55893998d60461671767c5f9c05f70c6b7 (patch) | |
tree | 04e20f69c813c67534d8a3bd9cd0d4cad84a3544 /util.cxx | |
parent | dd1636396623adacdb9e6502adabd9195ae7ef33 (diff) | |
parent | 952ce18c9672046c052fc77d5da8f98e8ae75735 (diff) | |
download | systemtap-steved-2c246d55893998d60461671767c5f9c05f70c6b7.tar.gz systemtap-steved-2c246d55893998d60461671767c5f9c05f70c6b7.tar.xz systemtap-steved-2c246d55893998d60461671767c5f9c05f70c6b7.zip |
Merge branch 'master' into pr6866
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 : */ |