From 822fd79aef8e3d85a05c3d9b7cea5e080b802184 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Sat, 24 Sep 2011 22:48:26 -0700
Subject: [PATCH] Fix ticket:48.  Use Carl's idea to use git to insert the
 appropriate comment into the compiled file.  If git is not found or if some
 other error occurs, the file comment is whatever string was given.

Need to update the file-comments of every file to remove erroneous
dates and revisions.
---
 compiler/main.lisp | 47 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/compiler/main.lisp b/compiler/main.lisp
index e168ebb46..08e808822 100644
--- a/compiler/main.lisp
+++ b/compiler/main.lisp
@@ -1101,13 +1101,46 @@ in the user USER-INFO slot of STREAM-SOURCE-LOCATIONs.")
   (unless (and (= (length form) 2) (stringp (second form)))
     (compiler-error _N"Bad FILE-COMMENT form: ~S." form))
   (let ((file (first (source-info-current-file *source-info*))))
-    (cond ((file-info-comment file)
-	   (compiler-warning _N"Ignoring extra file comment:~%  ~S." form))
-	  (t
-	   (let ((comment (coerce (second form) 'simple-string)))
-	     (setf (file-info-comment file) comment)
-	     (when *compile-verbose*
-	       (compiler-mumble (intl:gettext "~&; Comment: ~A~2&") comment)))))))
+    (labels
+	((run-git (path)
+	   (let ((cwd (default-directory))
+		 (new (make-pathname :directory (pathname-directory path))))
+	     (unwind-protect
+		  (progn
+		    ;; Cd to the directory containing the file so that
+		    ;; git can find the git repo, if available.
+		    (setf (default-directory) new)
+		    ;; Run git to get the info.  Don't signal any
+		    ;; errors if we can't find git and discard any
+		    ;; error messages from git.  We only use the
+		    ;; result if git returns a zero exit code, anyway.
+		    (handler-case
+			(run-program "git"
+				     (list "log"
+					   "-1"
+					   "--pretty=format:%h %ai %an"
+					   (namestring path))
+				     :output :stream
+				     :error nil)
+		      (error ()
+			nil)))
+	       (setf (default-directory) cwd))))
+	 (generate-comment (file-info)
+	   (let* ((name (pathname (source-info-stream file-info)))
+		  (proc (run-git name)))
+	     (if (and proc (zerop (process-exit-code proc)))
+		 (format nil "$Header: ~A ~A $"
+			 (enough-namestring name)
+			 (read-line (process-output proc)))
+		 (second form)))))
+      (cond ((file-info-comment file)
+	     (compiler-warning _N"Ignoring extra file comment:~%  ~S." form))
+	    (t
+	     (let ((comment (coerce (generate-comment *source-info*)
+				    'simple-string)))
+	       (setf (file-info-comment file) comment)
+	       (when *compile-verbose*
+		 (compiler-mumble (intl:gettext "~&; Comment: ~A~2&") comment))))))))
 
 
 ;;; PROCESS-COLD-LOAD-FORM  --  Internal
-- 
GitLab