summaryrefslogtreecommitdiff
path: root/include/git2/blob.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/git2/blob.h')
-rw-r--r--include/git2/blob.h87
1 files changed, 78 insertions, 9 deletions
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 551770678..0a2aa9d36 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2012 the libgit2 contributors
+ * Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
@@ -46,7 +46,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, unsigned int len)
+GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len)
{
return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB);
}
@@ -68,6 +68,17 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
git_object_free((git_object *) blob);
}
+/**
+ * Get the id of a blob.
+ *
+ * @param blob a previously loaded blob.
+ * @return SHA1 hash for this blob.
+ */
+GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
+{
+ return git_object_id((const git_object *)blob);
+}
+
/**
* Get a read-only buffer with the raw content of a blob.
@@ -80,7 +91,7 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
* @param blob pointer to the blob
* @return the pointer; NULL if the blob has no contents
*/
-GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
+GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
/**
* Get the size in bytes of the contents of a blob
@@ -88,34 +99,79 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
* @param blob pointer to the blob
* @return size on bytes
*/
-GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob);
+GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
/**
* Read a file from the working folder of a repository
* and write it to the Object Database as a loose blob
*
- * @param oid return the id of the written blob
+ * @param id return the id of the written blob
* @param repo repository where the blob will be written.
* this repository cannot be bare
- * @param path file from which the blob will be created,
+ * @param relative_path file from which the blob will be created,
* relative to the repository's working dir
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
/**
* Read a file from the filesystem and write its content
* to the Object Database as a loose blob
*
- * @param oid return the id of the written blob
+ * @param id return the id of the written blob
* @param repo repository where the blob will be written.
* this repository can be bare or not
* @param path file from which the blob will be created
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
+typedef int (*git_blob_chunk_cb)(char *content, size_t max_length, void *payload);
+
+/**
+ * Write a loose blob to the Object Database from a
+ * provider of chunks of data.
+ *
+ * Provided the `hintpath` parameter is filled, its value
+ * will help to determine what git filters should be applied
+ * to the object before it can be placed to the object database.
+ *
+ *
+ * The implementation of the callback has to respect the
+ * following rules:
+ *
+ * - `content` will have to be filled by the consumer. The maximum number
+ * of bytes that the buffer can accept per call is defined by the
+ * `max_length` parameter. Allocation and freeing of the buffer will be taken
+ * care of by the function.
+ *
+ * - The callback is expected to return the number of bytes
+ * that `content` have been filled with.
+ *
+ * - When there is no more data to stream, the callback should
+ * return 0. This will prevent it from being invoked anymore.
+ *
+ * - When an error occurs, the callback should return -1.
+ *
+ *
+ * @param id Return the id of the written blob
+ *
+ * @param repo repository where the blob will be written.
+ * This repository can be bare or not.
+ *
+ * @param hintpath if not NULL, will help selecting the filters
+ * to apply onto the content of the blob to be created.
+ *
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_blob_create_fromchunks(
+ git_oid *id,
+ git_repository *repo,
+ const char *hintpath,
+ git_blob_chunk_cb callback,
+ void *payload);
+
/**
* Write an in-memory buffer to the ODB as a blob
*
@@ -127,6 +183,19 @@ GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, con
*/
GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len);
+/**
+ * Determine if the blob content is most certainly binary or not.
+ *
+ * The heuristic used to guess if a file is binary is taken from core git:
+ * Searching for NUL bytes and looking for a reasonable ratio of printable
+ * to non-printable characters among the first 4000 bytes.
+ *
+ * @param blob The blob which content should be analyzed
+ * @return 1 if the content of the blob is detected
+ * as binary; 0 otherwise.
+ */
+GIT_EXTERN(int) git_blob_is_binary(git_blob *blob);
+
/** @} */
GIT_END_DECL
#endif