Blame SOURCES/git-1.7-el5-emacs-support.patch

842ec7
From 424058e0607b4b3c558d19633090e06e7bd2b851 Mon Sep 17 00:00:00 2001
842ec7
From: Todd Zullinger <tmz@pobox.com>
842ec7
Date: Wed, 2 Feb 2011 21:24:44 -0500
842ec7
Subject: [PATCH] Restore vc-git.el for basic compatibility on EL-5
842ec7
842ec7
This is the vc-git.el from 1.6.4.1, the last version to include it.
842ec7
Most uses will be better served by the vc-git.el which is provided by
842ec7
emacs >= 22.2, but on EL-5 we don't have the luxury of a modern emacs.
842ec7
---
842ec7
 contrib/emacs/Makefile  |    2 +-
842ec7
 contrib/emacs/vc-git.el |  216 +++++++++++++++++++++++++++++++++++++++++++++++
842ec7
 2 files changed, 217 insertions(+), 1 deletions(-)
842ec7
 create mode 100644 contrib/emacs/vc-git.el
842ec7
842ec7
diff --git a/contrib/emacs/Makefile b/contrib/emacs/Makefile
842ec7
index 24d9312..a48540a 100644
842ec7
--- a/contrib/emacs/Makefile
842ec7
+++ b/contrib/emacs/Makefile
842ec7
@@ -2,7 +2,7 @@
842ec7
 
842ec7
 EMACS = emacs
842ec7
 
842ec7
-ELC = git.elc git-blame.elc
842ec7
+ELC = git.elc vc-git.elc git-blame.elc
842ec7
 INSTALL ?= install
842ec7
 INSTALL_ELC = $(INSTALL) -m 644
842ec7
 prefix ?= $(HOME)
842ec7
diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
842ec7
new file mode 100644
842ec7
index 0000000..b8f6be5
842ec7
--- /dev/null
842ec7
+++ b/contrib/emacs/vc-git.el
842ec7
@@ -0,0 +1,216 @@
842ec7
+;;; vc-git.el --- VC backend for the git version control system
842ec7
+
842ec7
+;; Copyright (C) 2006 Alexandre Julliard
842ec7
+
842ec7
+;; This program is free software; you can redistribute it and/or
842ec7
+;; modify it under the terms of the GNU General Public License as
842ec7
+;; published by the Free Software Foundation; either version 2 of
842ec7
+;; the License, or (at your option) any later version.
842ec7
+;;
842ec7
+;; This program is distributed in the hope that it will be
842ec7
+;; useful, but WITHOUT ANY WARRANTY; without even the implied
842ec7
+;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
842ec7
+;; PURPOSE.  See the GNU General Public License for more details.
842ec7
+;;
842ec7
+;; You should have received a copy of the GNU General Public
842ec7
+;; License along with this program; if not, write to the Free
842ec7
+;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
842ec7
+;; MA 02111-1307 USA
842ec7
+
842ec7
+;;; Commentary:
842ec7
+
842ec7
+;; This file contains a VC backend for the git version control
842ec7
+;; system.
842ec7
+;;
842ec7
+;; To install: put this file on the load-path and add GIT to the list
842ec7
+;; of supported backends in `vc-handled-backends'; the following line,
842ec7
+;; placed in your ~/.emacs, will accomplish this:
842ec7
+;;
842ec7
+;;     (add-to-list 'vc-handled-backends 'GIT)
842ec7
+;;
842ec7
+;; TODO
842ec7
+;;  - changelog generation
842ec7
+;;  - working with revisions other than HEAD
842ec7
+;;
842ec7
+
842ec7
+(eval-when-compile (require 'cl))
842ec7
+
842ec7
+(defvar git-commits-coding-system 'utf-8
842ec7
+  "Default coding system for git commits.")
842ec7
+
842ec7
+(defun vc-git--run-command-string (file &rest args)
842ec7
+  "Run a git command on FILE and return its output as string."
842ec7
+  (let* ((ok t)
842ec7
+         (str (with-output-to-string
842ec7
+                (with-current-buffer standard-output
842ec7
+                  (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil
842ec7
+                                       (append args (list (file-relative-name file)))))
842ec7
+                    (setq ok nil))))))
842ec7
+    (and ok str)))
842ec7
+
842ec7
+(defun vc-git--run-command (file &rest args)
842ec7
+  "Run a git command on FILE, discarding any output."
842ec7
+  (let ((name (file-relative-name file)))
842ec7
+    (eq 0 (apply #'call-process "git" nil (get-buffer "*Messages") nil (append args (list name))))))
842ec7
+
842ec7
+(defun vc-git-registered (file)
842ec7
+  "Check whether FILE is registered with git."
842ec7
+  (with-temp-buffer
842ec7
+    (let* ((dir (file-name-directory file))
842ec7
+           (name (file-relative-name file dir)))
842ec7
+      (and (ignore-errors
842ec7
+             (when dir (cd dir))
842ec7
+             (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
842ec7
+           (let ((str (buffer-string)))
842ec7
+             (and (> (length str) (length name))
842ec7
+                  (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))
842ec7
+
842ec7
+(defun vc-git-state (file)
842ec7
+  "git-specific version of `vc-state'."
842ec7
+  (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--")))
842ec7
+    (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff))
842ec7
+        'edited
842ec7
+      'up-to-date)))
842ec7
+
842ec7
+(defun vc-git-workfile-version (file)
842ec7
+  "git-specific version of `vc-workfile-version'."
842ec7
+  (let ((str (with-output-to-string
842ec7
+               (with-current-buffer standard-output
842ec7
+                 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD")))))
842ec7
+    (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
842ec7
+        (match-string 2 str)
842ec7
+      str)))
842ec7
+
842ec7
+(defun vc-git-symbolic-commit (commit)
842ec7
+  "Translate COMMIT string into symbolic form.
842ec7
+Returns nil if not possible."
842ec7
+  (and commit
842ec7
+       (with-temp-buffer
842ec7
+	 (and
842ec7
+	  (zerop
842ec7
+	   (call-process "git" nil '(t nil) nil "name-rev"
842ec7
+			 "--name-only" "--tags"
842ec7
+			 commit))
842ec7
+	  (goto-char (point-min))
842ec7
+	  (= (forward-line 2) 1)
842ec7
+	  (bolp)
842ec7
+	  (buffer-substring-no-properties (point-min) (1- (point-max)))))))
842ec7
+
842ec7
+(defun vc-git-previous-version (file rev)
842ec7
+  "git-specific version of `vc-previous-version'."
842ec7
+  (let ((default-directory (file-name-directory (expand-file-name file)))
842ec7
+	(file (file-name-nondirectory file)))
842ec7
+    (vc-git-symbolic-commit
842ec7
+     (with-temp-buffer
842ec7
+       (and
842ec7
+	(zerop
842ec7
+	 (call-process "git" nil '(t nil) nil "rev-list"
842ec7
+		       "-2" rev "--" file))
842ec7
+	(goto-char (point-max))
842ec7
+	(bolp)
842ec7
+	(zerop (forward-line -1))
842ec7
+	(not (bobp))
842ec7
+	(buffer-substring-no-properties
842ec7
+	   (point)
842ec7
+	   (1- (point-max))))))))
842ec7
+
842ec7
+(defun vc-git-next-version (file rev)
842ec7
+  "git-specific version of `vc-next-version'."
842ec7
+  (let* ((default-directory (file-name-directory
842ec7
+			     (expand-file-name file)))
842ec7
+	(file (file-name-nondirectory file))
842ec7
+	(current-rev
842ec7
+	 (with-temp-buffer
842ec7
+	   (and
842ec7
+	    (zerop
842ec7
+	     (call-process "git" nil '(t nil) nil "rev-list"
842ec7
+			   "-1" rev "--" file))
842ec7
+	    (goto-char (point-max))
842ec7
+	    (bolp)
842ec7
+	    (zerop (forward-line -1))
842ec7
+	    (bobp)
842ec7
+	    (buffer-substring-no-properties
842ec7
+	     (point)
842ec7
+	     (1- (point-max)))))))
842ec7
+    (and current-rev
842ec7
+	 (vc-git-symbolic-commit
842ec7
+	  (with-temp-buffer
842ec7
+	    (and
842ec7
+	     (zerop
842ec7
+	      (call-process "git" nil '(t nil) nil "rev-list"
842ec7
+			    "HEAD" "--" file))
842ec7
+	     (goto-char (point-min))
842ec7
+	     (search-forward current-rev nil t)
842ec7
+	     (zerop (forward-line -1))
842ec7
+	     (buffer-substring-no-properties
842ec7
+	      (point)
842ec7
+	      (progn (forward-line 1) (1- (point))))))))))
842ec7
+
842ec7
+(defun vc-git-revert (file &optional contents-done)
842ec7
+  "Revert FILE to the version stored in the git repository."
842ec7
+  (if contents-done
842ec7
+      (vc-git--run-command file "update-index" "--")
842ec7
+    (vc-git--run-command file "checkout" "HEAD")))
842ec7
+
842ec7
+(defun vc-git-checkout-model (file)
842ec7
+  'implicit)
842ec7
+
842ec7
+(defun vc-git-workfile-unchanged-p (file)
842ec7
+  (let ((sha1 (vc-git--run-command-string file "hash-object" "--"))
842ec7
+        (head (vc-git--run-command-string file "ls-tree" "-z" "HEAD" "--")))
842ec7
+    (and head
842ec7
+         (string-match "[0-7]\\{6\\} blob \\([0-9a-f]\\{40\\}\\)\t[^\0]+\0" head)
842ec7
+         (string= (car (split-string sha1 "\n")) (match-string 1 head)))))
842ec7
+
842ec7
+(defun vc-git-register (file &optional rev comment)
842ec7
+  "Register FILE into the git version-control system."
842ec7
+  (vc-git--run-command file "update-index" "--add" "--"))
842ec7
+
842ec7
+(defun vc-git-print-log (file &optional buffer)
842ec7
+  (let ((name (file-relative-name file))
842ec7
+        (coding-system-for-read git-commits-coding-system))
842ec7
+    (vc-do-command buffer 'async "git" name "rev-list" "--pretty" "HEAD" "--")))
842ec7
+
842ec7
+(defun vc-git-diff (file &optional rev1 rev2 buffer)
842ec7
+  (let ((name (file-relative-name file))
842ec7
+        (buf (or buffer "*vc-diff*")))
842ec7
+    (if (and rev1 rev2)
842ec7
+        (vc-do-command buf 0 "git" name "diff-tree" "-p" rev1 rev2 "--")
842ec7
+      (vc-do-command buf 0 "git" name "diff-index" "-p" (or rev1 "HEAD") "--"))
842ec7
+    ; git-diff-index doesn't set exit status like diff does
842ec7
+    (if (vc-git-workfile-unchanged-p file) 0 1)))
842ec7
+
842ec7
+(defun vc-git-checkin (file rev comment)
842ec7
+  (let ((coding-system-for-write git-commits-coding-system))
842ec7
+    (vc-git--run-command file "commit" "-m" comment "--only" "--")))
842ec7
+
842ec7
+(defun vc-git-checkout (file &optional editable rev destfile)
842ec7
+  (if destfile
842ec7
+      (let ((fullname (substring
842ec7
+                       (vc-git--run-command-string file "ls-files" "-z" "--full-name" "--")
842ec7
+                       0 -1))
842ec7
+            (coding-system-for-read 'no-conversion)
842ec7
+            (coding-system-for-write 'no-conversion))
842ec7
+        (with-temp-file destfile
842ec7
+          (eq 0 (call-process "git" nil t nil "cat-file" "blob"
842ec7
+                              (concat (or rev "HEAD") ":" fullname)))))
842ec7
+    (vc-git--run-command file "checkout" (or rev "HEAD"))))
842ec7
+
842ec7
+(defun vc-git-annotate-command (file buf &optional rev)
842ec7
+  ; FIXME: rev is ignored
842ec7
+  (let ((name (file-relative-name file)))
842ec7
+    (call-process "git" nil buf nil "blame" name)))
842ec7
+
842ec7
+(defun vc-git-annotate-time ()
842ec7
+  (and (re-search-forward "[0-9a-f]+ (.* \\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([-+0-9]+\\) +[0-9]+)" nil t)
842ec7
+       (vc-annotate-convert-time
842ec7
+        (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7))))))
842ec7
+
842ec7
+;; Not really useful since we can't do anything with the revision yet
842ec7
+;;(defun vc-annotate-extract-revision-at-line ()
842ec7
+;;  (save-excursion
842ec7
+;;    (move-beginning-of-line 1)
842ec7
+;;    (and (looking-at "[0-9a-f]+")
842ec7
+;;         (buffer-substring (match-beginning 0) (match-end 0)))))
842ec7
+
842ec7
+(provide 'vc-git)
842ec7
-- 
842ec7
1.7.3.4
842ec7