Commit Graph

136 Commits

Author SHA1 Message Date
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
Pierre-Olivier Latour
d88766c4e1 Changed context_lines and interhunk_lines to uint32_t to match struct s_xdemitconf 2014-10-27 09:17:01 -07:00
Carlos Martín Nieto
12e1803188 Update some documentation 2014-10-18 15:22:19 +02:00
Ciro Santilli
062804570c Join typedef and struct definitions in single file. 2014-09-24 11:00:51 +02:00
Alan Rogers
35b1471f01 Move the UNREADABLE enums to the correct group. 2014-07-22 11:17:42 +10:00
Alan Rogers
dc49e1b5b3 Merge remote-tracking branch 'origin/development' into fix-git-status-list-new-unreadable-folder
Conflicts:
	include/git2/diff.h
2014-06-04 15:36:28 -07:00
Alan Rogers
7b491a7dea GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED 2014-06-03 17:50:00 -07:00
Carlos Martín Nieto
11e2665e50 Formatting fixes for the docs
These are some issues I found while playing around with the new parser
for docurium.
2014-06-03 16:05:35 +02:00
Alan Rogers
61bef72dc3 Start adding GIT_DELTA_UNREADABLE and GIT_STATUS_WT_UNREADABLE. 2014-05-20 23:57:40 +10:00
Russell Belfer
702efc891f Make init_options fns use unsigned ints and macro
Use an unsigned int for the version and add a helper macro so the
code is simplified (and so the error message is a common string).
2014-05-02 09:21:33 -07:00
Russell Belfer
9c8ed49997 Remove trace / add git_diff_perfdata struct + api 2014-05-02 09:21:33 -07:00
Russell Belfer
7a2e56a3f6 Get rid of redundant git_diff_options_init fn
Since git_diff_init_options was introduced, remove this old fn.
2014-05-02 09:21:33 -07:00
Russell Belfer
94fb4aadc8 Add diff option to update index stat cache
When diff is scanning the working directory, if it finds a file
where it is not sure if the index entry matches the working dir,
it will recalculate the OID (which is pretty expensive).  This
adds a new flag to diff so that if the OID calculation finds that
the file actually has not changed (i.e. just the modified time was
altered or such), then it will refresh the stat cache in the index
so that future calls to diff will not have to check the oid again.
2014-05-02 09:21:33 -07:00
Vicent Marti
212b6205d7 Merge pull request #2291 from ethomson/patch_binary
patch: emit deflated binary patches (optionally)
2014-04-23 09:27:15 -07:00
Edward Thomson
e349ed500b patch: emit binary patches (optionally) 2014-04-22 19:08:21 -05:00
Russell Belfer
8d09efa24e Use git_diff_get_stats in example/diff + refactor
This takes the `--stat` and related example options in the example
diff.c program and converts them to use the `git_diff_get_stats`
API which nicely formats stats for you.

I went to add bar-graph scaling to the stats formatter and noticed
that the `git_diff_stats` structure was holding on to all of the
`git_patch` objects.  Unfortunately, each of these objects keeps
the full text of the diff in memory, so this is very expensive.  I
ended up modifying `git_diff_stats` to keep just the data that it
needs to keep and allowed it to release the patches.  Then, I added
width scaling to the output on top of that.

In making the diff example program match 'git diff' output, I ended
up removing an newline from the sumamry output which I then had to
compensate for in the email formatting to match the expectations.

Lastly, I went through and refactored the tests to use a couple of
helper functions and reduce the overall amount of code there.
2014-04-22 12:33:27 -07:00
Russell Belfer
12e422a056 Some doc and examples/diff.c changes
I was playing with "git diff-index" and wanted to be able to
emulate that behavior a little more closely with the diff example.

Also, I wanted to play with running `git_diff_tree_to_workdir`
directly even though core Git doesn't exactly have the equivalent,
so I added a command line option for that and tweaked some other
things in the example code.

This changes a minor output thing in that the "raw" print helper
function will no longer add ellipses (...) if the OID is not
actually abbreviated.
2014-04-22 09:17:29 -07:00
Jacques Germishuys
d8cc1fb653 Introduce git_diff_format_email and git_diff_commit_as_email 2014-04-15 17:22:17 +02:00
Jacques Germishuys
360314c9db Introduce git_diff_get_stats, git_diff_stats_files_changed, git_diff_stats_insertions, git_diff_stats_deletions and git_diff_stats_to_buf 2014-04-15 17:22:12 +02:00
Matthew Bowen
b9f819978c Added function-based initializers for every options struct.
The basic structure of each function is courtesy of arrbee.
2014-03-05 21:49:23 -05:00
Russell Belfer
6789b7a75d Add buffer to buffer diff and patch APIs
This adds `git_diff_buffers` and `git_patch_from_buffers`.  This
also includes a bunch of internal refactoring to increase the
shared code between these functions and the blob-to-blob and
blob-to-buffer APIs, as well as some higher level assert helpers
in the tests to also remove redundancy.
2014-02-27 14:13:22 -08:00
Carlos Martín Nieto
86bfc3e1c6 diff: change id abbrev option's name to id_abbrev
Same as the other commits in the series, we use 'id' when talking about
thing rather than the datatype.
2014-01-25 08:15:44 +01:00
Carlos Martín Nieto
9950bb4e8d diff: rename the file's 'oid' to 'id'
In the same vein as the previous commits in this series.
2014-01-25 08:15:44 +01:00
Russell Belfer
373cf6a932 Update docs for new callback return value behavior 2013-12-11 10:57:50 -08:00
Russell Belfer
9f77b3f6f5 Add config read fns with controlled error behavior
This adds `git_config__lookup_entry` which will look up a key in
a config and return either the entry or NULL if the key was not
present.  Optionally, it can either suppress all errors or can
return them (although not finding the key is not an error for this
function).  Unlike other accessors, this does not normalize the
config key string, so it must only be used when the key is known
to be in normalized form (i.e. all lower-case before the first dot
and after the last dot, with no invalid characters).

This also adds three high-level helper functions to look up config
values with no errors and a fallback value.  The three functions
are for string, bool, and int values, and will resort to the
fallback value for any error that arises.  They are:

* `git_config__get_string_force`
* `git_config__get_bool_force`
* `git_config__get_int_force`

None of them normalize the config `key` either, so they can only
be used for internal cases where the key is known to be in normal
format.
2013-12-11 10:57:49 -08:00
Ben Straub
a7c83aec21 Clarify docs 2013-12-06 13:39:08 -08:00
Ben Straub
710f383868 Clarify default value and behavior 2013-12-06 09:32:09 -08:00
Ben Straub
a6ebc2bdb3 Introduce GIT_DIFF_FIND_BY_CONFIG 2013-12-05 08:11:00 -08:00
Russell Belfer
f62c174d0d GIT_DIFF_FIND_REMOVE_UNMODIFIED sounds better 2013-12-02 13:49:58 -08:00
Russell Belfer
97ad85b88d Add GIT_DIFF_FIND_DELETE_UNMODIFIED flag
When doing copy detection, it is often necessary to include
UNMODIFIED records in the git_diff so they are available as source
records for GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED.  Yet in the final
diff, often you will not want to have these UNMODIFIED records.
This adds a flag which marks these UNMODIFIED records for deletion
from the diff list so they will be removed after the rename detect
phase is over.
2013-12-02 13:30:05 -08:00
Nick Hengeveld
d8e7ffc2a2 Add content offset to git_diff_line
For additions and deletions, external consumers like subversion
can make use of the content offset to generate diffs in their
proprietary formats.
2013-11-18 14:03:25 -08:00
Russell Belfer
a5c16f3cfb Add git_diff_options_init helper
Sometimes the static initializer for git_diff_options cannot be
used and since setting them to all zeroes doesn't actually work
quite right, this adds a new helper for that situation.

This also adds an explicit new value to the submodule settings
options to be used when those enums need static initialization.
2013-11-01 10:20:51 -07:00
Russell Belfer
4bf630b6ba Make diff and status perform soft index reload
This changes `git_index_read` to have two modes - a hard index
reload that always resets the index to match the on-disk data
(which was the old behavior) and a soft index reload that uses
the timestamp / file size information and only replaces the index
data if the file on disk has been modified.

This then updates the git_status code to do a soft reload unless
the new GIT_STATUS_OPT_NO_REFRESH flag is passed in.

This also changes the behavior of the git_diff functions that use
the index so that when an index is not explicitly passed in (i.e.
when the functions call git_repository_index for you), they will
also do a soft reload for you.

This intentionally breaks the file signature of git_index_read
because there has been some confusion about the behavior previously
and it seems like all existing uses of the API should probably be
examined to select the desired behavior.
2013-11-01 10:20:51 -07:00
Russell Belfer
7ce60099ee Fix typo 2013-10-22 11:12:44 -07:00
Russell Belfer
5de4ec8104 Implement patience and minimal diff flags
It seems that to implement these options, we just have to pass
the appropriate flags through to the libxdiff code taken from
core git.  So let's do it (and add a test).
2013-10-21 15:36:38 -07:00
Russell Belfer
3b5f795446 Create git_diff_line and extend git_diff_hunk
Instead of having functions with so very many parameters to pass
hunk and line data, this takes the existing git_diff_hunk struct
and extends it with more hunk data, plus adds a git_diff_line.
Those structs are used to pass back hunk and line data instead of
the old APIs that took tons of parameters.

Some work that was previously only being done for git_diff_patch
creation (scanning the diff content for exact line counts) is now
done for all callbacks, but the performance difference should not
be noticable.
2013-10-21 13:42:42 -07:00
Russell Belfer
74a627f045 Tweak to git_diff_delta structure for nfiles
While the base git_diff_delta structure always contains two files,
when we introduce conflict data, it will be helpful to have an
indicator when an additional file is involved.
2013-10-21 09:07:19 -07:00
Russell Belfer
10672e3e45 Diff API cleanup
This lays groundwork for separating formatting options from diff
creation options.  This groups the formatting flags separately
from the diff list creation flags and reorders the options.  This
also tweaks some APIs to further separate code that uses patches
from code that just looks at git_diffs.
2013-10-15 15:10:07 -07:00
Russell Belfer
3ff1d12373 Rename diff objects and split patch.h
This makes no functional change to diff but renames a couple of
the objects and splits the new git_patch (formerly git_diff_patch)
into a new header file.
2013-10-11 14:51:54 -07:00
Edward Thomson
17c7fbf6d2 Split rewrites, status doesn't return rewrites
Ensure that we apply splits to rewrites, even if we're not
interested in examining it closely for rename/copy detection.

In keeping with core git, status should not display rewrites,
it should simply show files as "modified".
2013-08-28 08:30:19 -05:00
Russell Belfer
eb1c1707ab Restore GIT_DIFF_LINE_BINARY usage
This restores the usage of GIT_DIFF_LINE_BINARY for the diff
output line that reads "Binary files x and y differ" so that it
can be optionally colorized independently of the file header.
2013-07-23 15:45:58 -07:00
Russell Belfer
197b8966db Add hunk/file headers to git_diff_patch_size
This allows git_diff_patch_size to account for hunk headers and
file headers in the returned size.  This required some refactoring
of the code that is used to print file headers so that it could be
invoked by the git_diff_patch_size API.

Also this increases the test coverage and fixes an off-by-one bug
in the size calculation when newline changes happen at the end of
the file.
2013-07-23 14:34:31 -07:00
Russell Belfer
b4a4cf24a5 Add git_diff_patch_size() API
This adds a new API to get the size in bytes of the diffs in a
git_diff_patch object.
2013-07-22 16:07:56 -07:00
Russell Belfer
f9775a37aa Add ignore_submodules to diff options
This adds correct support for an equivalent to --ignore-submodules
in diff, where an actual ignore value can be passed to diff to
override the per submodule settings in the configuration.

This required tweaking the constants for ignore values so that
zero would not be used and could represent an unset option to the
diff.  This was an opportunity to move the submodule values into
include/git2/types.h and to rename the poorly named DEFAULT values
for ignore and update constants to RESET instead.

Now the GIT_DIFF_IGNORE_SUBMODULES flag is exactly the same as
setting the ignore_submodules option to GIT_SUBMODULE_IGNORE_ALL
(which is actually a minor change from the old behavior in that
submodules will now be treated as UNMODIFIED deltas instead of
being left out totally - if you set GIT_DIFF_INCLUDE_UNMODIFIED).

This includes tests for the various new settings.
2013-07-10 12:15:03 -07:00