summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorDave Brolley <brolley@redhat.com>2009-03-26 11:31:04 -0400
committerDave Brolley <brolley@redhat.com>2009-03-26 11:31:04 -0400
commit4407fecb4b4e7466b256a26d1bfd63333bf367a2 (patch)
treed50e95d0928ef85e7a354926e71dace88ae82ff5 /util.cxx
parent666d747e2a8880c2906c1e2ead49182cf061df74 (diff)
parenta5e8d632f443c6a882dcabc669236dc4798b1fd7 (diff)
downloadsystemtap-steved-4407fecb4b4e7466b256a26d1bfd63333bf367a2.tar.gz
systemtap-steved-4407fecb4b4e7466b256a26d1bfd63333bf367a2.tar.xz
systemtap-steved-4407fecb4b4e7466b256a26d1bfd63333bf367a2.zip
Merge branch 'master' of git://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 00b064dc..a20e8292 100644
--- a/util.cxx
+++ b/util.cxx
@@ -267,4 +267,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 : */