summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-01-25 09:03:18 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-01-28 08:09:38 (GMT)
commit46a6c2620ba421397eec627b8eb18eb530e694fc (patch)
tree9222e809b0d77ad10e7304073d4c053c7edd9266
parent6b94f1e404afc552e5139c4357331843f5be61ad (diff)
downloadgit-46a6c2620ba421397eec627b8eb18eb530e694fc.zip
git-46a6c2620ba421397eec627b8eb18eb530e694fc.tar.gz
git-46a6c2620ba421397eec627b8eb18eb530e694fc.tar.bz2
abbrev cleanup: use symbolic constants
The minimum length of abbreviated object name was hardcoded in different places to be 4, risking inconsistencies in the future. Also there were three different "default abbreviation precision". Use two C preprocessor symbols to clean up this mess. Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--cache.h3
-rw-r--r--describe.c3
-rw-r--r--diff.c4
-rw-r--r--diff.h3
-rw-r--r--sha1_name.c2
5 files changed, 7 insertions, 8 deletions
diff --git a/cache.h b/cache.h
index 1e8e27f..bdbe2d6 100644
--- a/cache.h
+++ b/cache.h
@@ -221,6 +221,9 @@ extern int has_pack_file(const unsigned char *sha1);
extern int has_pack_index(const unsigned char *sha1);
/* Convert to/from hex/sha1 representation */
+#define MINIMUM_ABBREV 4
+#define DEFAULT_ABBREV 7
+
extern int get_sha1(const char *str, unsigned char *sha1);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
diff --git a/describe.c b/describe.c
index 4866510..ff65742 100644
--- a/describe.c
+++ b/describe.c
@@ -11,7 +11,6 @@ static const char describe_usage[] =
static int all = 0; /* Default to annotated tags only */
static int tags = 0; /* But allow any tags if --tags is specified */
-#define DEFAULT_ABBREV 8 /* maybe too many */
static int abbrev = DEFAULT_ABBREV;
static int names = 0, allocs = 0;
@@ -155,7 +154,7 @@ int main(int argc, char **argv)
tags = 1;
else if (!strncmp(arg, "--abbrev=", 9)) {
abbrev = strtoul(arg + 9, NULL, 10);
- if (abbrev < 4 || 40 <= abbrev)
+ if (abbrev < MINIMUM_ABBREV || 40 <= abbrev)
abbrev = DEFAULT_ABBREV;
}
else
diff --git a/diff.c b/diff.c
index 17d68fa..69767b9 100644
--- a/diff.c
+++ b/diff.c
@@ -723,7 +723,7 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
if (memcmp(one->sha1, two->sha1, 20)) {
char one_sha1[41];
- int abbrev = o->full_index ? 40 : DIFF_DEFAULT_INDEX_ABBREV;
+ int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
memcpy(one_sha1, sha1_to_hex(one->sha1), 41);
len += snprintf(msg + len, sizeof(msg) - len,
@@ -846,7 +846,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
else if (!strcmp(arg, "--find-copies-harder"))
options->find_copies_harder = 1;
else if (!strcmp(arg, "--abbrev"))
- options->abbrev = DIFF_DEFAULT_ABBREV;
+ options->abbrev = DEFAULT_ABBREV;
else if (!strncmp(arg, "--abbrev=", 9))
options->abbrev = strtoul(arg + 9, NULL, 10);
else
diff --git a/diff.h b/diff.h
index 5696f2a..122c814 100644
--- a/diff.h
+++ b/diff.h
@@ -88,9 +88,6 @@ extern int diff_setup_done(struct diff_options *);
#define DIFF_PICKAXE_ALL 1
-#define DIFF_DEFAULT_INDEX_ABBREV 7 /* hex digits */
-#define DIFF_DEFAULT_ABBREV 7 /* hex digits */
-
extern void diffcore_std(struct diff_options *);
extern void diffcore_std_no_resolve(struct diff_options *);
diff --git a/sha1_name.c b/sha1_name.c
index e18a96d..ba0747c 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -155,7 +155,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
char canonical[40];
unsigned char res[20];
- if (len < 4)
+ if (len < MINIMUM_ABBREV)
return -1;
memset(res, 0, 20);
memset(canonical, 'x', 40);