git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Pat Notz <patnotz@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output
Date: Wed, 13 Oct 2010 16:44:14 -0600	[thread overview]
Message-ID: <AANLkTi=+eBn86WBmcnASyhfDot1_5Cqkzvcn-Y_-cvrX@mail.gmail.com> (raw)
In-Reply-To: <7vd3rdiwjh.fsf@alter.siamese.dyndns.org>

On Wed, Oct 13, 2010 at 3:59 PM, Junio C Hamano <gitster@pobox.com> wrote:
> "Pat Notz" <patnotz@gmail.com> writes:
>
>> diff --git a/pretty.c b/pretty.c
>> index a607fd6..e5ce7fb 100644
>> --- a/pretty.c
>> +++ b/pretty.c
>> @@ -1009,16 +1009,47 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
>>
>>  void format_commit_message(const struct commit *commit,
>>                          const char *format, struct strbuf *sb,
>> -                        const struct pretty_print_context *pretty_ctx)
>> +                        const struct pretty_print_context *pretty_ctx,
>> +                        const char *output_encoding)
>>  {
>>       struct format_commit_context context;
>> +     static char utf8[] = "UTF-8";
>> +     char *enc;
>> +     char *buffer;
>> +     char *enc_buffer;
>> +     struct strbuf scratch_sb = STRBUF_INIT;
>> +     struct strbuf *sb_ptr;
>> +
>> +     enc = get_header(commit, "encoding");
>> +     enc = enc ? enc : utf8;
>> +     if(output_encoding && strcmp(enc,output_encoding)) {
>> +             sb_ptr = &scratch_sb;
>> +     } else {
>> +             sb_ptr = sb;
>> +     }
>
> Style...
>
>>       memset(&context, 0, sizeof(context));
>>       context.commit = commit;
>>       context.pretty_ctx = pretty_ctx;
>>       context.wrap_start = sb->len;
>> -     strbuf_expand(sb, format, format_commit_item, &context);
>> -     rewrap_message_tail(sb, &context, 0, 0, 0);
>> +     strbuf_expand(sb_ptr, format, format_commit_item, &context);
>> +     rewrap_message_tail(sb_ptr, &context, 0, 0, 0);
>> +
>> +     if(sb_ptr != sb) {
>> +             /* if re-encoding fails, take the content byte-for-byte */
>> +             buffer = strbuf_detach(sb_ptr, 0);
>> +             enc_buffer = reencode_string(buffer, output_encoding, enc);
>> +             enc_buffer = enc_buffer ? enc_buffer : buffer;
>> +
>> +             strbuf_addstr(sb,enc_buffer);
>> +
>> +             if(enc_buffer != buffer)
>> +                     free(enc_buffer);
>> +             free(buffer);
>> +     }
>> +
>> +     if(enc != utf8)
>> +             free(enc);
>>  }
>
> You are expanding and wrapping commit->buf before re-encoding, but I am
> not sure it is the right thing to do.  Wouldn't it become much simpler and
> more consistent if you re-encode first and then give the result to later
> expansion and wrapping process?  format_commit_one() would need to take
> "msg" not from c->commit->buffer but from a new field to hold reencoded
> result you will add in your patch to the structure, if you do so, of
> course.
>
> Besides, I am a bit lost as to what this patch has to do with the stated
> goal of the series, "Add commit message options for rebase --autosquash".

Thank you for the reviews; I'll digest your comments shortly. In
response to your final comment, this patch was in response to your
earlier suggestion[1] to teach format_commit_message() to deal with
potentially different encodings.  I went for your option #3 there but
perhaps it's overkill.  I still think that's the right thing to do
despite my implementation.  Otherwise, this routine is just adding
bits to the buffer without regard for consistent encoding.  My goal
was to introduce this separately from any new features.

Again, thanks for all your comments -- I'll try to improve the series.

[1] http://thread.gmane.org/gmane.comp.version-control.git/156883/focus=156891

  reply	other threads:[~2010-10-13 22:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-07 19:10 [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 1/8] commit.c: prefer get_header() to manual searching Pat Notz
2010-10-07 21:11   ` Sverre Rabbelier
2010-10-07 21:12     ` Sverre Rabbelier
2010-10-13 21:59   ` Junio C Hamano
2010-10-07 19:10 ` [PATCHv5 2/8] commit.c: new function for looking up a comit by name Pat Notz
2010-10-13 21:59   ` Junio C Hamano
2010-10-07 19:10 ` [PATCHv5 3/8] pretty.c: helper methods for getting output encodings Pat Notz
2010-10-07 19:10 ` [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output Pat Notz
2010-10-13 21:59   ` Junio C Hamano
2010-10-13 22:44     ` Pat Notz [this message]
2010-10-07 19:10 ` [PATCHv5 5/8] commit: --fixup option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 6/8] add tests of commit --fixup Pat Notz
2010-10-07 19:10 ` [PATCHv5 7/8] commit: --squash option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 8/8] add tests of commit --squash Pat Notz
2010-10-11 21:06 ` [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-12  9:36   ` Sverre Rabbelier

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='AANLkTi=+eBn86WBmcnASyhfDot1_5Cqkzvcn-Y_-cvrX@mail.gmail.com' \
    --to=patnotz@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).