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>
Junio C Hamano committed
Mar 2, 2008 at 00:57 UTC
c8c16f2865f7c9c0d59b31ce66d50a4ecae72fd0
1 file changed
+6
-7
diff-lib.c
+6
-7
@@ -472,22 +472,21 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
472
static void diff_index_show_file(struct rev_info *revs,
473
const char *prefix,
474
struct cache_entry *ce,
475
- unsigned char *sha1, unsigned int mode)
475
+ const unsigned char *sha1, unsigned int mode)
476
{
477
diff_addremove(&revs->diffopt, prefix[0], mode,
478
sha1, ce->name, NULL);
479
}
480
481
static int get_stat_data(struct cache_entry *ce,
482
- unsigned char **sha1p,
482
+ const unsigned char **sha1p,
483
unsigned int *modep,
484
int cached, int match_missing)
485
{
486
- unsigned char *sha1 = ce->sha1;
486
+ const unsigned char *sha1 = ce->sha1;
487
unsigned int mode = ce->ce_mode;
488
489
if (!cached) {
490
- static unsigned char no_sha1[20];
490
int changed;
491
struct stat st;
492
if (lstat(ce->name, &st) < 0) {
@@ -501,7 +500,7 @@ static int get_stat_data(struct cache_entry *ce,
500
changed = ce_match_stat(ce, &st, 0);
501
if (changed) {
502
mode = ce_mode_from_stat(ce, st.st_mode);
504
- sha1 = no_sha1;
503
+ sha1 = null_sha1;
504
}
505
}
506
@@ -514,7 +513,7 @@ static void show_new_file(struct rev_info *revs,
513
struct cache_entry *new,
514
int cached, int match_missing)
515
{
517
- unsigned char *sha1;
516
+ const unsigned char *sha1;
517
unsigned int mode;
518
519
/* New file in the index: it might actually be different in
@@ -533,7 +532,7 @@ static int show_modified(struct rev_info *revs,
532
int cached, int match_missing)
533
{
534
unsigned int mode, oldmode;
536
- unsigned char *sha1;
535
+ const unsigned char *sha1;
536
537
if (get_stat_data(new, &sha1, &mode, cached, match_missing) < 0) {
538
if (report_missing)