@@ -83,6 +83,21 @@ static int write_rr(struct string_list *rr, int out_fd)
83
83
return 0 ;
84
84
}
85
85
86
+ /*
87
+ * "rerere" interacts with conflicted file contents using this I/O
88
+ * abstraction. It reads a conflicted contents from one place via
89
+ * "getline()" method, and optionally can write it out after
90
+ * normalizing the conflicted hunks to the "output". Subclasses of
91
+ * rerere_io embed this structure at the beginning of their own
92
+ * rerere_io object.
93
+ */
94
+ struct rerere_io {
95
+ int (* getline )(struct strbuf * , struct rerere_io * );
96
+ FILE * output ;
97
+ int wrerror ;
98
+ /* some more stuff */
99
+ };
100
+
86
101
static void ferr_write (const void * p , size_t count , FILE * fp , int * err )
87
102
{
88
103
if (!count || * err )
@@ -96,19 +111,15 @@ static inline void ferr_puts(const char *s, FILE *fp, int *err)
96
111
ferr_write (s , strlen (s ), fp , err );
97
112
}
98
113
99
- struct rerere_io {
100
- int (* getline )(struct strbuf * , struct rerere_io * );
101
- FILE * output ;
102
- int wrerror ;
103
- /* some more stuff */
104
- };
105
-
106
114
static void rerere_io_putstr (const char * str , struct rerere_io * io )
107
115
{
108
116
if (io -> output )
109
117
ferr_puts (str , io -> output , & io -> wrerror );
110
118
}
111
119
120
+ /*
121
+ * Write a conflict marker to io->output (if defined).
122
+ */
112
123
static void rerere_io_putconflict (int ch , int size , struct rerere_io * io )
113
124
{
114
125
char buf [64 ];
@@ -137,11 +148,17 @@ static void rerere_io_putmem(const char *mem, size_t sz, struct rerere_io *io)
137
148
ferr_write (mem , sz , io -> output , & io -> wrerror );
138
149
}
139
150
151
+ /*
152
+ * Subclass of rerere_io that reads from an on-disk file
153
+ */
140
154
struct rerere_io_file {
141
155
struct rerere_io io ;
142
156
FILE * input ;
143
157
};
144
158
159
+ /*
160
+ * ... and its getline() method implementation
161
+ */
145
162
static int rerere_file_getline (struct strbuf * sb , struct rerere_io * io_ )
146
163
{
147
164
struct rerere_io_file * io = (struct rerere_io_file * )io_ ;
@@ -286,11 +303,18 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
286
303
return hunk_no ;
287
304
}
288
305
306
+ /*
307
+ * Subclass of rerere_io that reads from an in-core buffer that is a
308
+ * strbuf
309
+ */
289
310
struct rerere_io_mem {
290
311
struct rerere_io io ;
291
312
struct strbuf input ;
292
313
};
293
314
315
+ /*
316
+ * ... and its getline() method implementation
317
+ */
294
318
static int rerere_mem_getline (struct strbuf * sb , struct rerere_io * io_ )
295
319
{
296
320
struct rerere_io_mem * io = (struct rerere_io_mem * )io_ ;
0 commit comments