;;; vc-git.el --- VC backend for the git version control system -*- lexical-binding: t -*-
-;; Copyright (C) 2006-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2013 Free Software Foundation, Inc.
;; Author: Alexandre Julliard <julliard@winehq.org>
;; Keywords: vc tools
;;;###autoload "Return non-nil if FILE is registered with git."
;;;###autoload (if (vc-find-root file ".git") ; Short cut.
;;;###autoload (progn
-;;;###autoload (load "vc-git")
+;;;###autoload (load "vc-git" nil t)
;;;###autoload (vc-git-registered file))))
(defun vc-git-registered (file)
(vc-git--state-code diff-letter)))
(if (vc-git--empty-db-p) 'added 'up-to-date))))
-(defun vc-git-working-revision (_file)
+(defun vc-git-working-revision (file)
"Git-specific version of `vc-working-revision'."
(let* (process-file-side-effects
- (str (with-output-to-string
- (with-current-buffer standard-output
- (vc-git--out-ok "symbolic-ref" "HEAD")))))
- (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
- (match-string 2 str)
- str)))
+ (str (vc-git--run-command-string nil "symbolic-ref" "HEAD")))
+ (vc-file-setprop file 'vc-git-detached (null str))
+ (if str
+ (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
+ (match-string 2 str)
+ str)
+ (vc-git--rev-parse "HEAD"))))
(defun vc-git-workfile-unchanged-p (file)
(eq 'up-to-date (vc-git-state file)))
(defun vc-git-mode-line-string (file)
"Return a string for `vc-mode-line' to put in the mode line for FILE."
- (let* ((branch (vc-working-revision file))
+ (let* ((rev (vc-working-revision file))
+ (detached (vc-file-getprop file 'vc-git-detached))
(def-ml (vc-default-mode-line-string 'Git file))
(help-echo (get-text-property 0 'help-echo def-ml)))
- (if (zerop (length branch))
- (propertize
- (concat def-ml "!")
- 'help-echo (concat help-echo "\nNo current branch (detached HEAD)"))
- (propertize def-ml
- 'help-echo (concat help-echo "\nCurrent branch: " branch)))))
+ (propertize (if detached
+ (substring def-ml 0 (- 7 (length rev)))
+ def-ml)
+ 'help-echo (concat help-echo "\nCurrent revision: " rev))))
(cl-defstruct (vc-git-extra-fileinfo
(:copier nil)
(when next-stage
(vc-git-dir-status-goto-stage next-stage files update-function))))
+;; Follows vc-git-command (or vc-do-async-command), which uses vc-do-command
+;; from vc-dispatcher.
+(declare-function vc-exec-after "vc-dispatcher" (code))
+;; Follows vc-exec-after.
+(declare-function vc-set-async-update "vc-dispatcher" (process-buffer))
+
(defun vc-git-dir-status-goto-stage (stage files update-function)
(erase-buffer)
(pcase stage
;;; HISTORY FUNCTIONS
+(autoload 'vc-setup-buffer "vc-dispatcher")
+
(defun vc-git-print-log (files buffer &optional shortlog start-revision limit)
- "Get change log associated with FILES.
-Note that using SHORTLOG requires at least Git version 1.5.6,
-for the --graph option."
+ "Print commit log associated with FILES into specified BUFFER.
+If SHORTLOG is non-nil, use a short format based on `vc-git-root-log-format'.
+\(This requires at least Git version 1.5.6, for the --graph option.)
+If START-REVISION is non-nil, it is the newest revision to show.
+If LIMIT is non-nil, show no more than this many entries."
(let ((coding-system-for-read vc-git-commits-coding-system))
;; `vc-do-command' creates the buffer, but we need it before running
;; the command.
(indent-region (point-min) (point-max) 2)
(buffer-string))))
+(autoload 'vc-switches "vc")
+
(defun vc-git-diff (files &optional rev1 rev2 buffer)
"Get a difference report using Git between two revisions of FILES."
(let (process-file-side-effects)
(point)
(1- (point-max)))))))
(or (vc-git-symbolic-commit prev-rev) prev-rev))
- (with-temp-buffer
- (and
- (vc-git--out-ok "rev-parse" (concat rev "^"))
- (buffer-substring-no-properties (point-min) (+ (point-min) 40))))))
+ (vc-git--rev-parse (concat rev "^"))))
+
+(defun vc-git--rev-parse (rev)
+ (with-temp-buffer
+ (and
+ (vc-git--out-ok "rev-parse" rev)
+ (buffer-substring-no-properties (point-min) (+ (point-min) 40)))))
(defun vc-git-next-revision (file rev)
"Git-specific version of `vc-next-revision'."
(or (vc-file-getprop file 'git-root)
(vc-file-setprop file 'git-root (vc-find-root file ".git"))))
+;; grep-compute-defaults autoloads grep.
+(declare-function grep-read-regexp "grep" ())
+(declare-function grep-read-files "grep" (regexp))
+(declare-function grep-expand-template "grep"
+ (template &optional regexp files dir excl))
+
;; Derived from `lgrep'.
(defun vc-git-grep (regexp &optional files dir)
"Run git grep, searching for REGEXP in FILES in directory DIR.
(if (eq next-error-last-buffer (current-buffer))
(setq default-directory dir))))))
+;; Everywhere but here, follows vc-git-command, which uses vc-do-command
+;; from vc-dispatcher.
+(autoload 'vc-resynch-buffer "vc-dispatcher")
+
(defun vc-git-stash (name)
"Create a stash."
(interactive "sStash name: ")
(match-string 1)
(error "Cannot find stash at point"))))
+;; vc-git-stash-delete-at-point must be called from a vc-dir buffer.
+(declare-function vc-dir-refresh "vc-dir" ())
+
(defun vc-git-stash-delete-at-point ()
(interactive)
(let ((stash (vc-git-stash-get-at-point (point))))
The difference to vc-do-command is that this function always invokes
`vc-git-program'."
(apply 'vc-do-command (or buffer "*vc*") okstatus vc-git-program
- file-or-list flags))
+ file-or-list (cons "--no-pager" flags)))
(defun vc-git--empty-db-p ()
"Check if the git db is empty (no commit done yet)."