rugged 0.24.6.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/rugged/extconf.rb +9 -2
  4. data/ext/rugged/rugged.c +85 -21
  5. data/ext/rugged/rugged.h +7 -21
  6. data/ext/rugged/rugged_backend.c +3 -20
  7. data/ext/rugged/rugged_blame.c +7 -24
  8. data/ext/rugged/rugged_blob.c +136 -59
  9. data/ext/rugged/rugged_branch.c +3 -20
  10. data/ext/rugged/rugged_branch_collection.c +3 -20
  11. data/ext/rugged/rugged_commit.c +251 -101
  12. data/ext/rugged/rugged_config.c +3 -20
  13. data/ext/rugged/rugged_cred.c +3 -20
  14. data/ext/rugged/rugged_diff.c +3 -20
  15. data/ext/rugged/rugged_diff_delta.c +3 -20
  16. data/ext/rugged/rugged_diff_hunk.c +3 -20
  17. data/ext/rugged/rugged_diff_line.c +3 -20
  18. data/ext/rugged/rugged_index.c +46 -229
  19. data/ext/rugged/rugged_note.c +3 -20
  20. data/ext/rugged/rugged_object.c +3 -20
  21. data/ext/rugged/rugged_patch.c +192 -34
  22. data/ext/rugged/rugged_rebase.c +90 -48
  23. data/ext/rugged/rugged_reference.c +4 -21
  24. data/ext/rugged/rugged_reference_collection.c +3 -20
  25. data/ext/rugged/rugged_remote.c +70 -42
  26. data/ext/rugged/rugged_remote_collection.c +3 -20
  27. data/ext/rugged/rugged_repo.c +50 -59
  28. data/ext/rugged/rugged_revwalk.c +4 -21
  29. data/ext/rugged/rugged_settings.c +3 -20
  30. data/ext/rugged/rugged_signature.c +3 -20
  31. data/ext/rugged/rugged_submodule.c +4 -21
  32. data/ext/rugged/rugged_submodule_collection.c +3 -20
  33. data/ext/rugged/rugged_tag.c +3 -20
  34. data/ext/rugged/rugged_tag_collection.c +3 -20
  35. data/ext/rugged/rugged_tree.c +189 -184
  36. data/lib/rugged/attributes.rb +5 -0
  37. data/lib/rugged/blob.rb +5 -0
  38. data/lib/rugged/branch.rb +6 -1
  39. data/lib/rugged/commit.rb +5 -0
  40. data/lib/rugged/console.rb +5 -0
  41. data/lib/rugged/credentials.rb +5 -0
  42. data/lib/rugged/diff/delta.rb +5 -0
  43. data/lib/rugged/diff/hunk.rb +5 -0
  44. data/lib/rugged/diff/line.rb +5 -0
  45. data/lib/rugged/diff.rb +5 -0
  46. data/lib/rugged/index.rb +120 -0
  47. data/lib/rugged/object.rb +5 -0
  48. data/lib/rugged/patch.rb +5 -0
  49. data/lib/rugged/reference.rb +5 -0
  50. data/lib/rugged/remote.rb +5 -0
  51. data/lib/rugged/repository.rb +9 -4
  52. data/lib/rugged/submodule_collection.rb +5 -0
  53. data/lib/rugged/tag.rb +5 -0
  54. data/lib/rugged/tree.rb +156 -1
  55. data/lib/rugged/version.rb +6 -1
  56. data/lib/rugged/walker.rb +5 -0
  57. data/lib/rugged.rb +5 -0
  58. data/vendor/libgit2/CMakeLists.txt +12 -2
  59. data/vendor/libgit2/include/git2/blob.h +39 -28
  60. data/vendor/libgit2/include/git2/commit.h +76 -0
  61. data/vendor/libgit2/include/git2/common.h +21 -1
  62. data/vendor/libgit2/include/git2/describe.h +5 -2
  63. data/vendor/libgit2/include/git2/diff.h +62 -7
  64. data/vendor/libgit2/include/git2/errors.h +2 -1
  65. data/vendor/libgit2/include/git2/index.h +25 -0
  66. data/vendor/libgit2/include/git2/merge.h +10 -1
  67. data/vendor/libgit2/include/git2/odb.h +47 -1
  68. data/vendor/libgit2/include/git2/pack.h +4 -4
  69. data/vendor/libgit2/include/git2/patch.h +1 -1
  70. data/vendor/libgit2/include/git2/proxy.h +92 -0
  71. data/vendor/libgit2/include/git2/refs.h +11 -0
  72. data/vendor/libgit2/include/git2/remote.h +21 -8
  73. data/vendor/libgit2/include/git2/repository.h +20 -1
  74. data/vendor/libgit2/include/git2/revwalk.h +4 -6
  75. data/vendor/libgit2/include/git2/signature.h +13 -0
  76. data/vendor/libgit2/include/git2/submodule.h +11 -3
  77. data/vendor/libgit2/include/git2/sys/merge.h +177 -0
  78. data/vendor/libgit2/include/git2/sys/odb_backend.h +11 -0
  79. data/vendor/libgit2/include/git2/sys/remote.h +16 -0
  80. data/vendor/libgit2/include/git2/sys/stream.h +2 -1
  81. data/vendor/libgit2/include/git2/sys/time.h +31 -0
  82. data/vendor/libgit2/include/git2/sys/transport.h +3 -1
  83. data/vendor/libgit2/include/git2/tag.h +9 -0
  84. data/vendor/libgit2/include/git2/transaction.h +9 -0
  85. data/vendor/libgit2/include/git2/tree.h +55 -0
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2.h +1 -0
  88. data/vendor/libgit2/src/annotated_commit.c +99 -80
  89. data/vendor/libgit2/src/annotated_commit.h +5 -2
  90. data/vendor/libgit2/src/apply.c +377 -0
  91. data/vendor/libgit2/src/apply.h +21 -0
  92. data/vendor/libgit2/src/array.h +0 -1
  93. data/vendor/libgit2/src/blob.c +71 -39
  94. data/vendor/libgit2/src/branch.c +7 -5
  95. data/vendor/libgit2/src/buffer.c +252 -20
  96. data/vendor/libgit2/src/buffer.h +8 -0
  97. data/vendor/libgit2/src/checkout.c +69 -42
  98. data/vendor/libgit2/src/clone.c +0 -8
  99. data/vendor/libgit2/src/commit.c +193 -49
  100. data/vendor/libgit2/src/commit_list.c +8 -3
  101. data/vendor/libgit2/src/commit_list.h +1 -0
  102. data/vendor/libgit2/src/common.h +2 -1
  103. data/vendor/libgit2/src/config.c +3 -3
  104. data/vendor/libgit2/src/config_file.c +20 -10
  105. data/vendor/libgit2/src/crlf.c +1 -0
  106. data/vendor/libgit2/src/curl_stream.c +106 -6
  107. data/vendor/libgit2/src/delta.c +238 -62
  108. data/vendor/libgit2/src/delta.h +79 -58
  109. data/vendor/libgit2/src/describe.c +1 -1
  110. data/vendor/libgit2/src/diff.c +32 -1554
  111. data/vendor/libgit2/src/diff.h +14 -122
  112. data/vendor/libgit2/src/diff_driver.c +4 -6
  113. data/vendor/libgit2/src/diff_file.c +3 -0
  114. data/vendor/libgit2/src/diff_generate.c +1613 -0
  115. data/vendor/libgit2/src/diff_generate.h +123 -0
  116. data/vendor/libgit2/src/diff_parse.c +101 -0
  117. data/vendor/libgit2/src/diff_parse.h +18 -0
  118. data/vendor/libgit2/src/diff_print.c +263 -144
  119. data/vendor/libgit2/src/diff_stats.c +21 -12
  120. data/vendor/libgit2/src/diff_tform.c +1 -0
  121. data/vendor/libgit2/src/diff_tform.h +22 -0
  122. data/vendor/libgit2/src/diff_xdiff.c +9 -9
  123. data/vendor/libgit2/src/diff_xdiff.h +5 -5
  124. data/vendor/libgit2/src/fetchhead.c +8 -8
  125. data/vendor/libgit2/src/filebuf.c +6 -1
  126. data/vendor/libgit2/src/filebuf.h +1 -0
  127. data/vendor/libgit2/src/fileops.c +22 -1
  128. data/vendor/libgit2/src/fileops.h +8 -2
  129. data/vendor/libgit2/src/fnmatch.c +18 -5
  130. data/vendor/libgit2/src/global.c +21 -4
  131. data/vendor/libgit2/src/global.h +6 -0
  132. data/vendor/libgit2/src/graph.c +1 -1
  133. data/vendor/libgit2/src/index.c +159 -46
  134. data/vendor/libgit2/src/index.h +2 -0
  135. data/vendor/libgit2/src/iterator.c +1573 -1468
  136. data/vendor/libgit2/src/iterator.h +52 -69
  137. data/vendor/libgit2/src/merge.c +163 -64
  138. data/vendor/libgit2/src/merge.h +61 -2
  139. data/vendor/libgit2/src/merge_driver.c +397 -0
  140. data/vendor/libgit2/src/merge_driver.h +60 -0
  141. data/vendor/libgit2/src/merge_file.c +11 -49
  142. data/vendor/libgit2/src/netops.c +12 -10
  143. data/vendor/libgit2/src/object_api.c +19 -1
  144. data/vendor/libgit2/src/odb.c +228 -52
  145. data/vendor/libgit2/src/odb_loose.c +19 -1
  146. data/vendor/libgit2/src/odb_mempack.c +1 -1
  147. data/vendor/libgit2/src/odb_pack.c +27 -1
  148. data/vendor/libgit2/src/openssl_stream.c +4 -5
  149. data/vendor/libgit2/src/pack-objects.c +105 -76
  150. data/vendor/libgit2/src/pack-objects.h +13 -12
  151. data/vendor/libgit2/src/pack.c +16 -10
  152. data/vendor/libgit2/src/pack.h +2 -0
  153. data/vendor/libgit2/src/patch.c +216 -0
  154. data/vendor/libgit2/src/patch.h +66 -0
  155. data/vendor/libgit2/src/{diff_patch.c → patch_generate.c} +203 -376
  156. data/vendor/libgit2/src/patch_generate.h +68 -0
  157. data/vendor/libgit2/src/patch_parse.c +1159 -0
  158. data/vendor/libgit2/src/patch_parse.h +56 -0
  159. data/vendor/libgit2/src/path.c +38 -2
  160. data/vendor/libgit2/src/path.h +18 -0
  161. data/vendor/libgit2/src/pathspec.c +1 -1
  162. data/vendor/libgit2/src/pool.h +5 -0
  163. data/vendor/libgit2/src/pqueue.c +12 -5
  164. data/vendor/libgit2/src/pqueue.h +1 -0
  165. data/vendor/libgit2/src/proxy.c +32 -0
  166. data/vendor/libgit2/src/proxy.h +14 -0
  167. data/vendor/libgit2/src/push.c +1 -1
  168. data/vendor/libgit2/src/rebase.c +63 -36
  169. data/vendor/libgit2/src/refdb.c +4 -2
  170. data/vendor/libgit2/src/refdb_fs.c +82 -54
  171. data/vendor/libgit2/src/refs.c +13 -1
  172. data/vendor/libgit2/src/remote.c +20 -81
  173. data/vendor/libgit2/src/repository.c +212 -29
  174. data/vendor/libgit2/src/reset.c +1 -1
  175. data/vendor/libgit2/src/revparse.c +1 -1
  176. data/vendor/libgit2/src/revwalk.c +260 -184
  177. data/vendor/libgit2/src/settings.c +11 -3
  178. data/vendor/libgit2/src/signature.c +27 -2
  179. data/vendor/libgit2/src/sortedcache.c +14 -5
  180. data/vendor/libgit2/src/stash.c +1 -0
  181. data/vendor/libgit2/src/status.c +1 -0
  182. data/vendor/libgit2/src/stransport_stream.c +4 -2
  183. data/vendor/libgit2/src/stream.h +2 -2
  184. data/vendor/libgit2/src/submodule.c +16 -4
  185. data/vendor/libgit2/src/sysdir.c +1 -1
  186. data/vendor/libgit2/src/transport.c +3 -5
  187. data/vendor/libgit2/src/transports/http.c +38 -13
  188. data/vendor/libgit2/src/transports/local.c +4 -1
  189. data/vendor/libgit2/src/transports/smart.c +6 -0
  190. data/vendor/libgit2/src/transports/smart.h +1 -0
  191. data/vendor/libgit2/src/transports/smart_pkt.c +5 -13
  192. data/vendor/libgit2/src/transports/smart_protocol.c +22 -7
  193. data/vendor/libgit2/src/transports/winhttp.c +144 -11
  194. data/vendor/libgit2/src/tree.c +267 -2
  195. data/vendor/libgit2/src/unix/posix.h +10 -0
  196. data/vendor/libgit2/src/unix/pthread.h +2 -0
  197. data/vendor/libgit2/src/util.c +25 -2
  198. data/vendor/libgit2/src/util.h +10 -0
  199. data/vendor/libgit2/src/varint.c +44 -0
  200. data/vendor/libgit2/src/varint.h +15 -0
  201. data/vendor/libgit2/src/vector.c +58 -0
  202. data/vendor/libgit2/src/vector.h +8 -0
  203. data/vendor/libgit2/src/win32/posix.h +3 -0
  204. data/vendor/libgit2/src/win32/thread.c +18 -0
  205. data/vendor/libgit2/src/win32/thread.h +2 -0
  206. data/vendor/libgit2/src/win32/w32_util.h +1 -1
  207. data/vendor/libgit2/src/zstream.c +37 -8
  208. data/vendor/libgit2/src/zstream.h +8 -1
  209. metadata +100 -82
  210. data/vendor/libgit2/Makefile.embed +0 -60
  211. data/vendor/libgit2/src/delta-apply.c +0 -166
  212. data/vendor/libgit2/src/delta-apply.h +0 -62
  213. data/vendor/libgit2/src/diff_patch.h +0 -83
@@ -4,275 +4,21 @@
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.
6
6
  */
7
+ #include "git2/version.h"
7
8
  #include "common.h"
8
9
  #include "diff.h"
9
- #include "fileops.h"
10
- #include "config.h"
11
- #include "attr_file.h"
12
- #include "filter.h"
13
- #include "pathspec.h"
10
+ #include "diff_generate.h"
11
+ #include "patch.h"
12
+ #include "commit.h"
14
13
  #include "index.h"
15
- #include "odb.h"
16
- #include "submodule.h"
17
14
 
18
- #define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0)
19
- #define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0)
15
+ #define DIFF_FLAG_IS_SET(DIFF,FLAG) \
16
+ (((DIFF)->opts.flags & (FLAG)) != 0)
17
+ #define DIFF_FLAG_ISNT_SET(DIFF,FLAG) \
18
+ (((DIFF)->opts.flags & (FLAG)) == 0)
20
19
  #define DIFF_FLAG_SET(DIFF,FLAG,VAL) (DIFF)->opts.flags = \
21
20
  (VAL) ? ((DIFF)->opts.flags | (FLAG)) : ((DIFF)->opts.flags & ~(VAL))
22
21
 
23
- static git_diff_delta *diff_delta__alloc(
24
- git_diff *diff,
25
- git_delta_t status,
26
- const char *path)
27
- {
28
- git_diff_delta *delta = git__calloc(1, sizeof(git_diff_delta));
29
- if (!delta)
30
- return NULL;
31
-
32
- delta->old_file.path = git_pool_strdup(&diff->pool, path);
33
- if (delta->old_file.path == NULL) {
34
- git__free(delta);
35
- return NULL;
36
- }
37
-
38
- delta->new_file.path = delta->old_file.path;
39
-
40
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) {
41
- switch (status) {
42
- case GIT_DELTA_ADDED: status = GIT_DELTA_DELETED; break;
43
- case GIT_DELTA_DELETED: status = GIT_DELTA_ADDED; break;
44
- default: break; /* leave other status values alone */
45
- }
46
- }
47
- delta->status = status;
48
-
49
- return delta;
50
- }
51
-
52
- static int diff_insert_delta(
53
- git_diff *diff, git_diff_delta *delta, const char *matched_pathspec)
54
- {
55
- int error = 0;
56
-
57
- if (diff->opts.notify_cb) {
58
- error = diff->opts.notify_cb(
59
- diff, delta, matched_pathspec, diff->opts.payload);
60
-
61
- if (error) {
62
- git__free(delta);
63
-
64
- if (error > 0) /* positive value means to skip this delta */
65
- return 0;
66
- else /* negative value means to cancel diff */
67
- return giterr_set_after_callback_function(error, "git_diff");
68
- }
69
- }
70
-
71
- if ((error = git_vector_insert(&diff->deltas, delta)) < 0)
72
- git__free(delta);
73
-
74
- return error;
75
- }
76
-
77
- static bool diff_pathspec_match(
78
- const char **matched_pathspec,
79
- git_diff *diff,
80
- const git_index_entry *entry)
81
- {
82
- bool disable_pathspec_match =
83
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH);
84
-
85
- /* If we're disabling fnmatch, then the iterator has already applied
86
- * the filters to the files for us and we don't have to do anything.
87
- * However, this only applies to *files* - the iterator will include
88
- * directories that we need to recurse into when not autoexpanding,
89
- * so we still need to apply the pathspec match to directories.
90
- */
91
- if ((S_ISLNK(entry->mode) || S_ISREG(entry->mode)) &&
92
- disable_pathspec_match) {
93
- *matched_pathspec = entry->path;
94
- return true;
95
- }
96
-
97
- return git_pathspec__match(
98
- &diff->pathspec, entry->path, disable_pathspec_match,
99
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE),
100
- matched_pathspec, NULL);
101
- }
102
-
103
- static int diff_delta__from_one(
104
- git_diff *diff,
105
- git_delta_t status,
106
- const git_index_entry *oitem,
107
- const git_index_entry *nitem)
108
- {
109
- const git_index_entry *entry = nitem;
110
- bool has_old = false;
111
- git_diff_delta *delta;
112
- const char *matched_pathspec;
113
-
114
- assert((oitem != NULL) ^ (nitem != NULL));
115
-
116
- if (oitem) {
117
- entry = oitem;
118
- has_old = true;
119
- }
120
-
121
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE))
122
- has_old = !has_old;
123
-
124
- if ((entry->flags & GIT_IDXENTRY_VALID) != 0)
125
- return 0;
126
-
127
- if (status == GIT_DELTA_IGNORED &&
128
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_IGNORED))
129
- return 0;
130
-
131
- if (status == GIT_DELTA_UNTRACKED &&
132
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNTRACKED))
133
- return 0;
134
-
135
- if (status == GIT_DELTA_UNREADABLE &&
136
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNREADABLE))
137
- return 0;
138
-
139
- if (!diff_pathspec_match(&matched_pathspec, diff, entry))
140
- return 0;
141
-
142
- delta = diff_delta__alloc(diff, status, entry->path);
143
- GITERR_CHECK_ALLOC(delta);
144
-
145
- /* This fn is just for single-sided diffs */
146
- assert(status != GIT_DELTA_MODIFIED);
147
- delta->nfiles = 1;
148
-
149
- if (has_old) {
150
- delta->old_file.mode = entry->mode;
151
- delta->old_file.size = entry->file_size;
152
- delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
153
- git_oid_cpy(&delta->old_file.id, &entry->id);
154
- } else /* ADDED, IGNORED, UNTRACKED */ {
155
- delta->new_file.mode = entry->mode;
156
- delta->new_file.size = entry->file_size;
157
- delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
158
- git_oid_cpy(&delta->new_file.id, &entry->id);
159
- }
160
-
161
- delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
162
-
163
- if (has_old || !git_oid_iszero(&delta->new_file.id))
164
- delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
165
-
166
- return diff_insert_delta(diff, delta, matched_pathspec);
167
- }
168
-
169
- static int diff_delta__from_two(
170
- git_diff *diff,
171
- git_delta_t status,
172
- const git_index_entry *old_entry,
173
- uint32_t old_mode,
174
- const git_index_entry *new_entry,
175
- uint32_t new_mode,
176
- const git_oid *new_id,
177
- const char *matched_pathspec)
178
- {
179
- const git_oid *old_id = &old_entry->id;
180
- git_diff_delta *delta;
181
- const char *canonical_path = old_entry->path;
182
-
183
- if (status == GIT_DELTA_UNMODIFIED &&
184
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNMODIFIED))
185
- return 0;
186
-
187
- if (!new_id)
188
- new_id = &new_entry->id;
189
-
190
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) {
191
- uint32_t temp_mode = old_mode;
192
- const git_index_entry *temp_entry = old_entry;
193
- const git_oid *temp_id = old_id;
194
-
195
- old_entry = new_entry;
196
- new_entry = temp_entry;
197
- old_mode = new_mode;
198
- new_mode = temp_mode;
199
- old_id = new_id;
200
- new_id = temp_id;
201
- }
202
-
203
- delta = diff_delta__alloc(diff, status, canonical_path);
204
- GITERR_CHECK_ALLOC(delta);
205
- delta->nfiles = 2;
206
-
207
- if (!git_index_entry_is_conflict(old_entry)) {
208
- delta->old_file.size = old_entry->file_size;
209
- delta->old_file.mode = old_mode;
210
- git_oid_cpy(&delta->old_file.id, old_id);
211
- delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID |
212
- GIT_DIFF_FLAG_EXISTS;
213
- }
214
-
215
- if (!git_index_entry_is_conflict(new_entry)) {
216
- git_oid_cpy(&delta->new_file.id, new_id);
217
- delta->new_file.size = new_entry->file_size;
218
- delta->new_file.mode = new_mode;
219
- delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
220
- delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
221
-
222
- if (!git_oid_iszero(&new_entry->id))
223
- delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
224
- }
225
-
226
- return diff_insert_delta(diff, delta, matched_pathspec);
227
- }
228
-
229
- static git_diff_delta *diff_delta__last_for_item(
230
- git_diff *diff,
231
- const git_index_entry *item)
232
- {
233
- git_diff_delta *delta = git_vector_last(&diff->deltas);
234
- if (!delta)
235
- return NULL;
236
-
237
- switch (delta->status) {
238
- case GIT_DELTA_UNMODIFIED:
239
- case GIT_DELTA_DELETED:
240
- if (git_oid__cmp(&delta->old_file.id, &item->id) == 0)
241
- return delta;
242
- break;
243
- case GIT_DELTA_ADDED:
244
- if (git_oid__cmp(&delta->new_file.id, &item->id) == 0)
245
- return delta;
246
- break;
247
- case GIT_DELTA_UNREADABLE:
248
- case GIT_DELTA_UNTRACKED:
249
- if (diff->strcomp(delta->new_file.path, item->path) == 0 &&
250
- git_oid__cmp(&delta->new_file.id, &item->id) == 0)
251
- return delta;
252
- break;
253
- case GIT_DELTA_MODIFIED:
254
- if (git_oid__cmp(&delta->old_file.id, &item->id) == 0 ||
255
- git_oid__cmp(&delta->new_file.id, &item->id) == 0)
256
- return delta;
257
- break;
258
- default:
259
- break;
260
- }
261
-
262
- return NULL;
263
- }
264
-
265
- static char *diff_strdup_prefix(git_pool *pool, const char *prefix)
266
- {
267
- size_t len = strlen(prefix);
268
-
269
- /* append '/' at end if needed */
270
- if (len > 0 && prefix[len - 1] != '/')
271
- return git_pool_strcat(pool, prefix, "/");
272
- else
273
- return git_pool_strndup(pool, prefix, len + 1);
274
- }
275
-
276
22
  GIT_INLINE(const char *) diff_delta__path(const git_diff_delta *delta)
277
23
  {
278
24
  const char *str = delta->old_file.path;
@@ -305,73 +51,7 @@ int git_diff_delta__casecmp(const void *a, const void *b)
305
51
  return val ? val : ((int)da->status - (int)db->status);
306
52
  }
307
53
 
308
- GIT_INLINE(const char *) diff_delta__i2w_path(const git_diff_delta *delta)
309
- {
310
- return delta->old_file.path ?
311
- delta->old_file.path : delta->new_file.path;
312
- }
313
-
314
- int git_diff_delta__i2w_cmp(const void *a, const void *b)
315
- {
316
- const git_diff_delta *da = a, *db = b;
317
- int val = strcmp(diff_delta__i2w_path(da), diff_delta__i2w_path(db));
318
- return val ? val : ((int)da->status - (int)db->status);
319
- }
320
-
321
- int git_diff_delta__i2w_casecmp(const void *a, const void *b)
322
- {
323
- const git_diff_delta *da = a, *db = b;
324
- int val = strcasecmp(diff_delta__i2w_path(da), diff_delta__i2w_path(db));
325
- return val ? val : ((int)da->status - (int)db->status);
326
- }
327
-
328
- bool git_diff_delta__should_skip(
329
- const git_diff_options *opts, const git_diff_delta *delta)
330
- {
331
- uint32_t flags = opts ? opts->flags : 0;
332
-
333
- if (delta->status == GIT_DELTA_UNMODIFIED &&
334
- (flags & GIT_DIFF_INCLUDE_UNMODIFIED) == 0)
335
- return true;
336
-
337
- if (delta->status == GIT_DELTA_IGNORED &&
338
- (flags & GIT_DIFF_INCLUDE_IGNORED) == 0)
339
- return true;
340
-
341
- if (delta->status == GIT_DELTA_UNTRACKED &&
342
- (flags & GIT_DIFF_INCLUDE_UNTRACKED) == 0)
343
- return true;
344
-
345
- if (delta->status == GIT_DELTA_UNREADABLE &&
346
- (flags & GIT_DIFF_INCLUDE_UNREADABLE) == 0)
347
- return true;
348
-
349
- return false;
350
- }
351
-
352
-
353
- static const char *diff_mnemonic_prefix(
354
- git_iterator_type_t type, bool left_side)
355
- {
356
- const char *pfx = "";
357
-
358
- switch (type) {
359
- case GIT_ITERATOR_TYPE_EMPTY: pfx = "c"; break;
360
- case GIT_ITERATOR_TYPE_TREE: pfx = "c"; break;
361
- case GIT_ITERATOR_TYPE_INDEX: pfx = "i"; break;
362
- case GIT_ITERATOR_TYPE_WORKDIR: pfx = "w"; break;
363
- case GIT_ITERATOR_TYPE_FS: pfx = left_side ? "1" : "2"; break;
364
- default: break;
365
- }
366
-
367
- /* note: without a deeper look at pathspecs, there is no easy way
368
- * to get the (o)bject / (w)ork tree mnemonics working...
369
- */
370
-
371
- return pfx;
372
- }
373
-
374
- static int diff_entry_cmp(const void *a, const void *b)
54
+ int git_diff__entry_cmp(const void *a, const void *b)
375
55
  {
376
56
  const git_index_entry *entry_a = a;
377
57
  const git_index_entry *entry_b = b;
@@ -379,7 +59,7 @@ static int diff_entry_cmp(const void *a, const void *b)
379
59
  return strcmp(entry_a->path, entry_b->path);
380
60
  }
381
61
 
382
- static int diff_entry_icmp(const void *a, const void *b)
62
+ int git_diff__entry_icmp(const void *a, const void *b)
383
63
  {
384
64
  const git_index_entry *entry_a = a;
385
65
  const git_index_entry *entry_b = b;
@@ -387,198 +67,12 @@ static int diff_entry_icmp(const void *a, const void *b)
387
67
  return strcasecmp(entry_a->path, entry_b->path);
388
68
  }
389
69
 
390
- static void diff_set_ignore_case(git_diff *diff, bool ignore_case)
391
- {
392
- if (!ignore_case) {
393
- diff->opts.flags &= ~GIT_DIFF_IGNORE_CASE;
394
-
395
- diff->strcomp = git__strcmp;
396
- diff->strncomp = git__strncmp;
397
- diff->pfxcomp = git__prefixcmp;
398
- diff->entrycomp = diff_entry_cmp;
399
-
400
- git_vector_set_cmp(&diff->deltas, git_diff_delta__cmp);
401
- } else {
402
- diff->opts.flags |= GIT_DIFF_IGNORE_CASE;
403
-
404
- diff->strcomp = git__strcasecmp;
405
- diff->strncomp = git__strncasecmp;
406
- diff->pfxcomp = git__prefixcmp_icase;
407
- diff->entrycomp = diff_entry_icmp;
408
-
409
- git_vector_set_cmp(&diff->deltas, git_diff_delta__casecmp);
410
- }
411
-
412
- git_vector_sort(&diff->deltas);
413
- }
414
-
415
- static git_diff *diff_list_alloc(
416
- git_repository *repo,
417
- git_iterator *old_iter,
418
- git_iterator *new_iter)
419
- {
420
- git_diff_options dflt = GIT_DIFF_OPTIONS_INIT;
421
- git_diff *diff = git__calloc(1, sizeof(git_diff));
422
- if (!diff)
423
- return NULL;
424
-
425
- assert(repo && old_iter && new_iter);
426
-
427
- GIT_REFCOUNT_INC(diff);
428
- diff->repo = repo;
429
- diff->old_src = old_iter->type;
430
- diff->new_src = new_iter->type;
431
- memcpy(&diff->opts, &dflt, sizeof(diff->opts));
432
-
433
- git_pool_init(&diff->pool, 1);
434
-
435
- if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0) {
436
- git_diff_free(diff);
437
- return NULL;
438
- }
439
-
440
- /* Use case-insensitive compare if either iterator has
441
- * the ignore_case bit set */
442
- diff_set_ignore_case(
443
- diff,
444
- git_iterator_ignore_case(old_iter) ||
445
- git_iterator_ignore_case(new_iter));
446
-
447
- return diff;
448
- }
449
-
450
- static int diff_list_apply_options(
451
- git_diff *diff,
452
- const git_diff_options *opts)
453
- {
454
- git_config *cfg = NULL;
455
- git_repository *repo = diff->repo;
456
- git_pool *pool = &diff->pool;
457
- int val;
458
-
459
- if (opts) {
460
- /* copy user options (except case sensitivity info from iterators) */
461
- bool icase = DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE);
462
- memcpy(&diff->opts, opts, sizeof(diff->opts));
463
- DIFF_FLAG_SET(diff, GIT_DIFF_IGNORE_CASE, icase);
464
-
465
- /* initialize pathspec from options */
466
- if (git_pathspec__vinit(&diff->pathspec, &opts->pathspec, pool) < 0)
467
- return -1;
468
- }
469
-
470
- /* flag INCLUDE_TYPECHANGE_TREES implies INCLUDE_TYPECHANGE */
471
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES))
472
- diff->opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
473
-
474
- /* flag INCLUDE_UNTRACKED_CONTENT implies INCLUDE_UNTRACKED */
475
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_SHOW_UNTRACKED_CONTENT))
476
- diff->opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED;
477
-
478
- /* load config values that affect diff behavior */
479
- if ((val = git_repository_config_snapshot(&cfg, repo)) < 0)
480
- return val;
481
-
482
- if (!git_config__cvar(&val, cfg, GIT_CVAR_SYMLINKS) && val)
483
- diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_HAS_SYMLINKS;
484
-
485
- if (!git_config__cvar(&val, cfg, GIT_CVAR_IGNORESTAT) && val)
486
- diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_IGNORE_STAT;
487
-
488
- if ((diff->opts.flags & GIT_DIFF_IGNORE_FILEMODE) == 0 &&
489
- !git_config__cvar(&val, cfg, GIT_CVAR_FILEMODE) && val)
490
- diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_MODE_BITS;
491
-
492
- if (!git_config__cvar(&val, cfg, GIT_CVAR_TRUSTCTIME) && val)
493
- diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_CTIME;
494
-
495
- /* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */
496
-
497
- /* If not given explicit `opts`, check `diff.xyz` configs */
498
- if (!opts) {
499
- int context = git_config__get_int_force(cfg, "diff.context", 3);
500
- diff->opts.context_lines = context >= 0 ? (uint32_t)context : 3;
501
-
502
- /* add other defaults here */
503
- }
504
-
505
- /* Reverse src info if diff is reversed */
506
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) {
507
- git_iterator_type_t tmp_src = diff->old_src;
508
- diff->old_src = diff->new_src;
509
- diff->new_src = tmp_src;
510
- }
511
-
512
- /* Unset UPDATE_INDEX unless diffing workdir and index */
513
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) &&
514
- (!(diff->old_src == GIT_ITERATOR_TYPE_WORKDIR ||
515
- diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ||
516
- !(diff->old_src == GIT_ITERATOR_TYPE_INDEX ||
517
- diff->new_src == GIT_ITERATOR_TYPE_INDEX)))
518
- diff->opts.flags &= ~GIT_DIFF_UPDATE_INDEX;
519
-
520
- /* if ignore_submodules not explicitly set, check diff config */
521
- if (diff->opts.ignore_submodules <= 0) {
522
- git_config_entry *entry;
523
- git_config__lookup_entry(&entry, cfg, "diff.ignoresubmodules", true);
524
-
525
- if (entry && git_submodule_parse_ignore(
526
- &diff->opts.ignore_submodules, entry->value) < 0)
527
- giterr_clear();
528
- git_config_entry_free(entry);
529
- }
530
-
531
- /* if either prefix is not set, figure out appropriate value */
532
- if (!diff->opts.old_prefix || !diff->opts.new_prefix) {
533
- const char *use_old = DIFF_OLD_PREFIX_DEFAULT;
534
- const char *use_new = DIFF_NEW_PREFIX_DEFAULT;
535
-
536
- if (git_config__get_bool_force(cfg, "diff.noprefix", 0))
537
- use_old = use_new = "";
538
- else if (git_config__get_bool_force(cfg, "diff.mnemonicprefix", 0)) {
539
- use_old = diff_mnemonic_prefix(diff->old_src, true);
540
- use_new = diff_mnemonic_prefix(diff->new_src, false);
541
- }
542
-
543
- if (!diff->opts.old_prefix)
544
- diff->opts.old_prefix = use_old;
545
- if (!diff->opts.new_prefix)
546
- diff->opts.new_prefix = use_new;
547
- }
548
-
549
- /* strdup prefix from pool so we're not dependent on external data */
550
- diff->opts.old_prefix = diff_strdup_prefix(pool, diff->opts.old_prefix);
551
- diff->opts.new_prefix = diff_strdup_prefix(pool, diff->opts.new_prefix);
552
-
553
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_REVERSE)) {
554
- const char *tmp_prefix = diff->opts.old_prefix;
555
- diff->opts.old_prefix = diff->opts.new_prefix;
556
- diff->opts.new_prefix = tmp_prefix;
557
- }
558
-
559
- git_config_free(cfg);
560
-
561
- /* check strdup results for error */
562
- return (!diff->opts.old_prefix || !diff->opts.new_prefix) ? -1 : 0;
563
- }
564
-
565
- static void diff_list_free(git_diff *diff)
566
- {
567
- git_vector_free_deep(&diff->deltas);
568
-
569
- git_pathspec__vfree(&diff->pathspec);
570
- git_pool_clear(&diff->pool);
571
-
572
- git__memzero(diff, sizeof(*diff));
573
- git__free(diff);
574
- }
575
-
576
70
  void git_diff_free(git_diff *diff)
577
71
  {
578
72
  if (!diff)
579
73
  return;
580
74
 
581
- GIT_REFCOUNT_DEC(diff, diff_list_free);
75
+ GIT_REFCOUNT_DEC(diff, diff->free_fn);
582
76
  }
583
77
 
584
78
  void git_diff_addref(git_diff *diff)
@@ -586,903 +80,6 @@ void git_diff_addref(git_diff *diff)
586
80
  GIT_REFCOUNT_INC(diff);
587
81
  }
588
82
 
589
- int git_diff__oid_for_file(
590
- git_oid *out,
591
- git_diff *diff,
592
- const char *path,
593
- uint16_t mode,
594
- git_off_t size)
595
- {
596
- git_index_entry entry;
597
-
598
- memset(&entry, 0, sizeof(entry));
599
- entry.mode = mode;
600
- entry.file_size = size;
601
- entry.path = (char *)path;
602
-
603
- return git_diff__oid_for_entry(out, diff, &entry, mode, NULL);
604
- }
605
-
606
- int git_diff__oid_for_entry(
607
- git_oid *out,
608
- git_diff *diff,
609
- const git_index_entry *src,
610
- uint16_t mode,
611
- const git_oid *update_match)
612
- {
613
- int error = 0;
614
- git_buf full_path = GIT_BUF_INIT;
615
- git_index_entry entry = *src;
616
- git_filter_list *fl = NULL;
617
-
618
- memset(out, 0, sizeof(*out));
619
-
620
- if (git_buf_joinpath(
621
- &full_path, git_repository_workdir(diff->repo), entry.path) < 0)
622
- return -1;
623
-
624
- if (!mode) {
625
- struct stat st;
626
-
627
- diff->perf.stat_calls++;
628
-
629
- if (p_stat(full_path.ptr, &st) < 0) {
630
- error = git_path_set_error(errno, entry.path, "stat");
631
- git_buf_free(&full_path);
632
- return error;
633
- }
634
-
635
- git_index_entry__init_from_stat(
636
- &entry, &st, (diff->diffcaps & GIT_DIFFCAPS_TRUST_MODE_BITS) != 0);
637
- }
638
-
639
- /* calculate OID for file if possible */
640
- if (S_ISGITLINK(mode)) {
641
- git_submodule *sm;
642
-
643
- if (!git_submodule_lookup(&sm, diff->repo, entry.path)) {
644
- const git_oid *sm_oid = git_submodule_wd_id(sm);
645
- if (sm_oid)
646
- git_oid_cpy(out, sm_oid);
647
- git_submodule_free(sm);
648
- } else {
649
- /* if submodule lookup failed probably just in an intermediate
650
- * state where some init hasn't happened, so ignore the error
651
- */
652
- giterr_clear();
653
- }
654
- } else if (S_ISLNK(mode)) {
655
- error = git_odb__hashlink(out, full_path.ptr);
656
- diff->perf.oid_calculations++;
657
- } else if (!git__is_sizet(entry.file_size)) {
658
- giterr_set(GITERR_OS, "File size overflow (for 32-bits) on '%s'",
659
- entry.path);
660
- error = -1;
661
- } else if (!(error = git_filter_list_load(
662
- &fl, diff->repo, NULL, entry.path,
663
- GIT_FILTER_TO_ODB, GIT_FILTER_ALLOW_UNSAFE)))
664
- {
665
- int fd = git_futils_open_ro(full_path.ptr);
666
- if (fd < 0)
667
- error = fd;
668
- else {
669
- error = git_odb__hashfd_filtered(
670
- out, fd, (size_t)entry.file_size, GIT_OBJ_BLOB, fl);
671
- p_close(fd);
672
- diff->perf.oid_calculations++;
673
- }
674
-
675
- git_filter_list_free(fl);
676
- }
677
-
678
- /* update index for entry if requested */
679
- if (!error && update_match && git_oid_equal(out, update_match)) {
680
- git_index *idx;
681
- git_index_entry updated_entry;
682
-
683
- memcpy(&updated_entry, &entry, sizeof(git_index_entry));
684
- updated_entry.mode = mode;
685
- git_oid_cpy(&updated_entry.id, out);
686
-
687
- if (!(error = git_repository_index__weakptr(&idx, diff->repo))) {
688
- error = git_index_add(idx, &updated_entry);
689
- diff->index_updated = true;
690
- }
691
- }
692
-
693
- git_buf_free(&full_path);
694
- return error;
695
- }
696
-
697
- typedef struct {
698
- git_repository *repo;
699
- git_iterator *old_iter;
700
- git_iterator *new_iter;
701
- const git_index_entry *oitem;
702
- const git_index_entry *nitem;
703
- } diff_in_progress;
704
-
705
- #define MODE_BITS_MASK 0000777
706
-
707
- static int maybe_modified_submodule(
708
- git_delta_t *status,
709
- git_oid *found_oid,
710
- git_diff *diff,
711
- diff_in_progress *info)
712
- {
713
- int error = 0;
714
- git_submodule *sub;
715
- unsigned int sm_status = 0;
716
- git_submodule_ignore_t ign = diff->opts.ignore_submodules;
717
-
718
- *status = GIT_DELTA_UNMODIFIED;
719
-
720
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_SUBMODULES) ||
721
- ign == GIT_SUBMODULE_IGNORE_ALL)
722
- return 0;
723
-
724
- if ((error = git_submodule_lookup(
725
- &sub, diff->repo, info->nitem->path)) < 0) {
726
-
727
- /* GIT_EEXISTS means dir with .git in it was found - ignore it */
728
- if (error == GIT_EEXISTS) {
729
- giterr_clear();
730
- error = 0;
731
- }
732
- return error;
733
- }
734
-
735
- if (ign <= 0 && git_submodule_ignore(sub) == GIT_SUBMODULE_IGNORE_ALL)
736
- /* ignore it */;
737
- else if ((error = git_submodule__status(
738
- &sm_status, NULL, NULL, found_oid, sub, ign)) < 0)
739
- /* return error below */;
740
-
741
- /* check IS_WD_UNMODIFIED because this case is only used
742
- * when the new side of the diff is the working directory
743
- */
744
- else if (!GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(sm_status))
745
- *status = GIT_DELTA_MODIFIED;
746
-
747
- /* now that we have a HEAD OID, check if HEAD moved */
748
- else if ((sm_status & GIT_SUBMODULE_STATUS_IN_WD) != 0 &&
749
- !git_oid_equal(&info->oitem->id, found_oid))
750
- *status = GIT_DELTA_MODIFIED;
751
-
752
- git_submodule_free(sub);
753
- return error;
754
- }
755
-
756
- static int maybe_modified(
757
- git_diff *diff,
758
- diff_in_progress *info)
759
- {
760
- git_oid noid;
761
- git_delta_t status = GIT_DELTA_MODIFIED;
762
- const git_index_entry *oitem = info->oitem;
763
- const git_index_entry *nitem = info->nitem;
764
- unsigned int omode = oitem->mode;
765
- unsigned int nmode = nitem->mode;
766
- bool new_is_workdir = (info->new_iter->type == GIT_ITERATOR_TYPE_WORKDIR);
767
- bool modified_uncertain = false;
768
- const char *matched_pathspec;
769
- int error = 0;
770
-
771
- if (!diff_pathspec_match(&matched_pathspec, diff, oitem))
772
- return 0;
773
-
774
- memset(&noid, 0, sizeof(noid));
775
-
776
- /* on platforms with no symlinks, preserve mode of existing symlinks */
777
- if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir &&
778
- !(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS))
779
- nmode = omode;
780
-
781
- /* on platforms with no execmode, just preserve old mode */
782
- if (!(diff->diffcaps & GIT_DIFFCAPS_TRUST_MODE_BITS) &&
783
- (nmode & MODE_BITS_MASK) != (omode & MODE_BITS_MASK) &&
784
- new_is_workdir)
785
- nmode = (nmode & ~MODE_BITS_MASK) | (omode & MODE_BITS_MASK);
786
-
787
- /* if one side is a conflict, mark the whole delta as conflicted */
788
- if (git_index_entry_is_conflict(oitem) ||
789
- git_index_entry_is_conflict(nitem)) {
790
- status = GIT_DELTA_CONFLICTED;
791
-
792
- /* support "assume unchanged" (poorly, b/c we still stat everything) */
793
- } else if ((oitem->flags & GIT_IDXENTRY_VALID) != 0) {
794
- status = GIT_DELTA_UNMODIFIED;
795
-
796
- /* support "skip worktree" index bit */
797
- } else if ((oitem->flags_extended & GIT_IDXENTRY_SKIP_WORKTREE) != 0) {
798
- status = GIT_DELTA_UNMODIFIED;
799
-
800
- /* if basic type of file changed, then split into delete and add */
801
- } else if (GIT_MODE_TYPE(omode) != GIT_MODE_TYPE(nmode)) {
802
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE)) {
803
- status = GIT_DELTA_TYPECHANGE;
804
- }
805
-
806
- else if (nmode == GIT_FILEMODE_UNREADABLE) {
807
- if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL)))
808
- error = diff_delta__from_one(diff, GIT_DELTA_UNREADABLE, NULL, nitem);
809
- return error;
810
- }
811
-
812
- else {
813
- if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL)))
814
- error = diff_delta__from_one(diff, GIT_DELTA_ADDED, NULL, nitem);
815
- return error;
816
- }
817
-
818
- /* if oids and modes match (and are valid), then file is unmodified */
819
- } else if (git_oid_equal(&oitem->id, &nitem->id) &&
820
- omode == nmode &&
821
- !git_oid_iszero(&oitem->id)) {
822
- status = GIT_DELTA_UNMODIFIED;
823
-
824
- /* if we have an unknown OID and a workdir iterator, then check some
825
- * circumstances that can accelerate things or need special handling
826
- */
827
- } else if (git_oid_iszero(&nitem->id) && new_is_workdir) {
828
- bool use_ctime = ((diff->diffcaps & GIT_DIFFCAPS_TRUST_CTIME) != 0);
829
- git_index *index;
830
- git_iterator_index(&index, info->new_iter);
831
-
832
- status = GIT_DELTA_UNMODIFIED;
833
-
834
- if (S_ISGITLINK(nmode)) {
835
- if ((error = maybe_modified_submodule(&status, &noid, diff, info)) < 0)
836
- return error;
837
- }
838
-
839
- /* if the stat data looks different, then mark modified - this just
840
- * means that the OID will be recalculated below to confirm change
841
- */
842
- else if (omode != nmode || oitem->file_size != nitem->file_size) {
843
- status = GIT_DELTA_MODIFIED;
844
- modified_uncertain =
845
- (oitem->file_size <= 0 && nitem->file_size > 0);
846
- }
847
- else if (!git_index_time_eq(&oitem->mtime, &nitem->mtime) ||
848
- (use_ctime && !git_index_time_eq(&oitem->ctime, &nitem->ctime)) ||
849
- oitem->ino != nitem->ino ||
850
- oitem->uid != nitem->uid ||
851
- oitem->gid != nitem->gid ||
852
- git_index_entry_newer_than_index(nitem, index))
853
- {
854
- status = GIT_DELTA_MODIFIED;
855
- modified_uncertain = true;
856
- }
857
-
858
- /* if mode is GITLINK and submodules are ignored, then skip */
859
- } else if (S_ISGITLINK(nmode) &&
860
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_SUBMODULES)) {
861
- status = GIT_DELTA_UNMODIFIED;
862
- }
863
-
864
- /* if we got here and decided that the files are modified, but we
865
- * haven't calculated the OID of the new item, then calculate it now
866
- */
867
- if (modified_uncertain && git_oid_iszero(&nitem->id)) {
868
- const git_oid *update_check =
869
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_UPDATE_INDEX) && omode == nmode ?
870
- &oitem->id : NULL;
871
-
872
- if ((error = git_diff__oid_for_entry(
873
- &noid, diff, nitem, nmode, update_check)) < 0)
874
- return error;
875
-
876
- /* if oid matches, then mark unmodified (except submodules, where
877
- * the filesystem content may be modified even if the oid still
878
- * matches between the index and the workdir HEAD)
879
- */
880
- if (omode == nmode && !S_ISGITLINK(omode) &&
881
- git_oid_equal(&oitem->id, &noid))
882
- status = GIT_DELTA_UNMODIFIED;
883
- }
884
-
885
- /* If we want case changes, then break this into a delete of the old
886
- * and an add of the new so that consumers can act accordingly (eg,
887
- * checkout will update the case on disk.)
888
- */
889
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE) &&
890
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_CASECHANGE) &&
891
- strcmp(oitem->path, nitem->path) != 0) {
892
-
893
- if (!(error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem, NULL)))
894
- error = diff_delta__from_one(diff, GIT_DELTA_ADDED, NULL, nitem);
895
-
896
- return error;
897
- }
898
-
899
- return diff_delta__from_two(
900
- diff, status, oitem, omode, nitem, nmode,
901
- git_oid_iszero(&noid) ? NULL : &noid, matched_pathspec);
902
- }
903
-
904
- static bool entry_is_prefixed(
905
- git_diff *diff,
906
- const git_index_entry *item,
907
- const git_index_entry *prefix_item)
908
- {
909
- size_t pathlen;
910
-
911
- if (!item || diff->pfxcomp(item->path, prefix_item->path) != 0)
912
- return false;
913
-
914
- pathlen = strlen(prefix_item->path);
915
-
916
- return (prefix_item->path[pathlen - 1] == '/' ||
917
- item->path[pathlen] == '\0' ||
918
- item->path[pathlen] == '/');
919
- }
920
-
921
- static int iterator_current(
922
- const git_index_entry **entry,
923
- git_iterator *iterator)
924
- {
925
- int error;
926
-
927
- if ((error = git_iterator_current(entry, iterator)) == GIT_ITEROVER) {
928
- *entry = NULL;
929
- error = 0;
930
- }
931
-
932
- return error;
933
- }
934
-
935
- static int iterator_advance(
936
- const git_index_entry **entry,
937
- git_iterator *iterator)
938
- {
939
- const git_index_entry *prev_entry = *entry;
940
- int cmp, error;
941
-
942
- /* if we're looking for conflicts, we only want to report
943
- * one conflict for each file, instead of all three sides.
944
- * so if this entry is a conflict for this file, and the
945
- * previous one was a conflict for the same file, skip it.
946
- */
947
- while ((error = git_iterator_advance(entry, iterator)) == 0) {
948
- if (!(iterator->flags & GIT_ITERATOR_INCLUDE_CONFLICTS) ||
949
- !git_index_entry_is_conflict(prev_entry) ||
950
- !git_index_entry_is_conflict(*entry))
951
- break;
952
-
953
- cmp = (iterator->flags & GIT_ITERATOR_IGNORE_CASE) ?
954
- strcasecmp(prev_entry->path, (*entry)->path) :
955
- strcmp(prev_entry->path, (*entry)->path);
956
-
957
- if (cmp)
958
- break;
959
- }
960
-
961
- if (error == GIT_ITEROVER) {
962
- *entry = NULL;
963
- error = 0;
964
- }
965
-
966
- return error;
967
- }
968
-
969
- static int iterator_advance_into(
970
- const git_index_entry **entry,
971
- git_iterator *iterator)
972
- {
973
- int error;
974
-
975
- if ((error = git_iterator_advance_into(entry, iterator)) == GIT_ITEROVER) {
976
- *entry = NULL;
977
- error = 0;
978
- }
979
-
980
- return error;
981
- }
982
-
983
- static int iterator_advance_over_with_status(
984
- const git_index_entry **entry,
985
- git_iterator_status_t *status,
986
- git_iterator *iterator)
987
- {
988
- int error;
989
-
990
- if ((error = git_iterator_advance_over_with_status(
991
- entry, status, iterator)) == GIT_ITEROVER) {
992
- *entry = NULL;
993
- error = 0;
994
- }
995
-
996
- return error;
997
- }
998
-
999
- static int handle_unmatched_new_item(
1000
- git_diff *diff, diff_in_progress *info)
1001
- {
1002
- int error = 0;
1003
- const git_index_entry *nitem = info->nitem;
1004
- git_delta_t delta_type = GIT_DELTA_UNTRACKED;
1005
- bool contains_oitem;
1006
-
1007
- /* check if this is a prefix of the other side */
1008
- contains_oitem = entry_is_prefixed(diff, info->oitem, nitem);
1009
-
1010
- /* update delta_type if this item is conflicted */
1011
- if (git_index_entry_is_conflict(nitem))
1012
- delta_type = GIT_DELTA_CONFLICTED;
1013
-
1014
- /* update delta_type if this item is ignored */
1015
- else if (git_iterator_current_is_ignored(info->new_iter))
1016
- delta_type = GIT_DELTA_IGNORED;
1017
-
1018
- if (nitem->mode == GIT_FILEMODE_TREE) {
1019
- bool recurse_into_dir = contains_oitem;
1020
-
1021
- /* check if user requests recursion into this type of dir */
1022
- recurse_into_dir = contains_oitem ||
1023
- (delta_type == GIT_DELTA_UNTRACKED &&
1024
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_RECURSE_UNTRACKED_DIRS)) ||
1025
- (delta_type == GIT_DELTA_IGNORED &&
1026
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_RECURSE_IGNORED_DIRS));
1027
-
1028
- /* do not advance into directories that contain a .git file */
1029
- if (recurse_into_dir && !contains_oitem) {
1030
- git_buf *full = NULL;
1031
- if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
1032
- return -1;
1033
- if (full && git_path_contains(full, DOT_GIT)) {
1034
- /* TODO: warning if not a valid git repository */
1035
- recurse_into_dir = false;
1036
- }
1037
- }
1038
-
1039
- /* still have to look into untracked directories to match core git -
1040
- * with no untracked files, directory is treated as ignored
1041
- */
1042
- if (!recurse_into_dir &&
1043
- delta_type == GIT_DELTA_UNTRACKED &&
1044
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS))
1045
- {
1046
- git_diff_delta *last;
1047
- git_iterator_status_t untracked_state;
1048
-
1049
- /* attempt to insert record for this directory */
1050
- if ((error = diff_delta__from_one(diff, delta_type, NULL, nitem)) != 0)
1051
- return error;
1052
-
1053
- /* if delta wasn't created (because of rules), just skip ahead */
1054
- last = diff_delta__last_for_item(diff, nitem);
1055
- if (!last)
1056
- return iterator_advance(&info->nitem, info->new_iter);
1057
-
1058
- /* iterate into dir looking for an actual untracked file */
1059
- if ((error = iterator_advance_over_with_status(
1060
- &info->nitem, &untracked_state, info->new_iter)) < 0)
1061
- return error;
1062
-
1063
- /* if we found nothing that matched our pathlist filter, exclude */
1064
- if (untracked_state == GIT_ITERATOR_STATUS_FILTERED) {
1065
- git_vector_pop(&diff->deltas);
1066
- git__free(last);
1067
- }
1068
-
1069
- /* if we found nothing or just ignored items, update the record */
1070
- if (untracked_state == GIT_ITERATOR_STATUS_IGNORED ||
1071
- untracked_state == GIT_ITERATOR_STATUS_EMPTY) {
1072
- last->status = GIT_DELTA_IGNORED;
1073
-
1074
- /* remove the record if we don't want ignored records */
1075
- if (DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_IGNORED)) {
1076
- git_vector_pop(&diff->deltas);
1077
- git__free(last);
1078
- }
1079
- }
1080
-
1081
- return 0;
1082
- }
1083
-
1084
- /* try to advance into directory if necessary */
1085
- if (recurse_into_dir) {
1086
- error = iterator_advance_into(&info->nitem, info->new_iter);
1087
-
1088
- /* if real error or no error, proceed with iteration */
1089
- if (error != GIT_ENOTFOUND)
1090
- return error;
1091
- giterr_clear();
1092
-
1093
- /* if directory is empty, can't advance into it, so either skip
1094
- * it or ignore it
1095
- */
1096
- if (contains_oitem)
1097
- return iterator_advance(&info->nitem, info->new_iter);
1098
- delta_type = GIT_DELTA_IGNORED;
1099
- }
1100
- }
1101
-
1102
- else if (delta_type == GIT_DELTA_IGNORED &&
1103
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_RECURSE_IGNORED_DIRS) &&
1104
- git_iterator_current_tree_is_ignored(info->new_iter))
1105
- /* item contained in ignored directory, so skip over it */
1106
- return iterator_advance(&info->nitem, info->new_iter);
1107
-
1108
- else if (info->new_iter->type != GIT_ITERATOR_TYPE_WORKDIR) {
1109
- if (delta_type != GIT_DELTA_CONFLICTED)
1110
- delta_type = GIT_DELTA_ADDED;
1111
- }
1112
-
1113
- else if (nitem->mode == GIT_FILEMODE_COMMIT) {
1114
- /* ignore things that are not actual submodules */
1115
- if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) {
1116
- giterr_clear();
1117
- delta_type = GIT_DELTA_IGNORED;
1118
-
1119
- /* if this contains a tracked item, treat as normal TREE */
1120
- if (contains_oitem) {
1121
- error = iterator_advance_into(&info->nitem, info->new_iter);
1122
- if (error != GIT_ENOTFOUND)
1123
- return error;
1124
-
1125
- giterr_clear();
1126
- return iterator_advance(&info->nitem, info->new_iter);
1127
- }
1128
- }
1129
- }
1130
-
1131
- else if (nitem->mode == GIT_FILEMODE_UNREADABLE) {
1132
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED))
1133
- delta_type = GIT_DELTA_UNTRACKED;
1134
- else
1135
- delta_type = GIT_DELTA_UNREADABLE;
1136
- }
1137
-
1138
- /* Actually create the record for this item if necessary */
1139
- if ((error = diff_delta__from_one(diff, delta_type, NULL, nitem)) != 0)
1140
- return error;
1141
-
1142
- /* If user requested TYPECHANGE records, then check for that instead of
1143
- * just generating an ADDED/UNTRACKED record
1144
- */
1145
- if (delta_type != GIT_DELTA_IGNORED &&
1146
- DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES) &&
1147
- contains_oitem)
1148
- {
1149
- /* this entry was prefixed with a tree - make TYPECHANGE */
1150
- git_diff_delta *last = diff_delta__last_for_item(diff, nitem);
1151
- if (last) {
1152
- last->status = GIT_DELTA_TYPECHANGE;
1153
- last->old_file.mode = GIT_FILEMODE_TREE;
1154
- }
1155
- }
1156
-
1157
- return iterator_advance(&info->nitem, info->new_iter);
1158
- }
1159
-
1160
- static int handle_unmatched_old_item(
1161
- git_diff *diff, diff_in_progress *info)
1162
- {
1163
- git_delta_t delta_type = GIT_DELTA_DELETED;
1164
- int error;
1165
-
1166
- /* update delta_type if this item is conflicted */
1167
- if (git_index_entry_is_conflict(info->oitem))
1168
- delta_type = GIT_DELTA_CONFLICTED;
1169
-
1170
- if ((error = diff_delta__from_one(diff, delta_type, info->oitem, NULL)) < 0)
1171
- return error;
1172
-
1173
- /* if we are generating TYPECHANGE records then check for that
1174
- * instead of just generating a DELETE record
1175
- */
1176
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES) &&
1177
- entry_is_prefixed(diff, info->nitem, info->oitem))
1178
- {
1179
- /* this entry has become a tree! convert to TYPECHANGE */
1180
- git_diff_delta *last = diff_delta__last_for_item(diff, info->oitem);
1181
- if (last) {
1182
- last->status = GIT_DELTA_TYPECHANGE;
1183
- last->new_file.mode = GIT_FILEMODE_TREE;
1184
- }
1185
-
1186
- /* If new_iter is a workdir iterator, then this situation
1187
- * will certainly be followed by a series of untracked items.
1188
- * Unless RECURSE_UNTRACKED_DIRS is set, skip over them...
1189
- */
1190
- if (S_ISDIR(info->nitem->mode) &&
1191
- DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_RECURSE_UNTRACKED_DIRS))
1192
- return iterator_advance(&info->nitem, info->new_iter);
1193
- }
1194
-
1195
- return iterator_advance(&info->oitem, info->old_iter);
1196
- }
1197
-
1198
- static int handle_matched_item(
1199
- git_diff *diff, diff_in_progress *info)
1200
- {
1201
- int error = 0;
1202
-
1203
- if ((error = maybe_modified(diff, info)) < 0)
1204
- return error;
1205
-
1206
- if (!(error = iterator_advance(&info->oitem, info->old_iter)))
1207
- error = iterator_advance(&info->nitem, info->new_iter);
1208
-
1209
- return error;
1210
- }
1211
-
1212
- int git_diff__from_iterators(
1213
- git_diff **diff_ptr,
1214
- git_repository *repo,
1215
- git_iterator *old_iter,
1216
- git_iterator *new_iter,
1217
- const git_diff_options *opts)
1218
- {
1219
- int error = 0;
1220
- diff_in_progress info;
1221
- git_diff *diff;
1222
-
1223
- *diff_ptr = NULL;
1224
-
1225
- diff = diff_list_alloc(repo, old_iter, new_iter);
1226
- GITERR_CHECK_ALLOC(diff);
1227
-
1228
- info.repo = repo;
1229
- info.old_iter = old_iter;
1230
- info.new_iter = new_iter;
1231
-
1232
- /* make iterators have matching icase behavior */
1233
- if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) {
1234
- if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 ||
1235
- (error = git_iterator_set_ignore_case(new_iter, true)) < 0)
1236
- goto cleanup;
1237
- }
1238
-
1239
- /* finish initialization */
1240
- if ((error = diff_list_apply_options(diff, opts)) < 0)
1241
- goto cleanup;
1242
-
1243
- if ((error = iterator_current(&info.oitem, old_iter)) < 0 ||
1244
- (error = iterator_current(&info.nitem, new_iter)) < 0)
1245
- goto cleanup;
1246
-
1247
- /* run iterators building diffs */
1248
- while (!error && (info.oitem || info.nitem)) {
1249
- int cmp;
1250
-
1251
- /* report progress */
1252
- if (opts && opts->progress_cb) {
1253
- if ((error = opts->progress_cb(diff,
1254
- info.oitem ? info.oitem->path : NULL,
1255
- info.nitem ? info.nitem->path : NULL,
1256
- opts->payload)))
1257
- break;
1258
- }
1259
-
1260
- cmp = info.oitem ?
1261
- (info.nitem ? diff->entrycomp(info.oitem, info.nitem) : -1) : 1;
1262
-
1263
- /* create DELETED records for old items not matched in new */
1264
- if (cmp < 0)
1265
- error = handle_unmatched_old_item(diff, &info);
1266
-
1267
- /* create ADDED, TRACKED, or IGNORED records for new items not
1268
- * matched in old (and/or descend into directories as needed)
1269
- */
1270
- else if (cmp > 0)
1271
- error = handle_unmatched_new_item(diff, &info);
1272
-
1273
- /* otherwise item paths match, so create MODIFIED record
1274
- * (or ADDED and DELETED pair if type changed)
1275
- */
1276
- else
1277
- error = handle_matched_item(diff, &info);
1278
- }
1279
-
1280
- diff->perf.stat_calls += old_iter->stat_calls + new_iter->stat_calls;
1281
-
1282
- cleanup:
1283
- if (!error)
1284
- *diff_ptr = diff;
1285
- else
1286
- git_diff_free(diff);
1287
-
1288
- return error;
1289
- }
1290
-
1291
- #define DIFF_FROM_ITERATORS(MAKE_FIRST, FLAGS_FIRST, MAKE_SECOND, FLAGS_SECOND) do { \
1292
- git_iterator *a = NULL, *b = NULL; \
1293
- char *pfx = (opts && !(opts->flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH)) ? \
1294
- git_pathspec_prefix(&opts->pathspec) : NULL; \
1295
- git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, \
1296
- b_opts = GIT_ITERATOR_OPTIONS_INIT; \
1297
- a_opts.flags = FLAGS_FIRST; \
1298
- a_opts.start = pfx; \
1299
- a_opts.end = pfx; \
1300
- b_opts.flags = FLAGS_SECOND; \
1301
- b_opts.start = pfx; \
1302
- b_opts.end = pfx; \
1303
- GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \
1304
- if (opts && (opts->flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH)) { \
1305
- a_opts.pathlist.strings = opts->pathspec.strings; \
1306
- a_opts.pathlist.count = opts->pathspec.count; \
1307
- b_opts.pathlist.strings = opts->pathspec.strings; \
1308
- b_opts.pathlist.count = opts->pathspec.count; \
1309
- } \
1310
- if (!error && !(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
1311
- error = git_diff__from_iterators(diff, repo, a, b, opts); \
1312
- git__free(pfx); git_iterator_free(a); git_iterator_free(b); \
1313
- } while (0)
1314
-
1315
- int git_diff_tree_to_tree(
1316
- git_diff **diff,
1317
- git_repository *repo,
1318
- git_tree *old_tree,
1319
- git_tree *new_tree,
1320
- const git_diff_options *opts)
1321
- {
1322
- git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE;
1323
- int error = 0;
1324
-
1325
- assert(diff && repo);
1326
-
1327
- /* for tree to tree diff, be case sensitive even if the index is
1328
- * currently case insensitive, unless the user explicitly asked
1329
- * for case insensitivity
1330
- */
1331
- if (opts && (opts->flags & GIT_DIFF_IGNORE_CASE) != 0)
1332
- iflag = GIT_ITERATOR_IGNORE_CASE;
1333
-
1334
- DIFF_FROM_ITERATORS(
1335
- git_iterator_for_tree(&a, old_tree, &a_opts), iflag,
1336
- git_iterator_for_tree(&b, new_tree, &b_opts), iflag
1337
- );
1338
-
1339
- return error;
1340
- }
1341
-
1342
- static int diff_load_index(git_index **index, git_repository *repo)
1343
- {
1344
- int error = git_repository_index__weakptr(index, repo);
1345
-
1346
- /* reload the repository index when user did not pass one in */
1347
- if (!error && git_index_read(*index, false) < 0)
1348
- giterr_clear();
1349
-
1350
- return error;
1351
- }
1352
-
1353
- int git_diff_tree_to_index(
1354
- git_diff **diff,
1355
- git_repository *repo,
1356
- git_tree *old_tree,
1357
- git_index *index,
1358
- const git_diff_options *opts)
1359
- {
1360
- git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE |
1361
- GIT_ITERATOR_INCLUDE_CONFLICTS;
1362
- bool index_ignore_case = false;
1363
- int error = 0;
1364
-
1365
- assert(diff && repo);
1366
-
1367
- if (!index && (error = diff_load_index(&index, repo)) < 0)
1368
- return error;
1369
-
1370
- index_ignore_case = index->ignore_case;
1371
-
1372
- DIFF_FROM_ITERATORS(
1373
- git_iterator_for_tree(&a, old_tree, &a_opts), iflag,
1374
- git_iterator_for_index(&b, repo, index, &b_opts), iflag
1375
- );
1376
-
1377
- /* if index is in case-insensitive order, re-sort deltas to match */
1378
- if (!error && index_ignore_case)
1379
- diff_set_ignore_case(*diff, true);
1380
-
1381
- return error;
1382
- }
1383
-
1384
- int git_diff_index_to_workdir(
1385
- git_diff **diff,
1386
- git_repository *repo,
1387
- git_index *index,
1388
- const git_diff_options *opts)
1389
- {
1390
- int error = 0;
1391
-
1392
- assert(diff && repo);
1393
-
1394
- if (!index && (error = diff_load_index(&index, repo)) < 0)
1395
- return error;
1396
-
1397
- DIFF_FROM_ITERATORS(
1398
- git_iterator_for_index(&a, repo, index, &a_opts),
1399
- GIT_ITERATOR_INCLUDE_CONFLICTS,
1400
-
1401
- git_iterator_for_workdir(&b, repo, index, NULL, &b_opts),
1402
- GIT_ITERATOR_DONT_AUTOEXPAND
1403
- );
1404
-
1405
- if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX) && (*diff)->index_updated)
1406
- error = git_index_write(index);
1407
-
1408
- return error;
1409
- }
1410
-
1411
- int git_diff_tree_to_workdir(
1412
- git_diff **diff,
1413
- git_repository *repo,
1414
- git_tree *old_tree,
1415
- const git_diff_options *opts)
1416
- {
1417
- int error = 0;
1418
- git_index *index;
1419
-
1420
- assert(diff && repo);
1421
-
1422
- if ((error = git_repository_index__weakptr(&index, repo)))
1423
- return error;
1424
-
1425
- DIFF_FROM_ITERATORS(
1426
- git_iterator_for_tree(&a, old_tree, &a_opts), 0,
1427
- git_iterator_for_workdir(&b, repo, index, old_tree, &b_opts), GIT_ITERATOR_DONT_AUTOEXPAND
1428
- );
1429
-
1430
- return error;
1431
- }
1432
-
1433
- int git_diff_tree_to_workdir_with_index(
1434
- git_diff **diff,
1435
- git_repository *repo,
1436
- git_tree *old_tree,
1437
- const git_diff_options *opts)
1438
- {
1439
- int error = 0;
1440
- git_diff *d1 = NULL, *d2 = NULL;
1441
- git_index *index = NULL;
1442
-
1443
- assert(diff && repo);
1444
-
1445
- if ((error = diff_load_index(&index, repo)) < 0)
1446
- return error;
1447
-
1448
- if (!(error = git_diff_tree_to_index(&d1, repo, old_tree, index, opts)) &&
1449
- !(error = git_diff_index_to_workdir(&d2, repo, index, opts)))
1450
- error = git_diff_merge(d1, d2);
1451
-
1452
- git_diff_free(d2);
1453
-
1454
- if (error) {
1455
- git_diff_free(d1);
1456
- d1 = NULL;
1457
- }
1458
-
1459
- *diff = d1;
1460
- return error;
1461
- }
1462
-
1463
- int git_diff_index_to_index(
1464
- git_diff **diff,
1465
- git_repository *repo,
1466
- git_index *old_index,
1467
- git_index *new_index,
1468
- const git_diff_options *opts)
1469
- {
1470
- int error = 0;
1471
-
1472
- assert(diff && old_index && new_index);
1473
-
1474
- DIFF_FROM_ITERATORS(
1475
- git_iterator_for_index(&a, repo, old_index, &a_opts), GIT_ITERATOR_DONT_IGNORE_CASE,
1476
- git_iterator_for_index(&b, repo, new_index, &b_opts), GIT_ITERATOR_DONT_IGNORE_CASE
1477
- );
1478
-
1479
- /* if index is in case-insensitive order, re-sort deltas to match */
1480
- if (!error && (old_index->ignore_case || new_index->ignore_case))
1481
- diff_set_ignore_case(*diff, true);
1482
-
1483
- return error;
1484
- }
1485
-
1486
83
  size_t git_diff_num_deltas(const git_diff *diff)
1487
84
  {
1488
85
  assert(diff);
@@ -1523,137 +120,6 @@ int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
1523
120
  return 0;
1524
121
  }
1525
122
 
1526
- int git_diff__paired_foreach(
1527
- git_diff *head2idx,
1528
- git_diff *idx2wd,
1529
- int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload),
1530
- void *payload)
1531
- {
1532
- int cmp, error = 0;
1533
- git_diff_delta *h2i, *i2w;
1534
- size_t i, j, i_max, j_max;
1535
- int (*strcomp)(const char *, const char *) = git__strcmp;
1536
- bool h2i_icase, i2w_icase, icase_mismatch;
1537
-
1538
- i_max = head2idx ? head2idx->deltas.length : 0;
1539
- j_max = idx2wd ? idx2wd->deltas.length : 0;
1540
- if (!i_max && !j_max)
1541
- return 0;
1542
-
1543
- /* At some point, tree-to-index diffs will probably never ignore case,
1544
- * even if that isn't true now. Index-to-workdir diffs may or may not
1545
- * ignore case, but the index filename for the idx2wd diff should
1546
- * still be using the canonical case-preserving name.
1547
- *
1548
- * Therefore the main thing we need to do here is make sure the diffs
1549
- * are traversed in a compatible order. To do this, we temporarily
1550
- * resort a mismatched diff to get the order correct.
1551
- *
1552
- * In order to traverse renames in the index->workdir, we need to
1553
- * ensure that we compare the index name on both sides, so we
1554
- * always sort by the old name in the i2w list.
1555
- */
1556
- h2i_icase = head2idx != NULL &&
1557
- (head2idx->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
1558
-
1559
- i2w_icase = idx2wd != NULL &&
1560
- (idx2wd->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
1561
-
1562
- icase_mismatch =
1563
- (head2idx != NULL && idx2wd != NULL && h2i_icase != i2w_icase);
1564
-
1565
- if (icase_mismatch && h2i_icase) {
1566
- git_vector_set_cmp(&head2idx->deltas, git_diff_delta__cmp);
1567
- git_vector_sort(&head2idx->deltas);
1568
- }
1569
-
1570
- if (i2w_icase && !icase_mismatch) {
1571
- strcomp = git__strcasecmp;
1572
-
1573
- git_vector_set_cmp(&idx2wd->deltas, git_diff_delta__i2w_casecmp);
1574
- git_vector_sort(&idx2wd->deltas);
1575
- } else if (idx2wd != NULL) {
1576
- git_vector_set_cmp(&idx2wd->deltas, git_diff_delta__i2w_cmp);
1577
- git_vector_sort(&idx2wd->deltas);
1578
- }
1579
-
1580
- for (i = 0, j = 0; i < i_max || j < j_max; ) {
1581
- h2i = head2idx ? GIT_VECTOR_GET(&head2idx->deltas, i) : NULL;
1582
- i2w = idx2wd ? GIT_VECTOR_GET(&idx2wd->deltas, j) : NULL;
1583
-
1584
- cmp = !i2w ? -1 : !h2i ? 1 :
1585
- strcomp(h2i->new_file.path, i2w->old_file.path);
1586
-
1587
- if (cmp < 0) {
1588
- i++; i2w = NULL;
1589
- } else if (cmp > 0) {
1590
- j++; h2i = NULL;
1591
- } else {
1592
- i++; j++;
1593
- }
1594
-
1595
- if ((error = cb(h2i, i2w, payload)) != 0) {
1596
- giterr_set_after_callback(error);
1597
- break;
1598
- }
1599
- }
1600
-
1601
- /* restore case-insensitive delta sort */
1602
- if (icase_mismatch && h2i_icase) {
1603
- git_vector_set_cmp(&head2idx->deltas, git_diff_delta__casecmp);
1604
- git_vector_sort(&head2idx->deltas);
1605
- }
1606
-
1607
- /* restore idx2wd sort by new path */
1608
- if (idx2wd != NULL) {
1609
- git_vector_set_cmp(&idx2wd->deltas,
1610
- i2w_icase ? git_diff_delta__casecmp : git_diff_delta__cmp);
1611
- git_vector_sort(&idx2wd->deltas);
1612
- }
1613
-
1614
- return error;
1615
- }
1616
-
1617
- int git_diff__commit(
1618
- git_diff **diff,
1619
- git_repository *repo,
1620
- const git_commit *commit,
1621
- const git_diff_options *opts)
1622
- {
1623
- git_commit *parent = NULL;
1624
- git_diff *commit_diff = NULL;
1625
- git_tree *old_tree = NULL, *new_tree = NULL;
1626
- size_t parents;
1627
- int error = 0;
1628
-
1629
- if ((parents = git_commit_parentcount(commit)) > 1) {
1630
- char commit_oidstr[GIT_OID_HEXSZ + 1];
1631
-
1632
- error = -1;
1633
- giterr_set(GITERR_INVALID, "Commit %s is a merge commit",
1634
- git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
1635
- goto on_error;
1636
- }
1637
-
1638
- if (parents > 0)
1639
- if ((error = git_commit_parent(&parent, commit, 0)) < 0 ||
1640
- (error = git_commit_tree(&old_tree, parent)) < 0)
1641
- goto on_error;
1642
-
1643
- if ((error = git_commit_tree(&new_tree, commit)) < 0 ||
1644
- (error = git_diff_tree_to_tree(&commit_diff, repo, old_tree, new_tree, opts)) < 0)
1645
- goto on_error;
1646
-
1647
- *diff = commit_diff;
1648
-
1649
- on_error:
1650
- git_tree_free(new_tree);
1651
- git_tree_free(old_tree);
1652
- git_commit_free(parent);
1653
-
1654
- return error;
1655
- }
1656
-
1657
123
  int git_diff_format_email__append_header_tobuf(
1658
124
  git_buf *out,
1659
125
  const git_oid *id,
@@ -1671,7 +137,8 @@ int git_diff_format_email__append_header_tobuf(
1671
137
  git_oid_fmt(idstr, id);
1672
138
  idstr[GIT_OID_HEXSZ] = '\0';
1673
139
 
1674
- if ((error = git__date_rfc2822_fmt(date_str, sizeof(date_str), &author->when)) < 0)
140
+ if ((error = git__date_rfc2822_fmt(date_str, sizeof(date_str),
141
+ &author->when)) < 0)
1675
142
  return error;
1676
143
 
1677
144
  error = git_buf_printf(out,
@@ -1690,7 +157,8 @@ int git_diff_format_email__append_header_tobuf(
1690
157
  if (total_patches == 1) {
1691
158
  error = git_buf_puts(out, "[PATCH] ");
1692
159
  } else {
1693
- error = git_buf_printf(out, "[PATCH %"PRIuZ"/%"PRIuZ"] ", patch_no, total_patches);
160
+ error = git_buf_printf(out, "[PATCH %"PRIuZ"/%"PRIuZ"] ",
161
+ patch_no, total_patches);
1694
162
  }
1695
163
 
1696
164
  if (error < 0)
@@ -1748,16 +216,24 @@ int git_diff_format_email(
1748
216
  assert(out && diff && opts);
1749
217
  assert(opts->summary && opts->id && opts->author);
1750
218
 
1751
- GITERR_CHECK_VERSION(opts, GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, "git_format_email_options");
219
+ GITERR_CHECK_VERSION(opts,
220
+ GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
221
+ "git_format_email_options");
222
+
223
+ ignore_marker = (opts->flags &
224
+ GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0;
1752
225
 
1753
- if ((ignore_marker = opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) == false) {
226
+ if (!ignore_marker) {
1754
227
  if (opts->patch_no > opts->total_patches) {
1755
- giterr_set(GITERR_INVALID, "patch %"PRIuZ" out of range. max %"PRIuZ, opts->patch_no, opts->total_patches);
228
+ giterr_set(GITERR_INVALID,
229
+ "patch %"PRIuZ" out of range. max %"PRIuZ,
230
+ opts->patch_no, opts->total_patches);
1756
231
  return -1;
1757
232
  }
1758
233
 
1759
234
  if (opts->patch_no == 0) {
1760
- giterr_set(GITERR_INVALID, "invalid patch no %"PRIuZ". should be >0", opts->patch_no);
235
+ giterr_set(GITERR_INVALID,
236
+ "invalid patch no %"PRIuZ". should be >0", opts->patch_no);
1761
237
  return -1;
1762
238
  }
1763
239
  }
@@ -1782,8 +258,8 @@ int git_diff_format_email(
1782
258
  }
1783
259
 
1784
260
  error = git_diff_format_email__append_header_tobuf(out,
1785
- opts->id, opts->author, summary == NULL ? opts->summary : summary,
1786
- opts->body, opts->patch_no, opts->total_patches, ignore_marker);
261
+ opts->id, opts->author, summary == NULL ? opts->summary : summary,
262
+ opts->body, opts->patch_no, opts->total_patches, ignore_marker);
1787
263
 
1788
264
  if (error < 0)
1789
265
  goto on_error;
@@ -1816,7 +292,8 @@ int git_diff_commit_as_email(
1816
292
  const git_diff_options *diff_opts)
1817
293
  {
1818
294
  git_diff *diff = NULL;
1819
- git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
295
+ git_diff_format_email_options opts =
296
+ GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
1820
297
  int error;
1821
298
 
1822
299
  assert (out && repo && commit);
@@ -1861,3 +338,4 @@ int git_diff_format_email_init_options(
1861
338
  GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT);
1862
339
  return 0;
1863
340
  }
341
+