Skip to content

Commit aa035a2

Browse files
committed
hooks: simplify handle_hook_replacement()
Now that we don't skip the post-index-change hook, we don't need to pass the return value as an out-parameter in this method. Signed-off-by: Derrick Stolee <[email protected]>
1 parent e1cfb52 commit aa035a2

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

hook.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ static int post_index_change_sentinel_exists(struct repository *r)
236236
/**
237237
* See if we can replace the requested hook with an internal behavior.
238238
* Returns 0 if the real hook should run. Returns nonzero if we instead
239-
* executed custom internal behavior and the value to return is set to
240-
* 'result'.
239+
* executed custom internal behavior and the real hook should not run.
241240
*/
242241
static int handle_hook_replacement(struct repository *r,
243242
const char *hook_name,
244-
struct strvec *args,
245-
int *result)
243+
struct strvec *args)
246244
{
247245
const char *strval;
248246
if (repo_config_get_string_tmp(r, "postcommand.strategy", &strval) ||
@@ -252,17 +250,14 @@ static int handle_hook_replacement(struct repository *r,
252250
if (!strcmp(hook_name, "post-index-change")) {
253251
/* Create a sentinel file only if the worktree changed. */
254252
if (!strcmp(args->v[0], "1"))
255-
*result = write_post_index_change_sentinel(r);
256-
else
257-
*result = 0;
253+
write_post_index_change_sentinel(r);
258254

259255
/* We don't skip post-index-change hooks that exist. */
260256
return 0;
261257
}
262258
if (!strcmp(hook_name, "post-command") &&
263259
!post_index_change_sentinel_exists(r)) {
264260
/* We skip the post-command hook in this case. */
265-
*result = 0;
266261
return 1;
267262
}
268263

@@ -295,12 +290,9 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
295290
};
296291

297292
/* Interject hook behavior depending on strategy. */
298-
if (r && r->gitdir) {
299-
int result = 0;
300-
if (handle_hook_replacement(r, hook_name,
301-
&options->args, &result))
302-
return result;
303-
}
293+
if (r && r->gitdir &&
294+
handle_hook_replacement(r, hook_name, &options->args))
295+
return 0;
304296

305297
hook_path = find_hook(r, hook_name);
306298

0 commit comments

Comments
 (0)