[PATCH 2/7] Add basic support for customization (vc-git.el)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* vc-git, vc-git-program-name, vc-git-author-name
  vc-git-author-email : defcustom

* replace all occurences of call to git to vc-git-program-name

* add --author switch to vc-git-checkin

* add docstring to vc-git-checkin

Signed-off-by: Xavier Maillard <zedek@xxxxxxx>
---
 contrib/emacs/vc-git.el |   56 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el
index 3d43ca0..8ec470c 100644
--- a/contrib/emacs/vc-git.el
+++ b/contrib/emacs/vc-git.el
@@ -36,6 +36,28 @@
 ;; Add it automatically
 (add-to-list 'vc-handled-backends 'GIT)
 
+(defgroup vc-git nil
+  "*This is GIT backend for vc."
+  :prefix "vc-git-"
+  :group 'vc)
+
+(defcustom vc-git-program-name "git"
+  "*The name of the git command."
+  :type 'string
+  :group 'vc-git)
+
+(defcustom vc-git-author-name nil
+"*Author name to use in git. If nil, we check for environment variables
+GIT_AUTHOR_NAME or `user_full_name'."
+  :type '(choice string (const nil))
+  :group 'vc-git)
+
+(defcustom vc-git-author-email nil
+"*Author email to use in git. If nil, we check for environment variables
+GIT_AUTHOR_ADDRESS and if still nil, `user_mail_address'."
+  :type '(choice string (const nil))
+  :group 'vc-git)
+
 (defvar git-commits-coding-system 'utf-8
   "Default coding system for git commits.")
 
@@ -44,7 +66,7 @@
   (let* ((ok t)
          (str (with-output-to-string
                 (with-current-buffer standard-output
-                  (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil
+                  (unless (eq 0 (apply #'call-process vc-git-program-name nil '(t nil) nil
                                        (append args (list (file-relative-name file)))))
                     (setq ok nil))))))
     (and ok str)))
@@ -52,7 +74,7 @@
 (defun vc-git--run-command (file &rest args)
   "Run a git command on FILE, discarding any output."
   (let ((name (file-relative-name file)))
-    (eq 0 (apply #'call-process "git" nil (get-buffer "*Messages") nil (append args (list name))))))
+    (eq 0 (apply #'call-process vc-git-program-name nil (get-buffer "*Messages") nil (append args (list name))))))
 
 (defun vc-git-registered (file)
   "Check whether FILE is registered with git."
@@ -61,7 +83,7 @@
            (name (file-relative-name file dir)))
       (and (ignore-errors
              (when dir (cd dir))
-             (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
+             (eq 0 (call-process vc-git-program-name nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
            (let ((str (buffer-string)))
              (and (> (length str) (length name))
                   (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))
@@ -77,7 +99,7 @@
   "git-specific version of `vc-workfile-version'."
   (let ((str (with-output-to-string
                (with-current-buffer standard-output
-                 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD")))))
+                 (call-process vc-git-program-name nil '(t nil) nil "symbolic-ref" "HEAD")))))
     (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
         (match-string 2 str)
       str)))
@@ -105,20 +127,32 @@
 (defun vc-git-print-log (file &optional buffer)
   (let ((name (file-relative-name file))
         (coding-system-for-read git-commits-coding-system))
-    (vc-do-command buffer 'async "git" name "rev-list" "--pretty" "HEAD" "--")))
+    (vc-do-command buffer 'async vc-git-program-name name "rev-list" "--pretty" "HEAD" "--")))
 
 (defun vc-git-diff (file &optional rev1 rev2 buffer)
   (let ((name (file-relative-name file))
         (buf (or buffer "*vc-diff*")))
     (if (and rev1 rev2)
-        (vc-do-command buf 0 "git" name "diff-tree" "-p" rev1 rev2 "--")
-      (vc-do-command buf 0 "git" name "diff-index" "-p" (or rev1 "HEAD") "--"))
+        (vc-do-command buf 0 vc-git-program-name name "diff-tree" "-p" rev1 rev2 "--")
+      (vc-do-command buf 0 vc-git-program-name name "diff-index" "-p" (or rev1 "HEAD") "--"))
     ; git-diff-index doesn't set exit status like diff does
     (if (vc-git-workfile-unchanged-p file) 0 1)))
 
 (defun vc-git-checkin (file rev comment)
-  (let ((coding-system-for-write git-commits-coding-system))
-    (vc-git--run-command file "commit" "-m" comment "--only" "--")))
+  "Record FILE to git. REV should always be nil and is ignored,
+COMMENT is the new comment."
+  (let ((coding-system-for-write git-commits-coding-system)
+	(author-name (or vc-git-author-name
+			 (getenv "GIT_AUTHOR_NAME")
+			 user-full-name))
+	(author-email (or vc-git-author-email
+			 (getenv "GIT_AUTHOR_ADDRESS")
+			 user-mail-address)))
+    
+    (vc-git--run-command (file-name-nondirectory file) "commit" "-m" 
+			 comment 
+			 "--author" (concat author-name " <" author-email ">")
+			 "--only" "--")))
 
 (defun vc-git-checkout (file &optional editable rev destfile)
   (if destfile
@@ -128,14 +162,14 @@
             (coding-system-for-read 'no-conversion)
             (coding-system-for-write 'no-conversion))
         (with-temp-file destfile
-          (eq 0 (call-process "git" nil t nil "cat-file" "blob"
+          (eq 0 (call-process vc-git-program-name nil t nil "cat-file" "blob"
                               (concat (or rev "HEAD") ":" fullname)))))
     (vc-git--run-command file "checkout" (or rev "HEAD"))))
 
 (defun vc-git-annotate-command (file buf &optional rev)
   ; FIXME: rev is ignored
   (let ((name (file-relative-name file)))
-    (call-process "git" nil buf nil "blame" name)))
+    (call-process vc-git-program-name nil buf nil "blame" name)))
 
 (defun vc-git-annotate-time ()
   (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)
-- 
1.5.0
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]