Mercurial > emacs
comparison lisp/vc-git.el @ 86403:d2c8f5a27761
(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.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Sat, 24 Nov 2007 15:20:58 +0000 |
parents | fdd891feb624 |
children | 68e2cdfcf931 |
comparison
equal
deleted
inserted
replaced
86402:aa024a0d77d4 | 86403:d2c8f5a27761 |
---|---|
133 (with-temp-buffer | 133 (with-temp-buffer |
134 (let* ((dir (file-name-directory file)) | 134 (let* ((dir (file-name-directory file)) |
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))) |
143 (concat name "\0"))))))))) | 142 (concat name "\0"))))))))) |
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)) |
151 'edited | 150 'edited |
152 'up-to-date))) | 151 'up-to-date))) |
182 | 181 |
183 (defun vc-git-working-revision (file) | 182 (defun vc-git-working-revision (file) |
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))) |
191 | 190 |
192 (defun vc-git-checkout-model (file) | 191 (defun vc-git-checkout-model (file) |
395 (let ((default-directory (file-name-directory (expand-file-name file))) | 394 (let ((default-directory (file-name-directory (expand-file-name file))) |
396 (file (file-name-nondirectory file))) | 395 (file (file-name-nondirectory file))) |
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)) |
406 (not (bobp)) | 403 (not (bobp)) |
407 (buffer-substring-no-properties | 404 (buffer-substring-no-properties |
414 (expand-file-name file))) | 411 (expand-file-name file))) |
415 (file (file-name-nondirectory file)) | 412 (file (file-name-nondirectory file)) |
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)) |
425 (bobp) | 420 (bobp) |
426 (buffer-substring-no-properties | 421 (buffer-substring-no-properties |
428 (1- (point-max))))))) | 423 (1- (point-max))))))) |
429 (and current-rev | 424 (and current-rev |
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)) |
439 (buffer-substring-no-properties | 432 (buffer-substring-no-properties |
440 (point) | 433 (point) |
455 (defun vc-git-command (buffer okstatus file-or-list &rest flags) | 448 (defun vc-git-command (buffer okstatus file-or-list &rest flags) |
456 "A wrapper around `vc-do-command' for use in vc-git.el. | 449 "A wrapper around `vc-do-command' for use in vc-git.el. |
457 The difference to vc-do-command is that this function always invokes `git'." | 450 The 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 |
471 (defun vc-git-symbolic-commit (commit) | 470 (defun vc-git-symbolic-commit (commit) |
472 "Translate COMMIT string into symbolic form. | 471 "Translate COMMIT string into symbolic form. |
473 Returns nil if not possible." | 472 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) |
484 (buffer-substring-no-properties (point-min) (1- (point-max))))))) | 480 (buffer-substring-no-properties (point-min) (1- (point-max))))))) |
485 | 481 |