odb: deprecate git_odb_hash

Hash generation is not a concern of the object database; deprecate
`git_odb_hash`.
This commit is contained in:
Edward Thomson
2025-01-03 13:15:33 +00:00
parent 8bb32e5780
commit 63c0757b4f
3 changed files with 54 additions and 66 deletions

View File

@@ -677,6 +677,56 @@ GIT_EXTERN(int) git_object_typeisloose(git_object_t type);
/**@}*/
/** @name Deprecated Object Database Functions
*
* These functions are retained for backward compatibility. The newer
* versions of these functions should be preferred in all new code.
*
* There is no plan to remove these backward compatibility functions at
* this time.
*/
/**@{*/
/**
* Generate the SHA1 object ID for a given data buffer.
*
* @deprecated use `git_object_id_from_buffer`
*
* @param[out] oid the resulting object ID.
* @param data data to hash
* @param len size of the data
* @param object_type of the data to hash
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(
git_oid *oid,
const void *data,
size_t len,
git_object_t object_type);
/**
* Read a file from disk and fill a git_oid with the object id
* that the file would have if it were written to the Object
* Database as an object of the given type (w/o applying filters).
* Similar functionality to git.git's `git hash-object` without
* the `-w` flag, however, with the --no-filters flag.
* If you need filters, see `git_repository_hashfile` or
* `git_object_id_from_file.
*
* @deprecated use `git_object_id_from_file`
*
* @param[out] oid oid structure the result is written into.
* @param path file to read and determine object id for
* @param object_type of the data to hash
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hashfile(
git_oid *oid,
const char *path,
git_object_t object_type);
/**@}*/
/** @name Deprecated Remote Functions
*
* These functions are retained for backward compatibility. The newer

View File

@@ -500,72 +500,6 @@ GIT_EXTERN(int) git_odb_write_pack(
GIT_EXTERN(int) git_odb_write_multi_pack_index(
git_odb *db);
#ifdef GIT_EXPERIMENTAL_SHA256
/**
* Generate the object ID (in SHA1 or SHA256 format) for a given data buffer.
*
* @param[out] oid the resulting object ID.
* @param data data to hash
* @param len size of the data
* @param object_type of the data to hash
* @param oid_type the oid type to hash to
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(
git_oid *oid,
const void *data,
size_t len,
git_object_t object_type,
git_oid_t oid_type);
/**
* Determine the object ID of a file on disk.
*
* @param[out] oid oid structure the result is written into.
* @param path file to read and determine object id for
* @param object_type of the data to hash
* @param oid_type the oid type to hash to
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hashfile(
git_oid *oid,
const char *path,
git_object_t object_type,
git_oid_t oid_type);
#else
/**
* Determine the object-ID (sha1 or sha256 hash) of a data buffer
*
* The resulting OID will be the identifier for the data buffer as if
* the data buffer it were to written to the ODB.
*
* @param[out] oid the resulting object-ID.
* @param data data to hash
* @param len size of the data
* @param object_type of the data to hash
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(git_oid *oid, const void *data, size_t len, git_object_t object_type);
/**
* Read a file from disk and fill a git_oid with the object id
* that the file would have if it were written to the Object
* Database as an object of the given type (w/o applying filters).
* Similar functionality to git.git's `git hash-object` without
* the `-w` flag, however, with the --no-filters flag.
* If you need filters, see git_repository_hashfile.
*
* @param[out] oid oid structure the result is written into.
* @param path file to read and determine object id for
* @param object_type of the data to hash
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hashfile(git_oid *oid, const char *path, git_object_t object_type);
#endif
/**
* Create a copy of an odb_object
*

View File

@@ -162,6 +162,8 @@ void git_odb_object_free(git_odb_object *object)
git_cached_obj_decref(object);
}
#ifndef GIT_DEPRECATE_HARD
int git_odb_hashfile(
git_oid *out,
const char *path,
@@ -191,6 +193,8 @@ int git_odb_hash(
return git_object_id_from_buffer(id, data, len, &opts);
}
#endif
/**
* FAKE WSTREAM
*/