Commit Graph

179 Commits

Author SHA1 Message Date
Edward Thomson
338ceb93b6 Improve documentation 2024-11-26 21:44:09 +00:00
Edward Thomson
db2a794dda diff: parse patches with sha256 2023-04-10 14:21:16 +01:00
Edward Thomson
dbc4ac1c76 oid: GIT_OID_*SZ is now GIT_OID_SHA1_*SIZE
In preparation for SHA256 support, `GIT_OID_RAWSZ` and `GIT_OID_HEXSZ`
need to indicate that they're the size of _SHA1_ OIDs.
2022-06-14 22:29:57 -04:00
Edward Thomson
359240b674 diff: indicate when the file size is "valid"
When we know the file size (because we're producing it from a working
directory iterator, or an index with an up-to-date cache) then set a
flag indicating as such.  This removes the ambiguity about a 0 file
size, which could indicate that a file exists and is 0 bytes, or that we
haven't read it yet.
2022-02-12 06:59:09 -05:00
Edward Thomson
258df9c18d Merge pull request #6168 from punkymaniac/patch-documentation-2
Improve documentation
2022-01-17 22:03:26 -05:00
punkymaniac
68bc511abb Add documentation about parameter and return value 2022-01-09 10:17:51 +01:00
Dimitris Apostolou
90df43022a Fix typos 2022-01-05 16:35:52 +02:00
Peter Pettersson
38c3449822 Make enum in includes C90 compliant by removing trailing comma. 2021-11-15 16:45:40 +01:00
Edward Thomson
1738f7320d diff: document updated rename limit 2021-10-13 11:36:07 -04:00
Edward Thomson
1ba7c32709 diff: update GIT_DIFF_IGNORE_BLANK_LINES
`GIT_DIFF_IGNORE_BLANK_LINES` needs to be within a (signed) int, per the
`enum` definition of ISO C.
2021-09-21 20:23:44 -04:00
Edward Thomson
ba3595af0f diff: deprecate diff_format_email
`git_diff_format_email` is deprecated in favor of `git_email_create`.
2021-09-18 08:32:42 -04:00
punkymaniac
131f080539 Fix documentation formatting for git_diff_file 2021-07-06 17:39:58 +02:00
yuuri
ed94f54940 diff:add option to ignore blank line changes 2021-05-01 20:26:49 +08:00
Marco Sirabella
965855970e Fix diff_entrycount -> diff_num_deltas doc typo
This just fixes a typo in the documentation, actual rename change was
done in 5f69a31f
2021-04-12 23:54:21 -07:00
Patrick Steinhardt
fb439c975a Merge pull request #5306 from herrerog/patchid
diff: complete support for git patchid
2019-11-28 14:41:58 +01:00
Edward Thomson
4334b1779f blob: use git_object_size_t for object size
Instead of using a signed type (`off_t`) use a new `git_object_size_t`
for the sizes of objects.
2019-11-22 15:10:19 +11:00
Gregory Herrero
b921964b25 diff_print: add support for GIT_DIFF_FORMAT_PATCH_ID.
Git is generating patch-id using a stripped down version of a patch
where hunk header and index information are not present.

Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
2019-11-19 09:33:12 +01:00
Sven Strickroth
452b7f8f4c Don't use enum for flags
Using an `enum` causes trouble when used with C++ as bitwise operations are not possible w/o casting (e.g., `opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;` is invalid as there is no `&=` operator for `enum`).

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2019-09-26 08:26:09 +02:00
Edward Thomson
0b5ba0d744 Rename opt init functions to options_init
In libgit2 nomenclature, when we need to verb a direct object, we name
a function `git_directobject_verb`.  Thus, if we need to init an options
structure named `git_foo_options`, then the name of the function that
does that should be `git_foo_options_init`.

The previous names of `git_foo_init_options` is close - it _sounds_ as
if it's initializing the options of a `foo`, but in fact
`git_foo_options` is its own noun that should be respected.

Deprecate the old names; they'll now call directly to the new ones.
2019-06-14 09:57:00 +01:00
Edward Thomson
22d2062d95 Introduce GIT_CALLBACK macro to enforce cdecl
Since we now always build the library with cdecl calling conventions,
our callbacks should be decorated as such so that users will not be able
to provide callbacks defined with other calling conventions.

The `GIT_CALLBACK` macro will inject the `__cdecl` attribute as
appropriate.
2019-01-17 21:17:32 +00:00
Etienne Samson
a4a028be7b diff: documentation mashup 2018-08-29 22:52:40 +02:00
Patrick Steinhardt
2d9d246409 diff: fix enum value being out of allowed range
The C89 standard states in §6.7.2.2 "Enumeration specifiers":

> The expression that defines the value of an enumeration constant shall
> be an integer constant expression that has a value representable as an
> int.

On most platforms, this effectively limits the range to a 32 bit signed
integer. The enum `git_diff_option_t` though recently gained an entry
`GIT_DIFF_INDENT_HEURISTIC = (1u << 31)`, which breaks this limit.

Fix the issue by using a gap in `git_diff_option_t`'s enum values. While
this has the benefit of retaining our API, it may break applications
which do not get recompiled after upgrading libgit2. But as we are
bumping the soversion on each release anyway and thus force a recompile
of dependents, this is not a problem.
2018-06-12 10:34:10 +02:00
Etienne Samson
04c48afc3c docs: standardize struct git_*_options comments 2018-05-07 21:50:38 +02:00
Etienne Samson
ca5a15e51b docs: standardize comment block for git_*_init_options functions 2018-05-07 21:50:38 +02:00
Jacques Germishuys
5f6383ca50 diff: ensure an unsigned number is shifted 2018-03-08 08:17:29 +02:00
Carlos Martín Nieto
7e3faf58cb diff: expose the "indent heuristic" in the diff options
We default to off, but we might want to consider changing `GIT_DIFF_NORMAL` to
include it.
2017-11-19 08:20:18 +01:00
Alpha
2a3cfc236d Docs: Fix inline comments for git_diff_hunk 2017-08-11 17:15:51 -04:00
Patrick Steinhardt
89a3482829 diff: implement function to calculate patch ID
The upstream git project provides the ability to calculate a so-called
patch ID. Quoting from git-patch-id(1):

    A "patch ID" is nothing but a sum of SHA-1 of the file diffs
    associated with a patch, with whitespace and line numbers ignored."

Patch IDs can be used to identify two patches which are probably the
same thing, e.g. when a patch has been cherry-picked to another branch.

This commit implements a new function `git_diff_patchid`, which gets a
patch and derives an OID from the diff. Note the different terminology
here: a patch in libgit2 are the differences in a single file and a diff
can contain multiple patches for different files. The implementation
matches the upstream implementation and should derive the same OID for
the same diff. In fact, some code has been directly derived from the
upstream implementation.

The upstream implementation has two different modes to calculate patch
IDs, which is the stable and unstable mode. The old way of calculating
the patch IDs was unstable in a sense that a different ordering the
diffs was leading to different results. This oversight was fixed in git
1.9, but as git tries hard to never break existing workflows, the old
and unstable way is still default. The newer and stable way does not
care for ordering of the diff hunks, and in fact it is the mode that
should probably be used today. So right now, we only implement the
stable way of generating the patch ID.
2017-06-26 15:39:26 +02:00
Edward Thomson
adedac5aba diff: treat binary patches with no data special
When creating and printing diffs, deal with binary deltas that have
binary data specially, versus diffs that have a binary file but lack the
actual binary data.
2016-09-05 12:26:47 -05:00
Edward Thomson
e2e7f31ad0 diff: document git_diff_from_buffer 2016-08-05 20:01:52 -04:00
Edward Thomson
002c8e29a1 git_diff_file: move id_abbrev
Move `id_abbrev` to a more reasonable place where it packs more nicely
(before anybody starts using it).
2016-08-03 17:57:37 -04:00
Edward Thomson
728274904f Introduce git_diff_to_buf
Like `git_patch_to_buf`, provide a simple helper method that can
print an entire diff directory to a `git_buf`.
2016-05-26 13:01:09 -05:00
Edward Thomson
7166bb1665 introduce git_diff_from_buffer to parse diffs
Parse diff files into a `git_diff` structure.
2016-05-26 13:01:09 -05:00
Edward Thomson
d68cb73677 diff: include oid length in deltas
Now that `git_diff_delta` data can be produced by reading patch
file data, which may have an abbreviated oid, allow consumers to
know that the id is abbreviated.
2016-05-26 13:01:05 -05:00
Edward Thomson
d34f68261e Patch parsing from patch files 2016-05-26 11:36:11 -05:00
Ephemera
804bcd6b95 Fix typo 2016-02-05 01:59:07 +09:00
Patrick Steinhardt
254e0a33ee diff: include commit message when formatting patch
When formatting a patch as email we do not include the commit's
message in the formatted patch output. Implement this and add a
test that verifies behavior.
2015-12-01 10:12:53 +01:00
Jason Haslam
3138ad9366 Add diff progress callback. 2015-11-02 16:33:58 -05:00
Edward Thomson
53c2296bfe iterator: better document GIT_DIFF_DISABLE_PATHSPEC_MATCH 2015-08-31 19:41:43 -04:00
Edward Thomson
56ed415a24 diff: drop FILELIST_MATCH
Now that non-pathspec matching diffs are implemented at the iterator
level, drop `FILELIST_MATCH`ing.
2015-08-30 19:11:31 -04:00
Edward Thomson
3273ab3f0b diff: better document GIT_DIFF_PATHSPEC_DISABLE
Document that `GIT_DIFF_PATHSPEC_DISABLE` is not necessarily about
explicit path matching, but also includes matching of directory
names.  Enforce this in a test.
2015-08-28 20:45:08 -04:00
Edward Thomson
ef206124de Move filelist into the iterator handling itself. 2015-08-28 18:39:52 -04:00
Pierre-Olivier Latour
ccef5adb63 Added git_diff_index_to_index() 2015-06-30 10:03:32 -07:00
Carlos Martín Nieto
c2418f4613 Rename FALLBACK to UNSPECIFIED
Fallback describes the mechanism, while unspecified explains what the
user is thinking.
2015-06-25 12:48:44 +02:00
Carlos Martín Nieto
c6f489c964 submodule: add an ignore option to status
This lets us specify in the status call which ignore rules we want to
use (optionally falling back to whatever the submodule has in its
configuration).

This removes one of the reasons for having `_set_ignore()` set the value
in-memory. We re-use the `IGNORE_RESET` value for this as it is no
longer relevant but has a similar purpose to `IGNORE_FALLBACK`.

Similarly, we remove `IGNORE_DEFAULT` which does not have use outside of
initializers and move that to fall back to the configuration as well.
2015-06-22 17:02:55 +02:00
Edward Thomson
8147b1aff5 diff: introduce binary diff callbacks
Introduce a new binary diff callback to provide the actual binary
delta contents to callers.  Create this data from the diff contents
(instead of directly from the ODB) to support binary diffs including
the workdir, not just things coming out of the ODB.
2015-06-12 09:39:20 -04:00
Edward Thomson
10549a2df1 Introduce GIT_DIFF_FLAG_EXISTS
Mark the `old_file` and `new_file` sides of a delta with a new bit,
`GIT_DIFF_FLAG_EXISTS`, that introduces that a particular side of
the delta exists in the diff.

This is useful for indicating whether a working directory item exists
or not, in the presence of a conflict.  Diff users may have previously
used DELETED to determine this information.
2015-05-28 09:47:47 -04:00
Edward Thomson
7c94801400 diff/status: introduce conflicts
When diffing against an index, return a new `GIT_DELTA_CONFLICTED`
delta type for items that are conflicted.  For a single file path,
only one delta will be produced (despite the fact that there are
multiple entries in the index).

Index iterators now have the (optional) ability to return conflicts
in the index.  Prior to this change, they would be omitted, and callers
(like diff) would omit conflicted index entries entirely.
2015-05-28 09:44:02 -04:00
Edward Thomson
4beab1f8bb checkout: break case-changes into delete/add
When checking out with a case-insensitive working directory, we
want to change the case of items in the working directory to
reflect changes that occured in the checkout target.  Diff now
has an option to break case-changing renames into delete/add.
2015-05-04 07:18:28 -05:00
Edward Thomson
3538f8f131 diff docs: update git_diff_delta description 2015-02-03 13:41:35 -05:00