threads / patch / 44075

patchcheckout: constify parameters of checkout_stage() and checkout_merged()

Subject: [PATCH] checkout: constify parameters of checkout_stage() and checkout_merged()

## tl;dr

2 messages between Sep 13, 2016 and Sep 13, 2016. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Sep 13, 2016, 17:11 UTC · lore

Document the fact that checkout_stage() and checkout_merged() don't change the objects passed to them by adding the modifier const.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/checkout.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to builtin/checkout.c +3 −3
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 8672d07..afbff3e 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -154,8 +154,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
 	return 0;
 }
 
-static int checkout_stage(int stage, struct cache_entry *ce, int pos,
-			  struct checkout *state)
+static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
+			  const struct checkout *state)
 {
 	while (pos < active_nr &&
 	       !strcmp(active_cache[pos]->name, ce->name)) {
@@ -169,7 +169,7 @@ static int checkout_stage(int stage, struct cache_entry *ce, int pos,
 		return error(_("path '%s' does not have their version"), ce->name);
 }
 
-static int checkout_merged(int pos, struct checkout *state)
+static int checkout_merged(int pos, const struct checkout *state)
 {
 	struct cache_entry *ce = active_cache[pos];
 	const char *path = ce->name;
-- 
2.10.0
Jeff King· Sep 13, 2016, 18:18 UTC · re: René Scharfe · lore

Re: [PATCH] checkout: constify parameters of checkout_stage() and checkout_merged()

On Tue, Sep 13, 2016 at 07:11:52PM +0200, René Scharfe wrote:
> Document the fact that checkout_stage() and checkout_merged() don't
> change the objects passed to them by adding the modifier const.

Hmm. Sometimes these big "context" objects are hard to make const, because we end up using them to hold or pass state between functions (e.g., see diff_options). So I'd worry slightly that we'll end up un-consting this in the long run.

That being said, it is easy to revert, and it provides some small benefit, so I don't mind it in the meantime.

-Peff

← back to recent threads