@@ -87,12 +87,12 @@ static int handle_file(const char *path,
87
87
unsigned char * sha1 , const char * output )
88
88
{
89
89
git_SHA_CTX ctx ;
90
- char buf [1024 ];
91
90
int hunk_no = 0 ;
92
91
enum {
93
92
RR_CONTEXT = 0 , RR_SIDE_1 , RR_SIDE_2 , RR_ORIGINAL ,
94
93
} hunk = RR_CONTEXT ;
95
94
struct strbuf one = STRBUF_INIT , two = STRBUF_INIT ;
95
+ struct strbuf buf = STRBUF_INIT ;
96
96
FILE * f = fopen (path , "r" );
97
97
FILE * out = NULL ;
98
98
int wrerror = 0 ;
@@ -111,20 +111,20 @@ static int handle_file(const char *path,
111
111
if (sha1 )
112
112
git_SHA1_Init (& ctx );
113
113
114
- while (fgets ( buf , sizeof ( buf ), f )) {
115
- if (!prefixcmp (buf , "<<<<<<< " )) {
114
+ while (! strbuf_getwholeline ( & buf , f , '\n' )) {
115
+ if (!prefixcmp (buf . buf , "<<<<<<< " )) {
116
116
if (hunk != RR_CONTEXT )
117
117
goto bad ;
118
118
hunk = RR_SIDE_1 ;
119
- } else if (!prefixcmp (buf , "|||||||" ) && isspace (buf [7 ])) {
119
+ } else if (!prefixcmp (buf . buf , "|||||||" ) && isspace (buf . buf [7 ])) {
120
120
if (hunk != RR_SIDE_1 )
121
121
goto bad ;
122
122
hunk = RR_ORIGINAL ;
123
- } else if (!prefixcmp (buf , "=======" ) && isspace (buf [7 ])) {
123
+ } else if (!prefixcmp (buf . buf , "=======" ) && isspace (buf . buf [7 ])) {
124
124
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL )
125
125
goto bad ;
126
126
hunk = RR_SIDE_2 ;
127
- } else if (!prefixcmp (buf , ">>>>>>> " )) {
127
+ } else if (!prefixcmp (buf . buf , ">>>>>>> " )) {
128
128
if (hunk != RR_SIDE_2 )
129
129
goto bad ;
130
130
if (strbuf_cmp (& one , & two ) > 0 )
@@ -147,20 +147,21 @@ static int handle_file(const char *path,
147
147
strbuf_reset (& one );
148
148
strbuf_reset (& two );
149
149
} else if (hunk == RR_SIDE_1 )
150
- strbuf_addstr (& one , buf );
150
+ strbuf_addstr (& one , buf . buf );
151
151
else if (hunk == RR_ORIGINAL )
152
152
; /* discard */
153
153
else if (hunk == RR_SIDE_2 )
154
- strbuf_addstr (& two , buf );
154
+ strbuf_addstr (& two , buf . buf );
155
155
else if (out )
156
- ferr_puts (buf , out , & wrerror );
156
+ ferr_puts (buf . buf , out , & wrerror );
157
157
continue ;
158
158
bad :
159
159
hunk = 99 ; /* force error exit */
160
160
break ;
161
161
}
162
162
strbuf_release (& one );
163
163
strbuf_release (& two );
164
+ strbuf_release (& buf );
164
165
165
166
fclose (f );
166
167
if (wrerror )
0 commit comments