Re: "git intepret-trailers" vs. "sed script" to add the signature

2017-07-04 Thread Junio C Hamano
Kaartic Sivaraam  writes:

> On Mon, 2017-07-03 at 09:58 -0700, Junio C Hamano wrote:
>> Kaartic Sivaraam  writes:
>> 
>> > I'll send a typical patch that uses "git interpret-headers" as a
>> > follow-up.
>> 
>> When you say a "typical" patch, what do you exactly mean?  Does
>> anybody else send typical patches (or atypical ones for that matter)
>> to the list?
>> 
> I apologise for the inconsistent wordings. I try to mean a patch which
> I'm not sure is acceptable (or) not. I guess that's [PATCH/RFC] in the
> language of this list. I'm not acquainted to the wordings as I'm an
> "off-list" person trying to help and get help! I'll try to use
> consistent wordings as far as I could. Once again, please excuse my
> ignorance.

Oh no need to apologise for "ignorance"; that goes both ways. I
wasn't familiar with a phrase you used "a typical patch" (which I
suspected that is something you may be used to from your involvement
in other development community) and showing _my_ ignorance and
asking for help to clarify, so that both of us can understand each
other better.

My reading of your response is that it is a normal patch that
proposes a change, as opposed to the final version of a patch meant
for inclusion, after it has been discussed here and everybody
supports---let me know if I am still not reading you correctly.

Thanks.


Re: "git intepret-trailers" vs. "sed script" to add the signature

2017-07-04 Thread Kaartic Sivaraam
On Mon, 2017-07-03 at 09:58 -0700, Junio C Hamano wrote:
> Kaartic Sivaraam  writes:
> 
> > So, it seems that excepting for 'commit' it has quite a nice
> > spacing. I
> > guess we could add something like the following to fix that,
> > 
> > # Add new line after SOB in case of "git commit"
> > NEW_LINE='\
> > '
> > if [ -z "$2" ]
> > then
> >   sed -i "1i$NEW_LINE" "$1"
> > fi
> 
> Isn't "sed -i" GNUism that is not portable?
> 
It does seem to be the case. Then the alternative would be the
following,

if [ -z "$2" ]
then
  sed -e "1i$NEW_LINE" "$1" >"sed-output.temp"
  mv "sed-output.temp" "$1"
fi

Actually the GNU's sed documentation tricked me into believing '-i'
wasn't a GNU extension. The '-i' option works with the '--posix' option
of GNU sed which made me believe it isn't an extension.

> > I'll send a typical patch that uses "git interpret-headers" as a
> > follow-up.
> 
> When you say a "typical" patch, what do you exactly mean?  Does
> anybody else send typical patches (or atypical ones for that matter)
> to the list?
> 
I apologise for the inconsistent wordings. I try to mean a patch which
I'm not sure is acceptable (or) not. I guess that's [PATCH/RFC] in the
language of this list. I'm not acquainted to the wordings as I'm an
"off-list" person trying to help and get help! I'll try to use
consistent wordings as far as I could. Once again, please excuse my
ignorance.

-- 
Kaartic


Re: "git intepret-trailers" vs. "sed script" to add the signature

2017-07-03 Thread Junio C Hamano
Kaartic Sivaraam  writes:

> So, it seems that excepting for 'commit' it has quite a nice spacing. I
> guess we could add something like the following to fix that,
>
> # Add new line after SOB in case of "git commit"
> NEW_LINE='\
> '
> if [ -z "$2" ]
> then
>   sed -i "1i$NEW_LINE" "$1"
> fi

Isn't "sed -i" GNUism that is not portable?

> I'll send a typical patch that uses "git interpret-headers" as a
> follow-up.

When you say a "typical" patch, what do you exactly mean?  Does
anybody else send typical patches (or atypical ones for that matter)
to the list?





"git intepret-trailers" vs. "sed script" to add the signature

2017-07-01 Thread Kaartic Sivaraam
On Sat, 2017-07-01 at 19:45 +0530, Kaartic Sivaraam wrote:
> On Fri, 2017-06-30 at 09:44 -0700, Junio C Hamano wrote:
> > It does look like a hack.  I was wondering if "interpret-trailers"
> > is mature enough and can be used for this by now.
> 
> It does look promising except for a few differences from the hook
> which
> I'll explain in the following mail.

interpet-trailers
=

After enabling the script I tried the following (shown here as a diff)
to add the signature with "interpret-trailers",

diff --git a/templates/hooks--prepare-commit-msg.sample 
b/templates/hooks--prepare-commit-msg.sample
index 6473bcacd..9f8cbe7fd 100755
--- a/templates/hooks--prepare-commit-msg.sample
+++ b/templates/hooks--prepare-commit-msg.sample
@@ -33,4 +33,4 @@ case "$2,$3" in
 esac
 
 SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: 
\1/p')
-grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+git interpret-trailers --in-place --trailer "$SOB" "$1"

It adds the signature if it's not present in the following cases,

* commit
* merge
* commit --amend
* commit -F
* cherry-pick

It's pretty good in adding the signature except that it's not in line
with "git commit -s" whose resulting "spacing" (new lines before and
after) as shown in the editor is given below,

> 
> 
> Signed-off-by: Test 
> 
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> ...

The spacing of "git interpret-trailers" in the editor for the relevant
cases are,

commit
--

> 
> Signed-off-by: Test 
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> ...


commit --amend
--

> Empty commit to test amending 
>  
> Signed-off-by: Test  
>  
> # Please enter the commit message for your changes. Lines starting 
> # with '#' will be ignored, and an empty message aborts the commit. 
> ...


merge
-
> Merge branch 'hook-test' into hook-test-merge
> 
> Signed-off-by: Test 
> 
> # Please enter a commit message to explain why this merge is necessary,
> # especially if it merges an updated upstream into a topic branch.
> #
> # Lines starting with '#' will be ignored, and an empty message aborts
> # the commit.

So, it seems that excepting for 'commit' it has quite a nice spacing. I
guess we could add something like the following to fix that,

# Add new line after SOB in case of "git commit"
NEW_LINE='\
'
if [ -z "$2" ]
then
  sed -i "1i$NEW_LINE" "$1"
fi


sed-script
==
I also tried to add the signature that immitates the "-s" option
of "git commit" using "sed" but it works only in following cases,

* commit
* commit --amend
* merge

It doesn't seem to work in cases where user doesn't edit the message
using the editor. I'm not sure why.

I'm not including a patch of my manual way here as "git interpret-
trailers" (with the fix added) seems quite promising (at least to me).

I'll send a typical patch that uses "git interpret-headers" as a
follow-up.

-- 
Regards,
Kaartic Sivaraam