From: Pang Yan Han <hidden> Date: 2016-06-15 22:52:06
Hi list,
Currently, receive-pack runs the pre-receive, update, post-receive and
post-update hooks during a push to delete corrupt or non-existent refs, eg:
git push origin :refs/heads/foo
where refs/heads/foo is missing from the remote origin.
The issue is reported here [1]
This is a patch series which teaches receive-pack not to run update hook for
corrupt or non existent refs during a push.
Patch 1/2 isn't really relevant to the topic. It's just something I stumbled
across while reading the code. It removes a redundant assignment in the is_url
function.
Patch 2/2 teaches receive-pack not to run update hook for corrupt or non
existent refs. In summary, I reordered the statements in the update function
so that the update hook is not run for corrupt / non existent refs.
Perhaps this isn't a good enough solution since the pre-receive, post-receive
and post-update hooks are still run. Also the tests aren't exactly good looking.
Any advice is highly appreciated. Thanks!
[1] http://thread.gmane.org/gmane.comp.version-control.git/181942
Pang Yan Han (2):
is_url: Remove redundant assignment
receive-pack: Don't run update hook for corrupt or nonexistent ref
builtin/receive-pack.c | 50 +++++++++++++++++++++++++++--------------------
t/t5516-fetch-push.sh | 33 +++++++++++++++++++++++++++++++
url.c | 1 -
3 files changed, 62 insertions(+), 22 deletions(-)
--
1.7.7.rc3.2.g29f2e6
@@ -22,7 +22,6 @@ int is_url(const char *url)if(!url)return0;-url2=url;first_slash=strchr(url,'/');/* Input with no slash at all or slash first can't be URL. */
From: Pang Yan Han <hidden> Date: 2016-06-15 22:52:06
Teach receive-pack not to run update hook for a corrupt or nonexistent ref.
In addition, update the warning message for deleting a corrupt or nonexistent
ref from:
"Allowing deletion of corrupt ref"
to:
"Allowing deletion of corrupt/nonexistent ref"
Noticed-by: Sitaram Chamarty [off-list ref]
Signed-off-by: Pang Yan Han <redacted>
---
builtin/receive-pack.c | 50 +++++++++++++++++++++++++++--------------------
t/t5516-fetch-push.sh | 33 +++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 21 deletions(-)
@@ -346,6 +346,17 @@ static void refuse_unconfigured_deny_delete_current(void)rp_error("%s",refuse_unconfigured_deny_delete_current_msg[i]);}+staticconstchar*delete_null_sha1_ref(constchar*namespaced_name,+constchar*name,+unsignedchar*old_sha1)+{+if(delete_ref(namespaced_name,old_sha1,0)){+rp_error("failed to delete %s",name);+return"failed to delete";+}+returnNULL;/* good */+}+staticconstchar*update(structcommand*cmd){constchar*name=cmd->ref_name;
@@ -438,33 +449,30 @@ static const char *update(struct command *cmd)return"non-fast-forward";}}++/* Don't run update hook for corrupt/nonexistent ref */+if(is_null_sha1(new_sha1)&&!parse_object(old_sha1)){+rp_warning("Allowing deletion of corrupt/nonexistent ref.");+old_sha1=NULL;+returndelete_null_sha1_ref(namespaced_name,name,old_sha1);+}+if(run_update_hook(cmd)){rp_error("hook declined to update %s",name);return"hook declined";}-if(is_null_sha1(new_sha1)){-if(!parse_object(old_sha1)){-rp_warning("Allowing deletion of corrupt ref.");-old_sha1=NULL;-}-if(delete_ref(namespaced_name,old_sha1,0)){-rp_error("failed to delete %s",name);-return"failed to delete";-}-returnNULL;/* good */-}-else{-lock=lock_any_ref_for_update(namespaced_name,old_sha1,0);-if(!lock){-rp_error("failed to lock %s",name);-return"failed to lock";-}-if(write_ref_sha1(lock,new_sha1,"push")){-return"failed to write";/* error() already called */-}-returnNULL;/* good */+if(is_null_sha1(new_sha1))+returndelete_null_sha1_ref(namespaced_name,name,old_sha1);++lock=lock_any_ref_for_update(namespaced_name,old_sha1,0);+if(!lock){+rp_error("failed to lock %s",name);+return"failed to lock";}+if(write_ref_sha1(lock,new_sha1,"push"))+return"failed to write";/* error() already called */+returnNULL;/* good */}staticcharupdate_post_hook[]="hooks/post-update";
On Sun, Sep 25, 2011 at 10:36 AM, Pang Yan Han [off-list ref] wrote:
Hi list,
Currently, receive-pack runs the pre-receive, update, post-receive and
post-update hooks during a push to delete corrupt or non-existent refs, eg:
git push origin :refs/heads/foo
where refs/heads/foo is missing from the remote origin.
The issue is reported here [1]
I did not report an issue. I asked if this was expected and could be
relied upon. I'm actually happy with the current behaviour because it
solves a problem very neatly for me, but before documenting it I
wanted to make sure it would not one day disappear.
This is a patch series which teaches receive-pack not to run update hook for
corrupt or non existent refs during a push.
Patch 1/2 isn't really relevant to the topic. It's just something I stumbled
across while reading the code. It removes a redundant assignment in the is_url
function.
Patch 2/2 teaches receive-pack not to run update hook for corrupt or non
existent refs. In summary, I reordered the statements in the update function
so that the update hook is not run for corrupt / non existent refs.
Perhaps this isn't a good enough solution since the pre-receive, post-receive
and post-update hooks are still run. Also the tests aren't exactly good looking.
It doesn't make sense to disable only the update hook. And although I
did not come right out and say it, it is the post-update that I care
about. If that still runs, my "issue" still exists.
Any advice is highly appreciated. Thanks!
[1] http://thread.gmane.org/gmane.comp.version-control.git/181942
Pang Yan Han (2):
is_url: Remove redundant assignment
receive-pack: Don't run update hook for corrupt or nonexistent ref
builtin/receive-pack.c | 50 +++++++++++++++++++++++++++--------------------
t/t5516-fetch-push.sh | 33 +++++++++++++++++++++++++++++++
url.c | 1 -
3 files changed, 62 insertions(+), 22 deletions(-)
--
1.7.7.rc3.2.g29f2e6
if (!url)
return 0;
- url2 = url;
first_slash = strchr(url, '/');
/* Input with no slash at all or slash first can't be URL. */
Looks correct. Perhaps you could mention in the patch message that
There are no operations on url2 until another assignment to it later
at line 41.
--
Cheers,
Ray Chuan
From: Pang Yan Han <hidden> Date: 2016-06-15 22:52:06
On Sun, Sep 25, 2011 at 01:28:31PM +0530, Sitaram Chamarty wrote:
On Sun, Sep 25, 2011 at 10:36 AM, Pang Yan Han [off-list ref] wrote:
quoted
Hi list,
Currently, receive-pack runs the pre-receive, update, post-receive and
post-update hooks during a push to delete corrupt or non-existent refs, eg:
git push origin :refs/heads/foo
where refs/heads/foo is missing from the remote origin.
The issue is reported here [1]
I did not report an issue. I asked if this was expected and could be
relied upon. I'm actually happy with the current behaviour because it
solves a problem very neatly for me, but before documenting it I
wanted to make sure it would not one day disappear.
quoted
This is a patch series which teaches receive-pack not to run update hook for
corrupt or non existent refs during a push.
Patch 1/2 isn't really relevant to the topic. It's just something I stumbled
across while reading the code. It removes a redundant assignment in the is_url
function.
Patch 2/2 teaches receive-pack not to run update hook for corrupt or non
existent refs. In summary, I reordered the statements in the update function
so that the update hook is not run for corrupt / non existent refs.
Perhaps this isn't a good enough solution since the pre-receive, post-receive
and post-update hooks are still run. Also the tests aren't exactly good looking.
It doesn't make sense to disable only the update hook. And although I
did not come right out and say it, it is the post-update that I care
about. If that still runs, my "issue" still exists.
Um I'm rather new to Git and the reason why I didn't reply this initially was
because I didn't know what to reply. Sorry but you sound rather aggressive and
I was really taken aback by this.
I've taken a look at the code again and here's another approach which will
result in heavier changes to builtin/receive-pack and may possibly work:
Check through the list of refs to be updated before even executing the
pre receive hook. Ensure that there is at least one "valid" ref update.
Essentially this is kind of like "dry running" the update function.
One way to do it is to shift the bulk of work determining valid and invalid
ref updates from the update function to a separate function.
We maintain 2 lists, one to store valid refs to be updated and another to
store non-existent/corrupt refs which will be deleted. Specifically, we will
be storing 'struct command'.
The update function can be cut down to these parts:
- determining namespaced_name
- lock_any_ref_for_update
- write_ref_sha1
The pre receive hook will only be executed if the list containing valid ref
pushes is non-empty. Same goes for the post receive and post update hooks.
What do you think of this approach (if it's even correct)?
quoted
Any advice is highly appreciated. Thanks!
[1] http://thread.gmane.org/gmane.comp.version-control.git/181942
Pang Yan Han (2):
is_url: Remove redundant assignment
receive-pack: Don't run update hook for corrupt or nonexistent ref
builtin/receive-pack.c | 50 +++++++++++++++++++++++++++--------------------
t/t5516-fetch-push.sh | 33 +++++++++++++++++++++++++++++++
url.c | 1 -
3 files changed, 62 insertions(+), 22 deletions(-)
--
1.7.7.rc3.2.g29f2e6
On Sun, Sep 25, 2011 at 3:18 PM, Pang Yan Han [off-list ref] wrote:
On Sun, Sep 25, 2011 at 01:28:31PM +0530, Sitaram Chamarty wrote:
[snip]
quoted
It doesn't make sense to disable only the update hook. And although I
did not come right out and say it, it is the post-update that I care
about. If that still runs, my "issue" still exists.
Um I'm rather new to Git and the reason why I didn't reply this initially was
because I didn't know what to reply. Sorry but you sound rather aggressive and
I was really taken aback by this.
Sorry if I sounded aggressive; I was going to brevity, and levity suffered :-)
[snip lots of stuff about new approach]
What do you think of this approach (if it's even correct)?
I'm sorry again but it's been almost 2 decades since I did any serious
C and I've never dug into git internals, so I can't tell you if you're
even on the right track. You should wait for one of the other folks
you cc-d to weigh in with their opinions.
Personally, anytime someone says "disable the update hook" I get very
worried -- I've got a heck of a lot invested in update hooks ;-)
I wasn't even *asking* about disabling that; I was asking about
*post*-update, which you didn't even address in your code.
From a philosophical point of view, update and pre-receive *check*
things to make sure everything is OK. IMO they should be allowed to
run even if the ref being deleted doesn't exist -- that could well be
an error condition that the guy who owns the repo wants to trap and
alert himself to in some special way. I would *not* like them
disabled.
Post-{update,receive} are for *after* a successful push. My
suggestion would be to make sure the inputs supplied to those hooks
(via STDIN for post-receive, and as arguments in case of post-update)
reflect this -- only successfully updated refs are sent in as args.
This might mean that in the case of 'git push origin
:refs/heads/non-existent-ref' the post-receive hook would run but
STDIN would be empty, and post-update would run but have no arguments.
That is, IMO, the correct way to deal with this.
From: Pang Yan Han <hidden> Date: 2016-06-15 22:52:06
The post-receive and post-update hooks are triggered with invalid input on
stdin and invalid args respectively during the deletion of corrupt or
non-existent refs during a push.
Teach receive-pack to run post-receive hook with empty stdin and post-update
hook with empty args in the event of an invalid ref deletion.
Signed-off-by: Pang Yan Han <redacted>
---
This has been updated with the suggestions from Sitaram Chamarty, as stated in
http://thread.gmane.org/gmane.comp.version-control.git/182056/focus=182065
builtin/receive-pack.c | 35 +++++++++++++-
t/t5516-fetch-push.sh | 118 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 150 insertions(+), 3 deletions(-)