summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b94f1e)
raw | patch | inline | side by side (parent: 6b94f1e)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 25 Jan 2006 09:03:18 +0000 (01:03 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 28 Jan 2006 08:09:38 +0000 (00:09 -0800) |
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>
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>
cache.h | patch | blob | history | |
describe.c | patch | blob | history | |
diff.c | patch | blob | history | |
diff.h | patch | blob | history | |
sha1_name.c | patch | blob | history |
index 1e8e27f7b33fb9adca642eab77e14f452bd2e4cb..bdbe2d683e18237e2a797573e45b9c38383eaf04 100644 (file)
--- a/cache.h
+++ b/cache.h
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 4866510eafa19fbfe74e11d20e5d2d1a0a44fd4b..ff65742615cb6862d3699e4f301d671a7eadc2e2 100644 (file)
--- a/describe.c
+++ b/describe.c
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;
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
index 17d68fa699f7c88aef8e6c1a0812575bfaec70e1..69767b9de97f27306032d7af1aa05d0bdbf5315f 100644 (file)
--- a/diff.c
+++ b/diff.c
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,
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
index 5696f2aff0644f331507679e0a58d7fcdc3501ec..122c8143a3b9274380f1a66785b3d7952e8609dd 100644 (file)
--- a/diff.h
+++ b/diff.h
#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 e18a96d772f4186cfaffe6053a3f1664a9fdad3f..ba0747c84dd1298093101e8726f2ee21d7ed23e6 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
char canonical[40];
unsigned char res[20];
- if (len < 4)
+ if (len < MINIMUM_ABBREV)
return -1;
memset(res, 0, 20);
memset(canonical, 'x', 40);