git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] commit: allow editing notes in commit message editor
Date: Tue, 08 Mar 2011 10:15:24 +0100	[thread overview]
Message-ID: <201103081015.24474.johan@herland.net> (raw)
In-Reply-To: <20110307234138.GB20912@sigill.intra.peff.net>

On Tuesday 08 March 2011, Jeff King wrote:
> Changes from v1:
> 
>   - fix bug with adding notes to new commit (we failed to
>     initialize the notes tree properly in this case)
> 
>   - you can now do "commit --notes=foo" to view/edit
>     refs/notes/foo

Nice. :)

>   - added tests for basic operations, plus interaction with
>     --cleanup and -v
> 
>   - turn off commit rewriting when we edit
> 
> Todo:
> 
>   - commit.notes config variable to have this on all the time
> 
>   - I punted on the separator decision here.

We probably want to make it configurable, as mentioned earlier in the 
thread. Still, making it configurable gives me the somewhat uneasy feeling 
that we're "blaming" the user for any false positives ("It's your fault for 
not choosing a more unique separator...")...

What if we start the separator with a comment character (e.g. "# ---"). That 
way, the user could not expect a false positive to make it into the commit 
message in the first place (since it'd be stripped along with other 
comments). Of course, we'd have to make sure that the notes separator was 
parsed before removing the comments, but I think that's already taken care 
of in the patch below.

>   - probably still some magic needed for rebase conflict
>     case; we will be making a new commit, so we don't know
>     to pull the notes in from the old commit as we do with
>     --amend.

Maybe add a "--notes-copy=<commit>" argument to "git commit" that causes 
"<commit>" to be passed to add_notes_from_commit(). Of course, in the case 
of --amend, the default is "--notes-copy=HEAD".

>   - still needs the format-patch component to make the
>     workflow complete :)
> 
>  builtin/commit.c        |   87 ++++++++++++++++++++++-
>  t/t7510-commit-notes.sh |  183 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 268 insertions(+), 2 deletions(-)
>  create mode 100755 t/t7510-commit-notes.sh
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index d71e1e0..f84ca23 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c

[...]

> @@ -559,6 +564,68 @@ static char *cut_ident_timestamp_part(char *string)
>  	return ket;
>  }
> 
> +static void init_edit_notes() {

style nit: move "{" to next line.

[...]

> +static void update_notes_for_commit(struct strbuf *notes,
> +				    unsigned char *commit_sha1)
> +{
> +	init_edit_notes();
> +
> +	if (cleanup_mode != CLEANUP_NONE)
> +		stripspace(notes, cleanup_mode == CLEANUP_ALL);
> +
> +	if (!notes->len)
> +		remove_note(&edit_notes_tree, commit_sha1);
> +	else {
> +		unsigned char blob_sha1[20];
> +		if (write_sha1_file(notes->buf, notes->len,
> +				    blob_type, blob_sha1) < 0)
> +			die("unable to write note blob");
> +		add_note(&edit_notes_tree, commit_sha1, blob_sha1,
> +			 combine_notes_overwrite);

We may want to consider adding a small convenience function to the notes API 
for turning a strbuf into a notes blob. (Maybe s/strbuf/char* + len/ to 
cater for binary notes blobs as well.) This would move some low-level 
details (#include "blob.h", and write_sha1_file(...)) out of the notes API 
users' code.


Otherwise, this looks really good.


Have fun! :)

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

  reply	other threads:[~2011-03-08  9:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-25 13:30 [RFC/PATCH] commit notes workflow Jeff King
2011-02-25 15:58 ` Johan Herland
2011-03-01 21:59   ` Jeff King
2011-03-02  0:21     ` Johan Herland
2011-03-03  1:57       ` Sverre Rabbelier
2011-03-03  3:50         ` Junio C Hamano
2011-03-03 11:12           ` Sverre Rabbelier
2011-03-03 11:23             ` [PATCH] commit, status: #comment diff output in verbose mode Ian Ward Comfort
2011-03-03 11:25               ` Sverre Rabbelier
2011-03-07 23:39       ` [RFC/PATCH] commit notes workflow Jeff King
2011-03-07 23:39         ` [PATCH 1/2] notes: make expand_notes_ref globally accessible Jeff King
2011-03-08  8:25           ` Johan Herland
2011-03-07 23:41         ` [PATCH 2/2] commit: allow editing notes in commit message editor Jeff King
2011-03-08  9:15           ` Johan Herland [this message]
2011-03-08 12:39         ` [RFC/PATCH] commit notes workflow Michel Lespinasse
2011-03-02  7:01     ` Chris Packham
2011-03-02 12:45       ` Drew Northup
2011-03-02 16:24       ` Piotr Krukowiecki
2011-02-25 18:59 ` Junio C Hamano
2011-02-25 20:30 ` Drew Northup
2011-03-01 22:00   ` Jeff King
2011-03-01 22:18     ` Drew Northup
2011-03-01 22:23       ` Jeff King
2011-03-01 22:26         ` Drew Northup
2011-02-27 14:31 ` Michael J Gruber
2011-03-01 22:01   ` Jeff King
2011-03-09  8:13 ` Yann Dirson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201103081015.24474.johan@herland.net \
    --to=johan@herland.net \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).