]> git.ipfire.org Git - thirdparty/git.git/commitdiff
update_refs(): fix constness
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 7 Apr 2014 13:47:57 +0000 (15:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2014 19:09:11 +0000 (12:09 -0700)
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>
builtin/update-ref.c
refs.c
refs.h

index f6345e5251c07ce085c2ec846e1023e7e5cf9510..a8a68e8a50a29370ede1023ef5d408074e180ad5 100644 (file)
@@ -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;
diff --git a/refs.c b/refs.c
index 196984e12ebb2ca92cd1c30da839a3d2bc342e65..1305eb1fcff6d9e6f9f9563fe691c8a0914ace24 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -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;
diff --git a/refs.h b/refs.h
index a713b34ad8a48c63a063732fcaf903f9fab1f17a..08e60ac07f261138c6bbcc38ebf761e7ace62cdc 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -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 *);