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

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