diff-lib.c: constness strengthening

The internal implementation of diff-index codepath used to use non const
pointer to pass sha1 around, but it did not have to.  With this, we can
also lose the private no_sha1[] array, as we can use the public null_sha1[]
array that exists exactly for the same purpose.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2008-03-02 00:57:26 -08:00
parent 2efb3b0617
commit c8c16f2865

View File

@ -472,22 +472,21 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
static void diff_index_show_file(struct rev_info *revs, static void diff_index_show_file(struct rev_info *revs,
const char *prefix, const char *prefix,
struct cache_entry *ce, struct cache_entry *ce,
unsigned char *sha1, unsigned int mode) const unsigned char *sha1, unsigned int mode)
{ {
diff_addremove(&revs->diffopt, prefix[0], mode, diff_addremove(&revs->diffopt, prefix[0], mode,
sha1, ce->name, NULL); sha1, ce->name, NULL);
} }
static int get_stat_data(struct cache_entry *ce, static int get_stat_data(struct cache_entry *ce,
unsigned char **sha1p, const unsigned char **sha1p,
unsigned int *modep, unsigned int *modep,
int cached, int match_missing) int cached, int match_missing)
{ {
unsigned char *sha1 = ce->sha1; const unsigned char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode; unsigned int mode = ce->ce_mode;
if (!cached) { if (!cached) {
static unsigned char no_sha1[20];
int changed; int changed;
struct stat st; struct stat st;
if (lstat(ce->name, &st) < 0) { if (lstat(ce->name, &st) < 0) {
@ -501,7 +500,7 @@ static int get_stat_data(struct cache_entry *ce,
changed = ce_match_stat(ce, &st, 0); changed = ce_match_stat(ce, &st, 0);
if (changed) { if (changed) {
mode = ce_mode_from_stat(ce, st.st_mode); mode = ce_mode_from_stat(ce, st.st_mode);
sha1 = no_sha1; sha1 = null_sha1;
} }
} }
@ -514,7 +513,7 @@ static void show_new_file(struct rev_info *revs,
struct cache_entry *new, struct cache_entry *new,
int cached, int match_missing) int cached, int match_missing)
{ {
unsigned char *sha1; const unsigned char *sha1;
unsigned int mode; unsigned int mode;
/* New file in the index: it might actually be different in /* New file in the index: it might actually be different in
@ -533,7 +532,7 @@ static int show_modified(struct rev_info *revs,
int cached, int match_missing) int cached, int match_missing)
{ {
unsigned int mode, oldmode; unsigned int mode, oldmode;
unsigned char *sha1; const unsigned char *sha1;
if (get_stat_data(new, &sha1, &mode, cached, match_missing) < 0) { if (get_stat_data(new, &sha1, &mode, cached, match_missing) < 0) {
if (report_missing) if (report_missing)