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

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