Skip to content

Commit

Permalink
update_refs(): fix constness
Browse files Browse the repository at this point in the history
The old signature of update_refs() required a
(const struct ref_update **) for its updates_orig argument.  The
"const" is presumably there to promise that the function will not
modify the contents of the structures.

But this declaration does not permit the function to be called with a
(struct ref_update **), which is perfectly legitimate.  C's type
system is not powerful enough to express what we'd like.  So remove
the first "const" from the declaration.

On the other hand, the function *can* promise not to modify the
pointers within the array that is passed to it without inconveniencing
its callers.  So add a "const" that has that effect, making the final
declaration
(struct ref_update * const *).

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Apr 7, 2014
1 parent f412411 commit 595deb8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion builtin/update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static const char * const git_update_ref_usage[] = {

static int updates_alloc;
static int updates_count;
static const struct ref_update **updates;
static struct ref_update **updates;

static char line_termination = '\n';
static int update_flags;
Expand Down
2 changes: 1 addition & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
return 0;
}

int update_refs(const char *action, const struct ref_update **updates_orig,
int update_refs(const char *action, struct ref_update * const *updates_orig,
int n, enum action_on_err onerr)
{
int ret = 0, delnum = 0, i;
Expand Down
2 changes: 1 addition & 1 deletion refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int update_ref(const char *action, const char *refname,
/**
* Lock all refs and then perform all modifications.
*/
int update_refs(const char *action, const struct ref_update **updates,
int update_refs(const char *action, struct ref_update * const *updates,
int n, enum action_on_err onerr);

extern int parse_hide_refs_config(const char *var, const char *value, const char *);
Expand Down

0 comments on commit 595deb8

Please sign in to comment.