You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Chris Pepper <pe...@reppep.com> on 2004/10/12 04:45:37 UTC

Diffs into default log template

	The default log "template" provided by "svn commit", listing 
files that are changed for review is quite useful. It would be even 
more useful if it showed the actual diffs about to be applied, so I 
could make sure my log message is complete and in sync with what I'm 
about to actually commit.

	Is there a way to accomplish this?


						Thanks,


						Chris Pepper
-- 
Chris Pepper:               <http://www.reppep.com/~pepper/>
Rockefeller University:     <http://www.rockefeller.edu/>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Max Bowsher <ma...@ukf.net>.
Chris Pepper wrote:
> The default log "template" provided by "svn commit", listing
> files that are changed for review is quite useful. It would be even
> more useful if it showed the actual diffs about to be applied, so I
> could make sure my log message is complete and in sync with what I'm
> about to actually commit.
>
> Is there a way to accomplish this?

Not directly in subversion, but depending on your editor, it might be very 
easy. For example, in vim, I just type:

:r !svn di

once the editor has started.

Max. 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by kf...@collab.net.
Chris Pepper <pe...@reppep.com> writes:
> > If the log message utility that you write is neat and tidy and
> > useful to lots of people, we could then include it as a tool in the
> > Subversion distribution.
> 
> 	Ugh. I'd have to start by patching the C code, either to
> provide a local custom feature (which I think would be broadly useful,
> but my query hasn't evoked any support for here...), or to add a new
> 'hook' which would pass enough information to an external program
> (probably a trivial shell script) to do the actual work. This would be
> useful if lots of people wanted to tweak the helper comment when
> writing logs with an interactive editor, but again I'm not sure that's
> a good investment if there's a lack of interest (here), or how many
> different options there are for customizing what is, after all, an
> ephemeral comment.

No C code patch would be necessary.  A wrapper script using 'svn st'
would be enough.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Julian Foad <ju...@btopenworld.com>.
Chris Pepper wrote:
> At 3:23 PM +0100 2004/10/14, Julian Foad wrote:
>> I'm sure some people would find it of some utility, but the trouble is 
>> that the more "svn" tries to write your log message for you, the less 
>> people it will satisfy - either that, or it grows lots of options and 
>> configurability and becomes a generic log message writer trying to 
>> suit everybody.
> 
>     No, actually. I'm not asking for any changes to the default log 
> message itself, which would remain blank. Instead I'm asking for an 
> enhancement to the 'comment' area, below "--This line, and those below, 
> will be ignored--", which would not show up in the log message, to help 
> *humans* write log messages.

I understand that.  When I said "log message" I meant "log message 
template".

>     It's my belief that more context here will encourage people to 
> confirm they're committing what they think, and make oversights in the 
> commit messages less likely.

I agree with you on that point.  That is why I usually append a diff to 
my log message template myself, but often I prefer to use a side-by-side 
diff in a separate window in my editor.  In addition to the diff, I like 
to automatically list the names of the files and functions affected, in 
the format chosen by the Subversion team for its log messages.  When 
working on different projects I would like to list this information in a 
different form.  If the diff is going to run to many megabytes then I 
don't append it to my log message template at all, but find some other 
way of reviewing it before or while writing the log message.

I have the flexibility to choose these sorts of options, and if we were 
to make "svn" append a diff it would need to have at least some of this 
flexibility.  I believe that this kind of feature is ideally suited to 
being implemented in a GUI or as an external program or wrapper script, 
and that it is not essential to the core purpose of the Subversion 
command-line client.  This is partly because the scope of the feature is 
not clearly defined and is subject to many subjective decisions.  What 
if the diff is "too big"?  How does the user specify a different diff 
program, or options to it?  Well, that is what the "svn diff" command is 
for.  The user should run "svn diff" to get the diff.  You can run it 
from within your editor if your editor lets you.  (Somebody earlier 
replied that in "vim" you can simply type ":r !svn diff" to append a 
diff to your file.)


On the other hand, on the subject of scripting...

It is wrong for us to tell users, "Oh, you can do that by writing a 
script."  Especially when we haven't tried it and so haven't realised 
how difficult it is.  We should take responsibility for providing such 
scripts when they are generally useful, like we provide some sample 
repository hook scripts.

>> I recommend writing an external log-message-generator [...]
>     Ugh. I'd have to start by patching the C code, [...]

I tried to write what you wanted as an SVN_EDITOR script, and found that 
it's difficult or impossible in the general case to get the correct set 
of diffs from the information provided in the default log message 
template.  One reason is that "svn diff" lacks a "--depth=0" mode for 
diffing the directories.

However, it is quite easy to get what you want by using a wrapper around 
"svn" in conjunction with an editor wrapper.  How about something like this?

~/tmp/sandbox> cat ~/bin/svn-commit
#!/bin/sh
svn diff "$@" > tmpdiff.txt
svn commit --editor-cmd=~/bin/svn-editor "$@"
~/tmp/sandbox> cat ~/bin/svneditor
#!/bin/sh
cat tmpdiff.txt >> "$1"
vim "$1"
~/tmp/sandbox> svn-commit ...

Does this do what you want?  If you insist that the command be "svn 
commit" instead of "svn-commit", then write a script called "svn" that 
calls the real "svn" unless the command is "commit".  If you want it to 
be installed and activated by default for your users, I'm sure we can 
work out a way to make that happen.  (Sorry if I'm sounding belligerent 
now.)

I wonder if this is the heart of the matter: it is not just that you 
want to have a way to review diffs while writing a log message, but that 
you want to encourage all users to do this.  Maybe we need to think more 
broadly about ways to achieve this.

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Chris Pepper <pe...@reppep.com>.
At 3:23 PM +0100 2004/10/14, Julian Foad wrote:
>Chris Pepper wrote:
>>     This is neat, but since I'm working with docs instead of 
>>functions, svnlog doesn't seem to get me anything more than "svn 
>>diff | bbedit", which I've been using. I'd like something to dump 
>>it into the log template, to save me a step.
>>
>>     I think what I really want would be a second loop in util.c, 
>>after the list of files with status has been generated. If a (new) 
>>flag was set, svn would loop across the files to be committed 
>>again, appending a diff for each one on this round. It would be 
>>cleaned out of the actual log message automatically, same as the 
>>current list of files is ignored.
>>
>>     Would anyone else find this useful??
>
>I'm sure some people would find it of some utility, but the trouble 
>is that the more "svn" tries to write your log message for you, the 
>less people it will satisfy - either that, or it grows lots of 
>options and configurability and becomes a generic log message writer 
>trying to suit everybody.

	No, actually. I'm not asking for any changes to the default 
log message itself, which would remain blank. Instead I'm asking for 
an enhancement to the 'comment' area, below "--This line, and those 
below, will be ignored--", which would not show up in the log 
message, to help *humans* write log messages.

	It's my belief that more context here will encourage people 
to confirm they're committing what they think, and make oversights in 
the commit messages less likely.

>I don't think that Subversion should head in that direction.  (I 
>don't even think it should invoke an editor for you, but I seem to 
>be in the minority there.)  I recommend writing an external 
>log-message-generator that suits your purposes, and put its name in 
>the SVN_EDITOR environment variable so that Subversion calls it 
>instead of a plain editor.
>
>If the log message utility that you write is neat and tidy and 
>useful to lots of people, we could then include it as a tool in the 
>Subversion distribution.

	Ugh. I'd have to start by patching the C code, either to 
provide a local custom feature (which I think would be broadly 
useful, but my query hasn't evoked any support for here...), or to 
add a new 'hook' which would pass enough information to an external 
program (probably a trivial shell script) to do the actual work. This 
would be useful if lots of people wanted to tweak the helper comment 
when writing logs with an interactive editor, but again I'm not sure 
that's a good investment if there's a lack of interest (here), or how 
many different options there are for customizing what is, after all, 
an ephemeral comment.


						Chris
-- 
Chris Pepper:               <http://www.reppep.com/~pepper/>
Rockefeller University:     <http://www.rockefeller.edu/>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Julian Foad <ju...@btopenworld.com>.
Chris Pepper wrote:
>     This is neat, but since I'm working with docs instead of functions, 
> svnlog doesn't seem to get me anything more than "svn diff | bbedit", 
> which I've been using. I'd like something to dump it into the log 
> template, to save me a step.
> 
>     I think what I really want would be a second loop in util.c, after 
> the list of files with status has been generated. If a (new) flag was 
> set, svn would loop across the files to be committed again, appending a 
> diff for each one on this round. It would be cleaned out of the actual 
> log message automatically, same as the current list of files is ignored.
> 
>     Would anyone else find this useful??

I'm sure some people would find it of some utility, but the trouble is 
that the more "svn" tries to write your log message for you, the less 
people it will satisfy - either that, or it grows lots of options and 
configurability and becomes a generic log message writer trying to suit 
everybody.

I don't think that Subversion should head in that direction.  (I don't 
even think it should invoke an editor for you, but I seem to be in the 
minority there.)  I recommend writing an external log-message-generator 
that suits your purposes, and put its name in the SVN_EDITOR environment 
variable so that Subversion calls it instead of a plain editor.

If the log message utility that you write is neat and tidy and useful to 
lots of people, we could then include it as a tool in the Subversion 
distribution.

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Chris Pepper <pe...@reppep.com>.
At 1:55 PM +0100 2004/10/12, Julian Foad wrote:
>Chris Pepper wrote:
>>     The default log "template" provided by "svn commit", listing 
>>files that are changed for review is quite useful. It would be even 
>>more useful if it showed the actual diffs about to be applied, so I 
>>could make sure my log message is complete and in sync with what 
>>I'm about to actually commit.
>>
>>     Is there a way to accomplish this?
>
>I create my log message like this:
>
>svnlogmsg | vim -
>
>where 'svnlogmsg' is a script I wrote (attached) to write the diff 
>and also write the names of files and functions changed, in the 
>format specified in HACKING; and 'vim -' invokes my editor starting 
>with text read from standard input.

Julian,

	This is neat, but since I'm working with docs instead of 
functions, svnlog doesn't seem to get me anything more than "svn diff 
| bbedit", which I've been using. I'd like something to dump it into 
the log template, to save me a step.


	I think what I really want would be a second loop in util.c, 
after the list of files with status has been generated. If a (new) 
flag was set, svn would loop across the files to be committed again, 
appending a diff for each one on this round. It would be cleaned out 
of the actual log message automatically, same as the current list of 
files is ignored.


	Would anyone else find this useful??


						Chris Pepper

>       for (i = 0; i < commit_items->nelts; i++)
>         {
>           svn_client_commit_item_t *item
>             = ((svn_client_commit_item_t **) commit_items->elts)[i];
>           const char *path = item->path;
>           char text_mod = '_', prop_mod = ' ';
>
>           if (! path)
>             path = item->url;
>           else if (! *path)
>             path = ".";
>
>           if (path && lmb->base_dir)
>             path = svn_path_is_child (lmb->base_dir, path, pool);
>
>           /* If still no path, then just use current directory. */
>           if (! path)
>             path = ".";
>
>           if ((item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
>               && (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD))
>             text_mod = 'R';
>           else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD)
>             text_mod = 'A';
>           else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
>             text_mod = 'D';
>           else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_TEXT_MODS)
>             text_mod = 'M';
>
>           if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_PROP_MODS)
>             prop_mod = 'M';
>
>           svn_stringbuf_appendbytes (tmp_message, &text_mod, 1);
>           svn_stringbuf_appendbytes (tmp_message, &prop_mod, 1);
>           svn_stringbuf_appendcstr (tmp_message, "   ");
>           svn_stringbuf_appendcstr (tmp_message, path);
>           svn_stringbuf_appendcstr (tmp_message, APR_EOL_STR);
>         }
--
Chris Pepper:               <http://www.reppep.com/~pepper/>
Rockefeller University:     <http://www.rockefeller.edu/>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Diffs into default log template

Posted by Julian Foad <ju...@btopenworld.com>.
Chris Pepper wrote:
>     The default log "template" provided by "svn commit", listing files 
> that are changed for review is quite useful. It would be even more 
> useful if it showed the actual diffs about to be applied, so I could 
> make sure my log message is complete and in sync with what I'm about to 
> actually commit.
> 
>     Is there a way to accomplish this?

I create my log message like this:

svnlogmsg | vim -

where 'svnlogmsg' is a script I wrote (attached) to write the diff and also write the names of files and functions changed, in the format specified in HACKING; and 'vim -' invokes my editor starting with text read from standard input.

I do this before issuing an 'svn commit', because there is usually something I want to check or change before finally committing it, but if you want this sort or thing to be invoked by 'svn commit' as a log message editor, I'm sure you can easily modify it into a suitable form.

'svnlogmsg' takes an optional list of paths, just as 'svn diff' does.

'svnlogmsg' uses GNU 'diff -p' to find the names of functions, and the result is not accurate - but it gets most of the right symbols most of the time and provides a reasonable starting point.

- Julian