@matheusbsbs / matheus-bagliano / commits / 46a6c2620b
Fork 0

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>

Junio C Hamano committed Jan 25, 2006 at 01:03 UTC 46a6c2620ba421397eec627b8eb18eb530e694fc
5 files changed +7 -8
cache.h
+3
@@ -221,6 +221,9 @@ extern int has_pack_file(const unsigned char *sha1);
221 extern int has_pack_index(const unsigned char *sha1);
222
223 /* Convert to/from hex/sha1 representation */
224 +#define MINIMUM_ABBREV 4
225 +#define DEFAULT_ABBREV 7
226 +
227 extern int get_sha1(const char *str, unsigned char *sha1);
228 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
229 extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
describe.c
+1 -2
@@ -11,7 +11,6 @@ static const char describe_usage[] =
11 static int all = 0; /* Default to annotated tags only */
12 static int tags = 0; /* But allow any tags if --tags is specified */
13
14 -#define DEFAULT_ABBREV 8 /* maybe too many */
14 static int abbrev = DEFAULT_ABBREV;
15
16 static int names = 0, allocs = 0;
@@ -155,7 +154,7 @@ int main(int argc, char **argv)
154 tags = 1;
155 else if (!strncmp(arg, "--abbrev=", 9)) {
156 abbrev = strtoul(arg + 9, NULL, 10);
158 - if (abbrev < 4 || 40 <= abbrev)
157 + if (abbrev < MINIMUM_ABBREV || 40 <= abbrev)
158 abbrev = DEFAULT_ABBREV;
159 }
160 else
diff.c
+2 -2
@@ -723,7 +723,7 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
723
724 if (memcmp(one->sha1, two->sha1, 20)) {
725 char one_sha1[41];
726 - int abbrev = o->full_index ? 40 : DIFF_DEFAULT_INDEX_ABBREV;
726 + int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
727 memcpy(one_sha1, sha1_to_hex(one->sha1), 41);
728
729 len += snprintf(msg + len, sizeof(msg) - len,
@@ -846,7 +846,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
846 else if (!strcmp(arg, "--find-copies-harder"))
847 options->find_copies_harder = 1;
848 else if (!strcmp(arg, "--abbrev"))
849 - options->abbrev = DIFF_DEFAULT_ABBREV;
849 + options->abbrev = DEFAULT_ABBREV;
850 else if (!strncmp(arg, "--abbrev=", 9))
851 options->abbrev = strtoul(arg + 9, NULL, 10);
852 else
diff.h
-3
@@ -88,9 +88,6 @@ extern int diff_setup_done(struct diff_options *);
88
89 #define DIFF_PICKAXE_ALL 1
90
91 -#define DIFF_DEFAULT_INDEX_ABBREV 7 /* hex digits */
92 -#define DIFF_DEFAULT_ABBREV 7 /* hex digits */
93 -
91 extern void diffcore_std(struct diff_options *);
92
93 extern void diffcore_std_no_resolve(struct diff_options *);
sha1_name.c
+1 -1
@@ -155,7 +155,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
155 char canonical[40];
156 unsigned char res[20];
157
158 - if (len < 4)
158 + if (len < MINIMUM_ABBREV)
159 return -1;
160 memset(res, 0, 20);
161 memset(canonical, 'x', 40);