Skip to content

Commit a96847c

Browse files
committed
rerere: explain the rerere I/O abstraction
Explain the internals of rerere as in-code comments. This one covers our thin I/O abstraction to read from either a file or a memory while optionally writing out to a file. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d4053b commit a96847c

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

rerere.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ static int write_rr(struct string_list *rr, int out_fd)
8383
return 0;
8484
}
8585

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+
86101
static void ferr_write(const void *p, size_t count, FILE *fp, int *err)
87102
{
88103
if (!count || *err)
@@ -96,19 +111,15 @@ static inline void ferr_puts(const char *s, FILE *fp, int *err)
96111
ferr_write(s, strlen(s), fp, err);
97112
}
98113

99-
struct rerere_io {
100-
int (*getline)(struct strbuf *, struct rerere_io *);
101-
FILE *output;
102-
int wrerror;
103-
/* some more stuff */
104-
};
105-
106114
static void rerere_io_putstr(const char *str, struct rerere_io *io)
107115
{
108116
if (io->output)
109117
ferr_puts(str, io->output, &io->wrerror);
110118
}
111119

120+
/*
121+
* Write a conflict marker to io->output (if defined).
122+
*/
112123
static void rerere_io_putconflict(int ch, int size, struct rerere_io *io)
113124
{
114125
char buf[64];
@@ -137,11 +148,17 @@ static void rerere_io_putmem(const char *mem, size_t sz, struct rerere_io *io)
137148
ferr_write(mem, sz, io->output, &io->wrerror);
138149
}
139150

151+
/*
152+
* Subclass of rerere_io that reads from an on-disk file
153+
*/
140154
struct rerere_io_file {
141155
struct rerere_io io;
142156
FILE *input;
143157
};
144158

159+
/*
160+
* ... and its getline() method implementation
161+
*/
145162
static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
146163
{
147164
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
286303
return hunk_no;
287304
}
288305

306+
/*
307+
* Subclass of rerere_io that reads from an in-core buffer that is a
308+
* strbuf
309+
*/
289310
struct rerere_io_mem {
290311
struct rerere_io io;
291312
struct strbuf input;
292313
};
293314

315+
/*
316+
* ... and its getline() method implementation
317+
*/
294318
static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
295319
{
296320
struct rerere_io_mem *io = (struct rerere_io_mem *)io_;

0 commit comments

Comments
 (0)