Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reading patch files #3223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Jun 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7cb904b
Introduce git_apply_patch
Apr 2, 2014
d34f682
Patch parsing from patch files
Apr 9, 2014
0004386
apply: handle empty patches
ethomson Jun 17, 2015
6a2d2f8
delta: move delta application to delta.c
ethomson Jun 17, 2015
1cd6599
delta: refactor git_delta functions for consistency
ethomson Jun 17, 2015
b88f171
zstream: offer inflating, `git_zstream_inflatebuf`
ethomson Jun 17, 2015
3149ff6
patch application: apply binary patches
ethomson Jun 18, 2015
5b78dbd
git_buf: decode base85 inputs
ethomson Jul 9, 2015
b8dc2fd
zstream: fail when asked to inflate garbage
ethomson Jul 9, 2015
5d17d72
patch parsing: parse binary patch files
ethomson Jul 10, 2015
8d2eef2
patch parsing: ensure empty patches are illegal
ethomson Jul 10, 2015
804d5fe
patch: abstract patches into diff'ed and parsed
ethomson Sep 11, 2015
b85bd8c
patch: use delta's old_file/new_file members
Sep 16, 2015
8bca8b9
apply: move patch data to patch_common.h
Sep 16, 2015
e7ec327
patch parse: unset path prefix
Sep 22, 2015
d68cb73
diff: include oid length in deltas
Sep 22, 2015
bc6a31c
patch: when parsing, set nfiles correctly in delta
Sep 22, 2015
42b3442
patch_parse: ensure we can parse a patch
Sep 22, 2015
2f3b922
patch_parse: test roundtrip patch parsing -> print
Sep 22, 2015
1462c95
patch_parse: set binary flag
Sep 23, 2015
28f7044
patch_parse: use names from `diff --git` header
Sep 23, 2015
d536cea
patch_parse: don't set new mode when deleted
Sep 23, 2015
19e4664
patch printing: include rename information
Sep 23, 2015
8217508
Introduce git_patch_options, handle prefixes
Sep 23, 2015
72806f4
patch: don't print some headers on pure renames
Sep 23, 2015
d3d95d5
git_buf_quote: quote ugly characters
Sep 23, 2015
4ac2d8a
patch: quote filenames when necessary
Sep 23, 2015
e2cdc14
patch: show modes when only the mode has changed
Sep 23, 2015
040ec88
patch: use strlen to mean string length
Sep 23, 2015
f941f03
patch: drop some warnings
ethomson Sep 24, 2015
6278fbc
patch parsing: squash some memory leaks
ethomson Sep 24, 2015
4117a23
patch parse: dup the patch from the callers
ethomson Sep 24, 2015
0267c34
patch application: drop unnecessary `patch_image_init`
Sep 25, 2015
8cb2722
git_buf_quote/unquote: handle > \177
Sep 25, 2015
0ff723c
apply: test postimages that grow/shrink original
Sep 25, 2015
e564fc6
git_vector_grow/shrink: correct shrink, and tests
Sep 25, 2015
a03952f
patch: formatting cleanups
Sep 25, 2015
00e63b3
patch: provide static string `advance_expected`
ethomson Nov 21, 2015
440e3ba
patch: `git_patch_from_patchfile` -> `git_patch_from_buffer`
ethomson Nov 21, 2015
53571f2
vector: more sensible names for `grow_at`/`shrink_at`
ethomson Nov 21, 2015
8d44f8b
patch: `patch_diff` -> `patch_generated`
Nov 24, 2015
aa4bfb3
parse: introduce parse_ctx_contains_s
Feb 7, 2016
9be638e
git_diff_generated: abstract generated diffs
Apr 19, 2016
17572f6
git_patch_parse_ctx: refcount the context
Apr 21, 2016
94e488a
patch: differentiate not found and invalid patches
Apr 24, 2016
7166bb1
introduce `git_diff_from_buffer` to parse diffs
Apr 25, 2016
7282749
Introduce `git_diff_to_buf`
Apr 25, 2016
33ae876
patch: identify non-binary patches as `NOT_BINARY`
Apr 25, 2016
853e585
patch: zero id and abbrev length for empty files
Apr 25, 2016
e774d5a
diff::parse tests: test parsing a diff
Apr 25, 2016
38a347e
patch::parse: handle patches with no hunks
Apr 25, 2016
8a670dc
patch::parse: test diff with simple rename
Apr 25, 2016
9eb1938
patch::parse: test diff with exact rename and copy
Apr 26, 2016
1a79cd9
patch: show copy information for identical copies
Apr 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions include/git2/diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -280,6 +285,7 @@ typedef enum {
*/
typedef struct {
git_oid id;
int id_abbrev;
const char *path;
git_off_t size;
uint32_t flags;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);

/**@}*/


Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/git2/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ typedef enum {
GITERR_CHERRYPICK,
GITERR_DESCRIBE,
GITERR_REBASE,
GITERR_FILESYSTEM
GITERR_FILESYSTEM,
GITERR_PATCH,
} git_error_t;

/**
Expand Down
Loading