summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorJim Keniston <jkenisto@us.ibm.com>2009-03-31 11:06:58 -0700
committerJim Keniston <jkenisto@us.ibm.com>2009-03-31 11:06:58 -0700
commit2020af07c2a7f58538874ce652b52a6883f7ada0 (patch)
tree25c9ae36d86a27963d52cdb5a780e4b90c5967f4 /util.cxx
parent1cd9c3ad40595180123083109e5b7d1230095f54 (diff)
parentc5746f91b1ba8f374b4230e16cb33e1b9206ca2b (diff)
downloadsystemtap-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.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/util.cxx b/util.cxx
index 7d191cd2..68cc27f7 100644
--- a/util.cxx
+++ b/util.cxx
@@ -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 : */