summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-06-25 23:33:05 -0400
committerGitHub <noreply@github.com>2016-06-25 23:33:05 -0400
commit20302aa43738a972e0bd2e2ee6ae479208427b31 (patch)
tree95d47b56ca5a69777e5a715b2afca464762ef707 /include
parent8774c47e81ef57ad0b1262459903fe08f7919626 (diff)
parent1a79cd959ba2991dd3295f9940b28b606e494ccf (diff)
downloadlibgit2-20302aa43738a972e0bd2e2ee6ae479208427b31.tar.gz
Merge pull request #3223 from ethomson/apply
Reading patch files
Diffstat (limited to 'include')
-rw-r--r--include/git2/diff.h42
-rw-r--r--include/git2/errors.h3
2 files changed, 37 insertions, 8 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h
index c35701a46..005b33965 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -264,10 +264,15 @@ typedef enum {
* link, a submodule commit id, or even a tree (although that only if you
* are tracking type changes or ignored/untracked directories).
*
- * The `oid` is the `git_oid` of the item. If the entry represents an
+ * The `id` is the `git_oid` of the item. If the entry represents an
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
* then the oid will be zeroes.
*
+ * The `id_abbrev` represents the known length of the `id` field, when
+ * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
+ * delta was created from reading a patch file, in which case it may be
+ * abbreviated to something reasonable, like 7 characters.
+ *
* `path` is the NUL-terminated path to the entry relative to the working
* directory of the repository.
*
@@ -280,6 +285,7 @@ typedef enum {
*/
typedef struct {
git_oid id;
+ int id_abbrev;
const char *path;
git_off_t size;
uint32_t flags;
@@ -448,6 +454,8 @@ typedef int (*git_diff_file_cb)(
float progress,
void *payload);
+#define GIT_DIFF_HUNK_HEADER_SIZE 128
+
/**
* When producing a binary diff, the binary data returned will be
* either the deflated full ("literal") contents of the file, or
@@ -499,12 +507,12 @@ typedef int(*git_diff_binary_cb)(
* Structure describing a hunk of a diff.
*/
typedef struct {
- int old_start; /**< Starting line number in old_file */
- int old_lines; /**< Number of lines in old_file */
- int new_start; /**< Starting line number in new_file */
- int new_lines; /**< Number of lines in new_file */
- size_t header_len; /**< Number of bytes in header text */
- char header[128]; /**< Header text, NUL-byte terminated */
+ int old_start; /** Starting line number in old_file */
+ int old_lines; /** Number of lines in old_file */
+ int new_start; /** Starting line number in new_file */
+ int new_lines; /** Number of lines in new_file */
+ size_t header_len; /** Number of bytes in header text */
+ char header[GIT_DIFF_HUNK_HEADER_SIZE]; /** Header text, NUL-byte terminated */
} git_diff_hunk;
/**
@@ -1046,6 +1054,21 @@ GIT_EXTERN(int) git_diff_print(
git_diff_line_cb print_cb,
void *payload);
+/**
+ * Produce the complete formatted text output from a diff into a
+ * buffer.
+ *
+ * @param out A pointer to a user-allocated git_buf that will
+ * contain the diff text
+ * @param diff A git_diff generated by one of the above functions.
+ * @param format A git_diff_format_t value to pick the text format.
+ * @return 0 on success or error code
+ */
+GIT_EXTERN(int) git_diff_to_buf(
+ git_buf *out,
+ git_diff *diff,
+ git_diff_format_t format);
+
/**@}*/
@@ -1166,6 +1189,11 @@ GIT_EXTERN(int) git_diff_buffers(
git_diff_line_cb line_cb,
void *payload);
+GIT_EXTERN(int) git_diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len);
+
/**
* This is an opaque structure which is allocated by `git_diff_get_stats`.
* You are responsible for releasing the object memory when done, using the
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 3ecea34bf..e959ffd8a 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -98,7 +98,8 @@ typedef enum {
GITERR_CHERRYPICK,
GITERR_DESCRIBE,
GITERR_REBASE,
- GITERR_FILESYSTEM
+ GITERR_FILESYSTEM,
+ GITERR_PATCH,
} git_error_t;
/**