patch_parse.h 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_patch_parse_h__
#define INCLUDE_patch_parse_h__

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
typedef struct {
	git_refcount rc;

	/* Original content buffer */
	const char *content;
	size_t content_len;

	git_patch_options opts;

	/* The remaining (unparsed) buffer */
	const char *remain;
	size_t remain_len;

	const char *line;
	size_t line_len;
	size_t line_num;
} git_patch_parse_ctx;

extern git_patch_parse_ctx *git_patch_parse_ctx_init(
	const char *content,
	size_t content_len,
	const git_patch_options *opts);

extern void git_patch_parse_ctx_free(git_patch_parse_ctx *ctx);

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/**
 * Create a patch for a single file from the contents of a patch buffer.
 *
 * @param out The patch to be created
 * @param contents The contents of a patch file
 * @param contents_len The length of the patch file
 * @param opts The git_patch_options
 * @return 0 on success, <0 on failure.
 */
extern int git_patch_from_buffer(
	git_patch **out,
	const char *contents,
	size_t contents_len,
	const git_patch_options *opts);

50 51 52 53
extern int git_patch_parse(
	git_patch **out,
	git_patch_parse_ctx *ctx);

54 55
extern int git_patch_parsed_from_diff(git_patch **, git_diff *, size_t);

56
#endif