diff options
-rw-r--r-- | hash.cxx | 4 | ||||
-rw-r--r-- | util.cxx | 27 | ||||
-rw-r--r-- | util.h | 1 |
3 files changed, 32 insertions, 0 deletions
@@ -95,6 +95,10 @@ get_base_hash (systemtap_session& s, hash& h) h.add_file(s.kernel_build_tree + "/include/linux/version.h"); h.add_file(s.kernel_build_tree + "/include/linux/utsrelease.h"); + // If the kernel is a git working directory, then add the git HEAD + // revision to our hash as well. + h.add(git_revision(s.kernel_build_tree)); + // Hash runtime path (that gets added in as "-R path"). h.add(s.runtime_path); @@ -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 : */ @@ -12,6 +12,7 @@ void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters); std::string find_executable(const std::string& name); const std::string cmdstr_quoted(const std::string& cmd); +std::string git_revision(const std::string& path); // stringification generics |