rugged 0.17.0.b7 → 0.18.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +88 -32
- data/ext/rugged/extconf.rb +4 -2
- data/ext/rugged/rugged.c +72 -10
- data/ext/rugged/rugged.h +14 -10
- data/ext/rugged/rugged_blob.c +8 -10
- data/ext/rugged/rugged_branch.c +11 -14
- data/ext/rugged/rugged_commit.c +31 -24
- data/ext/rugged/rugged_config.c +2 -2
- data/ext/rugged/rugged_index.c +133 -198
- data/ext/rugged/rugged_note.c +372 -0
- data/ext/rugged/rugged_object.c +50 -22
- data/ext/rugged/rugged_reference.c +122 -130
- data/ext/rugged/rugged_remote.c +72 -29
- data/ext/rugged/rugged_repo.c +402 -20
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +110 -0
- data/ext/rugged/rugged_signature.c +23 -7
- data/ext/rugged/rugged_tag.c +32 -16
- data/ext/rugged/rugged_tree.c +44 -15
- data/lib/rugged.rb +1 -0
- data/lib/rugged/index.rb +8 -0
- data/lib/rugged/remote.rb +13 -0
- data/lib/rugged/repository.rb +3 -3
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +13 -15
- data/test/branch_test.rb +32 -67
- data/test/commit_test.rb +50 -12
- data/test/config_test.rb +12 -11
- data/test/coverage/HEAD.json +1 -1
- data/test/coverage/cover.rb +40 -21
- data/test/errors_test.rb +34 -0
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
- data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
- data/test/index_test.rb +65 -69
- data/test/lib_test.rb +76 -11
- data/test/note_test.rb +158 -0
- data/test/object_test.rb +8 -11
- data/test/reference_test.rb +77 -85
- data/test/remote_test.rb +86 -8
- data/test/repo_pack_test.rb +9 -7
- data/test/repo_reset_test.rb +80 -0
- data/test/repo_test.rb +176 -53
- data/test/tag_test.rb +44 -7
- data/test/test_helper.rb +63 -35
- data/test/tree_test.rb +34 -13
- data/test/walker_test.rb +14 -14
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
- data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
- data/vendor/libgit2/deps/regex/regcomp.c +7 -6
- data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
- data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
- data/vendor/libgit2/deps/regex/regexec.c +5 -5
- data/vendor/libgit2/include/git2.h +5 -1
- data/vendor/libgit2/include/git2/attr.h +4 -2
- data/vendor/libgit2/include/git2/blob.h +39 -12
- data/vendor/libgit2/include/git2/branch.h +123 -35
- data/vendor/libgit2/include/git2/checkout.h +206 -48
- data/vendor/libgit2/include/git2/clone.h +72 -27
- data/vendor/libgit2/include/git2/commit.h +20 -17
- data/vendor/libgit2/include/git2/common.h +67 -1
- data/vendor/libgit2/include/git2/config.h +81 -60
- data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
- data/vendor/libgit2/include/git2/diff.h +459 -150
- data/vendor/libgit2/include/git2/errors.h +9 -1
- data/vendor/libgit2/include/git2/graph.h +41 -0
- data/vendor/libgit2/include/git2/ignore.h +7 -6
- data/vendor/libgit2/include/git2/index.h +323 -97
- data/vendor/libgit2/include/git2/indexer.h +27 -59
- data/vendor/libgit2/include/git2/inttypes.h +4 -0
- data/vendor/libgit2/include/git2/merge.h +13 -3
- data/vendor/libgit2/include/git2/message.h +14 -8
- data/vendor/libgit2/include/git2/net.h +9 -7
- data/vendor/libgit2/include/git2/notes.h +88 -29
- data/vendor/libgit2/include/git2/object.h +16 -6
- data/vendor/libgit2/include/git2/odb.h +80 -17
- data/vendor/libgit2/include/git2/odb_backend.h +47 -11
- data/vendor/libgit2/include/git2/oid.h +26 -17
- data/vendor/libgit2/include/git2/pack.h +62 -8
- data/vendor/libgit2/include/git2/push.h +131 -0
- data/vendor/libgit2/include/git2/refdb.h +103 -0
- data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
- data/vendor/libgit2/include/git2/reflog.h +30 -21
- data/vendor/libgit2/include/git2/refs.h +215 -193
- data/vendor/libgit2/include/git2/refspec.h +22 -2
- data/vendor/libgit2/include/git2/remote.h +158 -37
- data/vendor/libgit2/include/git2/repository.h +150 -31
- data/vendor/libgit2/include/git2/reset.h +43 -9
- data/vendor/libgit2/include/git2/revparse.h +48 -4
- data/vendor/libgit2/include/git2/revwalk.h +25 -10
- data/vendor/libgit2/include/git2/signature.h +20 -12
- data/vendor/libgit2/include/git2/stash.h +121 -0
- data/vendor/libgit2/include/git2/status.h +122 -53
- data/vendor/libgit2/include/git2/strarray.h +17 -11
- data/vendor/libgit2/include/git2/submodule.h +42 -7
- data/vendor/libgit2/include/git2/tag.h +72 -59
- data/vendor/libgit2/include/git2/threads.h +4 -2
- data/vendor/libgit2/include/git2/trace.h +68 -0
- data/vendor/libgit2/include/git2/transport.h +328 -0
- data/vendor/libgit2/include/git2/tree.h +149 -120
- data/vendor/libgit2/include/git2/types.h +13 -12
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/src/amiga/map.c +2 -2
- data/vendor/libgit2/src/attr.c +58 -48
- data/vendor/libgit2/src/attr.h +4 -18
- data/vendor/libgit2/src/attr_file.c +30 -6
- data/vendor/libgit2/src/attr_file.h +6 -8
- data/vendor/libgit2/src/attrcache.h +24 -0
- data/vendor/libgit2/src/blob.c +30 -7
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +361 -68
- data/vendor/libgit2/src/branch.h +17 -0
- data/vendor/libgit2/src/bswap.h +1 -1
- data/vendor/libgit2/src/buf_text.c +291 -0
- data/vendor/libgit2/src/buf_text.h +122 -0
- data/vendor/libgit2/src/buffer.c +27 -101
- data/vendor/libgit2/src/buffer.h +54 -39
- data/vendor/libgit2/src/cache.c +15 -6
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +3 -1
- data/vendor/libgit2/src/checkout.c +1165 -222
- data/vendor/libgit2/src/checkout.h +24 -0
- data/vendor/libgit2/src/clone.c +171 -86
- data/vendor/libgit2/src/commit.c +44 -45
- data/vendor/libgit2/src/commit.h +3 -3
- data/vendor/libgit2/src/commit_list.c +194 -0
- data/vendor/libgit2/src/commit_list.h +49 -0
- data/vendor/libgit2/src/common.h +44 -10
- data/vendor/libgit2/src/compress.c +1 -1
- data/vendor/libgit2/src/compress.h +1 -1
- data/vendor/libgit2/src/config.c +211 -124
- data/vendor/libgit2/src/config.h +23 -4
- data/vendor/libgit2/src/config_cache.c +2 -2
- data/vendor/libgit2/src/config_file.c +129 -53
- data/vendor/libgit2/src/config_file.h +10 -8
- data/vendor/libgit2/src/crlf.c +66 -67
- data/vendor/libgit2/src/date.c +12 -12
- data/vendor/libgit2/src/delta-apply.c +14 -1
- data/vendor/libgit2/src/delta-apply.h +18 -1
- data/vendor/libgit2/src/delta.c +40 -107
- data/vendor/libgit2/src/delta.h +19 -17
- data/vendor/libgit2/src/diff.c +347 -496
- data/vendor/libgit2/src/diff.h +27 -1
- data/vendor/libgit2/src/diff_output.c +564 -249
- data/vendor/libgit2/src/diff_output.h +15 -8
- data/vendor/libgit2/src/diff_tform.c +687 -0
- data/vendor/libgit2/src/errors.c +27 -36
- data/vendor/libgit2/src/fetch.c +13 -351
- data/vendor/libgit2/src/fetch.h +13 -3
- data/vendor/libgit2/src/fetchhead.c +295 -0
- data/vendor/libgit2/src/fetchhead.h +34 -0
- data/vendor/libgit2/src/filebuf.c +42 -15
- data/vendor/libgit2/src/filebuf.h +4 -2
- data/vendor/libgit2/src/fileops.c +466 -113
- data/vendor/libgit2/src/fileops.h +154 -28
- data/vendor/libgit2/src/filter.c +3 -75
- data/vendor/libgit2/src/filter.h +1 -29
- data/vendor/libgit2/src/fnmatch.c +1 -1
- data/vendor/libgit2/src/fnmatch.h +1 -1
- data/vendor/libgit2/src/global.c +54 -10
- data/vendor/libgit2/src/global.h +10 -1
- data/vendor/libgit2/src/graph.c +178 -0
- data/vendor/libgit2/src/hash.c +25 -52
- data/vendor/libgit2/src/hash.h +21 -9
- data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
- data/vendor/libgit2/src/hash/hash_generic.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
- data/vendor/libgit2/src/hash/hash_win32.c +291 -0
- data/vendor/libgit2/src/hash/hash_win32.h +140 -0
- data/vendor/libgit2/src/hashsig.c +368 -0
- data/vendor/libgit2/src/hashsig.h +72 -0
- data/vendor/libgit2/src/ignore.c +22 -15
- data/vendor/libgit2/src/ignore.h +6 -1
- data/vendor/libgit2/src/index.c +770 -171
- data/vendor/libgit2/src/index.h +13 -5
- data/vendor/libgit2/src/indexer.c +286 -431
- data/vendor/libgit2/src/iterator.c +854 -466
- data/vendor/libgit2/src/iterator.h +134 -109
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +296 -0
- data/vendor/libgit2/src/merge.h +22 -0
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/message.h +1 -1
- data/vendor/libgit2/src/mwindow.c +35 -30
- data/vendor/libgit2/src/mwindow.h +2 -2
- data/vendor/libgit2/src/netops.c +162 -98
- data/vendor/libgit2/src/netops.h +50 -15
- data/vendor/libgit2/src/notes.c +109 -58
- data/vendor/libgit2/src/notes.h +2 -1
- data/vendor/libgit2/src/object.c +46 -57
- data/vendor/libgit2/src/object.h +1 -8
- data/vendor/libgit2/src/odb.c +151 -40
- data/vendor/libgit2/src/odb.h +5 -1
- data/vendor/libgit2/src/odb_loose.c +4 -5
- data/vendor/libgit2/src/odb_pack.c +122 -80
- data/vendor/libgit2/src/offmap.h +65 -0
- data/vendor/libgit2/src/oid.c +12 -4
- data/vendor/libgit2/src/oidmap.h +1 -1
- data/vendor/libgit2/src/pack-objects.c +88 -61
- data/vendor/libgit2/src/pack-objects.h +8 -8
- data/vendor/libgit2/src/pack.c +293 -28
- data/vendor/libgit2/src/pack.h +49 -4
- data/vendor/libgit2/src/path.c +103 -14
- data/vendor/libgit2/src/path.h +23 -7
- data/vendor/libgit2/src/pathspec.c +168 -0
- data/vendor/libgit2/src/pathspec.h +40 -0
- data/vendor/libgit2/src/pool.c +29 -4
- data/vendor/libgit2/src/pool.h +8 -1
- data/vendor/libgit2/src/posix.c +26 -27
- data/vendor/libgit2/src/posix.h +2 -3
- data/vendor/libgit2/src/pqueue.c +23 -1
- data/vendor/libgit2/src/pqueue.h +23 -1
- data/vendor/libgit2/src/push.c +653 -0
- data/vendor/libgit2/src/push.h +51 -0
- data/vendor/libgit2/src/refdb.c +185 -0
- data/vendor/libgit2/src/refdb.h +46 -0
- data/vendor/libgit2/src/refdb_fs.c +1024 -0
- data/vendor/libgit2/src/refdb_fs.h +15 -0
- data/vendor/libgit2/src/reflog.c +77 -45
- data/vendor/libgit2/src/reflog.h +1 -3
- data/vendor/libgit2/src/refs.c +366 -1326
- data/vendor/libgit2/src/refs.h +22 -13
- data/vendor/libgit2/src/refspec.c +46 -7
- data/vendor/libgit2/src/refspec.h +11 -1
- data/vendor/libgit2/src/remote.c +758 -120
- data/vendor/libgit2/src/remote.h +10 -5
- data/vendor/libgit2/src/repo_template.h +6 -6
- data/vendor/libgit2/src/repository.c +315 -96
- data/vendor/libgit2/src/repository.h +5 -3
- data/vendor/libgit2/src/reset.c +99 -81
- data/vendor/libgit2/src/revparse.c +157 -84
- data/vendor/libgit2/src/revwalk.c +68 -470
- data/vendor/libgit2/src/revwalk.h +44 -0
- data/vendor/libgit2/src/sha1_lookup.c +1 -1
- data/vendor/libgit2/src/sha1_lookup.h +1 -1
- data/vendor/libgit2/src/signature.c +68 -200
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/stash.c +663 -0
- data/vendor/libgit2/src/status.c +101 -79
- data/vendor/libgit2/src/strmap.h +1 -1
- data/vendor/libgit2/src/submodule.c +67 -51
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/tag.c +35 -29
- data/vendor/libgit2/src/tag.h +1 -1
- data/vendor/libgit2/src/thread-utils.c +1 -1
- data/vendor/libgit2/src/thread-utils.h +2 -2
- data/vendor/libgit2/src/trace.c +39 -0
- data/vendor/libgit2/src/trace.h +56 -0
- data/vendor/libgit2/src/transport.c +81 -34
- data/vendor/libgit2/src/transports/cred.c +60 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
- data/vendor/libgit2/src/transports/git.c +234 -127
- data/vendor/libgit2/src/transports/http.c +761 -433
- data/vendor/libgit2/src/transports/local.c +460 -64
- data/vendor/libgit2/src/transports/smart.c +345 -0
- data/vendor/libgit2/src/transports/smart.h +179 -0
- data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
- data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
- data/vendor/libgit2/src/transports/winhttp.c +1136 -0
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree-cache.h +1 -1
- data/vendor/libgit2/src/tree.c +239 -166
- data/vendor/libgit2/src/tree.h +11 -2
- data/vendor/libgit2/src/tsort.c +39 -23
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +12 -2
- data/vendor/libgit2/src/unix/realpath.c +30 -0
- data/vendor/libgit2/src/util.c +250 -13
- data/vendor/libgit2/src/util.h +71 -14
- data/vendor/libgit2/src/vector.c +123 -60
- data/vendor/libgit2/src/vector.h +24 -22
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/dir.h +1 -1
- data/vendor/libgit2/src/win32/error.c +77 -0
- data/vendor/libgit2/src/win32/error.h +13 -0
- data/vendor/libgit2/src/win32/findfile.c +143 -54
- data/vendor/libgit2/src/win32/findfile.h +10 -6
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
- data/vendor/libgit2/src/win32/posix.h +10 -1
- data/vendor/libgit2/src/win32/posix_w32.c +132 -63
- data/vendor/libgit2/src/win32/precompiled.c +1 -1
- data/vendor/libgit2/src/win32/pthread.c +1 -1
- data/vendor/libgit2/src/win32/pthread.h +1 -1
- data/vendor/libgit2/src/win32/utf-conv.c +5 -5
- data/vendor/libgit2/src/win32/utf-conv.h +3 -3
- data/vendor/libgit2/src/win32/version.h +20 -0
- metadata +308 -252
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb~ +0 -218
- data/vendor/libgit2/src/pkt.h +0 -91
- data/vendor/libgit2/src/ppc/sha1.c +0 -70
- data/vendor/libgit2/src/ppc/sha1.h +0 -26
- data/vendor/libgit2/src/protocol.c +0 -110
- data/vendor/libgit2/src/protocol.h +0 -21
- data/vendor/libgit2/src/sha1.h +0 -33
- data/vendor/libgit2/src/transport.h +0 -148
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#ifndef INCLUDE_git_cred_helpers_h__
|
8
|
+
#define INCLUDE_git_cred_helpers_h__
|
9
|
+
|
10
|
+
#include "git2/transport.h"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @file git2/cred_helpers.h
|
14
|
+
* @brief Utility functions for credential management
|
15
|
+
* @defgroup git_cred_helpers credential management helpers
|
16
|
+
* @ingroup Git
|
17
|
+
* @{
|
18
|
+
*/
|
19
|
+
GIT_BEGIN_DECL
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Payload for git_cred_stock_userpass_plaintext.
|
23
|
+
*/
|
24
|
+
typedef struct git_cred_userpass_payload {
|
25
|
+
char *username;
|
26
|
+
char *password;
|
27
|
+
} git_cred_userpass_payload;
|
28
|
+
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Stock callback usable as a git_cred_acquire_cb. This calls
|
32
|
+
* git_cred_userpass_plaintext_new unless the protocol has not specified
|
33
|
+
* GIT_CREDTYPE_USERPASS_PLAINTEXT as an allowed type.
|
34
|
+
*
|
35
|
+
* @param cred The newly created credential object.
|
36
|
+
* @param url The resource for which we are demanding a credential.
|
37
|
+
* @param username_from_url The username that was embedded in a "user@host"
|
38
|
+
* remote url, or NULL if not included.
|
39
|
+
* @param allowed_types A bitmask stating which cred types are OK to return.
|
40
|
+
* @param payload The payload provided when specifying this callback. (This is
|
41
|
+
* interpreted as a `git_cred_userpass_payload*`.)
|
42
|
+
*/
|
43
|
+
GIT_EXTERN(int) git_cred_userpass(
|
44
|
+
git_cred **cred,
|
45
|
+
const char *url,
|
46
|
+
const char *user_from_url,
|
47
|
+
unsigned int allowed_types,
|
48
|
+
void *payload);
|
49
|
+
|
50
|
+
|
51
|
+
/** @} */
|
52
|
+
GIT_END_DECL
|
53
|
+
#endif
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (C)
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
3
|
*
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
@@ -17,6 +17,9 @@
|
|
17
17
|
* @file git2/diff.h
|
18
18
|
* @brief Git tree and file differencing routines.
|
19
19
|
*
|
20
|
+
* Overview
|
21
|
+
* --------
|
22
|
+
*
|
20
23
|
* Calculating diffs is generally done in two phases: building a diff list
|
21
24
|
* then traversing the diff list. This makes is easier to share logic
|
22
25
|
* across the various types of diffs (tree vs tree, workdir vs index, etc.),
|
@@ -24,6 +27,35 @@
|
|
24
27
|
* such as rename detected, in between the steps. When you are done with a
|
25
28
|
* diff list object, it must be freed.
|
26
29
|
*
|
30
|
+
* Terminology
|
31
|
+
* -----------
|
32
|
+
*
|
33
|
+
* To understand the diff APIs, you should know the following terms:
|
34
|
+
*
|
35
|
+
* - A `diff` or `diff list` represents the cumulative list of differences
|
36
|
+
* between two snapshots of a repository (possibly filtered by a set of
|
37
|
+
* file name patterns). This is the `git_diff_list` object.
|
38
|
+
* - A `delta` is a file pair with an old and new revision. The old version
|
39
|
+
* may be absent if the file was just created and the new version may be
|
40
|
+
* absent if the file was deleted. A diff is mostly just a list of deltas.
|
41
|
+
* - A `binary` file / delta is a file (or pair) for which no text diffs
|
42
|
+
* should be generated. A diff list can contain delta entries that are
|
43
|
+
* binary, but no diff content will be output for those files. There is
|
44
|
+
* a base heuristic for binary detection and you can further tune the
|
45
|
+
* behavior with git attributes or diff flags and option settings.
|
46
|
+
* - A `hunk` is a span of modified lines in a delta along with some stable
|
47
|
+
* surrounding context. You can configure the amount of context and other
|
48
|
+
* properties of how hunks are generated. Each hunk also comes with a
|
49
|
+
* header that described where it starts and ends in both the old and new
|
50
|
+
* versions in the delta.
|
51
|
+
* - A `line` is a range of characters inside a hunk. It could be a context
|
52
|
+
* line (i.e. in both old and new versions), an added line (i.e. only in
|
53
|
+
* the new version), or a removed line (i.e. only in the old version).
|
54
|
+
* Unfortunately, we don't know anything about the encoding of data in the
|
55
|
+
* file being diffed, so we cannot tell you much about the line content.
|
56
|
+
* Line data will not be NUL-byte terminated, however, because it will be
|
57
|
+
* just a span of bytes inside the larger file.
|
58
|
+
*
|
27
59
|
* @ingroup Git
|
28
60
|
* @{
|
29
61
|
*/
|
@@ -33,7 +65,7 @@ GIT_BEGIN_DECL
|
|
33
65
|
* Flags for diff options. A combination of these flags can be passed
|
34
66
|
* in via the `flags` value in the `git_diff_options`.
|
35
67
|
*/
|
36
|
-
enum {
|
68
|
+
typedef enum {
|
37
69
|
/** Normal diff, the default */
|
38
70
|
GIT_DIFF_NORMAL = 0,
|
39
71
|
/** Reverse the sides of the diff */
|
@@ -56,10 +88,9 @@ enum {
|
|
56
88
|
GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
|
57
89
|
/** Include unmodified files in the diff list */
|
58
90
|
GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
|
59
|
-
/** Even with
|
60
|
-
*
|
61
|
-
*
|
62
|
-
* be included, too.
|
91
|
+
/** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked directory
|
92
|
+
* will be marked with only a single entry in the diff list; this flag
|
93
|
+
* adds all files under the directory as UNTRACKED entries, too.
|
63
94
|
*/
|
64
95
|
GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
|
65
96
|
/** If the pathspec is set in the diff options, this flags means to
|
@@ -86,154 +117,237 @@ enum {
|
|
86
117
|
* mode set to tree. Note: the tree SHA will not be available.
|
87
118
|
*/
|
88
119
|
GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1 << 16),
|
89
|
-
|
90
|
-
|
91
|
-
/**
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
*
|
98
|
-
* - flags: a combination of the GIT_DIFF_... values above
|
99
|
-
* - context_lines: number of lines of context to show around diffs
|
100
|
-
* - interhunk_lines: min lines between diff hunks to merge them
|
101
|
-
* - old_prefix: "directory" to prefix to old file names (default "a")
|
102
|
-
* - new_prefix: "directory" to prefix to new file names (default "b")
|
103
|
-
* - pathspec: array of paths / patterns to constrain diff
|
104
|
-
* - max_size: maximum blob size to diff, above this treated as binary
|
105
|
-
*/
|
106
|
-
typedef struct {
|
107
|
-
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
|
108
|
-
uint16_t context_lines; /**< defaults to 3 */
|
109
|
-
uint16_t interhunk_lines; /**< defaults to 0 */
|
110
|
-
char *old_prefix; /**< defaults to "a" */
|
111
|
-
char *new_prefix; /**< defaults to "b" */
|
112
|
-
git_strarray pathspec; /**< defaults to show all paths */
|
113
|
-
git_off_t max_size; /**< defaults to 512Mb */
|
114
|
-
} git_diff_options;
|
120
|
+
/** Ignore file mode changes */
|
121
|
+
GIT_DIFF_IGNORE_FILEMODE = (1 << 17),
|
122
|
+
/** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
|
123
|
+
* will be marked with only a single entry in the diff list; this flag
|
124
|
+
* adds all files under the directory as IGNORED entries, too.
|
125
|
+
*/
|
126
|
+
GIT_DIFF_RECURSE_IGNORED_DIRS = (1 << 18),
|
127
|
+
} git_diff_option_t;
|
115
128
|
|
116
129
|
/**
|
117
130
|
* The diff list object that contains all individual file deltas.
|
131
|
+
*
|
132
|
+
* This is an opaque structure which will be allocated by one of the diff
|
133
|
+
* generator functions below (such as `git_diff_tree_to_tree`). You are
|
134
|
+
* responsible for releasing the object memory when done, using the
|
135
|
+
* `git_diff_list_free()` function.
|
118
136
|
*/
|
119
137
|
typedef struct git_diff_list git_diff_list;
|
120
138
|
|
121
139
|
/**
|
122
|
-
* Flags
|
140
|
+
* Flags for the delta object and the file objects on each side.
|
123
141
|
*
|
124
|
-
*
|
125
|
-
*
|
142
|
+
* These flags are used for both the `flags` value of the `git_diff_delta`
|
143
|
+
* and the flags for the `git_diff_file` objects representing the old and
|
144
|
+
* new sides of the delta. Values outside of this public range should be
|
145
|
+
* considered reserved for internal or future use.
|
126
146
|
*/
|
127
|
-
enum {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
GIT_DIFF_FILE_FREE_DATA = (1 << 4), /** internal file data is allocated */
|
133
|
-
GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */
|
134
|
-
GIT_DIFF_FILE_NO_DATA = (1 << 6), /** file data should not be loaded */
|
135
|
-
};
|
147
|
+
typedef enum {
|
148
|
+
GIT_DIFF_FLAG_BINARY = (1 << 0), /** file(s) treated as binary data */
|
149
|
+
GIT_DIFF_FLAG_NOT_BINARY = (1 << 1), /** file(s) treated as text data */
|
150
|
+
GIT_DIFF_FLAG_VALID_OID = (1 << 2), /** `oid` value is known correct */
|
151
|
+
} git_diff_flag_t;
|
136
152
|
|
137
153
|
/**
|
138
154
|
* What type of change is described by a git_diff_delta?
|
155
|
+
*
|
156
|
+
* `GIT_DELTA_RENAMED` and `GIT_DELTA_COPIED` will only show up if you run
|
157
|
+
* `git_diff_find_similar()` on the diff list object.
|
158
|
+
*
|
159
|
+
* `GIT_DELTA_TYPECHANGE` only shows up given `GIT_DIFF_INCLUDE_TYPECHANGE`
|
160
|
+
* in the option flags (otherwise type changes will be split into ADDED /
|
161
|
+
* DELETED pairs).
|
139
162
|
*/
|
140
163
|
typedef enum {
|
141
|
-
GIT_DELTA_UNMODIFIED = 0,
|
142
|
-
GIT_DELTA_ADDED = 1,
|
143
|
-
GIT_DELTA_DELETED = 2,
|
144
|
-
GIT_DELTA_MODIFIED = 3,
|
145
|
-
GIT_DELTA_RENAMED = 4,
|
146
|
-
GIT_DELTA_COPIED = 5,
|
147
|
-
GIT_DELTA_IGNORED = 6,
|
148
|
-
GIT_DELTA_UNTRACKED = 7,
|
149
|
-
GIT_DELTA_TYPECHANGE = 8,
|
164
|
+
GIT_DELTA_UNMODIFIED = 0, /** no changes */
|
165
|
+
GIT_DELTA_ADDED = 1, /** entry does not exist in old version */
|
166
|
+
GIT_DELTA_DELETED = 2, /** entry does not exist in new version */
|
167
|
+
GIT_DELTA_MODIFIED = 3, /** entry content changed between old and new */
|
168
|
+
GIT_DELTA_RENAMED = 4, /** entry was renamed between old and new */
|
169
|
+
GIT_DELTA_COPIED = 5, /** entry was copied from another old entry */
|
170
|
+
GIT_DELTA_IGNORED = 6, /** entry is ignored item in workdir */
|
171
|
+
GIT_DELTA_UNTRACKED = 7, /** entry is untracked item in workdir */
|
172
|
+
GIT_DELTA_TYPECHANGE = 8, /** type of entry changed between old and new */
|
150
173
|
} git_delta_t;
|
151
174
|
|
152
175
|
/**
|
153
|
-
* Description of one side of a diff.
|
176
|
+
* Description of one side of a diff entry.
|
177
|
+
*
|
178
|
+
* Although this is called a "file", it may actually represent a file, a
|
179
|
+
* symbolic link, a submodule commit id, or even a tree (although that only
|
180
|
+
* if you are tracking type changes or ignored/untracked directories).
|
181
|
+
*
|
182
|
+
* The `oid` is the `git_oid` of the item. If the entry represents an
|
183
|
+
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
|
184
|
+
* then the oid will be zeroes.
|
185
|
+
*
|
186
|
+
* `path` is the NUL-terminated path to the entry relative to the working
|
187
|
+
* directory of the repository.
|
188
|
+
*
|
189
|
+
* `size` is the size of the entry in bytes.
|
190
|
+
*
|
191
|
+
* `flags` is a combination of the `git_diff_flag_t` types
|
192
|
+
*
|
193
|
+
* `mode` is, roughly, the stat() `st_mode` value for the item. This will
|
194
|
+
* be restricted to one of the `git_filemode_t` values.
|
154
195
|
*/
|
155
196
|
typedef struct {
|
156
|
-
git_oid
|
197
|
+
git_oid oid;
|
157
198
|
const char *path;
|
158
|
-
git_off_t
|
159
|
-
|
160
|
-
uint16_t
|
199
|
+
git_off_t size;
|
200
|
+
uint32_t flags;
|
201
|
+
uint16_t mode;
|
161
202
|
} git_diff_file;
|
162
203
|
|
163
204
|
/**
|
164
|
-
* Description of changes to one
|
205
|
+
* Description of changes to one entry.
|
206
|
+
*
|
207
|
+
* When iterating over a diff list object, this will be passed to most
|
208
|
+
* callback functions and you can use the contents to understand exactly
|
209
|
+
* what has changed.
|
165
210
|
*
|
166
|
-
*
|
167
|
-
*
|
168
|
-
*
|
211
|
+
* The `old_file` represents the "from" side of the diff and the `new_file`
|
212
|
+
* represents to "to" side of the diff. What those means depend on the
|
213
|
+
* function that was used to generate the diff and will be documented below.
|
214
|
+
* You can also use the `GIT_DIFF_REVERSE` flag to flip it around.
|
169
215
|
*
|
170
|
-
*
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
174
|
-
*
|
216
|
+
* Although the two sides of the delta are named "old_file" and "new_file",
|
217
|
+
* they actually may correspond to entries that represent a file, a symbolic
|
218
|
+
* link, a submodule commit id, or even a tree (if you are tracking type
|
219
|
+
* changes or ignored/untracked directories).
|
220
|
+
*
|
221
|
+
* Under some circumstances, in the name of efficiency, not all fields will
|
222
|
+
* be filled in, but we generally try to fill in as much as possible. One
|
223
|
+
* example is that the "flags" field may not have either the `BINARY` or the
|
224
|
+
* `NOT_BINARY` flag set to avoid examining file contents if you do not pass
|
225
|
+
* in hunk and/or line callbacks to the diff foreach iteration function. It
|
226
|
+
* will just use the git attributes for those files.
|
175
227
|
*/
|
176
228
|
typedef struct {
|
177
229
|
git_diff_file old_file;
|
178
230
|
git_diff_file new_file;
|
179
231
|
git_delta_t status;
|
180
|
-
|
181
|
-
|
232
|
+
uint32_t similarity; /**< for RENAMED and COPIED, value 0-100 */
|
233
|
+
uint32_t flags;
|
182
234
|
} git_diff_delta;
|
183
235
|
|
236
|
+
/**
|
237
|
+
* Diff notification callback function.
|
238
|
+
*
|
239
|
+
* The callback will be called for each file, just before the `git_delta_t`
|
240
|
+
* gets inserted into the diff list.
|
241
|
+
*
|
242
|
+
* When the callback:
|
243
|
+
* - returns < 0, the diff process will be aborted.
|
244
|
+
* - returns > 0, the delta will not be inserted into the diff list, but the
|
245
|
+
* diff process continues.
|
246
|
+
* - returns 0, the delta is inserted into the diff list, and the diff process
|
247
|
+
* continues.
|
248
|
+
*/
|
249
|
+
typedef int (*git_diff_notify_cb)(
|
250
|
+
const git_diff_list *diff_so_far,
|
251
|
+
const git_diff_delta *delta_to_add,
|
252
|
+
const char *matched_pathspec,
|
253
|
+
void *payload);
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Structure describing options about how the diff should be executed.
|
257
|
+
*
|
258
|
+
* Setting all values of the structure to zero will yield the default
|
259
|
+
* values. Similarly, passing NULL for the options structure will
|
260
|
+
* give the defaults. The default values are marked below.
|
261
|
+
*
|
262
|
+
* - `flags` is a combination of the `git_diff_option_t` values above
|
263
|
+
* - `context_lines` is the number of unchanged lines that define the
|
264
|
+
* boundary of a hunk (and to display before and after)
|
265
|
+
* - `interhunk_lines` is the maximum number of unchanged lines between
|
266
|
+
* hunk boundaries before the hunks will be merged into a one.
|
267
|
+
* - `old_prefix` is the virtual "directory" to prefix to old file names
|
268
|
+
* in hunk headers (default "a")
|
269
|
+
* - `new_prefix` is the virtual "directory" to prefix to new file names
|
270
|
+
* in hunk headers (default "b")
|
271
|
+
* - `pathspec` is an array of paths / fnmatch patterns to constrain diff
|
272
|
+
* - `max_size` is a file size (in bytes) above which a blob will be marked
|
273
|
+
* as binary automatically; pass a negative value to disable.
|
274
|
+
* - `notify_cb` is an optional callback function, notifying the consumer of
|
275
|
+
* which files are being examined as the diff is generated
|
276
|
+
* - `notify_payload` is the payload data to pass to the `notify_cb` function
|
277
|
+
*/
|
278
|
+
typedef struct {
|
279
|
+
unsigned int version; /**< version for the struct */
|
280
|
+
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
|
281
|
+
uint16_t context_lines; /**< defaults to 3 */
|
282
|
+
uint16_t interhunk_lines; /**< defaults to 0 */
|
283
|
+
const char *old_prefix; /**< defaults to "a" */
|
284
|
+
const char *new_prefix; /**< defaults to "b" */
|
285
|
+
git_strarray pathspec; /**< defaults to include all paths */
|
286
|
+
git_off_t max_size; /**< defaults to 512MB */
|
287
|
+
git_diff_notify_cb notify_cb;
|
288
|
+
void *notify_payload;
|
289
|
+
} git_diff_options;
|
290
|
+
|
291
|
+
#define GIT_DIFF_OPTIONS_VERSION 1
|
292
|
+
#define GIT_DIFF_OPTIONS_INIT {GIT_DIFF_OPTIONS_VERSION, GIT_DIFF_NORMAL, 3}
|
293
|
+
|
184
294
|
/**
|
185
295
|
* When iterating over a diff, callback that will be made per file.
|
296
|
+
*
|
297
|
+
* @param delta A pointer to the delta data for the file
|
298
|
+
* @param progress Goes from 0 to 1 over the diff list
|
299
|
+
* @param payload User-specified pointer from foreach function
|
186
300
|
*/
|
187
|
-
typedef int (*
|
188
|
-
void *cb_data,
|
301
|
+
typedef int (*git_diff_file_cb)(
|
189
302
|
const git_diff_delta *delta,
|
190
|
-
float progress
|
303
|
+
float progress,
|
304
|
+
void *payload);
|
191
305
|
|
192
306
|
/**
|
193
307
|
* Structure describing a hunk of a diff.
|
194
308
|
*/
|
195
309
|
typedef struct {
|
196
|
-
int old_start;
|
197
|
-
int old_lines;
|
198
|
-
int new_start;
|
199
|
-
int new_lines;
|
310
|
+
int old_start; /** Starting line number in old_file */
|
311
|
+
int old_lines; /** Number of lines in old_file */
|
312
|
+
int new_start; /** Starting line number in new_file */
|
313
|
+
int new_lines; /** Number of lines in new_file */
|
200
314
|
} git_diff_range;
|
201
315
|
|
202
316
|
/**
|
203
317
|
* When iterating over a diff, callback that will be made per hunk.
|
204
318
|
*/
|
205
|
-
typedef int (*
|
206
|
-
void *cb_data,
|
319
|
+
typedef int (*git_diff_hunk_cb)(
|
207
320
|
const git_diff_delta *delta,
|
208
321
|
const git_diff_range *range,
|
209
322
|
const char *header,
|
210
|
-
size_t header_len
|
323
|
+
size_t header_len,
|
324
|
+
void *payload);
|
211
325
|
|
212
326
|
/**
|
213
327
|
* Line origin constants.
|
214
328
|
*
|
215
329
|
* These values describe where a line came from and will be passed to
|
216
|
-
* the
|
330
|
+
* the git_diff_data_cb when iterating over a diff. There are some
|
217
331
|
* special origin constants at the end that are used for the text
|
218
332
|
* output callbacks to demarcate lines that are actually part of
|
219
333
|
* the file or hunk headers.
|
220
334
|
*/
|
221
|
-
enum {
|
222
|
-
/* These values will be sent to `
|
335
|
+
typedef enum {
|
336
|
+
/* These values will be sent to `git_diff_data_cb` along with the line */
|
223
337
|
GIT_DIFF_LINE_CONTEXT = ' ',
|
224
338
|
GIT_DIFF_LINE_ADDITION = '+',
|
225
339
|
GIT_DIFF_LINE_DELETION = '-',
|
226
340
|
GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< Removed line w/o LF & added one with */
|
227
341
|
GIT_DIFF_LINE_DEL_EOFNL = '\0', /**< LF was removed at end of file */
|
228
342
|
|
229
|
-
/* The following values will only be sent to a `
|
343
|
+
/* The following values will only be sent to a `git_diff_data_cb` when
|
230
344
|
* the content of a diff is being formatted (eg. through
|
231
345
|
* git_diff_print_patch() or git_diff_print_compact(), for instance).
|
232
346
|
*/
|
233
347
|
GIT_DIFF_LINE_FILE_HDR = 'F',
|
234
348
|
GIT_DIFF_LINE_HUNK_HDR = 'H',
|
235
349
|
GIT_DIFF_LINE_BINARY = 'B'
|
236
|
-
};
|
350
|
+
} git_diff_line_t;
|
237
351
|
|
238
352
|
/**
|
239
353
|
* When iterating over a diff, callback that will be made per text diff
|
@@ -243,13 +357,13 @@ enum {
|
|
243
357
|
* of text. This uses some extra GIT_DIFF_LINE_... constants for output
|
244
358
|
* of lines of file and hunk headers.
|
245
359
|
*/
|
246
|
-
typedef int (*
|
247
|
-
|
248
|
-
const
|
249
|
-
|
250
|
-
char
|
251
|
-
|
252
|
-
|
360
|
+
typedef int (*git_diff_data_cb)(
|
361
|
+
const git_diff_delta *delta, /** delta that contains this data */
|
362
|
+
const git_diff_range *range, /** range of lines containing this data */
|
363
|
+
char line_origin, /** git_diff_list_t value from above */
|
364
|
+
const char *content, /** diff data - not NUL terminated */
|
365
|
+
size_t content_len, /** number of bytes of diff data */
|
366
|
+
void *payload); /** user reference data */
|
253
367
|
|
254
368
|
/**
|
255
369
|
* The diff patch is used to store all the text diffs for a delta.
|
@@ -259,6 +373,92 @@ typedef int (*git_diff_data_fn)(
|
|
259
373
|
*/
|
260
374
|
typedef struct git_diff_patch git_diff_patch;
|
261
375
|
|
376
|
+
/**
|
377
|
+
* Flags to control the behavior of diff rename/copy detection.
|
378
|
+
*/
|
379
|
+
typedef enum {
|
380
|
+
/** look for renames? (`--find-renames`) */
|
381
|
+
GIT_DIFF_FIND_RENAMES = (1 << 0),
|
382
|
+
/** consider old side of modified for renames? (`--break-rewrites=N`) */
|
383
|
+
GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1 << 1),
|
384
|
+
|
385
|
+
/** look for copies? (a la `--find-copies`) */
|
386
|
+
GIT_DIFF_FIND_COPIES = (1 << 2),
|
387
|
+
/** consider unmodified as copy sources? (`--find-copies-harder`) */
|
388
|
+
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1 << 3),
|
389
|
+
|
390
|
+
/** split large rewrites into delete/add pairs (`--break-rewrites=/M`) */
|
391
|
+
GIT_DIFF_FIND_AND_BREAK_REWRITES = (1 << 4),
|
392
|
+
|
393
|
+
/** turn on all finding features */
|
394
|
+
GIT_DIFF_FIND_ALL = (0x1f),
|
395
|
+
|
396
|
+
/** measure similarity ignoring leading whitespace (default) */
|
397
|
+
GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0,
|
398
|
+
/** measure similarity ignoring all whitespace */
|
399
|
+
GIT_DIFF_FIND_IGNORE_WHITESPACE = (1 << 6),
|
400
|
+
/** measure similarity including all data */
|
401
|
+
GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE = (1 << 7),
|
402
|
+
} git_diff_find_t;
|
403
|
+
|
404
|
+
/**
|
405
|
+
* Pluggable similarity metric
|
406
|
+
*/
|
407
|
+
typedef struct {
|
408
|
+
int (*file_signature)(
|
409
|
+
void **out, const git_diff_file *file,
|
410
|
+
const char *fullpath, void *payload);
|
411
|
+
int (*buffer_signature)(
|
412
|
+
void **out, const git_diff_file *file,
|
413
|
+
const char *buf, size_t buflen, void *payload);
|
414
|
+
void (*free_signature)(void *sig, void *payload);
|
415
|
+
int (*similarity)(int *score, void *siga, void *sigb, void *payload);
|
416
|
+
void *payload;
|
417
|
+
} git_diff_similarity_metric;
|
418
|
+
|
419
|
+
/**
|
420
|
+
* Control behavior of rename and copy detection
|
421
|
+
*
|
422
|
+
* These options mostly mimic parameters that can be passed to git-diff.
|
423
|
+
*
|
424
|
+
* - `rename_threshold` is the same as the -M option with a value
|
425
|
+
* - `copy_threshold` is the same as the -C option with a value
|
426
|
+
* - `rename_from_rewrite_threshold` matches the top of the -B option
|
427
|
+
* - `break_rewrite_threshold` matches the bottom of the -B option
|
428
|
+
* - `target_limit` matches the -l option
|
429
|
+
*
|
430
|
+
* The `metric` option allows you to plug in a custom similarity metric.
|
431
|
+
* Set it to NULL for the default internal metric which is based on sampling
|
432
|
+
* hashes of ranges of data in the file. The default metric is a pretty
|
433
|
+
* good similarity approximation that should work fairly well for both text
|
434
|
+
* and binary data, and is pretty fast with fixed memory overhead.
|
435
|
+
*/
|
436
|
+
typedef struct {
|
437
|
+
unsigned int version;
|
438
|
+
|
439
|
+
/** Combination of git_diff_find_t values (default FIND_RENAMES) */
|
440
|
+
unsigned int flags;
|
441
|
+
|
442
|
+
/** Similarity to consider a file renamed (default 50) */
|
443
|
+
unsigned int rename_threshold;
|
444
|
+
/** Similarity of modified to be eligible rename source (default 50) */
|
445
|
+
unsigned int rename_from_rewrite_threshold;
|
446
|
+
/** Similarity to consider a file a copy (default 50) */
|
447
|
+
unsigned int copy_threshold;
|
448
|
+
/** Similarity to split modify into delete/add pair (default 60) */
|
449
|
+
unsigned int break_rewrite_threshold;
|
450
|
+
|
451
|
+
/** Maximum similarity sources to examine (a la diff's `-l` option or
|
452
|
+
* the `diff.renameLimit` config) (default 200)
|
453
|
+
*/
|
454
|
+
unsigned int target_limit;
|
455
|
+
|
456
|
+
/** Pluggable similarity metric; pass NULL to use internal metric */
|
457
|
+
git_diff_similarity_metric *metric;
|
458
|
+
} git_diff_find_options;
|
459
|
+
|
460
|
+
#define GIT_DIFF_FIND_OPTIONS_VERSION 1
|
461
|
+
#define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION}
|
262
462
|
|
263
463
|
/** @name Diff List Generator Functions
|
264
464
|
*
|
@@ -273,89 +473,104 @@ typedef struct git_diff_patch git_diff_patch;
|
|
273
473
|
GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
|
274
474
|
|
275
475
|
/**
|
276
|
-
*
|
476
|
+
* Create a diff list with the difference between two tree objects.
|
477
|
+
*
|
478
|
+
* This is equivalent to `git diff <old-tree> <new-tree>`
|
277
479
|
*
|
278
|
-
*
|
480
|
+
* The first tree will be used for the "old_file" side of the delta and the
|
481
|
+
* second tree will be used for the "new_file" side of the delta.
|
279
482
|
*
|
483
|
+
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
280
484
|
* @param repo The repository containing the trees.
|
281
|
-
* @param opts Structure with options to influence diff or NULL for defaults.
|
282
485
|
* @param old_tree A git_tree object to diff from.
|
283
486
|
* @param new_tree A git_tree object to diff to.
|
284
|
-
* @param
|
487
|
+
* @param opts Structure with options to influence diff or NULL for defaults.
|
285
488
|
*/
|
286
489
|
GIT_EXTERN(int) git_diff_tree_to_tree(
|
490
|
+
git_diff_list **diff,
|
287
491
|
git_repository *repo,
|
288
|
-
const git_diff_options *opts, /**< can be NULL for defaults */
|
289
492
|
git_tree *old_tree,
|
290
493
|
git_tree *new_tree,
|
291
|
-
|
494
|
+
const git_diff_options *opts); /**< can be NULL for defaults */
|
292
495
|
|
293
496
|
/**
|
294
|
-
*
|
497
|
+
* Create a diff list between a tree and repository index.
|
295
498
|
*
|
296
499
|
* This is equivalent to `git diff --cached <treeish>` or if you pass
|
297
500
|
* the HEAD tree, then like `git diff --cached`.
|
298
501
|
*
|
502
|
+
* The tree you pass will be used for the "old_file" side of the delta, and
|
503
|
+
* the index will be used for the "new_file" side of the delta.
|
504
|
+
*
|
505
|
+
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
299
506
|
* @param repo The repository containing the tree and index.
|
300
|
-
* @param opts Structure with options to influence diff or NULL for defaults.
|
301
507
|
* @param old_tree A git_tree object to diff from.
|
302
|
-
* @param
|
508
|
+
* @param index The index to diff with; repo index used if NULL.
|
509
|
+
* @param opts Structure with options to influence diff or NULL for defaults.
|
303
510
|
*/
|
304
|
-
GIT_EXTERN(int)
|
511
|
+
GIT_EXTERN(int) git_diff_tree_to_index(
|
512
|
+
git_diff_list **diff,
|
305
513
|
git_repository *repo,
|
306
|
-
const git_diff_options *opts, /**< can be NULL for defaults */
|
307
514
|
git_tree *old_tree,
|
308
|
-
|
515
|
+
git_index *index,
|
516
|
+
const git_diff_options *opts); /**< can be NULL for defaults */
|
309
517
|
|
310
518
|
/**
|
311
|
-
*
|
519
|
+
* Create a diff list between the repository index and the workdir directory.
|
312
520
|
*
|
313
521
|
* This matches the `git diff` command. See the note below on
|
314
|
-
* `
|
522
|
+
* `git_diff_tree_to_workdir` for a discussion of the difference between
|
315
523
|
* `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>`
|
316
524
|
* using libgit2.
|
317
525
|
*
|
526
|
+
* The index will be used for the "old_file" side of the delta, and the
|
527
|
+
* working directory will be used for the "new_file" side of the delta.
|
528
|
+
*
|
529
|
+
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
318
530
|
* @param repo The repository.
|
531
|
+
* @param index The index to diff from; repo index used if NULL.
|
319
532
|
* @param opts Structure with options to influence diff or NULL for defaults.
|
320
|
-
* @param diff A pointer to a git_diff_list pointer that will be allocated.
|
321
533
|
*/
|
322
|
-
GIT_EXTERN(int)
|
534
|
+
GIT_EXTERN(int) git_diff_index_to_workdir(
|
535
|
+
git_diff_list **diff,
|
323
536
|
git_repository *repo,
|
324
|
-
|
325
|
-
|
537
|
+
git_index *index,
|
538
|
+
const git_diff_options *opts); /**< can be NULL for defaults */
|
326
539
|
|
327
540
|
/**
|
328
|
-
*
|
541
|
+
* Create a diff list between a tree and the working directory.
|
329
542
|
*
|
330
|
-
*
|
331
|
-
*
|
332
|
-
*
|
543
|
+
* The tree you provide will be used for the "old_file" side of the delta,
|
544
|
+
* and the working directory will be used for the "new_file" side.
|
545
|
+
*
|
546
|
+
* Please note: this is *NOT* the same as `git diff <treeish>`. Running
|
547
|
+
* `git diff HEAD` or the like actually uses information from the index,
|
548
|
+
* along with the tree and working directory info.
|
333
549
|
*
|
334
550
|
* This function returns strictly the differences between the tree and the
|
335
551
|
* files contained in the working directory, regardless of the state of
|
336
552
|
* files in the index. It may come as a surprise, but there is no direct
|
337
553
|
* equivalent in core git.
|
338
554
|
*
|
339
|
-
* To emulate `git diff <treeish>`,
|
340
|
-
* `
|
341
|
-
*
|
342
|
-
* matches the git output.
|
555
|
+
* To emulate `git diff <treeish>`, call both `git_diff_tree_to_index` and
|
556
|
+
* `git_diff_index_to_workdir`, then call `git_diff_merge` on the results.
|
557
|
+
* That will yield a `git_diff_list` that matches the git output.
|
343
558
|
*
|
344
559
|
* If this seems confusing, take the case of a file with a staged deletion
|
345
560
|
* where the file has then been put back into the working dir and modified.
|
346
561
|
* The tree-to-workdir diff for that file is 'modified', but core git would
|
347
562
|
* show status 'deleted' since there is a pending deletion in the index.
|
348
563
|
*
|
564
|
+
* @param diff A pointer to a git_diff_list pointer that will be allocated.
|
349
565
|
* @param repo The repository containing the tree.
|
350
|
-
* @param opts Structure with options to influence diff or NULL for defaults.
|
351
566
|
* @param old_tree A git_tree object to diff from.
|
352
|
-
* @param
|
567
|
+
* @param opts Structure with options to influence diff or NULL for defaults.
|
353
568
|
*/
|
354
|
-
GIT_EXTERN(int)
|
569
|
+
GIT_EXTERN(int) git_diff_tree_to_workdir(
|
570
|
+
git_diff_list **diff,
|
355
571
|
git_repository *repo,
|
356
|
-
const git_diff_options *opts, /**< can be NULL for defaults */
|
357
572
|
git_tree *old_tree,
|
358
|
-
|
573
|
+
const git_diff_options *opts); /**< can be NULL for defaults */
|
359
574
|
|
360
575
|
/**
|
361
576
|
* Merge one diff list into another.
|
@@ -374,6 +589,22 @@ GIT_EXTERN(int) git_diff_merge(
|
|
374
589
|
git_diff_list *onto,
|
375
590
|
const git_diff_list *from);
|
376
591
|
|
592
|
+
/**
|
593
|
+
* Transform a diff list marking file renames, copies, etc.
|
594
|
+
*
|
595
|
+
* This modifies a diff list in place, replacing old entries that look
|
596
|
+
* like renames or copies with new entries reflecting those changes.
|
597
|
+
* This also will, if requested, break modified files into add/remove
|
598
|
+
* pairs if the amount of change is above a threshold.
|
599
|
+
*
|
600
|
+
* @param diff Diff list to run detection algorithms on
|
601
|
+
* @param options Control how detection should be run, NULL for defaults
|
602
|
+
* @return 0 on success, -1 on failure
|
603
|
+
*/
|
604
|
+
GIT_EXTERN(int) git_diff_find_similar(
|
605
|
+
git_diff_list *diff,
|
606
|
+
git_diff_find_options *options);
|
607
|
+
|
377
608
|
/**@}*/
|
378
609
|
|
379
610
|
|
@@ -399,7 +630,6 @@ GIT_EXTERN(int) git_diff_merge(
|
|
399
630
|
* the iteration and cause this return `GIT_EUSER`.
|
400
631
|
*
|
401
632
|
* @param diff A git_diff_list generated by one of the above functions.
|
402
|
-
* @param cb_data Reference pointer that will be passed to your callbacks.
|
403
633
|
* @param file_cb Callback function to make per file in the diff.
|
404
634
|
* @param hunk_cb Optional callback to make per hunk of text diff. This
|
405
635
|
* callback is called to describe a range of lines in the
|
@@ -407,14 +637,15 @@ GIT_EXTERN(int) git_diff_merge(
|
|
407
637
|
* @param line_cb Optional callback to make per line of diff text. This
|
408
638
|
* same callback will be made for context lines, added, and
|
409
639
|
* removed lines, and even for a deleted trailing newline.
|
640
|
+
* @param payload Reference pointer that will be passed to your callbacks.
|
410
641
|
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
411
642
|
*/
|
412
643
|
GIT_EXTERN(int) git_diff_foreach(
|
413
644
|
git_diff_list *diff,
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
645
|
+
git_diff_file_cb file_cb,
|
646
|
+
git_diff_hunk_cb hunk_cb,
|
647
|
+
git_diff_data_cb line_cb,
|
648
|
+
void *payload);
|
418
649
|
|
419
650
|
/**
|
420
651
|
* Iterate over a diff generating text output like "git diff --name-status".
|
@@ -423,14 +654,14 @@ GIT_EXTERN(int) git_diff_foreach(
|
|
423
654
|
* iteration and cause this return `GIT_EUSER`.
|
424
655
|
*
|
425
656
|
* @param diff A git_diff_list generated by one of the above functions.
|
426
|
-
* @param cb_data Reference pointer that will be passed to your callback.
|
427
657
|
* @param print_cb Callback to make per line of diff text.
|
658
|
+
* @param payload Reference pointer that will be passed to your callback.
|
428
659
|
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
429
660
|
*/
|
430
661
|
GIT_EXTERN(int) git_diff_print_compact(
|
431
662
|
git_diff_list *diff,
|
432
|
-
|
433
|
-
|
663
|
+
git_diff_data_cb print_cb,
|
664
|
+
void *payload);
|
434
665
|
|
435
666
|
/**
|
436
667
|
* Look up the single character abbreviation for a delta status code.
|
@@ -455,7 +686,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
|
|
455
686
|
* iteration and cause this return `GIT_EUSER`.
|
456
687
|
*
|
457
688
|
* @param diff A git_diff_list generated by one of the above functions.
|
458
|
-
* @param
|
689
|
+
* @param payload Reference pointer that will be passed to your callbacks.
|
459
690
|
* @param print_cb Callback function to output lines of the diff. This
|
460
691
|
* same function will be called for file headers, hunk
|
461
692
|
* headers, and diff lines. Fortunately, you can probably
|
@@ -465,8 +696,8 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
|
|
465
696
|
*/
|
466
697
|
GIT_EXTERN(int) git_diff_print_patch(
|
467
698
|
git_diff_list *diff,
|
468
|
-
|
469
|
-
|
699
|
+
git_diff_data_cb print_cb,
|
700
|
+
void *payload);
|
470
701
|
|
471
702
|
/**
|
472
703
|
* Query how many diff records are there in a diff list.
|
@@ -510,15 +741,15 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
|
|
510
741
|
* It is okay to pass NULL for either of the output parameters; if you pass
|
511
742
|
* NULL for the `git_diff_patch`, then the text diff will not be calculated.
|
512
743
|
*
|
513
|
-
* @param
|
514
|
-
* @param
|
744
|
+
* @param patch_out Output parameter for the delta patch object
|
745
|
+
* @param delta_out Output parameter for the delta object
|
515
746
|
* @param diff Diff list object
|
516
747
|
* @param idx Index into diff list
|
517
748
|
* @return 0 on success, other value < 0 on error
|
518
749
|
*/
|
519
750
|
GIT_EXTERN(int) git_diff_get_patch(
|
520
|
-
git_diff_patch **
|
521
|
-
const git_diff_delta **
|
751
|
+
git_diff_patch **patch_out,
|
752
|
+
const git_diff_delta **delta_out,
|
522
753
|
git_diff_list *diff,
|
523
754
|
size_t idx);
|
524
755
|
|
@@ -540,6 +771,28 @@ GIT_EXTERN(const git_diff_delta *) git_diff_patch_delta(
|
|
540
771
|
GIT_EXTERN(size_t) git_diff_patch_num_hunks(
|
541
772
|
git_diff_patch *patch);
|
542
773
|
|
774
|
+
/**
|
775
|
+
* Get line counts of each type in a patch.
|
776
|
+
*
|
777
|
+
* This helps imitate a diff --numstat type of output. For that purpose,
|
778
|
+
* you only need the `total_additions` and `total_deletions` values, but we
|
779
|
+
* include the `total_context` line count in case you want the total number
|
780
|
+
* of lines of diff output that will be generated.
|
781
|
+
*
|
782
|
+
* All outputs are optional. Pass NULL if you don't need a particular count.
|
783
|
+
*
|
784
|
+
* @param total_context Count of context lines in output, can be NULL.
|
785
|
+
* @param total_additions Count of addition lines in output, can be NULL.
|
786
|
+
* @param total_deletions Count of deletion lines in output, can be NULL.
|
787
|
+
* @param patch The git_diff_patch object
|
788
|
+
* @return Number of lines in hunk or -1 if invalid hunk index
|
789
|
+
*/
|
790
|
+
GIT_EXTERN(int) git_diff_patch_line_stats(
|
791
|
+
size_t *total_context,
|
792
|
+
size_t *total_additions,
|
793
|
+
size_t *total_deletions,
|
794
|
+
const git_diff_patch *patch);
|
795
|
+
|
543
796
|
/**
|
544
797
|
* Get the information about a hunk in a patch
|
545
798
|
*
|
@@ -603,6 +856,34 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
|
|
603
856
|
size_t hunk_idx,
|
604
857
|
size_t line_of_hunk);
|
605
858
|
|
859
|
+
/**
|
860
|
+
* Serialize the patch to text via callback.
|
861
|
+
*
|
862
|
+
* Returning a non-zero value from the callback will terminate the iteration
|
863
|
+
* and cause this return `GIT_EUSER`.
|
864
|
+
*
|
865
|
+
* @param patch A git_diff_patch representing changes to one file
|
866
|
+
* @param print_cb Callback function to output lines of the patch. Will be
|
867
|
+
* called for file headers, hunk headers, and diff lines.
|
868
|
+
* @param payload Reference pointer that will be passed to your callbacks.
|
869
|
+
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
870
|
+
*/
|
871
|
+
GIT_EXTERN(int) git_diff_patch_print(
|
872
|
+
git_diff_patch *patch,
|
873
|
+
git_diff_data_cb print_cb,
|
874
|
+
void *payload);
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Get the content of a patch as a single diff text.
|
878
|
+
*
|
879
|
+
* @param string Allocated string; caller must free.
|
880
|
+
* @param patch A git_diff_patch representing changes to one file
|
881
|
+
* @return 0 on success, <0 on failure.
|
882
|
+
*/
|
883
|
+
GIT_EXTERN(int) git_diff_patch_to_str(
|
884
|
+
char **string,
|
885
|
+
git_diff_patch *patch);
|
886
|
+
|
606
887
|
/**@}*/
|
607
888
|
|
608
889
|
|
@@ -611,27 +892,55 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
|
|
611
892
|
*/
|
612
893
|
|
613
894
|
/**
|
614
|
-
* Directly run a
|
895
|
+
* Directly run a diff on two blobs.
|
615
896
|
*
|
616
897
|
* Compared to a file, a blob lacks some contextual information. As such,
|
617
|
-
* the `git_diff_file`
|
618
|
-
*
|
619
|
-
*
|
898
|
+
* the `git_diff_file` given to the callback will have some fake data; i.e.
|
899
|
+
* `mode` will be 0 and `path` will be NULL.
|
900
|
+
*
|
901
|
+
* NULL is allowed for either `old_blob` or `new_blob` and will be treated
|
902
|
+
* as an empty blob, with the `oid` set to NULL in the `git_diff_file` data.
|
903
|
+
* Passing NULL for both blobs is a noop; no callbacks will be made at all.
|
620
904
|
*
|
621
|
-
*
|
622
|
-
* `git_diff_delta` binary attribute will be set
|
623
|
-
* hunk_cb nor line_cb will be made
|
905
|
+
* We do run a binary content check on the blob content and if either blob
|
906
|
+
* looks like binary data, the `git_diff_delta` binary attribute will be set
|
907
|
+
* to 1 and no call to the hunk_cb nor line_cb will be made (unless you pass
|
908
|
+
* `GIT_DIFF_FORCE_TEXT` of course).
|
624
909
|
*
|
625
910
|
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
626
911
|
*/
|
627
912
|
GIT_EXTERN(int) git_diff_blobs(
|
628
|
-
git_blob *old_blob,
|
629
|
-
git_blob *new_blob,
|
913
|
+
const git_blob *old_blob,
|
914
|
+
const git_blob *new_blob,
|
915
|
+
const git_diff_options *options,
|
916
|
+
git_diff_file_cb file_cb,
|
917
|
+
git_diff_hunk_cb hunk_cb,
|
918
|
+
git_diff_data_cb line_cb,
|
919
|
+
void *payload);
|
920
|
+
|
921
|
+
/**
|
922
|
+
* Directly run a diff between a blob and a buffer.
|
923
|
+
*
|
924
|
+
* As with `git_diff_blobs`, comparing a blob and buffer lacks some context,
|
925
|
+
* so the `git_diff_file` parameters to the callbacks will be faked a la the
|
926
|
+
* rules for `git_diff_blobs()`.
|
927
|
+
*
|
928
|
+
* Passing NULL for `old_blob` will be treated as an empty blob (i.e. the
|
929
|
+
* `file_cb` will be invoked with GIT_DELTA_ADDED and the diff will be the
|
930
|
+
* entire content of the buffer added). Passing NULL to the buffer will do
|
931
|
+
* the reverse, with GIT_DELTA_REMOVED and blob content removed.
|
932
|
+
*
|
933
|
+
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
934
|
+
*/
|
935
|
+
GIT_EXTERN(int) git_diff_blob_to_buffer(
|
936
|
+
const git_blob *old_blob,
|
937
|
+
const char *buffer,
|
938
|
+
size_t buffer_len,
|
630
939
|
const git_diff_options *options,
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
940
|
+
git_diff_file_cb file_cb,
|
941
|
+
git_diff_hunk_cb hunk_cb,
|
942
|
+
git_diff_data_cb data_cb,
|
943
|
+
void *payload);
|
635
944
|
|
636
945
|
GIT_END_DECL
|
637
946
|
|