;;; vc-git.el --- VC backend for the git version control system
-;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Alexandre Julliard <julliard@winehq.org>
;; Keywords: tools
;; * checkout-model (files) OK
;; - workfile-unchanged-p (file) OK
;; - mode-line-string (file) OK
-;; - prettify-state-info (file) OK
;; STATE-CHANGING FUNCTIONS
;; * create-repo () OK
;; * register (files &optional rev comment) OK
(eval-when-compile
(require 'cl)
(require 'vc)
+ (require 'vc-dir)
(require 'grep))
+(defcustom vc-git-diff-switches t
+ "String or list of strings specifying switches for Git diff under VC.
+If nil, use the value of `vc-diff-switches'. If t, use no switches."
+ :type '(choice (const :tag "Unspecified" nil)
+ (const :tag "None" t)
+ (string :tag "Argument String")
+ (repeat :tag "Argument List" :value ("") string))
+ :version "23.1"
+ :group 'vc)
+
(defvar git-commits-coding-system 'utf-8
"Default coding system for git commits.")
(when (vc-git-root file)
(with-temp-buffer
(let* ((dir (file-name-directory file))
- (name (file-relative-name file dir)))
- (and (ignore-errors
- (when dir (cd dir))
- (vc-git--out-ok "ls-files" "-c" "-z" "--" name))
- (let ((str (buffer-string)))
- (and (> (length str) (length name))
- (string= (substring str 0 (1+ (length name)))
- (concat name "\0")))))))))
+ (name (file-relative-name file dir))
+ (str (ignore-errors
+ (when dir (cd dir))
+ (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
+ ;; if result is empty, use ls-tree to check for deleted file
+ (when (eq (point-min) (point-max))
+ (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" "--" name))
+ (buffer-string))))
+ (and str
+ (> (length str) (length name))
+ (string= (substring str 0 (1+ (length name)))
+ (concat name "\0")))))))
(defun vc-git--state-code (code)
"Convert from a string to a added/deleted/modified state."
(vc-git--state-code (match-string 1 diff))
(if (vc-git--empty-db-p) 'added 'up-to-date)))))
-(defun vc-git--ls-files-state (state &rest args)
- "Set state to STATE on all files found with git-ls-files ARGS."
- (with-temp-buffer
- (apply 'vc-git-command (current-buffer) nil nil "ls-files" "-z" args)
- (goto-char (point-min))
- (let ((start (point)))
- (while (search-forward "\0" nil t)
- (let ((file (expand-file-name
- (buffer-substring-no-properties start (1- (point))))))
- (vc-file-setprop file 'vc-backend (if state 'Git 'none))
- (vc-file-setprop file 'vc-state state))
- (setq start (point))))))
-
(defun vc-git-working-revision (file)
"Git-specific version of `vc-working-revision'."
(let ((str (with-output-to-string
(if (eq 0 (logand ?\111 old-perm)) "+x" "-x"))
'face 'font-lock-type-face))
-(defun vc-git-status-printer (info)
+(defun vc-git-dir-printer (info)
"Pretty-printer for the vc-dir-fileinfo structure."
- (let* ((state (if (vc-dir-fileinfo->directory info)
- 'DIRECTORY
- (vc-dir-fileinfo->state info)))
+ (let* ((isdir (vc-dir-fileinfo->directory info))
+ (state (if isdir "" (vc-dir-fileinfo->state info)))
(extra (vc-dir-fileinfo->extra info))
(old-perm (when extra (vc-git-extra-fileinfo->old-perm extra)))
(new-perm (when extra (vc-git-extra-fileinfo->new-perm extra))))
(t 'font-lock-variable-name-face))
'mouse-face 'highlight)
" " (vc-git-permissions-as-string old-perm new-perm)
- " "
+ " "
(propertize (vc-git-escape-file-name (vc-dir-fileinfo->name info))
- 'face 'font-lock-function-name-face
- 'mouse-face 'highlight)
+ 'face (if isdir 'font-lock-comment-delimiter-face 'font-lock-function-name-face)
+ 'help-echo
+ (if isdir
+ "Directory\nVC operations can be applied to it\nmouse-3: Pop-up menu"
+ "File\nmouse-3: Pop-up menu")
+ 'mouse-face 'highlight)
(vc-git-file-type-as-string old-perm new-perm)
(vc-git-rename-as-string state extra))))
"Return a list of (FILE STATE EXTRA) entries for FILES in DIR."
(vc-git-dir-status-goto-stage 'update-index files update-function))
-(defun vc-git-status-extra-headers (dir)
+(defun vc-git-dir-extra-headers (dir)
(let ((str (with-output-to-string
(with-current-buffer standard-output
(vc-git--out-ok "symbolic-ref" "HEAD")))))
;; If the buffer exists from a previous invocation it might be
;; read-only.
(let ((inhibit-read-only t))
- ;; XXX `log-view-mode' needs to have something to identify where
- ;; the log for each individual file starts. It seems that by
- ;; default git does not output this info. So loop here and call
- ;; "git rev-list" on each file separately to make sure that each
- ;; file gets a "File:" header before the corresponding
- ;; log. Maybe there is a way to do this with one command...
- (dolist (file flist)
- (with-current-buffer
- buffer
- (insert "File: " (file-name-nondirectory file) "\n"))
- (vc-git-command buffer 'async (file-relative-name file)
+ (with-current-buffer
+ buffer
+ (vc-git-command buffer 'async files
"rev-list" "--pretty" "HEAD" "--")))))
(defvar log-view-message-re)
(defvar log-view-file-re)
(defvar log-view-font-lock-keywords)
+(defvar log-view-per-file-logs)
(define-derived-mode vc-git-log-view-mode log-view-mode "Git-Log-View"
(require 'add-log) ;; we need the faces add-log
;; Don't have file markers, so use impossible regexp.
- (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)")
+ (set (make-local-variable 'log-view-file-re) "\\`a\\`")
+ (set (make-local-variable 'log-view-per-file-logs) nil)
(set (make-local-variable 'log-view-message-re)
"^commit *\\([0-9a-z]+\\)")
(set (make-local-variable 'log-view-font-lock-keywords)
(append
- `((,log-view-message-re (1 'change-log-acknowledgement))
- (,log-view-file-re (1 'change-log-file-face)))
+ `((,log-view-message-re (1 'change-log-acknowledgement)))
;; Handle the case:
;; user: foo@bar
'(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)"
REVISION may have the form BRANCH, BRANCH~N,
or BRANCH^ (where \"^\" can be repeated)."
(goto-char (point-min))
- (search-forward "\ncommit" nil t
- (cond ((string-match "~\\([0-9]\\)$" revision)
- (1+ (string-to-number (match-string 1 revision))))
- ((string-match "\\^+$" revision)
- (1+ (length (match-string 0 revision))))
- (t nil)))
+ (when revision
+ (search-forward (format "\ncommit %s" revision) nil t
+ (cond ((string-match "~\\([0-9]\\)$" revision)
+ (1+ (string-to-number (match-string 1 revision))))
+ ((string-match "\\^+$" revision)
+ (1+ (length (match-string 0 revision))))
+ (t nil))))
(beginning-of-line))
(defun vc-git-diff (files &optional rev1 rev2 buffer)
- (let ((buf (or buffer "*vc-diff*")))
- (if (and rev1 rev2)
- (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p"
- rev1 rev2 "--")
- (vc-git-command buf 1 files "diff-index" "--exit-code" "-p"
- (or rev1 "HEAD") "--"))))
+ "Get a difference report using Git between two revisions of FILES."
+ (apply #'vc-git-command (or buffer "*vc-diff*") 1 files
+ (if (and rev1 rev2) "diff-tree" "diff-index")
+ "--exit-code"
+ (append (vc-switches 'git 'diff)
+ (list "-p" (or rev1 "HEAD") rev2 "--"))))
(defun vc-git-revision-table (files)
;; What about `files'?!? --Stef
table))
(defun vc-git-annotate-command (file buf &optional rev)
- ;; FIXME: rev is ignored
(let ((name (file-relative-name file)))
- (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev)))))
+ (vc-git-command buf 0 name "blame" rev)))
+
+(declare-function vc-annotate-convert-time "vc-annotate" (time))
(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)
(defun vc-git-previous-revision (file rev)
"Git-specific version of `vc-previous-revision'."
- (let ((default-directory (file-name-directory (expand-file-name file)))
- (file (file-name-nondirectory file)))
- (vc-git-symbolic-commit
- (with-temp-buffer
- (and
- (vc-git--out-ok "rev-list" "-2" rev "--" file)
- (goto-char (point-max))
- (bolp)
- (zerop (forward-line -1))
- (not (bobp))
- (buffer-substring-no-properties
- (point)
- (1- (point-max))))))))
+ (if file
+ (let ((default-directory (file-name-directory (expand-file-name file)))
+ (file (file-name-nondirectory file)))
+ (vc-git-symbolic-commit
+ (with-temp-buffer
+ (and
+ (vc-git--out-ok "rev-list" "-2" rev "--" file)
+ (goto-char (point-max))
+ (bolp)
+ (zerop (forward-line -1))
+ (not (bobp))
+ (buffer-substring-no-properties
+ (point)
+ (1- (point-max)))))))
+ (with-temp-buffer
+ (and
+ (vc-git--out-ok "rev-parse" (concat rev "^"))
+ (buffer-substring-no-properties (point-min) (+ (point-min) 40))))))
(defun vc-git-next-revision (file rev)
"Git-specific version of `vc-next-revision'."