Blame src/odb.h

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