summaryrefslogtreecommitdiff
path: root/include/git2/diff.h
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-02-02 18:03:43 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-03-02 15:49:28 -0800
commit65b09b1deddec64fa5639e9fea10c048d31901fa (patch)
tree426f17e38fceaed529cd5e8a2b1544e469d98fb7 /include/git2/diff.h
parentcd33323b7251e0bb15c5ee476e918859b661cc5f (diff)
downloadlibgit2-65b09b1deddec64fa5639e9fea10c048d31901fa.tar.gz
Implement diff lists and formatters
This reworks the diff API to separate the steps of producing a diff descriptions from formatting the diff. This will allow us to share diff output code with the various diff creation scenarios and will allow us to implement rename detection as an optional pass that can be run on a diff list.
Diffstat (limited to 'include/git2/diff.h')
-rw-r--r--include/git2/diff.h137
1 files changed, 91 insertions, 46 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 1d3a8d408..0f4b0783b 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -21,81 +21,126 @@
*/
GIT_BEGIN_DECL
+typedef struct {
+ int context_lines;
+ int interhunk_lines;
+ int ignore_whitespace;
+ int force_text;
+ git_strarray pathspec;
+} git_diff_options;
+
+typedef struct {
+ git_status_t status; /* value from tree.h */
+ unsigned int old_attr;
+ unsigned int new_attr;
+ git_oid old_oid;
+ git_oid new_oid;
+ git_blob *old_blob;
+ git_blob *new_blob;
+ const char *path;
+ const char *new_path; /* NULL unless status is RENAMED or COPIED */
+ int similarity; /* value from 0 to 100 */
+ int binary; /* diff as binary? */
+} git_diff_delta;
+
typedef int (*git_diff_file_fn)(
void *cb_data,
- const git_oid *old,
- const char *old_path,
- int old_mode,
- const git_oid *new, /* hashed object if from work tree */
- const char *new_path,
- int new_mode);
+ git_diff_delta *delta,
+ float progress);
+
+typedef struct {
+ int old_start;
+ int old_lines;
+ int new_start;
+ int new_lines;
+} git_diff_range;
typedef int (*git_diff_hunk_fn)(
void *cb_data,
- int old_start,
- int old_lines,
- int new_start,
- int new_lines);
+ git_diff_delta *delta,
+ git_diff_range *range,
+ const char *header,
+ size_t header_len);
-#define GIT_DIFF_LINE_CONTEXT 0
-#define GIT_DIFF_LINE_ADDITION 1
-#define GIT_DIFF_LINE_DELETION 2
+#define GIT_DIFF_LINE_CONTEXT ' '
+#define GIT_DIFF_LINE_ADDITION '+'
+#define GIT_DIFF_LINE_DELETION '-'
+#define GIT_DIFF_LINE_ADD_EOFNL '\n'
+#define GIT_DIFF_LINE_DEL_EOFNL '\0'
typedef int (*git_diff_line_fn)(
void *cb_data,
- int origin, /* GIT_DIFF_LINE value from above */
+ git_diff_delta *delta,
+ char line_origin, /* GIT_DIFF_LINE value from above */
const char *content,
size_t content_len);
-typedef struct {
- int context_lines;
- int interhunk_lines;
- int ignore_whitespace;
-
- git_diff_file_fn file_cb;
- git_diff_hunk_fn hunk_cb;
- git_diff_line_fn line_cb;
- void *cb_data;
-} git_diff_opts;
-
+typedef struct git_diff_list git_diff_list;
-GIT_EXTERN(int) git_diff_blobs(
- git_repository *repo,
- git_blob *old,
- git_blob *new,
- git_diff_opts *options);
+/*
+ * Generate diff lists
+ */
-GIT_EXTERN(int) git_diff_trees(
+GIT_EXTERN(int) git_diff_tree_to_tree(
git_repository *repo,
+ const git_diff_options *opts,
git_tree *old,
git_tree *new,
- git_diff_opts *options);
+ git_diff_list **diff);
-GIT_EXTERN(int) git_diff_index(
+GIT_EXTERN(int) git_diff_index_to_tree(
git_repository *repo,
+ const git_diff_options *opts,
git_tree *old,
- git_diff_opts *options);
+ git_diff_list **diff);
-/* pass NULL for the git_tree to diff workdir against index */
-GIT_EXTERN(int) git_diff_workdir(
+GIT_EXTERN(int) git_diff_workdir_to_tree(
git_repository *repo,
+ const git_diff_options *opts,
git_tree *old,
- git_diff_opts *options);
+ git_diff_list **diff);
-GIT_EXTERN(int) git_diff_workdir_file(
+GIT_EXTERN(int) git_diff_workdir_to_index(
git_repository *repo,
- git_blob *old,
- const char *path,
- git_diff_opts *options);
+ const git_diff_options *opts,
+ git_diff_list **diff);
-/* pass git_objects to diff against or NULL for index.
- * can handle: blob->blob, tree->index, tree->tree
- * it will be an error if object types don't match
+GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
+
+/*
+ * Process diff lists
*/
-/* pass git_object to diff WT against or NULL for index
- * can handle: index->wt, tree->wt, blob->wt with path
+
+GIT_EXTERN(int) git_diff_foreach(
+ git_diff_list *diff,
+ void *cb_data,
+ git_diff_file_fn file_cb,
+ git_diff_hunk_fn hunk_cb,
+ git_diff_line_fn line_cb);
+
+#ifndef _STDIO_H_
+#include <stdio.h>
+#endif
+
+GIT_EXTERN(int) git_diff_print_compact(
+ FILE *fp, git_diff_list *diff);
+
+GIT_EXTERN(int) git_diff_print_patch(
+ FILE *fp, git_diff_list *diff);
+
+/*
+ * Misc
*/
+GIT_EXTERN(int) git_diff_blobs(
+ git_repository *repo,
+ git_blob *old,
+ git_blob *new,
+ git_diff_options *options,
+ void *cb_data,
+ git_diff_hunk_fn hunk_cb,
+ git_diff_line_fn line_cb);
+
GIT_END_DECL
/** @} */