* [PATCH] unpack-trees: pass checkout state explicitly to check_updates()
@ 2016-09-13 17:37 René Scharfe
2016-09-13 23:25 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2016-09-13 17:37 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Add a parameter for the struct checkout variable to check_updates()
instead of using a static global variable. Passing it explicitly makes
object ownership and usage more easily apparent. And we get rid of a
static variable; those can be problematic in library-like code.
Signed-off-by: Rene Scharfe <l.s.r@web•de>
---
unpack-trees.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 11c37fb..74d6dd4 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -218,8 +218,8 @@ static void unlink_entry(const struct cache_entry *ce)
schedule_dir_for_removal(ce->name, ce_namelen(ce));
}
-static struct checkout state;
-static int check_updates(struct unpack_trees_options *o)
+static int check_updates(struct unpack_trees_options *o,
+ const struct checkout *state)
{
unsigned cnt = 0, total = 0;
struct progress *progress = NULL;
@@ -264,7 +264,7 @@ static int check_updates(struct unpack_trees_options *o)
display_progress(progress, ++cnt);
ce->ce_flags &= ~CE_UPDATE;
if (o->update && !o->dry_run) {
- errs |= checkout_entry(ce, &state, NULL);
+ errs |= checkout_entry(ce, state, NULL);
}
}
}
@@ -1094,6 +1094,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
int i, ret;
static struct cache_entry *dfc;
struct exclude_list el;
+ struct checkout state;
if (len > MAX_UNPACK_TREES)
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
@@ -1239,7 +1240,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
}
o->src_index = NULL;
- ret = check_updates(o) ? (-2) : 0;
+ ret = check_updates(o, &state) ? (-2) : 0;
if (o->dst_index) {
if (!ret) {
if (!o->result.cache_tree)
--
2.10.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] unpack-trees: pass checkout state explicitly to check_updates()
2016-09-13 17:37 [PATCH] unpack-trees: pass checkout state explicitly to check_updates() René Scharfe
@ 2016-09-13 23:25 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2016-09-13 23:25 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List
René Scharfe <l.s.r@web•de> writes:
> Add a parameter for the struct checkout variable to check_updates()
> instead of using a static global variable. Passing it explicitly makes
> object ownership and usage more easily apparent. And we get rid of a
> static variable; those can be problematic in library-like code.
> ...
> diff --git a/unpack-trees.c b/unpack-trees.c
> index 11c37fb..74d6dd4 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -218,8 +218,8 @@ static void unlink_entry(const struct cache_entry *ce)
> schedule_dir_for_removal(ce->name, ce_namelen(ce));
> }
>
> -static struct checkout state;
> ...
> @@ -1094,6 +1094,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
> int i, ret;
> static struct cache_entry *dfc;
> struct exclude_list el;
> + struct checkout state;
Does the distinction between this thing in BSS implicitly cleared
and the new one on stack that does not seem to have any
initialization matter?
... goes and looks ...
OK, after this hunk we clear and set up everything in state, so
there is no difference in behaviour. Just we got rid of an
unnecessary file-scope global.
Nice. Thanks.
> if (len > MAX_UNPACK_TREES)
> die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
> @@ -1239,7 +1240,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
> }
>
> o->src_index = NULL;
> - ret = check_updates(o) ? (-2) : 0;
> + ret = check_updates(o, &state) ? (-2) : 0;
> if (o->dst_index) {
> if (!ret) {
> if (!o->result.cache_tree)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-13 23:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-13 17:37 [PATCH] unpack-trees: pass checkout state explicitly to check_updates() René Scharfe
2016-09-13 23:25 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox