summaryrefslogtreecommitdiff
path: root/rerere.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-07-01 05:33:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-24 22:11:05 (GMT)
commita96847cc1691840bd95cc56549d7c00b35f6d5a0 (patch)
treed7b61bbcc87d1113d5b937792e43fc0f95b68113 /rerere.c
parent7d4053b69b37927c0ccd98eac41f32707227eca0 (diff)
downloadgit-a96847cc1691840bd95cc56549d7c00b35f6d5a0.zip
git-a96847cc1691840bd95cc56549d7c00b35f6d5a0.tar.gz
git-a96847cc1691840bd95cc56549d7c00b35f6d5a0.tar.bz2
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 <gitster@pobox.com>
Diffstat (limited to 'rerere.c')
-rw-r--r--rerere.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/rerere.c b/rerere.c
index d665deb..7db5b54 100644
--- a/rerere.c
+++ b/rerere.c
@@ -83,6 +83,21 @@ static int write_rr(struct string_list *rr, int out_fd)
return 0;
}
+/*
+ * "rerere" interacts with conflicted file contents using this I/O
+ * abstraction. It reads a conflicted contents from one place via
+ * "getline()" method, and optionally can write it out after
+ * normalizing the conflicted hunks to the "output". Subclasses of
+ * rerere_io embed this structure at the beginning of their own
+ * rerere_io object.
+ */
+struct rerere_io {
+ int (*getline)(struct strbuf *, struct rerere_io *);
+ FILE *output;
+ int wrerror;
+ /* some more stuff */
+};
+
static void ferr_write(const void *p, size_t count, FILE *fp, int *err)
{
if (!count || *err)
@@ -96,19 +111,15 @@ static inline void ferr_puts(const char *s, FILE *fp, int *err)
ferr_write(s, strlen(s), fp, err);
}
-struct rerere_io {
- int (*getline)(struct strbuf *, struct rerere_io *);
- FILE *output;
- int wrerror;
- /* some more stuff */
-};
-
static void rerere_io_putstr(const char *str, struct rerere_io *io)
{
if (io->output)
ferr_puts(str, io->output, &io->wrerror);
}
+/*
+ * Write a conflict marker to io->output (if defined).
+ */
static void rerere_io_putconflict(int ch, int size, struct rerere_io *io)
{
char buf[64];
@@ -137,11 +148,17 @@ static void rerere_io_putmem(const char *mem, size_t sz, struct rerere_io *io)
ferr_write(mem, sz, io->output, &io->wrerror);
}
+/*
+ * Subclass of rerere_io that reads from an on-disk file
+ */
struct rerere_io_file {
struct rerere_io io;
FILE *input;
};
+/*
+ * ... and its getline() method implementation
+ */
static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
{
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
return hunk_no;
}
+/*
+ * Subclass of rerere_io that reads from an in-core buffer that is a
+ * strbuf
+ */
struct rerere_io_mem {
struct rerere_io io;
struct strbuf input;
};
+/*
+ * ... and its getline() method implementation
+ */
static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
{
struct rerere_io_mem *io = (struct rerere_io_mem *)io_;