From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/3] diff-lib.c: constness strengthening
Date: Sun, 2 Mar 2008 01:43:30 -0800 [thread overview]
Message-ID: <1204451012-17487-2-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1204451012-17487-1-git-send-email-gitster@pobox.com>
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>
---
diff-lib.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 94b150e..4581b59 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -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,
const char *prefix,
struct cache_entry *ce,
- unsigned char *sha1, unsigned int mode)
+ const unsigned char *sha1, unsigned int mode)
{
diff_addremove(&revs->diffopt, prefix[0], mode,
sha1, ce->name, NULL);
}
static int get_stat_data(struct cache_entry *ce,
- unsigned char **sha1p,
+ const unsigned char **sha1p,
unsigned int *modep,
int cached, int match_missing)
{
- unsigned char *sha1 = ce->sha1;
+ const unsigned char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode;
if (!cached) {
- static unsigned char no_sha1[20];
int changed;
struct stat st;
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);
if (changed) {
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,
int cached, int match_missing)
{
- unsigned char *sha1;
+ const unsigned char *sha1;
unsigned int mode;
/* 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)
{
unsigned int mode, oldmode;
- unsigned char *sha1;
+ const unsigned char *sha1;
if (get_stat_data(new, &sha1, &mode, cached, match_missing) < 0) {
if (report_missing)
--
1.5.4.3.468.g36990
next prev parent reply other threads:[~2008-03-02 9:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-02 9:43 [PATCH 0/3] fix "diff --raw" on the work tree side Junio C Hamano
2008-03-02 9:43 ` Junio C Hamano [this message]
2008-03-02 9:43 ` [PATCH 2/3] diff: make sure work tree side is shown as 0{40} when different Junio C Hamano
2008-03-02 9:43 ` [PATCH 3/3] diff: show submodule object name when available even on the work tree side Junio C Hamano
2008-03-02 10:41 ` [PATCH 0/3] fix "diff --raw" " Ping Yin
2008-03-02 17:11 ` Junio C Hamano
2008-03-02 17:15 ` Ping Yin
2008-03-02 17:48 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1204451012-17487-2-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).