git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
@ 2007-07-18 15:54 Johannes Schindelin
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Schindelin @ 2007-07-18 15:54 UTC (permalink / raw)
  To: git, gitster


With this function, a commit filter can leave out unwanted commits
(such as temporary commits).  It does _not_ undo the changeset
corresponding to that commit, but it _skips_ the revision.  IOW
its childrens' tree objects remain the same.

If you like to commit early and often, but want to filter out all
intermediate commits, marked by "@@@" in the commit message, you can
now do this with

	git filter-branch --commit-filter '
		if git cat-file commit $GIT_COMMIT | grep '@@@' > /dev/null;
		then
			skip_commit "$@";
		else
			git commit-tree "$@";
		fi' newbranch

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Documentation/git-filter-branch.txt |   39 ++++++++++++++++++++++++----------
 git-filter-branch.sh                |   14 ++++++++++++
 t/t7003-filter-branch.sh            |    8 +------
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index eaea82d..9dade65 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -111,6 +111,11 @@ OPTIONS
 As a special extension, the commit filter may emit multiple
 commit ids; in that case, ancestors of the original commit will
 have all of them as parents.
++
+You can use the 'map' convenience function in this filter, and other
+convenience functions, too.  For example, calling 'skip_commit "$@"'
+will leave out the current commit (but not its changes! If you want
+that, use gitlink:git-rebase[1] instead).
 
 --tag-name-filter <command>::
 	This is the filter for rewriting tag names. When passed,
@@ -199,34 +204,44 @@ To remove commits authored by "Darl McBribe" from the history:
 git filter-branch --commit-filter '
 	if [ "$GIT_AUTHOR_NAME" = "Darl McBribe" ];
 	then
-		shift;
-		while [ -n "$1" ];
-		do
-			shift;
-			echo "$1";
-			shift;
-		done;
+		skip_commit "$@";
 	else
 		git commit-tree "$@";
 	fi' newbranch
 ------------------------------------------------------------------------------
 
+Note that the changes introduced by the commits, and not reverted by
+subsequent commits, will still be in the rewritten branch. If you want
+to throw out _changes_ together with the commits, you should use the
+interactive mode of gitlink:git-rebase[1].
+
+The function 'skip_commits' is defined as follows:
+
+--------------------------
+skip_commit()
+{
+	shift;
+	while [ -n "$1" ];
+	do
+		shift;
+		map "$1";
+		shift;
+	done;
+}
+--------------------------
+
 The shift magic first throws away the tree id and then the -p
 parameters.  Note that this handles merges properly! In case Darl
 committed a merge between P1 and P2, it will be propagated properly
 and all children of the merge will become merge commits with P1,P2
 as their parents instead of the merge commit.
 
+
 To restrict rewriting to only part of the history, specify a revision
 range in addition to the new branch name.  The new branch name will
 point to the top-most revision that a 'git rev-list' of this range
 will print.
 
-Note that the changes introduced by the commits, and not reverted by
-subsequent commits, will still be in the rewritten branch. If you want
-to throw out _changes_ together with the commits, you should use the
-interactive mode of gitlink:git-rebase[1].
-
 Consider this history:
 
 ------------------
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index b574612..91f3677 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -23,6 +23,20 @@ map()
 	fi
 }
 
+# if you run 'skip_commit "$@"' in a commit filter, it will print
+# the (mapped) parents, effectively skipping the commit.
+
+skip_commit()
+{
+	shift;
+	while [ -n "$1" ];
+	do
+		shift;
+		map "$1";
+		shift;
+	done;
+}
+
 # override die(): this version puts in an extra line break, so that
 # the progress is still visible
 
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 4ddd656..22bb14a 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -132,13 +132,7 @@ test_expect_success "remove a certain author's commits" '
 	git-filter-branch --commit-filter "\
 		if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
 		then\
-			shift;\
-			while [ -n \"\$1\" ];\
-			do\
-				shift;\
-				echo \"\$1\";\
-				shift;\
-			done;\
+			skip_commit \"\$@\";
 		else\
 			git commit-tree \"\$@\";\
 		fi" removed-author &&
-- 
1.5.3.rc1.16.g9d6f-dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
@ 2007-08-31 19:06 Johannes Schindelin
  2007-08-31 19:19 ` Karl Hasselström
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2007-08-31 19:06 UTC (permalink / raw)
  To: git, gitster


With this function, a commit filter can leave out unwanted commits
(such as temporary commits).  It does _not_ undo the changeset
corresponding to that commit, but it _skips_ the revision.  IOW
its ancestors' tree objects remain the same.

If you like to commit early and often, but want to filter out all
intermediate commits, marked by "@@@" in the commit message, you can
now do this with

	git filter-branch --commit-filter '
		if git cat-file commit $GIT_COMMIT | grep '@@@' > /dev/null;
		then
			skip_commit "$@";
		else
			git commit-tree "$@";
		fi' newbranch

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	Same comment as for 1/2 applies here, too...

 Documentation/git-filter-branch.txt |   34 +++++++++++++++++++++++++++-------
 git-filter-branch.sh                |   14 ++++++++++++++
 t/t7003-filter-branch.sh            |    8 +-------
 3 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 456d52b..29bb8ce 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -112,6 +112,11 @@ OPTIONS
 As a special extension, the commit filter may emit multiple
 commit ids; in that case, ancestors of the original commit will
 have all of them as parents.
++
+You can use the 'map' convenience function in this filter, and other
+convenience functions, too.  For example, calling 'skip_commit "$@"'
+will leave out the current commit (but not its changes! If you want
+that, use gitlink:git-rebase[1] instead).
 
 --tag-name-filter <command>::
 	This is the filter for rewriting tag names. When passed,
@@ -209,24 +214,39 @@ To remove commits authored by "Darl McBribe" from the history:
 git filter-branch --commit-filter '
 	if [ "$GIT_AUTHOR_NAME" = "Darl McBribe" ];
 	then
-		shift;
-		while [ -n "$1" ];
-		do
-			shift;
-			echo "$1";
-			shift;
-		done;
+		skip_commit "$@";
 	else
 		git commit-tree "$@";
 	fi' HEAD
 ------------------------------------------------------------------------------
 
+Note that the changes introduced by the commits, and not reverted by
+subsequent commits, will still be in the rewritten branch. If you want
+to throw out _changes_ together with the commits, you should use the
+interactive mode of gitlink:git-rebase[1].
+
+The function 'skip_commits' is defined as follows:
+
+--------------------------
+skip_commit()
+{
+	shift;
+	while [ -n "$1" ];
+	do
+		shift;
+		map "$1";
+		shift;
+	done;
+}
+--------------------------
+
 The shift magic first throws away the tree id and then the -p
 parameters.  Note that this handles merges properly! In case Darl
 committed a merge between P1 and P2, it will be propagated properly
 and all children of the merge will become merge commits with P1,P2
 as their parents instead of the merge commit.
 
+
 To restrict rewriting to only part of the history, specify a revision
 range in addition to the new branch name.  The new branch name will
 point to the top-most revision that a 'git rev-list' of this range
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 3b041d8..a4b6577 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -23,6 +23,20 @@ map()
 	fi
 }
 
+# if you run 'skip_commit "$@"' in a commit filter, it will print
+# the (mapped) parents, effectively skipping the commit.
+
+skip_commit()
+{
+	shift;
+	while [ -n "$1" ];
+	do
+		shift;
+		map "$1";
+		shift;
+	done;
+}
+
 # override die(): this version puts in an extra line break, so that
 # the progress is still visible
 
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index c79853d..e935b20 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -138,13 +138,7 @@ test_expect_success "remove a certain author's commits" '
 	git-filter-branch -f --commit-filter "\
 		if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
 		then\
-			shift;\
-			while [ -n \"\$1\" ];\
-			do\
-				shift;\
-				echo \"\$1\";\
-				shift;\
-			done;\
+			skip_commit \"\$@\";
 		else\
 			git commit-tree \"\$@\";\
 		fi" removed-author &&
-- 
1.5.3.rc7.18.gc9b59

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
  2007-08-31 19:06 Johannes Schindelin
@ 2007-08-31 19:19 ` Karl Hasselström
  2007-08-31 21:05   ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Karl Hasselström @ 2007-08-31 19:19 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, gitster

On 2007-08-31 20:06:27 +0100, Johannes Schindelin wrote:

> It does _not_ undo the changeset corresponding to that commit, but
> it _skips_ the revision. IOW its ancestors' tree objects remain the
> same.

While this is true too, I'm guessing you intended to say that its
_descendants'_ tree objects remain the same. Right?

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
  2007-08-31 19:19 ` Karl Hasselström
@ 2007-08-31 21:05   ` Johannes Schindelin
  2007-08-31 21:32     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2007-08-31 21:05 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: git, gitster

Hi,

On Fri, 31 Aug 2007, Karl Hasselstr?m wrote:

> On 2007-08-31 20:06:27 +0100, Johannes Schindelin wrote:
> 
> > It does _not_ undo the changeset corresponding to that commit, but
> > it _skips_ the revision. IOW its ancestors' tree objects remain the
> > same.
> 
> While this is true too, I'm guessing you intended to say that its
> _descendants'_ tree objects remain the same. Right?

Right.  So how about:

IOW no tree objects are changed by this.

Hmm?

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
  2007-08-31 21:05   ` Johannes Schindelin
@ 2007-08-31 21:32     ` Junio C Hamano
  2007-08-31 21:39       ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-08-31 21:32 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Karl Hasselström, git, gitster

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi,
>
> On Fri, 31 Aug 2007, Karl Hasselstr?m wrote:
>
>> On 2007-08-31 20:06:27 +0100, Johannes Schindelin wrote:
>> 
>> > It does _not_ undo the changeset corresponding to that commit, but
>> > it _skips_ the revision. IOW its ancestors' tree objects remain the
>> > same.
>> 
>> While this is true too, I'm guessing you intended to say that its
>> _descendants'_ tree objects remain the same. Right?
>
> Right.  So how about:
>
> IOW no tree objects are changed by this.

Ok, will amend.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] filter-branch: introduce convenience function "skip_commit"
  2007-08-31 21:32     ` Junio C Hamano
@ 2007-08-31 21:39       ` Johannes Schindelin
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Schindelin @ 2007-08-31 21:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Karl Hasselström, git

Hi,

On Fri, 31 Aug 2007, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On Fri, 31 Aug 2007, Karl Hasselstr?m wrote:
> >
> >> On 2007-08-31 20:06:27 +0100, Johannes Schindelin wrote:
> >> 
> >> > It does _not_ undo the changeset corresponding to that commit, but
> >> > it _skips_ the revision. IOW its ancestors' tree objects remain the
> >> > same.
> >> 
> >> While this is true too, I'm guessing you intended to say that its
> >> _descendants'_ tree objects remain the same. Right?
> >
> > Right.  So how about:
> >
> > IOW no tree objects are changed by this.
> 
> Ok, will amend.

Thanks; this was the next mail I wanted to send ;-)

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-31 21:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18 15:54 [PATCH 2/2] filter-branch: introduce convenience function "skip_commit" Johannes Schindelin
  -- strict thread matches above, loose matches on Subject: below --
2007-08-31 19:06 Johannes Schindelin
2007-08-31 19:19 ` Karl Hasselström
2007-08-31 21:05   ` Johannes Schindelin
2007-08-31 21:32     ` Junio C Hamano
2007-08-31 21:39       ` Johannes Schindelin

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