diff options
| author | Russell Belfer <rb@github.com> | 2013-04-22 16:25:57 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-04-23 12:57:30 -0700 |
| commit | b1ff7004ab132c8d4bddd181127f1c8d5ce9b7b4 (patch) | |
| tree | 3b39b1bc22033c6b4910d8b7d8e3a74bac1482a7 /src/diff_output.c | |
| parent | 6be368bf16c86380ea84d7e39b65e0ebd9606174 (diff) | |
| download | libgit2-b1ff7004ab132c8d4bddd181127f1c8d5ce9b7b4.tar.gz | |
Improve diff config options handling
This makes diff use the cvar cache for config options where
possible, and also adds support for a number of other config
options to diff including "diff.context", "diff.ignoreSubmodules",
"diff.noprefix", "diff.mnemonicprefix", and "core.abbrev".
To make this natural, this involved a rearrangement of the code
that allocates the diff object vs. the code that initializes it
based on the combination of options passed in by the user and
read from the config.
This commit includes tests for most of these new options as well.
Diffstat (limited to 'src/diff_output.c')
| -rw-r--r-- | src/diff_output.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/diff_output.c b/src/diff_output.c index 34a3e506c..b8bb73bf7 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -1114,11 +1114,20 @@ int git_diff_print_compact( static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta) { - char start_oid[8], end_oid[8]; + int abbrevlen; + char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1]; - /* TODO: Determine a good actual OID range to print */ - git_oid_tostr(start_oid, sizeof(start_oid), &delta->old_file.oid); - git_oid_tostr(end_oid, sizeof(end_oid), &delta->new_file.oid); + if (git_repository__cvar(&abbrevlen, pi->diff->repo, GIT_CVAR_ABBREV) < 0) + return -1; + + abbrevlen += 1; /* for NUL byte */ + if (abbrevlen < 2) + abbrevlen = 2; + else if (abbrevlen > (int)sizeof(start_oid)) + abbrevlen = (int)sizeof(start_oid); + + git_oid_tostr(start_oid, abbrevlen, &delta->old_file.oid); + git_oid_tostr(end_oid, abbrevlen, &delta->new_file.oid); /* TODO: Match git diff more closely */ if (delta->old_file.mode == delta->new_file.mode) { |
