threads / patch / 31772

patchAdd --unannotate option to git-subtree

Subject: [PATCH] Add --unannotate option to git-subtree

## tl;dr

7 messages between Oct 9, 2012 and Jan 22, 2013. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

James Nylen· Oct 9, 2012, 20:26 UTC · lore

This new option does the reverse of --annotate, which is more useful when contributing back to a library which is also included in the repository for a larger project, and perhaps in other situations as well.

Rather than adding a marker to each commit when splitting out the commits back to the subproject, --unannotate removes the specified string (or bash glob pattern) from the beginning of the first line of the commit message. This enables the following workflow:

 - Commit to a library included in a large project, with message:
     Library: Make some amazing change
 - Use `git-subtree split` to send this change to the library maintainer
 - Pass ` --unannotate='Library: ' ` or ` --unannotate='*: ' `
 - This will turn the commit message for the library project into:
     Make some amazing change

This helps to keep the commit messages meaningful in both the large project and the library project.

Signed-off-by: James Nylen <jnylen@gmail.com>
---
Let me know if gmail has munged this patch.  You can also get at it
like this:
$ git remote add nylen git://github.com/nylen/git.git
$ git fetch nylen
$ git show nylen/subtree-unannotate
---
 contrib/subtree/git-subtree.sh  | 11 +++++++++--
 contrib/subtree/git-subtree.txt | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
Show changes to 2 files +24 −2

contrib/subtree/git-subtree.sh, contrib/subtree/git-subtree.txt

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..8d1ed05 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,6 +21,7 @@ P,prefix=     the name of the subdir to split out
 m,message=    use the given message as the commit message for the merge commit
  options for 'split'
 annotate=     add a prefix to commit message of new commits
+unannotate=   remove a prefix from new commit messages (supports bash globbing)
 b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
@@ -43,6 +44,7 @@ onto=
 rejoin=
 ignore_joins=
 annotate=
+unannotate=
 squash=
 message=

@@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
 		-d) debug=1 ;;
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
+		--unannotate) unannotate="$1"; shift ;;
+		--no-unannotate) unannotate= ;;
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
@@ -310,8 +314,11 @@ copy_commit()
 			GIT_COMMITTER_NAME \
 			GIT_COMMITTER_EMAIL \
 			GIT_COMMITTER_DATE
-		(echo -n "$annotate"; cat ) |
-		git commit-tree "$2" $3  # reads the rest of stdin
+		(
+			read FIRST_LINE
+			echo "$annotate${FIRST_LINE#$unannotate}"
+			cat  # reads the rest of stdin
+		) | git commit-tree "$2" $3
 	) || die "Can't copy commit $1"
 }

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 0c44fda..ae420aa 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -198,6 +198,21 @@ OPTIONS FOR split
 	git subtree tries to make it work anyway, particularly
 	if you use --rejoin, but it may not always be effective.

+--unannotate=<annotation>::
+	This option is only valid for the split command.
+
+	When generating synthetic history, try to remove the prefix
+	<annotation> from each commit message (using bash's "strip
+	shortest match from beginning" command, which supports
+	globbing).  This makes sense if you format library commits
+	like "library: Change something or other" when you're working
+	in your project's repository, but you want to remove this
+	prefix when pushing back to the library's upstream repository.
+	(In this case --unannotate='*: ' would work well.)
+	
+	Like --annotate,  you need to use the same <annotation>
+	whenever you split, or you may run into problems.
+
 -b <branch>::
 --branch=<branch>::
 	This option is only valid for the split command.
-- 
1.7.11.3
James Nylen· Oct 16, 2012, 12:47 UTC · re: James Nylen · lore

Re: [PATCH] Add --unannotate option to git-subtree

On Tue, Oct 9, 2012 at 4:26 PM, James Nylen <jnylen@gmail.com> wrote:
Show 25 quoted lines
> This new option does the reverse of --annotate, which is more useful
> when contributing back to a library which is also included in the
> repository for a larger project, and perhaps in other situations as
> well.
>
> Rather than adding a marker to each commit when splitting out the
> commits back to the subproject, --unannotate removes the specified
> string (or bash glob pattern) from the beginning of the first line of
> the commit message.  This enables the following workflow:
>
>  - Commit to a library included in a large project, with message:
>      Library: Make some amazing change
>
>  - Use `git-subtree split` to send this change to the library maintainer
>
>  - Pass ` --unannotate='Library: ' ` or ` --unannotate='*: ' `
>
>  - This will turn the commit message for the library project into:
>      Make some amazing change
>
> This helps to keep the commit messages meaningful in both the large
> project and the library project.
>
> Signed-off-by: James Nylen <jnylen@gmail.com>
> ---
Has anybody looked at this?
It has been very useful for me.
Show 82 quoted lines
> Let me know if gmail has munged this patch.  You can also get at it
> like this:
>
> $ git remote add nylen git://github.com/nylen/git.git
> $ git fetch nylen
> $ git show nylen/subtree-unannotate
> ---
>  contrib/subtree/git-subtree.sh  | 11 +++++++++--
>  contrib/subtree/git-subtree.txt | 15 +++++++++++++++
>  2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 920c664..8d1ed05 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -21,6 +21,7 @@ P,prefix=     the name of the subdir to split out
>  m,message=    use the given message as the commit message for the merge commit
>   options for 'split'
>  annotate=     add a prefix to commit message of new commits
> +unannotate=   remove a prefix from new commit messages (supports bash globbing)
>  b,branch=     create a new branch from the split subtree
>  ignore-joins  ignore prior --rejoin commits
>  onto=         try connecting new tree to an existing one
> @@ -43,6 +44,7 @@ onto=
>  rejoin=
>  ignore_joins=
>  annotate=
> +unannotate=
>  squash=
>  message=
>
> @@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
>                 -d) debug=1 ;;
>                 --annotate) annotate="$1"; shift ;;
>                 --no-annotate) annotate= ;;
> +               --unannotate) unannotate="$1"; shift ;;
> +               --no-unannotate) unannotate= ;;
>                 -b) branch="$1"; shift ;;
>                 -P) prefix="$1"; shift ;;
>                 -m) message="$1"; shift ;;
> @@ -310,8 +314,11 @@ copy_commit()
>                         GIT_COMMITTER_NAME \
>                         GIT_COMMITTER_EMAIL \
>                         GIT_COMMITTER_DATE
> -               (echo -n "$annotate"; cat ) |
> -               git commit-tree "$2" $3  # reads the rest of stdin
> +               (
> +                       read FIRST_LINE
> +                       echo "$annotate${FIRST_LINE#$unannotate}"
> +                       cat  # reads the rest of stdin
> +               ) | git commit-tree "$2" $3
>         ) || die "Can't copy commit $1"
>  }
>
> diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
> index 0c44fda..ae420aa 100644
> --- a/contrib/subtree/git-subtree.txt
> +++ b/contrib/subtree/git-subtree.txt
> @@ -198,6 +198,21 @@ OPTIONS FOR split
>         git subtree tries to make it work anyway, particularly
>         if you use --rejoin, but it may not always be effective.
>
> +--unannotate=<annotation>::
> +       This option is only valid for the split command.
> +
> +       When generating synthetic history, try to remove the prefix
> +       <annotation> from each commit message (using bash's "strip
> +       shortest match from beginning" command, which supports
> +       globbing).  This makes sense if you format library commits
> +       like "library: Change something or other" when you're working
> +       in your project's repository, but you want to remove this
> +       prefix when pushing back to the library's upstream repository.
> +       (In this case --unannotate='*: ' would work well.)
> +
> +       Like --annotate,  you need to use the same <annotation>
> +       whenever you split, or you may run into problems.
> +
>  -b <branch>::
>  --branch=<branch>::
>         This option is only valid for the split command.
> --
> 1.7.11.3
Herman van Rink· Oct 20, 2012, 19:33 UTC · re: James Nylen · lore

Re: [PATCH] Add --unannotate option to git-subtree

On 10/16/2012 02:47 PM, James Nylen wrote:
Show 29 quoted lines
> On Tue, Oct 9, 2012 at 4:26 PM, James Nylen <jnylen@gmail.com> wrote:
>> This new option does the reverse of --annotate, which is more useful
>> when contributing back to a library which is also included in the
>> repository for a larger project, and perhaps in other situations as
>> well.
>>
>> Rather than adding a marker to each commit when splitting out the
>> commits back to the subproject, --unannotate removes the specified
>> string (or bash glob pattern) from the beginning of the first line of
>> the commit message.  This enables the following workflow:
>>
>>  - Commit to a library included in a large project, with message:
>>      Library: Make some amazing change
>>
>>  - Use `git-subtree split` to send this change to the library maintainer
>>
>>  - Pass ` --unannotate='Library: ' ` or ` --unannotate='*: ' `
>>
>>  - This will turn the commit message for the library project into:
>>      Make some amazing change
>>
>> This helps to keep the commit messages meaningful in both the large
>> project and the library project.
>>
>> Signed-off-by: James Nylen <jnylen@gmail.com>
>> ---
> Has anybody looked at this?
>
> It has been very useful for me.

The version of subtree in contrib is rather out-dated unfortunately. Your patch looks interesting though. I can see how this could be useful.

I've collected a bunch of patches in https://github.com/helmo/git/tree/subtree-updates

Apart from a line in git-subtree.txt ending in whitespace I think I can merge it in there.

Show 88 quoted lines
>
>> Let me know if gmail has munged this patch.  You can also get at it
>> like this:
>>
>> $ git remote add nylen git://github.com/nylen/git.git
>> $ git fetch nylen
>> $ git show nylen/subtree-unannotate
>> ---
>>  contrib/subtree/git-subtree.sh  | 11 +++++++++--
>>  contrib/subtree/git-subtree.txt | 15 +++++++++++++++
>>  2 files changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
>> index 920c664..8d1ed05 100755
>> --- a/contrib/subtree/git-subtree.sh
>> +++ b/contrib/subtree/git-subtree.sh
>> @@ -21,6 +21,7 @@ P,prefix=     the name of the subdir to split out
>>  m,message=    use the given message as the commit message for the merge commit
>>   options for 'split'
>>  annotate=     add a prefix to commit message of new commits
>> +unannotate=   remove a prefix from new commit messages (supports bash globbing)
>>  b,branch=     create a new branch from the split subtree
>>  ignore-joins  ignore prior --rejoin commits
>>  onto=         try connecting new tree to an existing one
>> @@ -43,6 +44,7 @@ onto=
>>  rejoin=
>>  ignore_joins=
>>  annotate=
>> +unannotate=
>>  squash=
>>  message=
>>
>> @@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
>>                 -d) debug=1 ;;
>>                 --annotate) annotate="$1"; shift ;;
>>                 --no-annotate) annotate= ;;
>> +               --unannotate) unannotate="$1"; shift ;;
>> +               --no-unannotate) unannotate= ;;
>>                 -b) branch="$1"; shift ;;
>>                 -P) prefix="$1"; shift ;;
>>                 -m) message="$1"; shift ;;
>> @@ -310,8 +314,11 @@ copy_commit()
>>                         GIT_COMMITTER_NAME \
>>                         GIT_COMMITTER_EMAIL \
>>                         GIT_COMMITTER_DATE
>> -               (echo -n "$annotate"; cat ) |
>> -               git commit-tree "$2" $3  # reads the rest of stdin
>> +               (
>> +                       read FIRST_LINE
>> +                       echo "$annotate${FIRST_LINE#$unannotate}"
>> +                       cat  # reads the rest of stdin
>> +               ) | git commit-tree "$2" $3
>>         ) || die "Can't copy commit $1"
>>  }
>>
>> diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
>> index 0c44fda..ae420aa 100644
>> --- a/contrib/subtree/git-subtree.txt
>> +++ b/contrib/subtree/git-subtree.txt
>> @@ -198,6 +198,21 @@ OPTIONS FOR split
>>         git subtree tries to make it work anyway, particularly
>>         if you use --rejoin, but it may not always be effective.
>>
>> +--unannotate=<annotation>::
>> +       This option is only valid for the split command.
>> +
>> +       When generating synthetic history, try to remove the prefix
>> +       <annotation> from each commit message (using bash's "strip
>> +       shortest match from beginning" command, which supports
>> +       globbing).  This makes sense if you format library commits
>> +       like "library: Change something or other" when you're working
>> +       in your project's repository, but you want to remove this
>> +       prefix when pushing back to the library's upstream repository.
>> +       (In this case --unannotate='*: ' would work well.)
>> +
>> +       Like --annotate,  you need to use the same <annotation>
>> +       whenever you split, or you may run into problems.
>> +
>>  -b <branch>::
>>  --branch=<branch>::
>>         This option is only valid for the split command.
>> --
>> 1.7.11.3
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Met vriendelijke groet / Regards,

Herman van Rink
Initfour websolutions
greened@obbligato.org· Dec 31, 2012, 23:19 UTC · re: Herman van Rink · lore

Re: [PATCH] Add --unannotate option to git-subtree

Herman van Rink <rink@initfour.nl> writes:
>> Has anybody looked at this?
>>
>> It has been very useful for me.
I am looking at it now.
> The version of subtree in contrib is rather out-dated unfortunately.

It is the official version. What's missing? You have a bunch of changes that need rework to include into "mainline" but other than that I am not aware of any major missing pieces. If there are such changes I would very much like to get them integrated

> Your patch looks interesting though. I can see how this could be useful.
> I've collected a bunch of patches in
> https://github.com/helmo/git/tree/subtree-updates

I hope you will submit your changes for inclusion. Again, I'm not a gatekeeper but I do want the patches to have proper testcases and integrate into contrib/subtree.

                         -David
greened@obbligato.org· Jan 1, 2013, 01:15 UTC · re: James Nylen · lore

Re: [PATCH] Add --unannotate option to git-subtree

James Nylen <jnylen@gmail.com> writes:
> Rather than adding a marker to each commit when splitting out the
> commits back to the subproject, --unannotate removes the specified
> string (or bash glob pattern) from the beginning of the first line of
> the commit message.  This enables the following workflow:

I applied the patch to my working copy but it doesn't seem to do what I'd expect. The test script does something like this:

- create project A
- add file to project A with message "subproj: add F1"
- add file to project A with message "subproj: add F2"
- add project A as a subtree of project B under directory subdir
- add a file to subdir with message "subproj: add F3"
- do a split --unannotate="subproj:"

I expected to see a log with no mention of "subproj" anywhere. Instead I get:

add F3 subproj: add F2 subproj: add F1

Is this as you intend? Is --unannotate only supposed to strip the string for commits added when A was a subtree of B?

I guess this behavior makes sense in that the user would want to see the same commits that existed before A became a subproject.

                   -David
James Nylen· Jan 17, 2013, 20:56 UTC · re: greened@obbligato.org · lore

Re: [PATCH] Add --unannotate option to git-subtree

On Mon, Dec 31, 2012 at 8:15 PM,  <greened@obbligato.org> wrote:
Show 31 quoted lines
> James Nylen <jnylen@gmail.com> writes:
>
>> Rather than adding a marker to each commit when splitting out the
>> commits back to the subproject, --unannotate removes the specified
>> string (or bash glob pattern) from the beginning of the first line of
>> the commit message.  This enables the following workflow:
>
> I applied the patch to my working copy but it doesn't seem to do
> what I'd expect.  The test script does something like this:
>
> - create project A
> - add file to project A with message "subproj: add F1"
> - add file to project A with message "subproj: add F2"
> - add project A as a subtree of project B under directory subdir
> - add a file to subdir with message "subproj: add F3"
> - do a split --unannotate="subproj:"
>
> I expected to see a log with no mention of "subproj" anywhere.  Instead
> I get:
>
> add F3
> subproj: add F2
> subproj: add F1
>
> Is this as you intend?  Is --unannotate only supposed to strip the
> string for commits added when A was a subtree of B?
>
> I guess this behavior makes sense in that the user would want to
> see the same commits that existed before A became a subproject.
>
>                    -David

Wow, I missed a bunch of emails on this. Thanks for applying and for writing tests!

This is as intended. You wouldn't want subtree to modify commits that occurred in the full repository for project A. Furthermore, you wouldn't have a "subproj:" commit in project A's standalone repo since it wasn't a subproject at that time.

The --annotate option confused me because it was the reverse of what I wanted. As in your example, a typical use would be 'add a file to subdir with message "subproj: add F3" ' to make it clear that you were committing to the "subproj" part of a larger repository. Then, when splitting back out to subproj's main repository, you'd want to remove the prefix.

greened@obbligato.org· Jan 22, 2013, 08:41 UTC · re: James Nylen · lore

Re: [PATCH] Add --unannotate option to git-subtree

James Nylen <jnylen@gmail.com> writes:
> Wow, I missed a bunch of emails on this.  Thanks for applying and for
> writing tests!
Sorry it took so long.
> This is as intended.  You wouldn't want subtree to modify commits that
> occurred in the full repository for project A.  Furthermore, you
> wouldn't have a "subproj:" commit in project A's standalone repo since
> it wasn't a subproject at that time.
Yes, that makes sense.
Show 6 quoted lines
> The --annotate option confused me because it was the reverse of what I
> wanted.  As in your example, a typical use would be 'add a file to
> subdir with message "subproj: add F3" ' to make it clear that you were
> committing to the "subproj" part of a larger repository.  Then, when
> splitting back out to subproj's main repository, you'd want to remove
> the prefix.
Ok.  I'll re-submit as part of the final sequence.
Thanks for the patch!
                            -David

← back to recent threads