16
16
#include "map.h"
17
17
#include "buf_text.h"
18
18
19
+ GIT__USE_STRMAP ;
20
+
19
21
typedef enum {
20
22
DIFF_DRIVER_AUTO = 0 ,
21
23
DIFF_DRIVER_FALSE = 1 ,
33
35
struct git_diff_driver {
34
36
git_diff_driver_t type ;
35
37
git_strarray fn_patterns ;
36
- int binary ;
38
+ int binary ; /* 0 => treat as text, 1 => treat as binary, -1 => auto */
37
39
};
38
40
39
41
struct git_diff_driver_registry {
@@ -49,26 +51,54 @@ static git_diff_driver global_drivers[3] = {
49
51
50
52
git_diff_driver_registry * git_diff_driver_registry_new ()
51
53
{
52
- return git__calloc (1 , sizeof (git_diff_driver_registry ));
54
+ git_diff_driver_registry * reg =
55
+ git__calloc (1 , sizeof (git_diff_driver_registry ));
56
+ if (!reg )
57
+ return NULL ;
58
+
59
+ if (git_pool_init (& reg -> strings , 1 , 0 ) < 0 ||
60
+ (reg -> drivers = git_strmap_alloc ()) == NULL )
61
+ {
62
+ git_diff_driver_registry_free (reg );
63
+ return NULL ;
64
+ }
65
+
66
+ return reg ;
53
67
}
54
68
55
69
void git_diff_driver_registry_free (git_diff_driver_registry * reg )
56
70
{
71
+ if (!reg )
72
+ return ;
73
+
74
+ git_strmap_free (reg -> drivers );
75
+ git_pool_clear (& reg -> strings );
57
76
git__free (reg );
58
77
}
59
78
79
+ static int git_diff_driver_load (
80
+ git_diff_driver * * out , git_repository * repo , const char * name )
81
+ {
82
+ GIT_UNUSED (out );
83
+ GIT_UNUSED (repo );
84
+ GIT_UNUSED (name );
85
+
86
+ return GIT_ENOTFOUND ;
87
+ }
88
+
60
89
int git_diff_driver_lookup (
61
90
git_diff_driver * * out , git_repository * repo , const char * path )
62
91
{
92
+ int error = 0 ;
63
93
const char * value ;
64
94
65
95
assert (out );
66
96
67
97
if (!repo || !path || !strlen (path ))
68
98
goto use_auto ;
69
99
70
- if (git_attr_get (& value , repo , 0 , path , "diff" ) < 0 )
71
- return -1 ;
100
+ if (( error = git_attr_get (& value , repo , 0 , path , "diff" ) ) < 0 )
101
+ return error ;
72
102
73
103
if (GIT_ATTR_FALSE (value )) {
74
104
* out = & global_drivers [DIFF_DRIVER_FALSE ];
@@ -81,6 +111,12 @@ int git_diff_driver_lookup(
81
111
}
82
112
83
113
/* otherwise look for driver information in config and build driver */
114
+ if ((error = git_diff_driver_load (out , repo , value )) < 0 ) {
115
+ if (error != GIT_ENOTFOUND )
116
+ return error ;
117
+ else
118
+ giterr_clear ();
119
+ }
84
120
85
121
use_auto :
86
122
* out = & global_drivers [DIFF_DRIVER_AUTO ];
0 commit comments