Blame src/odb.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_odb_h__
Packit ae9e2a
#define INCLUDE_odb_h__
Packit ae9e2a
Packit ae9e2a
#include "git2/odb.h"
Packit ae9e2a
#include "git2/oid.h"
Packit ae9e2a
#include "git2/types.h"
Packit ae9e2a
Packit ae9e2a
#include "vector.h"
Packit ae9e2a
#include "cache.h"
Packit ae9e2a
#include "posix.h"
Packit ae9e2a
#include "filter.h"
Packit ae9e2a
Packit ae9e2a
#define GIT_OBJECTS_DIR "objects/"
Packit ae9e2a
#define GIT_OBJECT_DIR_MODE 0777
Packit ae9e2a
#define GIT_OBJECT_FILE_MODE 0444
Packit ae9e2a
Packit ae9e2a
extern bool git_odb__strict_hash_verification;
Packit ae9e2a
Packit ae9e2a
/* DO NOT EXPORT */
Packit ae9e2a
typedef struct {
Packit ae9e2a
	void *data;			/**< Raw, decompressed object data. */
Packit ae9e2a
	size_t len;			/**< Total number of bytes in data. */
Packit ae9e2a
	git_otype type;		/**< Type of this object. */
Packit ae9e2a
} git_rawobj;
Packit ae9e2a
Packit ae9e2a
/* EXPORT */
Packit ae9e2a
struct git_odb_object {
Packit ae9e2a
	git_cached_obj cached;
Packit ae9e2a
	void *buffer;
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
/* EXPORT */
Packit ae9e2a
struct git_odb {
Packit ae9e2a
	git_refcount rc;
Packit ae9e2a
	git_vector backends;
Packit ae9e2a
	git_cache own_cache;
Packit ae9e2a
	unsigned int do_fsync :1;
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
typedef enum {
Packit ae9e2a
	GIT_ODB_CAP_FROM_OWNER = -1,
Packit ae9e2a
} git_odb_cap_t;
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Set the capabilities for the object database.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__set_caps(git_odb *odb, int caps);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Add the default loose and packed backends for a database.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__add_default_backends(
Packit ae9e2a
	git_odb *db, const char *objects_dir,
Packit ae9e2a
	bool as_alternates, int alternate_depth);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Hash a git_rawobj internally.
Packit ae9e2a
 * The `git_rawobj` is supposed to be previously initialized
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__hashobj(git_oid *id, git_rawobj *obj);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Format the object header such as it would appear in the on-disk object
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__format_object_header(char *hdr, size_t n, git_off_t obj_len, git_otype obj_type);
Packit ae9e2a
/*
Packit ae9e2a
 * Hash an open file descriptor.
Packit ae9e2a
 * This is a performance call when the contents of a fd need to be hashed,
Packit ae9e2a
 * but the fd is already open and we have the size of the contents.
Packit ae9e2a
 *
Packit ae9e2a
 * Saves us some `stat` calls.
Packit ae9e2a
 *
Packit ae9e2a
 * The fd is never closed, not even on error. It must be opened and closed
Packit ae9e2a
 * by the caller
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Hash an open file descriptor applying an array of filters
Packit ae9e2a
 * Acts just like git_odb__hashfd with the addition of filters...
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__hashfd_filtered(
Packit ae9e2a
	git_oid *out, git_file fd, size_t len, git_otype type, git_filter_list *fl);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Hash a `path`, assuming it could be a POSIX symlink: if the path is a
Packit ae9e2a
 * symlink, then the raw contents of the symlink will be hashed. Otherwise,
Packit ae9e2a
 * this will fallback to `git_odb__hashfd`.
Packit ae9e2a
 *
Packit ae9e2a
 * The hash type for this call is always `GIT_OBJ_BLOB` because symlinks may
Packit ae9e2a
 * only point to blobs.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__hashlink(git_oid *out, const char *path);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Generate a GIT_EMISMATCH error for the ODB.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__error_mismatch(
Packit ae9e2a
	const git_oid *expected, const git_oid *actual);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Generate a GIT_ENOTFOUND error for the ODB.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__error_notfound(
Packit ae9e2a
	const char *message, const git_oid *oid, size_t oid_len);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Generate a GIT_EAMBIGUOUS error for the ODB.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__error_ambiguous(const char *message);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Attempt to read object header or just return whole object if it could
Packit ae9e2a
 * not be read.
Packit ae9e2a
 */
Packit ae9e2a
int git_odb__read_header_or_object(
Packit ae9e2a
	git_odb_object **out, size_t *len_p, git_otype *type_p,
Packit ae9e2a
	git_odb *db, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/* freshen an entry in the object database */
Packit ae9e2a
int git_odb__freshen(git_odb *db, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/* fully free the object; internal method, DO NOT EXPORT */
Packit ae9e2a
void git_odb_object__free(void *object);
Packit ae9e2a
Packit ae9e2a
#endif