chiark / gitweb /
stgit.el: Add "d" for a few diff commands, similar to git.el
authorGustav Hållberg <gustav@virtutech.com>
Mon, 3 Aug 2009 13:35:42 +0000 (15:35 +0200)
committerGustav Hållberg <gustav@virtutech.com>
Thu, 6 Aug 2009 20:49:07 +0000 (22:49 +0200)
"b" shows diff against base
"c" shows combined diff
"o" shows diff against our version
"t" shows diff against their version

"m" runs smerge-ediff

Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
contrib/stgit.el

index a9d787aec9addd6dc63c50c9bd8e4657f7acfc4c..e19be3374a1562c545651032bcbca1813252ac0a 100644 (file)
@@ -605,6 +605,12 @@ (defun stgit-find-file-other-window ()
   (interactive)
   (stgit-find-file t))
 
+(defun stgit-find-file-merge ()
+  "Open file at point and merge it using `smerge-ediff'."
+  (interactive)
+  (stgit-find-file t)
+  (smerge-ediff))
+
 (defun stgit-quit ()
   "Hide the stgit buffer."
   (interactive)
@@ -658,7 +664,15 @@ (defvar stgit-mode-map nil
   "Keymap for StGit major mode.")
 
 (unless stgit-mode-map
-  (let ((toggle-map (make-keymap)))
+  (let ((diff-map   (make-keymap))
+        (toggle-map (make-keymap)))
+    (suppress-keymap diff-map)
+    (mapc (lambda (arg) (define-key diff-map (car arg) (cdr arg)))
+          '(("b" .        stgit-diff-base)
+            ("c" .        stgit-diff-combined)
+            ("m" .        stgit-find-file-merge)
+            ("o" .        stgit-diff-ours)
+            ("t" .        stgit-diff-theirs)))
     (suppress-keymap toggle-map)
     (mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg)))
           '(("t" .        stgit-toggle-worktree)
@@ -700,12 +714,13 @@ (unless stgit-mode-map
             ("<" .        stgit-pop-next)
             ("P" .        stgit-push-or-pop)
             ("G" .        stgit-goto)
-            ("=" .        stgit-show)
+            ("=" .        stgit-diff)
             ("D" .        stgit-delete)
             ([(control ?/)] . stgit-undo)
             ("\C-_" .     stgit-undo)
             ("B" .        stgit-branch)
             ("t" .        ,toggle-map)
+            ("d" .        ,diff-map)
             ("q" .        stgit-quit)))))
 
 (defun stgit-mode ()
@@ -1023,9 +1038,11 @@ (defun stgit-id (patchsym)
        (error "Cannot find commit id for %s" patchsym))
       (match-string 1 result))))
 
-(defun stgit-show ()
-  "Show the patch on the current line."
-  (interactive)
+(defun stgit-show-patch (unmerged-stage)
+  "Show the patch on the current line.
+
+UNMERGED-STAGE is the argument to `git-diff' that that selects
+which stage to diff against in the case of unmerged files."
   (stgit-capture-output "*StGit patch*"
     (case (get-text-property (point) 'entry-type)
       ('file
@@ -1042,7 +1059,7 @@ (defun stgit-show ()
                             (cond ((eq patch-id :index)
                                    '("--cached"))
                                   ((eq patch-id :work)
-                                   '("--ours"))
+                                   (list unmerged-stage))
                                   (t
                                    (list (concat patch-id "^") patch-id)))
                             '("--")
@@ -1059,7 +1076,7 @@ (defun stgit-show ()
                     (stgit-find-copies-harder-diff-arg)
                     (if (eq patch-id :index)
                         '("--cached")
-                      '("--ours")))
+                      (list unmerged-stage)))
            (stgit-run "show" "-O" "--patch-with-stat" "-O" "-M"
                       (stgit-patch-name-at-point)))))
       (t
@@ -1068,6 +1085,39 @@ (defun stgit-show ()
       (goto-char (point-min))
       (diff-mode))))
 
+(defun stgit-diff ()
+  "Show the patch on the current line."
+  (interactive)
+  (stgit-show-patch "--ours"))
+
+(defun stgit-diff-ours ()
+  "Show the patch on the current line.
+
+For unmerged files, diff against our branch."
+  (interactive)
+  (stgit-show-patch "--ours"))
+
+(defun stgit-diff-theirs ()
+  "Show the patch on the current line.
+
+For unmerged files, diff against their branch."
+  (interactive)
+  (stgit-show-patch "--theirs"))
+
+(defun stgit-diff-base ()
+  "Show the patch on the current line.
+
+For unmerged files, diff against the base version."
+  (interactive)
+  (stgit-show-patch "--base"))
+
+(defun stgit-diff-combined ()
+  "Show the patch on the current line.
+
+For unmerged files, show a combined diff."
+  (interactive)
+  (stgit-show-patch "--cc"))
+
 (defun stgit-move-change-to-index (file)
   "Copies the workspace state of FILE to index, using git add or git rm"
   (let ((op (if (or (file-exists-p file) (file-symlink-p file))