view mercurial/mpatch.h @ 38630:e1987261dd05

patch: don't separate \r and \n when colorizing diff output When displaying diffs, \r at the end of a line is treated as trailing whitespace. This causes an ANSI escape code to be inserted between \r and \n. Some programs, such as less since version 530 (maybe earlier, but at least not version 487) displays ^M when it encounters a lone \r. This causes a lot of noise in diff output on Windows, where \r\n is used to terminate lines. We avoid that by treating both \n and \r\n as end of line when considering trailing whitespace.
author Sune Foldager <cryo@cyanite.org>
date Tue, 10 Jul 2018 13:18:34 +0200
parents 761355833867
children d86908050375
line wrap: on
line source

#ifndef _HG_MPATCH_H_
#define _HG_MPATCH_H_

#define MPATCH_ERR_NO_MEM -3
#define MPATCH_ERR_CANNOT_BE_DECODED -2
#define MPATCH_ERR_INVALID_PATCH -1

struct mpatch_frag {
	int start, end, len;
	const char *data;
};

struct mpatch_flist {
	struct mpatch_frag *base, *head, *tail;
};

int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist **res);
ssize_t mpatch_calcsize(ssize_t len, struct mpatch_flist *l);
void mpatch_lfree(struct mpatch_flist *a);
int mpatch_apply(char *buf, const char *orig, ssize_t len,
                 struct mpatch_flist *l);
struct mpatch_flist *
mpatch_fold(void *bins, struct mpatch_flist *(*get_next_item)(void *, ssize_t),
            ssize_t start, ssize_t end);

#endif