Skip to contentSkip to conversation

doc: filter-branch does not require re-export of vars

PATCH In review Andreas Heiduk 4 participants 7 messages May 26, 2017 – May 29, 2017 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 doc: filter-branch does not require re-export of vars

The function set_ident in filter-branch exported the variables GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE) at least since 6f6826c52b in 2007. Therefore the filter scripts don't need to re-eport them again.

---
 Documentation/git-filter-branch.txt | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
Documentation/git-filter-branch.txt +1 -4
index 6e4bb0220..7b695dbb7 100644
@@ -86,8 +86,7 @@ OPTIONS
 	This filter may be used if you only need to modify the environment
 	in which the commit will be performed.  Specifically, you might
 	want to rewrite the author/committer name/email/time environment
-	variables (see linkgit:git-commit-tree[1] for details).  Do not forget
-	to re-export the variables.
+	variables (see linkgit:git-commit-tree[1] for details).
 
 --tree-filter <command>::
 	This is the filter for rewriting the tree and its contents.
@@ -340,12 +339,10 @@ git filter-branch --env-filter '
 	if test "$GIT_AUTHOR_EMAIL" = "root@localhost"
 	then
 		[email protected]
-		export GIT_AUTHOR_EMAIL
 	fi
 	if test "$GIT_COMMITTER_EMAIL" = "root@localhost"
 	then
 		[email protected]
-		export GIT_COMMITTER_EMAIL
 	fi
 ' -- --all
 --------------------------------------------------------
Signature · 1 line
2.13.0
#1 lore raw
Quoted 3 lines · Andreas Heiduk

The function set_ident in filter-branch exported the variables GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE) at least since 6f6826c52b in 2007. Therefore the filter scripts don't need to re-eport them again.

Some old shells keep separate values for the internal and exporter versions of variables. I.e., this:

foo=one
export foo
foo=two

would continue to export $foo as "one", even though it is "two" inside the script.

However, I think POSIX mandates the behavior you'd expect. And the only shell I know that misbehaves in this way is Solaris /bin/sh, which we have already declared too broken to support. According to

https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html#export

it sounds like there are some other antique shells which may do the same (it doesn't cover this case explicitly, but the "coexist" cases it mentions are likely to behave in this way).

At this point, I'd be inclined to remove the text as you suggest and either make a small note at the bottom of the page, or just omit it entirely and assume that anybody on an old non-POSIX shell can fend for themselves.

-Peff

#2 lore raw
Quoted 9 lines · Jeff King
Quoted 3 lines · Andreas Heiduk

The function set_ident in filter-branch exported the variables GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE) at least since 6f6826c52b in 2007. Therefore the filter scripts don't need to re-eport them again.

Some old shells keep separate values for the internal and exporter versions of variables. I.e., this:

Quoted 6 lines

foo=one
export foo
foo=two

would continue to export $foo as "one", even though it is "two" inside the script.

Yup, that sounds like a grandfather's war story at this point, though ;-)

Quoted 6 lines

However, I think POSIX mandates the behavior you'd expect. ...
...
At this point, I'd be inclined to remove the text as you suggest and either make a small note at the bottom of the page, or just omit it entirely and assume that anybody on an old non-POSIX shell can fend for themselves.

Sounds good to me. Thanks.

#3 lore raw
In reply to Jeff King
Quoted 14 lines · Jeff King
Quoted 3 lines · Andreas Heiduk

The function set_ident in filter-branch exported the variables GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE) at least since 6f6826c52b in 2007. Therefore the filter scripts don't need to re-eport them again.

Some old shells keep separate values for the internal and exporter versions of variables. I.e., this:

foo=one
export foo
foo=two

Quoted 6 lines

would continue to export $foo as "one", even though it is "two" inside the script.

However, I think POSIX mandates the behavior you'd expect. And the only shell I know that misbehaves in this way is Solaris /bin/sh, which we have already declared too broken to support.

Off-topic, but where is this explicitly documented?

Quoted 14 lines

According to

https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html#export

it sounds like there are some other antique shells which may do the same (it doesn't cover this case explicitly, but the "coexist" cases it mentions are likely to behave in this way).

At this point, I'd be inclined to remove the text as you suggest and either make a small note at the bottom of the page, or just omit it entirely and assume that anybody on an old non-POSIX shell can fend for themselves.

-Peff

#4 lore raw
Quoted 5 lines · Samuel Lijin
Quoted 3 lines

However, I think POSIX mandates the behavior you'd expect. And the only shell I know that misbehaves in this way is Solaris /bin/sh, which we have already declared too broken to support.

Off-topic, but where is this explicitly documented?

I couldn't find a place that mentioned it explicitly, but POSIX defines the concept as "the export attribute" of the variables. Which implies to me that the bit is tied to the variable itself, not its value.

It also says that the flag is cleared when a variable is unset, so:

foo=one
export foo
sh -c 'echo $foo should be one'
unset foo
foo=two
sh -c 'echo $foo is not exported'

That could potentially affect somebody writing a filter-branch snippet, but presumably if they are using "unset" they know what they're doing.

-Peff

#5 lore raw
In reply to Samuel Lijin
Quoted 5 lines · Samuel Lijin
Quoted 3 lines

However, I think POSIX mandates the behavior you'd expect. And the only shell I know that misbehaves in this way is Solaris /bin/sh, which we have already declared too broken to support.

Off-topic, but where is this explicitly documented?

One link I had readily available was

https://public-inbox.org/git/[email protected]/

but there may be older discussions that were the actual process of our officially having "written its /bin/sh off as broken and unusable" if you dig further in the list archive.

#6 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Samuel Lijin
Quoted 3 lines

However, I think POSIX mandates the behavior you'd expect. And the only shell I know that misbehaves in this way is Solaris /bin/sh, which we have already declared too broken to support.

Off-topic, but where is this explicitly documented?

Quoted 7 lines

One link I had readily available was

https://public-inbox.org/git/[email protected]/

but there may be older discussions that were the actual process of our officially having "written its /bin/sh off as broken and unusable" if you dig further in the list archive.

Ah, I had taken Samuel's question as "where is the POSIX behavior documented". :)

The link above is a good explanation of the $() problem on Solaris. It also doesn't do ${parameter#word}. I couldn't find a specific moment of outlawing that /bin/sh, but there are several mentions of problems with it going back to the beginning. Here's one from 2007:

http://public-inbox.org/git/[email protected]/

We had already given up on it by then.

I don't think there's anything in CodingGuidelines (though t/README does call it "broken"), though it explicitly endorses $(), which rules out Solaris /bin/sh.

I think we found in the last year or two that there are some old versions of ksh that don't like our scripts (definitely ksh88, and maybe ksh93?). Some light reading for the curious:

http://public-inbox.org/git/CALR6jEhviK9KZxR6R6xzkZ5EAO-RjWj3xYah_DOSDXhEjYsT-A@mail.gmail.com/

http://public-inbox.org/git/CALR6jEjWjJA0X2qXsxqObqc_yxrgX87LYf8cmJ0MmJFF6PkmTQ@mail.gmail.com/

http://public-inbox.org/git/[email protected]/

The problems are around backslash-escaping, signal exit codes, and doubled parentheses. There are some patches, but I think we decided not to pursue it (I couldn't find that exact decision, but it's referenced later on).

-Peff