Skip to content

Commit

Permalink
fix font lock keywords to highlight marked and renamed files
Browse files Browse the repository at this point in the history
fix lgit-add to not squash the RM to M_ when adding mods from a renamed file

fix lgit-commit-finish to update the status buffer post commit

fix lgit-change-file-index-state, lgit-change-file-working-state,
lgit-current-file to know about renamed file display "foo -> bar"
  • Loading branch information
Bart Robinson committed Feb 16, 2012
1 parent 036f003 commit c80cc45
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions lgit.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -136,19 +136,18 @@ the \\[lgit-explain-this-line] command.")


(defvar lgit-common-font-lock-keywords (defvar lgit-common-font-lock-keywords
'( '(
("^[MDA].*" . lgit-modified-face) ("^[MDAR].*" . lgit-modified-face)
("^.[M].*" . lgit-modified-face) ("^.[M].*" . lgit-modified-face)
("^C.*" . lgit-conflicted-face) ("^C.*" . lgit-conflicted-face)
("^.C.*" . lgit-conflicted-face) ("^.C.*" . lgit-conflicted-face)
("^......[C]" . lgit-conflicted-face)
)) ))
(defvar lgit-status-font-lock-keywords (defvar lgit-status-font-lock-keywords
(append (append
'( '(
("^.......?\\*.*" . lgit-marked-face) ("^..\\*.*" . lgit-marked-face)
) )
lgit-common-font-lock-keywords)) lgit-common-font-lock-keywords))
(defvar lgit-ustatus-font-lock-keywords (defvar lgit-ustatus-font-lock-keywords ;XXX/lomew unuesd
(append (append
'( '(
("^....................?\\*.*" . lgit-marked-face) ("^....................?\\*.*" . lgit-marked-face)
Expand Down Expand Up @@ -623,10 +622,12 @@ formally committed."
(setq file (car (car cur)) (setq file (car (car cur))
state (cdr (car cur))) state (cdr (car cur)))
(setq cur (cdr cur)) (setq cur (cdr cur))
(if (memq 'untracked state) (cond
(lgit-change-file-index-state file 'i-added) ((memq 'untracked state) ; ?? -> A_
(lgit-change-file-index-state file 'i-modified)) (lgit-change-file-index-state file 'i-added))
(lgit-change-file-working-state file 'w-unmodified))) ((memq 'i-unmodified state) ; _x -> Mx
(lgit-change-file-index-state file 'i-modified)))
(lgit-change-file-working-state file 'w-unmodified))) ; xx -> x_
;; Otherwise an error happened, bitch appropriately ;; Otherwise an error happened, bitch appropriately
(pop-to-buffer "*GIT-add*") (pop-to-buffer "*GIT-add*")
(goto-char (point-min)) (goto-char (point-min))
Expand Down Expand Up @@ -915,9 +916,6 @@ This mode is not meant to be user invoked."
(goto-char (point-min)) (goto-char (point-min))
(insert lgit-commit-initial-buffer-contents) (insert lgit-commit-initial-buffer-contents)
(error "Please specify a non-empty commit message"))) (error "Please specify a non-empty commit message")))
;; Make sure any buffers visiting those files aren't dirty.
;; XXX/lomew
;- (lgit-ensure-saved justfiles)
;; Store the commit message in a temp file to ;; Store the commit message in a temp file to
;; avoid any limits on argv size. ;; avoid any limits on argv size.
(setq message-file (make-temp-name (concat (file-name-as-directory (setq message-file (make-temp-name (concat (file-name-as-directory
Expand All @@ -942,20 +940,10 @@ This mode is not meant to be user invoked."
;; Complain loudly if the commit failed. ;; Complain loudly if the commit failed.
(if (zerop status) (if (zerop status)
(progn (progn
(pop-to-buffer commit-bufname) (pop-to-buffer parent)
(insert "\n" (lgit-commit-update-index-display)
"*** XXX/lomew deal with this buffer\n"
"\n")
;; Only chuck buffer when all is good. ;; Only chuck buffer when all is good.
(kill-buffer logbuf)) (kill-buffer logbuf))
;- (let ((cur justfiles) file)
;- (while cur
;- (setq file (car cur))
;- (lgit-revert-buffers-visiting-file file)
;- (lgit-remove-file-line file)
;- (setq cur (cdr cur)))
;- ;; Only chuck buffer when all is good.
;- (kill-buffer logbuf))
;; Commit failed. ;; Commit failed.
(pop-to-buffer commit-bufname) (pop-to-buffer commit-bufname)
(goto-char (point-min)) (goto-char (point-min))
Expand All @@ -966,6 +954,24 @@ This mode is not meant to be user invoked."
"\n") "\n")
(error "Commit failed, see %s buffer for details." commit-bufname)))) (error "Commit failed, see %s buffer for details." commit-bufname))))


(defun lgit-commit-update-index-display ()
;; Update the display post-commit for files that were in the index.
;; XXX/lomew svn/cvs ones revert the buffers for the files, prob for $Id$ crap.
(save-excursion
(goto-char (point-min))
(while (re-search-forward lgit-linepat nil t)
(let ((state (lgit-current-file-state)))
(if (or (memq 'i-modified state)
(memq 'i-added state)
(memq 'i-deleted state)
(memq 'i-renamed state)
(memq 'i-copied state))
(progn
(lgit-change-this-file-index-state 'i-unmodified)
(if (memq 'w-unmodified state)
;; Nothing to display for this file, remove the line.
(lgit-remove-file-line (lgit-current-file)))))))))

(defun lgit-commit-tidy-up-buffer () (defun lgit-commit-tidy-up-buffer ()
(save-excursion (save-excursion
;; Remove leading blank lines. ;; Remove leading blank lines.
Expand Down Expand Up @@ -1013,12 +1019,19 @@ This mode is not meant to be user invoked."


;; Internal functions. ;; Internal functions.


(defun lgit-filepat (file)
(concat lgit-linepat "\\(.+ -> \\)?" (regexp-quote file) "$"))

(defun lgit-current-file () (defun lgit-current-file ()
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(if (looking-at lgit-linepat) (if (looking-at lgit-linepat)
(buffer-substring (match-end 0) (let ((file-part (buffer-substring (match-end 0)
(progn (end-of-line) (point))) (progn (end-of-line) (point)))))
;; handle the output from "git mv" files foo -> bar, take bar.
(if (string-match "\\(.+\\) -> \\(.+\\)" file-part)
(match-string 2 file-part)
file-part))
(error "No file on this line")))) (error "No file on this line"))))


(defun lgit-current-file-state () (defun lgit-current-file-state ()
Expand Down Expand Up @@ -1265,23 +1278,11 @@ the value of `foo'."
(goto-char (point-min)) (goto-char (point-min))
;; Remove the line. ;; Remove the line.
(let ((buffer-read-only nil)) (let ((buffer-read-only nil))
(delete-matching-lines (concat lgit-linepat (regexp-quote file) "$"))) (delete-matching-lines (lgit-filepat file)))
;; Update marked files. ;; Update marked files.
(if (assoc file lgit-marked-files) (if (assoc file lgit-marked-files)
(setq lgit-marked-files (lgit-remassoc file lgit-marked-files))))) (setq lgit-marked-files (lgit-remassoc file lgit-marked-files)))))


(defun lgit-remove-conflict-file-lines (file)
;; Delete lines in the (readonly) status buffer that match the conflict
;; files for a file name. These are the file.mine, file.r123 files.
(save-excursion
(goto-char (point-min))
;; Remove the matching lines.
(let ((buffer-read-only nil))
(delete-matching-lines (concat lgit-linepat (regexp-quote file) "\\.mine$"))
(delete-matching-lines (concat lgit-linepat (regexp-quote file) "\\.r[0-9]+$")))
;; XXX/lomew we assume they aren't in the marked files, see lgit-mark-file.
))

(defun lgit-change-this-file-index-state (newstate) (defun lgit-change-this-file-index-state (newstate)
;; Change the displayed index state of the file on this line. ;; Change the displayed index state of the file on this line.
;; If the file in in the marked list, update that too. ;; If the file in in the marked list, update that too.
Expand Down Expand Up @@ -1339,14 +1340,14 @@ the value of `foo'."
;; Change the displayed index state of a file. ;; Change the displayed index state of a file.
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(if (re-search-forward (concat lgit-linepat (regexp-quote file) "$") nil t) (if (re-search-forward (lgit-filepat file) nil t)
(lgit-change-this-file-index-state newstate)))) (lgit-change-this-file-index-state newstate))))


(defun lgit-change-file-working-state (file newstate) (defun lgit-change-file-working-state (file newstate)
;; Change the displayed working-tree state of a file. ;; Change the displayed working-tree state of a file.
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(if (re-search-forward (concat lgit-linepat (regexp-quote file) "$") nil t) (if (re-search-forward (lgit-filepat file) nil t)
(lgit-change-this-file-working-state newstate)))) (lgit-change-this-file-working-state newstate))))


(defun lgit-info () (defun lgit-info ()
Expand Down

0 comments on commit c80cc45

Please sign in to comment.