aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2007-11-24 15:22:07 +0000
committerThien-Thi Nguyen2007-11-24 15:22:07 +0000
commit5fdbecd8962cd426865930e3c8d718b6f13acf42 (patch)
tree8fdb6f36e1841688049e5e347adf250b8ed74ca9
parent7aa579d9f207502cedc021054655554edbf661b2 (diff)
downloademacs-5fdbecd8962cd426865930e3c8d718b6f13acf42.tar.gz
emacs-5fdbecd8962cd426865930e3c8d718b6f13acf42.zip
(vc-git--call, vc-git--out-ok): New funcs.
(vc-git-state): Use vc-git--call. (vc-git-registered, vc-git-working-revision) (vc-git-previous-revision, vc-git-next-revision) (vc-git--run-command-string, vc-git-symbolic-commit): Use vc-git--out-ok.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/vc-git.el36
2 files changed, 23 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 79836fb9adc..811cbfe4865 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,6 +2,13 @@
2 2
3 * vc-git.el (vc-git-show-log-entry): New func. 3 * vc-git.el (vc-git-show-log-entry): New func.
4 4
5 * vc-git.el (vc-git--call, vc-git--out-ok): New funcs.
6 (vc-git-state): Use vc-git--call.
7 (vc-git-registered, vc-git-working-revision)
8 (vc-git-previous-revision, vc-git-next-revision)
9 (vc-git--run-command-string, vc-git-symbolic-commit):
10 Use vc-git--out-ok.
11
52007-11-24 Glenn Morris <rgm@gnu.org> 122007-11-24 Glenn Morris <rgm@gnu.org>
6 13
7 * emacs-lisp/byte-run.el (declare-function): Doc fix. 14 * emacs-lisp/byte-run.el (declare-function): Doc fix.
diff --git a/lisp/vc-git.el b/lisp/vc-git.el
index 0810361e7fb..5652f386f7f 100644
--- a/lisp/vc-git.el
+++ b/lisp/vc-git.el
@@ -135,8 +135,7 @@
135 (name (file-relative-name file dir))) 135 (name (file-relative-name file dir)))
136 (and (ignore-errors 136 (and (ignore-errors
137 (when dir (cd dir)) 137 (when dir (cd dir))
138 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" 138 (vc-git--out-ok "ls-files" "-c" "-z" "--" name))
139 "-c" "-z" "--" name)))
140 (let ((str (buffer-string))) 139 (let ((str (buffer-string)))
141 (and (> (length str) (length name)) 140 (and (> (length str) (length name))
142 (string= (substring str 0 (1+ (length name))) 141 (string= (substring str 0 (1+ (length name)))
@@ -144,7 +143,7 @@
144 143
145(defun vc-git-state (file) 144(defun vc-git-state (file)
146 "Git-specific version of `vc-state'." 145 "Git-specific version of `vc-state'."
147 (call-process "git" nil nil nil "add" "--refresh" "--" (file-relative-name file)) 146 (vc-git--call nil "add" "--refresh" "--" (file-relative-name file))
148 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) 147 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--")))
149 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" 148 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0"
150 diff)) 149 diff))
@@ -184,7 +183,7 @@
184 "Git-specific version of `vc-working-revision'." 183 "Git-specific version of `vc-working-revision'."
185 (let ((str (with-output-to-string 184 (let ((str (with-output-to-string
186 (with-current-buffer standard-output 185 (with-current-buffer standard-output
187 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD"))))) 186 (vc-git--out-ok "symbolic-ref" "HEAD")))))
188 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) 187 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
189 (match-string 2 str) 188 (match-string 2 str)
190 str))) 189 str)))
@@ -397,9 +396,7 @@ or BRANCH^ (where \"^\" can be repeated)."
397 (vc-git-symbolic-commit 396 (vc-git-symbolic-commit
398 (with-temp-buffer 397 (with-temp-buffer
399 (and 398 (and
400 (zerop 399 (vc-git--out-ok "rev-list" "-2" rev "--" file)
401 (call-process "git" nil '(t nil) nil "rev-list"
402 "-2" rev "--" file))
403 (goto-char (point-max)) 400 (goto-char (point-max))
404 (bolp) 401 (bolp)
405 (zerop (forward-line -1)) 402 (zerop (forward-line -1))
@@ -416,9 +413,7 @@ or BRANCH^ (where \"^\" can be repeated)."
416 (current-rev 413 (current-rev
417 (with-temp-buffer 414 (with-temp-buffer
418 (and 415 (and
419 (zerop 416 (vc-git--out-ok "rev-list" "-1" rev "--" file)
420 (call-process "git" nil '(t nil) nil "rev-list"
421 "-1" rev "--" file))
422 (goto-char (point-max)) 417 (goto-char (point-max))
423 (bolp) 418 (bolp)
424 (zerop (forward-line -1)) 419 (zerop (forward-line -1))
@@ -430,9 +425,7 @@ or BRANCH^ (where \"^\" can be repeated)."
430 (vc-git-symbolic-commit 425 (vc-git-symbolic-commit
431 (with-temp-buffer 426 (with-temp-buffer
432 (and 427 (and
433 (zerop 428 (vc-git--out-ok "rev-list" "HEAD" "--" file)
434 (call-process "git" nil '(t nil) nil "rev-list"
435 "HEAD" "--" file))
436 (goto-char (point-min)) 429 (goto-char (point-min))
437 (search-forward current-rev nil t) 430 (search-forward current-rev nil t)
438 (zerop (forward-line -1)) 431 (zerop (forward-line -1))
@@ -457,14 +450,20 @@ or BRANCH^ (where \"^\" can be repeated)."
457The difference to vc-do-command is that this function always invokes `git'." 450The difference to vc-do-command is that this function always invokes `git'."
458 (apply 'vc-do-command buffer okstatus "git" file-or-list flags)) 451 (apply 'vc-do-command buffer okstatus "git" file-or-list flags))
459 452
453(defun vc-git--call (buffer command &rest args)
454 (apply 'call-process "git" nil buffer nil command args))
455
456(defun vc-git--out-ok (command &rest args)
457 (zerop (apply 'vc-git--call '(t nil) command args)))
458
460(defun vc-git--run-command-string (file &rest args) 459(defun vc-git--run-command-string (file &rest args)
461 "Run a git command on FILE and return its output as string." 460 "Run a git command on FILE and return its output as string."
462 (let* ((ok t) 461 (let* ((ok t)
463 (str (with-output-to-string 462 (str (with-output-to-string
464 (with-current-buffer standard-output 463 (with-current-buffer standard-output
465 (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil 464 (unless (apply 'vc-git--out-ok
466 (append args (list (file-relative-name 465 (append args (list (file-relative-name
467 file))))) 466 file))))
468 (setq ok nil)))))) 467 (setq ok nil))))))
469 (and ok str))) 468 (and ok str)))
470 469
@@ -474,10 +473,7 @@ Returns nil if not possible."
474 (and commit 473 (and commit
475 (with-temp-buffer 474 (with-temp-buffer
476 (and 475 (and
477 (zerop 476 (vc-git--out-ok "name-rev" "--name-only" "--tags" commit)
478 (call-process "git" nil '(t nil) nil "name-rev"
479 "--name-only" "--tags"
480 commit))
481 (goto-char (point-min)) 477 (goto-char (point-min))
482 (= (forward-line 2) 1) 478 (= (forward-line 2) 1)
483 (bolp) 479 (bolp)