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

10 11
#include "common.h"

12
#include "git2/blob.h"
13
#include "repository.h"
Vicent Marti committed
14
#include "odb.h"
15
#include "futils.h"
16 17 18

struct git_blob {
	git_object object;
19 20 21 22 23

	union {
		git_odb_object *odb;
		struct {
			const char *data;
24
			git_object_size_t size;
25 26 27
		} raw;
	} data;
	unsigned int raw:1;
28 29
};

30 31 32 33 34 35 36 37
#define GIT_ERROR_CHECK_BLOBSIZE(n) \
	do { \
		if (!git__is_sizet(n)) { \
			git_error_set(GIT_ERROR_NOMEMORY, "blob contents too large to fit in memory"); \
			return -1; \
		} \
	} while(0)

38
void git_blob__free(void *blob);
39
int git_blob__parse(void *blob, git_odb_object *obj);
40
int git_blob__parse_raw(void *blob, const char *data, size_t size);
41
int git_blob__getbuf(git_buf *buffer, git_blob *blob);
42

43 44 45 46 47 48 49 50 51
extern int git_blob__create_from_paths(
	git_oid *out_oid,
	struct stat *out_st,
	git_repository *repo,
	const char *full_path,
	const char *hint_path,
	mode_t hint_mode,
	bool apply_filters);

52
#endif