unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Magit and seeing the whole diff
@ 2010-12-18 20:21 Andrea Crotti
  2010-12-19 11:05 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Crotti @ 2010-12-18 20:21 UTC (permalink / raw)
  To: help-gnu-emacs

I was trying to make a small (but for me nice) enhancemente to magit.el.

I also forked the repo so then if it works I can try to propose it.

Don't know if someone used it but basically I would like to
1. see automatically the "diff --cached HEAD" when I execute
   magit-status.
2. when I write the commit message, see the whole diff right below.

In this way I'm sure that I'm not committing something I don't want and
I can write everything in the comments.

The function to modify could be this:

(defun magit-pop-to-log-edit (operation)
  (let ((dir default-directory)
	(buf (get-buffer-create magit-log-edit-buffer-name)))
    (setq magit-pre-log-edit-window-configuration
	  (current-window-configuration))
    (pop-to-buffer buf)
    (when (file-exists-p ".git/MERGE_MSG")
    ;; --- my addition
      ;TODO: not working yet, try to see the diff as show in the rest of the code 
      (insert (shell-command-to-string "git diff HEAD"))
    ;; --- end

      (insert-file-contents ".git/MERGE_MSG"))
    (setq default-directory dir)
    (magit-log-edit-mode)
    (message "Type C-c C-c to %s (C-c C-k to cancel)." operation)))

This is very rough and should be changed to use the code already present
to call git, but the thing is that if I evaluate this function like this
my instruction is completely SKIPPED!

I also tried with edebug to see what happens and well is just skipped.
In the doc before it was marked as a "compiled" function, but when I
modify and evaluate it it's marked as a lisp function, so from my
understanding is my own function, not the old compiled one.

Any idea?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Magit and seeing the whole diff
  2010-12-18 20:21 Magit and seeing the whole diff Andrea Crotti
@ 2010-12-19 11:05 ` Thien-Thi Nguyen
  2010-12-20 13:06   ` Andrea Crotti
  0 siblings, 1 reply; 6+ messages in thread
From: Thien-Thi Nguyen @ 2010-12-19 11:05 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

() Andrea Crotti <andrea.crotti.0@gmail.com>
() Sat, 18 Dec 2010 21:21:04 +0100

   Any idea?

I find the "git diff*" family of commands too flexible
to abstract precisely, when multiple files are involved.
For that, i use the simple shell script:

sed -i '1,/^####/!d' $0
date +"
                                                          %F %T" >> $0
#git diff -p --stat $(head -n 1 .last-release) ${1-HEAD} >> $0
git diff -p --stat q qq >> $0
exit 0
#### (progn (shell-command "sh .ttn.diff") (revert-buffer-t-t))




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Magit and seeing the whole diff
       [not found] <mailman.9.1292703974.5735.help-gnu-emacs@gnu.org>
@ 2010-12-20 12:48 ` Sébastien Vauban
  2010-12-20 13:51   ` Andrea Crotti
  0 siblings, 1 reply; 6+ messages in thread
From: Sébastien Vauban @ 2010-12-20 12:48 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Andrea,

Andrea Crotti wrote:
> Don't know if someone used it but basically I would like to
> 1. see automatically the "diff --cached HEAD" when I execute
>    magit-status.
> 2. when I write the commit message, see the whole diff right below.

For the second point (at least), use egg instead?

It's a fork of magit.

Best regards,
  Seb

-- 
Sébastien Vauban


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Magit and seeing the whole diff
  2010-12-19 11:05 ` Thien-Thi Nguyen
@ 2010-12-20 13:06   ` Andrea Crotti
  2010-12-21  9:31     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Crotti @ 2010-12-20 13:06 UTC (permalink / raw)
  To: help-gnu-emacs

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> () Andrea Crotti <andrea.crotti.0@gmail.com>
> () Sat, 18 Dec 2010 21:21:04 +0100
>
>    Any idea?
>
> I find the "git diff*" family of commands too flexible
> to abstract precisely, when multiple files are involved.
> For that, i use the simple shell script:
>
> sed -i '1,/^####/!d' $0
> date +"
>                                                           %F %T" >> $0
> #git diff -p --stat $(head -n 1 .last-release) ${1-HEAD} >> $0
> git diff -p --stat q qq >> $0
> exit 0
> #### (progn (shell-command "sh .ttn.diff") (revert-buffer-t-t))

I don't quite get what you mean...
How does this integrates with magit/emacs?

You keep a buffer with the diff and you revert it sometimes?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Magit and seeing the whole diff
  2010-12-20 12:48 ` Sébastien Vauban
@ 2010-12-20 13:51   ` Andrea Crotti
  0 siblings, 0 replies; 6+ messages in thread
From: Andrea Crotti @ 2010-12-20 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com>
writes:
> For the second point (at least), use egg instead?
>
> It's a fork of magit.
>
> Best regards,
>   Seb

I tried and yes, that's what I was looking for.
But actually I think that magit is much more complete, it also supports
git-svn and maybe more developed.

So it would be nice to just add this feature and then I would be happy...




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Magit and seeing the whole diff
  2010-12-20 13:06   ` Andrea Crotti
@ 2010-12-21  9:31     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 6+ messages in thread
From: Thien-Thi Nguyen @ 2010-12-21  9:31 UTC (permalink / raw)
  To: help-gnu-emacs

() Andrea Crotti <andrea.crotti.0@gmail.com>
() Mon, 20 Dec 2010 14:06:44 +0100

   I don't quite get what you mean...
   How does this integrates with magit/emacs?

Sorry, i sent the mail out before completing it.  That shell
script in fact doesn't integrate with anything, because i haven't
found any Emacs Lisp wrapping that lets me play (fully) with all
the git diff variants and options.

   You keep a buffer with the diff and you
   revert it sometimes?

Yes.  The shell script (aka $0 aka .ttn.diff) rewrites its tail on
every invocation (it requires a sed that supports ‘-i’, like GNU
sed).  Typically, i futz the command line to taste then move point
after the close-paren and type ‘C-x C-e’.  This invokes the script
and reverts the buffer; btw, here is ‘revert-buffer-t-t’:

  (defun revert-buffer-t-t ()
    (interactive)
    (revert-buffer t t))

The file is automatically placed into Diff mode because of its
name.  I usually immediately type ‘C-x C-q’ to toggle read-only,
which enables ‘n’ and ‘p’ bindings to for fast cruising, etc.

I suppose all of this can be translated into an Emacs Lisp
command.  Here's a lightly-tested sketch that does more or less
(it moves point, annoyingly) the same thing:

(defun update-diff ()
  "Update the current buffer using its \"git diff\" command.
The command should be near the beginning of the file at bol,
and start with \"git diff\" (so \"git diff-index\", etc, is ok).
It should be followed at some point by #### on a line by itself.
For example:

   #git diff-index [...]           ;; unused
   #git diff a q                   ;; unused
   git diff -p --stat q r/hack
   #git diff -p --stat q r/fix     ;; unused
   ####

The updated buffer has a time stamp and the output of the
git diff command.  It is in Diff mode, read-only."
  (interactive)
  (let ((me (buffer-file-name))
        (cmd (progn (goto-char (point-min))
                    (re-search-forward "^git diff")
                    (buffer-substring (match-beginning 0)
                                      (line-end-position)))))
    (re-search-forward "^####.*\n")
    (let ((inhibit-read-only t))
      (delete-region (point) (point-max))
      (save-excursion
        (insert (format-time-string "\n\t\t\t\t\t\t%F %T\n\n")
                (shell-command-to-string cmd))))
    (diff-mode)
    (toggle-read-only 1)))

Now that i've written it, probably i'll stop using the shell
script.  So, thanks for prompting this pleasant interlude!



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-12-21  9:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-18 20:21 Magit and seeing the whole diff Andrea Crotti
2010-12-19 11:05 ` Thien-Thi Nguyen
2010-12-20 13:06   ` Andrea Crotti
2010-12-21  9:31     ` Thien-Thi Nguyen
     [not found] <mailman.9.1292703974.5735.help-gnu-emacs@gnu.org>
2010-12-20 12:48 ` Sébastien Vauban
2010-12-20 13:51   ` Andrea Crotti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).