Blame include/git2/sys/hashsig.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_sys_hashsig_h__
Packit Service 20376f
#define INCLUDE_sys_hashsig_h__
Packit Service 20376f
Packit Service 20376f
#include "git2/common.h"
Packit Service 20376f
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Similarity signature of arbitrary text content based on line hashes
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_hashsig git_hashsig;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Options for hashsig computation
Packit Service 20376f
 *
Packit Service 20376f
 * The options GIT_HASHSIG_NORMAL, GIT_HASHSIG_IGNORE_WHITESPACE,
Packit Service 20376f
 * GIT_HASHSIG_SMART_WHITESPACE are exclusive and should not be combined.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/**
Packit Service 20376f
	 * Use all data
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_HASHSIG_NORMAL = 0,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Ignore whitespace
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_HASHSIG_IGNORE_WHITESPACE = (1 << 0),
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Ignore \r and all space after \n
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_HASHSIG_SMART_WHITESPACE = (1 << 1),
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Allow hashing of small files
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_HASHSIG_ALLOW_SMALL_FILES = (1 << 2)
Packit Service 20376f
} git_hashsig_option_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Compute a similarity signature for a text buffer
Packit Service 20376f
 *
Packit Service 20376f
 * If you have passed the option GIT_HASHSIG_IGNORE_WHITESPACE, then the
Packit Service 20376f
 * whitespace will be removed from the buffer while it is being processed,
Packit Service 20376f
 * modifying the buffer in place. Sorry about that!
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The computed similarity signature.
Packit Service 20376f
 * @param buf The input buffer.
Packit Service 20376f
 * @param buflen The input buffer size.
Packit Service 20376f
 * @param opts The signature computation options (see above).
Packit Service 20376f
 * @return 0 on success, GIT_EBUFS if the buffer doesn't contain enough data to
Packit Service 20376f
 * compute a valid signature (unless GIT_HASHSIG_ALLOW_SMALL_FILES is set), or
Packit Service 20376f
 * error code.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_hashsig_create(
Packit Service 20376f
	git_hashsig **out,
Packit Service 20376f
	const char *buf,
Packit Service 20376f
	size_t buflen,
Packit Service 20376f
	git_hashsig_option_t opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Compute a similarity signature for a text file
Packit Service 20376f
 *
Packit Service 20376f
 * This walks through the file, only loading a maximum of 4K of file data at
Packit Service 20376f
 * a time. Otherwise, it acts just like `git_hashsig_create`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The computed similarity signature.
Packit Service 20376f
 * @param path The path to the input file.
Packit Service 20376f
 * @param opts The signature computation options (see above).
Packit Service 20376f
 * @return 0 on success, GIT_EBUFS if the buffer doesn't contain enough data to
Packit Service 20376f
 * compute a valid signature (unless GIT_HASHSIG_ALLOW_SMALL_FILES is set), or
Packit Service 20376f
 * error code.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_hashsig_create_fromfile(
Packit Service 20376f
	git_hashsig **out,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	git_hashsig_option_t opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Release memory for a content similarity signature
Packit Service 20376f
 *
Packit Service 20376f
 * @param sig The similarity signature to free.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_hashsig_free(git_hashsig *sig);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Measure similarity score between two similarity signatures
Packit Service 20376f
 *
Packit Service 20376f
 * @param a The first similarity signature to compare.
Packit Service 20376f
 * @param b The second similarity signature to compare.
Packit Service 20376f
 * @return [0 to 100] on success as the similarity score, or error code.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_hashsig_compare(
Packit Service 20376f
	const git_hashsig *a,
Packit Service 20376f
	const git_hashsig *b);
Packit Service 20376f
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
Packit Service 20376f
#endif