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
@@ -7,49 +7,78 @@
7
7
  #include "common.h"
8
8
  #include "git2/blob.h"
9
9
  #include "diff.h"
10
+ #include "diff_generate.h"
10
11
  #include "diff_file.h"
11
12
  #include "diff_driver.h"
12
- #include "diff_patch.h"
13
+ #include "patch_generate.h"
13
14
  #include "diff_xdiff.h"
14
15
  #include "delta.h"
15
16
  #include "zstream.h"
16
17
  #include "fileops.h"
17
18
 
18
19
  static void diff_output_init(
19
- git_diff_output*, const git_diff_options*, git_diff_file_cb,
20
+ git_patch_generated_output *, const git_diff_options *, git_diff_file_cb,
20
21
  git_diff_binary_cb, git_diff_hunk_cb, git_diff_line_cb, void*);
21
22
 
22
- static void diff_output_to_patch(git_diff_output *, git_patch *);
23
+ static void diff_output_to_patch(
24
+ git_patch_generated_output *, git_patch_generated *);
23
25
 
24
- static void diff_patch_update_binary(git_patch *patch)
26
+ static void patch_generated_free(git_patch *p)
25
27
  {
26
- if ((patch->delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0)
28
+ git_patch_generated *patch = (git_patch_generated *)p;
29
+
30
+ git_array_clear(patch->base.lines);
31
+ git_array_clear(patch->base.hunks);
32
+
33
+ git__free((char *)patch->base.binary.old_file.data);
34
+ git__free((char *)patch->base.binary.new_file.data);
35
+
36
+ git_diff_file_content__clear(&patch->ofile);
37
+ git_diff_file_content__clear(&patch->nfile);
38
+
39
+ git_diff_free(patch->diff); /* decrements refcount */
40
+ patch->diff = NULL;
41
+
42
+ git_pool_clear(&patch->flattened);
43
+
44
+ git__free((char *)patch->base.diff_opts.old_prefix);
45
+ git__free((char *)patch->base.diff_opts.new_prefix);
46
+
47
+ if (patch->flags & GIT_PATCH_GENERATED_ALLOCATED)
48
+ git__free(patch);
49
+ }
50
+
51
+ static void patch_generated_update_binary(git_patch_generated *patch)
52
+ {
53
+ if ((patch->base.delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0)
27
54
  return;
28
55
 
29
56
  if ((patch->ofile.file->flags & GIT_DIFF_FLAG_BINARY) != 0 ||
30
57
  (patch->nfile.file->flags & GIT_DIFF_FLAG_BINARY) != 0)
31
- patch->delta->flags |= GIT_DIFF_FLAG_BINARY;
58
+ patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY;
32
59
 
33
60
  else if (patch->ofile.file->size > GIT_XDIFF_MAX_SIZE ||
34
- patch->nfile.file->size > GIT_XDIFF_MAX_SIZE)
35
- patch->delta->flags |= GIT_DIFF_FLAG_BINARY;
61
+ patch->nfile.file->size > GIT_XDIFF_MAX_SIZE)
62
+ patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY;
36
63
 
37
64
  else if ((patch->ofile.file->flags & DIFF_FLAGS_NOT_BINARY) != 0 &&
38
- (patch->nfile.file->flags & DIFF_FLAGS_NOT_BINARY) != 0)
39
- patch->delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
65
+ (patch->nfile.file->flags & DIFF_FLAGS_NOT_BINARY) != 0)
66
+ patch->base.delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
40
67
  }
41
68
 
42
- static void diff_patch_init_common(git_patch *patch)
69
+ static void patch_generated_init_common(git_patch_generated *patch)
43
70
  {
44
- diff_patch_update_binary(patch);
71
+ patch->base.free_fn = patch_generated_free;
72
+
73
+ patch_generated_update_binary(patch);
45
74
 
46
- patch->flags |= GIT_DIFF_PATCH_INITIALIZED;
75
+ patch->flags |= GIT_PATCH_GENERATED_INITIALIZED;
47
76
 
48
77
  if (patch->diff)
49
78
  git_diff_addref(patch->diff);
50
79
  }
51
80
 
52
- static int diff_patch_normalize_options(
81
+ static int patch_generated_normalize_options(
53
82
  git_diff_options *out,
54
83
  const git_diff_options *opts)
55
84
  {
@@ -75,38 +104,40 @@ static int diff_patch_normalize_options(
75
104
  return 0;
76
105
  }
77
106
 
78
- static int diff_patch_init_from_diff(
79
- git_patch *patch, git_diff *diff, size_t delta_index)
107
+ static int patch_generated_init(
108
+ git_patch_generated *patch, git_diff *diff, size_t delta_index)
80
109
  {
81
110
  int error = 0;
82
111
 
83
112
  memset(patch, 0, sizeof(*patch));
84
- patch->diff = diff;
85
- patch->delta = git_vector_get(&diff->deltas, delta_index);
113
+
114
+ patch->diff = diff;
115
+ patch->base.repo = diff->repo;
116
+ patch->base.delta = git_vector_get(&diff->deltas, delta_index);
86
117
  patch->delta_index = delta_index;
87
118
 
88
- if ((error = diff_patch_normalize_options(
89
- &patch->diff_opts, &diff->opts)) < 0 ||
119
+ if ((error = patch_generated_normalize_options(
120
+ &patch->base.diff_opts, &diff->opts)) < 0 ||
90
121
  (error = git_diff_file_content__init_from_diff(
91
- &patch->ofile, diff, patch->delta, true)) < 0 ||
122
+ &patch->ofile, diff, patch->base.delta, true)) < 0 ||
92
123
  (error = git_diff_file_content__init_from_diff(
93
- &patch->nfile, diff, patch->delta, false)) < 0)
124
+ &patch->nfile, diff, patch->base.delta, false)) < 0)
94
125
  return error;
95
126
 
96
- diff_patch_init_common(patch);
127
+ patch_generated_init_common(patch);
97
128
 
98
129
  return 0;
99
130
  }
100
131
 
101
- static int diff_patch_alloc_from_diff(
102
- git_patch **out, git_diff *diff, size_t delta_index)
132
+ static int patch_generated_alloc_from_diff(
133
+ git_patch_generated **out, git_diff *diff, size_t delta_index)
103
134
  {
104
135
  int error;
105
- git_patch *patch = git__calloc(1, sizeof(git_patch));
136
+ git_patch_generated *patch = git__calloc(1, sizeof(git_patch_generated));
106
137
  GITERR_CHECK_ALLOC(patch);
107
138
 
108
- if (!(error = diff_patch_init_from_diff(patch, diff, delta_index))) {
109
- patch->flags |= GIT_DIFF_PATCH_ALLOCATED;
139
+ if (!(error = patch_generated_init(patch, diff, delta_index))) {
140
+ patch->flags |= GIT_PATCH_GENERATED_ALLOCATED;
110
141
  GIT_REFCOUNT_INC(patch);
111
142
  } else {
112
143
  git__free(patch);
@@ -117,27 +148,27 @@ static int diff_patch_alloc_from_diff(
117
148
  return error;
118
149
  }
119
150
 
120
- GIT_INLINE(bool) should_skip_binary(git_patch *patch, git_diff_file *file)
151
+ GIT_INLINE(bool) should_skip_binary(git_patch_generated *patch, git_diff_file *file)
121
152
  {
122
- if ((patch->diff_opts.flags & GIT_DIFF_SHOW_BINARY) != 0)
153
+ if ((patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) != 0)
123
154
  return false;
124
155
 
125
156
  return (file->flags & GIT_DIFF_FLAG_BINARY) != 0;
126
157
  }
127
158
 
128
- static bool diff_patch_diffable(git_patch *patch)
159
+ static bool patch_generated_diffable(git_patch_generated *patch)
129
160
  {
130
161
  size_t olen, nlen;
131
162
 
132
- if (patch->delta->status == GIT_DELTA_UNMODIFIED)
163
+ if (patch->base.delta->status == GIT_DELTA_UNMODIFIED)
133
164
  return false;
134
165
 
135
166
  /* if we've determined this to be binary (and we are not showing binary
136
167
  * data) then we have skipped loading the map data. instead, query the
137
168
  * file data itself.
138
169
  */
139
- if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0 &&
140
- (patch->diff_opts.flags & GIT_DIFF_SHOW_BINARY) == 0) {
170
+ if ((patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) != 0 &&
171
+ (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) == 0) {
141
172
  olen = (size_t)patch->ofile.file->size;
142
173
  nlen = (size_t)patch->nfile.file->size;
143
174
  } else {
@@ -154,12 +185,12 @@ static bool diff_patch_diffable(git_patch *patch)
154
185
  !git_oid_equal(&patch->ofile.file->id, &patch->nfile.file->id));
155
186
  }
156
187
 
157
- static int diff_patch_load(git_patch *patch, git_diff_output *output)
188
+ static int patch_generated_load(git_patch_generated *patch, git_patch_generated_output *output)
158
189
  {
159
190
  int error = 0;
160
191
  bool incomplete_data;
161
192
 
162
- if ((patch->flags & GIT_DIFF_PATCH_LOADED) != 0)
193
+ if ((patch->flags & GIT_PATCH_GENERATED_LOADED) != 0)
163
194
  return 0;
164
195
 
165
196
  /* if no hunk and data callbacks and user doesn't care if data looks
@@ -180,13 +211,13 @@ static int diff_patch_load(git_patch *patch, git_diff_output *output)
180
211
  */
181
212
  if (patch->ofile.src == GIT_ITERATOR_TYPE_WORKDIR) {
182
213
  if ((error = git_diff_file_content__load(
183
- &patch->ofile, &patch->diff_opts)) < 0 ||
214
+ &patch->ofile, &patch->base.diff_opts)) < 0 ||
184
215
  should_skip_binary(patch, patch->ofile.file))
185
216
  goto cleanup;
186
217
  }
187
218
  if (patch->nfile.src == GIT_ITERATOR_TYPE_WORKDIR) {
188
219
  if ((error = git_diff_file_content__load(
189
- &patch->nfile, &patch->diff_opts)) < 0 ||
220
+ &patch->nfile, &patch->base.diff_opts)) < 0 ||
190
221
  should_skip_binary(patch, patch->nfile.file))
191
222
  goto cleanup;
192
223
  }
@@ -194,13 +225,13 @@ static int diff_patch_load(git_patch *patch, git_diff_output *output)
194
225
  /* once workdir has been tried, load other data as needed */
195
226
  if (patch->ofile.src != GIT_ITERATOR_TYPE_WORKDIR) {
196
227
  if ((error = git_diff_file_content__load(
197
- &patch->ofile, &patch->diff_opts)) < 0 ||
228
+ &patch->ofile, &patch->base.diff_opts)) < 0 ||
198
229
  should_skip_binary(patch, patch->ofile.file))
199
230
  goto cleanup;
200
231
  }
201
232
  if (patch->nfile.src != GIT_ITERATOR_TYPE_WORKDIR) {
202
233
  if ((error = git_diff_file_content__load(
203
- &patch->nfile, &patch->diff_opts)) < 0 ||
234
+ &patch->nfile, &patch->base.diff_opts)) < 0 ||
204
235
  should_skip_binary(patch, patch->nfile.file))
205
236
  goto cleanup;
206
237
  }
@@ -212,24 +243,24 @@ static int diff_patch_load(git_patch *patch, git_diff_output *output)
212
243
  patch->ofile.file->mode == patch->nfile.file->mode &&
213
244
  patch->ofile.file->mode != GIT_FILEMODE_COMMIT &&
214
245
  git_oid_equal(&patch->ofile.file->id, &patch->nfile.file->id) &&
215
- patch->delta->status == GIT_DELTA_MODIFIED) /* not RENAMED/COPIED! */
216
- patch->delta->status = GIT_DELTA_UNMODIFIED;
246
+ patch->base.delta->status == GIT_DELTA_MODIFIED) /* not RENAMED/COPIED! */
247
+ patch->base.delta->status = GIT_DELTA_UNMODIFIED;
217
248
 
218
249
  cleanup:
219
- diff_patch_update_binary(patch);
250
+ patch_generated_update_binary(patch);
220
251
 
221
252
  if (!error) {
222
- if (diff_patch_diffable(patch))
223
- patch->flags |= GIT_DIFF_PATCH_DIFFABLE;
253
+ if (patch_generated_diffable(patch))
254
+ patch->flags |= GIT_PATCH_GENERATED_DIFFABLE;
224
255
 
225
- patch->flags |= GIT_DIFF_PATCH_LOADED;
256
+ patch->flags |= GIT_PATCH_GENERATED_LOADED;
226
257
  }
227
258
 
228
259
  return error;
229
260
  }
230
261
 
231
- static int diff_patch_invoke_file_callback(
232
- git_patch *patch, git_diff_output *output)
262
+ static int patch_generated_invoke_file_callback(
263
+ git_patch_generated *patch, git_patch_generated_output *output)
233
264
  {
234
265
  float progress = patch->diff ?
235
266
  ((float)patch->delta_index / patch->diff->deltas.length) : 1.0f;
@@ -238,7 +269,7 @@ static int diff_patch_invoke_file_callback(
238
269
  return 0;
239
270
 
240
271
  return giterr_set_after_callback_function(
241
- output->file_cb(patch->delta, progress, output->payload),
272
+ output->file_cb(patch->base.delta, progress, output->payload),
242
273
  "git_patch");
243
274
  }
244
275
 
@@ -253,7 +284,7 @@ static int create_binary(
253
284
  size_t b_datalen)
254
285
  {
255
286
  git_buf deflate = GIT_BUF_INIT, delta = GIT_BUF_INIT;
256
- unsigned long delta_data_len;
287
+ size_t delta_data_len = 0;
257
288
  int error;
258
289
 
259
290
  /* The git_delta function accepts unsigned long only */
@@ -270,20 +301,24 @@ static int create_binary(
270
301
  }
271
302
 
272
303
  if (a_datalen && b_datalen) {
273
- void *delta_data = git_delta(
274
- a_data, (unsigned long)a_datalen,
275
- b_data, (unsigned long)b_datalen,
276
- &delta_data_len, (unsigned long)deflate.size);
304
+ void *delta_data;
305
+
306
+ error = git_delta(&delta_data, &delta_data_len,
307
+ a_data, a_datalen,
308
+ b_data, b_datalen,
309
+ deflate.size);
277
310
 
278
- if (delta_data) {
311
+ if (error == 0) {
279
312
  error = git_zstream_deflatebuf(
280
- &delta, delta_data, (size_t)delta_data_len);
313
+ &delta, delta_data, delta_data_len);
281
314
 
282
315
  git__free(delta_data);
283
-
284
- if (error < 0)
285
- goto done;
316
+ } else if (error == GIT_EBUFS) {
317
+ error = 0;
286
318
  }
319
+
320
+ if (error < 0)
321
+ goto done;
287
322
  }
288
323
 
289
324
  if (delta.size && delta.size < deflate.size) {
@@ -305,32 +340,38 @@ done:
305
340
  return error;
306
341
  }
307
342
 
308
- static int diff_binary(git_diff_output *output, git_patch *patch)
343
+ static int diff_binary(git_patch_generated_output *output, git_patch_generated *patch)
309
344
  {
310
- git_diff_binary binary = {{0}};
345
+ git_diff_binary binary = {0};
311
346
  const char *old_data = patch->ofile.map.data;
312
347
  const char *new_data = patch->nfile.map.data;
313
348
  size_t old_len = patch->ofile.map.len,
314
349
  new_len = patch->nfile.map.len;
315
350
  int error;
316
351
 
317
- /* Create the old->new delta (as the "new" side of the patch),
318
- * and the new->old delta (as the "old" side)
319
- */
320
- if ((error = create_binary(&binary.old_file.type,
321
- (char **)&binary.old_file.data,
322
- &binary.old_file.datalen,
323
- &binary.old_file.inflatedlen,
324
- new_data, new_len, old_data, old_len)) < 0 ||
325
- (error = create_binary(&binary.new_file.type,
326
- (char **)&binary.new_file.data,
327
- &binary.new_file.datalen,
328
- &binary.new_file.inflatedlen,
329
- old_data, old_len, new_data, new_len)) < 0)
330
- return error;
352
+ /* Only load contents if the user actually wants to diff
353
+ * binary files. */
354
+ if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) {
355
+ binary.contains_data = 1;
356
+
357
+ /* Create the old->new delta (as the "new" side of the patch),
358
+ * and the new->old delta (as the "old" side)
359
+ */
360
+ if ((error = create_binary(&binary.old_file.type,
361
+ (char **)&binary.old_file.data,
362
+ &binary.old_file.datalen,
363
+ &binary.old_file.inflatedlen,
364
+ new_data, new_len, old_data, old_len)) < 0 ||
365
+ (error = create_binary(&binary.new_file.type,
366
+ (char **)&binary.new_file.data,
367
+ &binary.new_file.datalen,
368
+ &binary.new_file.inflatedlen,
369
+ old_data, old_len, new_data, new_len)) < 0)
370
+ return error;
371
+ }
331
372
 
332
373
  error = giterr_set_after_callback_function(
333
- output->binary_cb(patch->delta, &binary, output->payload),
374
+ output->binary_cb(patch->base.delta, &binary, output->payload),
334
375
  "git_patch");
335
376
 
336
377
  git__free((char *) binary.old_file.data);
@@ -339,25 +380,27 @@ static int diff_binary(git_diff_output *output, git_patch *patch)
339
380
  return error;
340
381
  }
341
382
 
342
- static int diff_patch_generate(git_patch *patch, git_diff_output *output)
383
+ static int patch_generated_create(
384
+ git_patch_generated *patch,
385
+ git_patch_generated_output *output)
343
386
  {
344
387
  int error = 0;
345
388
 
346
- if ((patch->flags & GIT_DIFF_PATCH_DIFFED) != 0)
389
+ if ((patch->flags & GIT_PATCH_GENERATED_DIFFED) != 0)
347
390
  return 0;
348
391
 
349
392
  /* if we are not looking at the binary or text data, don't do the diff */
350
393
  if (!output->binary_cb && !output->hunk_cb && !output->data_cb)
351
394
  return 0;
352
395
 
353
- if ((patch->flags & GIT_DIFF_PATCH_LOADED) == 0 &&
354
- (error = diff_patch_load(patch, output)) < 0)
396
+ if ((patch->flags & GIT_PATCH_GENERATED_LOADED) == 0 &&
397
+ (error = patch_generated_load(patch, output)) < 0)
355
398
  return error;
356
399
 
357
- if ((patch->flags & GIT_DIFF_PATCH_DIFFABLE) == 0)
400
+ if ((patch->flags & GIT_PATCH_GENERATED_DIFFABLE) == 0)
358
401
  return 0;
359
402
 
360
- if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0) {
403
+ if ((patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) != 0) {
361
404
  if (output->binary_cb)
362
405
  error = diff_binary(output, patch);
363
406
  }
@@ -366,33 +409,10 @@ static int diff_patch_generate(git_patch *patch, git_diff_output *output)
366
409
  error = output->diff_cb(output, patch);
367
410
  }
368
411
 
369
- patch->flags |= GIT_DIFF_PATCH_DIFFED;
412
+ patch->flags |= GIT_PATCH_GENERATED_DIFFED;
370
413
  return error;
371
414
  }
372
415
 
373
- static void diff_patch_free(git_patch *patch)
374
- {
375
- git_diff_file_content__clear(&patch->ofile);
376
- git_diff_file_content__clear(&patch->nfile);
377
-
378
- git_array_clear(patch->lines);
379
- git_array_clear(patch->hunks);
380
-
381
- git_diff_free(patch->diff); /* decrements refcount */
382
- patch->diff = NULL;
383
-
384
- git_pool_clear(&patch->flattened);
385
-
386
- git__free((char *)patch->diff_opts.old_prefix);
387
- git__free((char *)patch->diff_opts.new_prefix);
388
-
389
- git__free((char *)patch->binary.old_file.data);
390
- git__free((char *)patch->binary.new_file.data);
391
-
392
- if (patch->flags & GIT_DIFF_PATCH_ALLOCATED)
393
- git__free(patch);
394
- }
395
-
396
416
  static int diff_required(git_diff *diff, const char *action)
397
417
  {
398
418
  if (diff)
@@ -412,7 +432,7 @@ int git_diff_foreach(
412
432
  int error = 0;
413
433
  git_xdiff_output xo;
414
434
  size_t idx;
415
- git_patch patch;
435
+ git_patch_generated patch;
416
436
 
417
437
  if ((error = diff_required(diff, "git_diff_foreach")) < 0)
418
438
  return error;
@@ -423,24 +443,24 @@ int git_diff_foreach(
423
443
  &xo.output, &diff->opts, file_cb, binary_cb, hunk_cb, data_cb, payload);
424
444
  git_xdiff_init(&xo, &diff->opts);
425
445
 
426
- git_vector_foreach(&diff->deltas, idx, patch.delta) {
446
+ git_vector_foreach(&diff->deltas, idx, patch.base.delta) {
427
447
 
428
448
  /* check flags against patch status */
429
- if (git_diff_delta__should_skip(&diff->opts, patch.delta))
449
+ if (git_diff_delta__should_skip(&diff->opts, patch.base.delta))
430
450
  continue;
431
451
 
432
452
  if (binary_cb || hunk_cb || data_cb) {
433
- if ((error = diff_patch_init_from_diff(&patch, diff, idx)) != 0 ||
434
- (error = diff_patch_load(&patch, &xo.output)) != 0)
453
+ if ((error = patch_generated_init(&patch, diff, idx)) != 0 ||
454
+ (error = patch_generated_load(&patch, &xo.output)) != 0)
435
455
  return error;
436
456
  }
437
457
 
438
- if ((error = diff_patch_invoke_file_callback(&patch, &xo.output)) == 0) {
458
+ if ((error = patch_generated_invoke_file_callback(&patch, &xo.output)) == 0) {
439
459
  if (binary_cb || hunk_cb || data_cb)
440
- error = diff_patch_generate(&patch, &xo.output);
460
+ error = patch_generated_create(&patch, &xo.output);
441
461
  }
442
462
 
443
- git_patch_free(&patch);
463
+ git_patch_free(&patch.base);
444
464
 
445
465
  if (error)
446
466
  break;
@@ -450,15 +470,15 @@ int git_diff_foreach(
450
470
  }
451
471
 
452
472
  typedef struct {
453
- git_patch patch;
473
+ git_patch_generated patch;
454
474
  git_diff_delta delta;
455
475
  char paths[GIT_FLEX_ARRAY];
456
- } diff_patch_with_delta;
476
+ } patch_generated_with_delta;
457
477
 
458
- static int diff_single_generate(diff_patch_with_delta *pd, git_xdiff_output *xo)
478
+ static int diff_single_generate(patch_generated_with_delta *pd, git_xdiff_output *xo)
459
479
  {
460
480
  int error = 0;
461
- git_patch *patch = &pd->patch;
481
+ git_patch_generated *patch = &pd->patch;
462
482
  bool has_old = ((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
463
483
  bool has_new = ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
464
484
 
@@ -469,24 +489,33 @@ static int diff_single_generate(diff_patch_with_delta *pd, git_xdiff_output *xo)
469
489
  if (git_oid_equal(&patch->nfile.file->id, &patch->ofile.file->id))
470
490
  pd->delta.status = GIT_DELTA_UNMODIFIED;
471
491
 
472
- patch->delta = &pd->delta;
492
+ patch->base.delta = &pd->delta;
473
493
 
474
- diff_patch_init_common(patch);
494
+ patch_generated_init_common(patch);
475
495
 
476
496
  if (pd->delta.status == GIT_DELTA_UNMODIFIED &&
477
- !(patch->ofile.opts_flags & GIT_DIFF_INCLUDE_UNMODIFIED))
497
+ !(patch->ofile.opts_flags & GIT_DIFF_INCLUDE_UNMODIFIED)) {
498
+
499
+ /* Even empty patches are flagged as binary, and even though
500
+ * there's no difference, we flag this as "containing data"
501
+ * (the data is known to be empty, as opposed to wholly unknown).
502
+ */
503
+ if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY)
504
+ patch->base.binary.contains_data = 1;
505
+
478
506
  return error;
507
+ }
479
508
 
480
- error = diff_patch_invoke_file_callback(patch, (git_diff_output *)xo);
509
+ error = patch_generated_invoke_file_callback(patch, (git_patch_generated_output *)xo);
481
510
 
482
511
  if (!error)
483
- error = diff_patch_generate(patch, (git_diff_output *)xo);
512
+ error = patch_generated_create(patch, (git_patch_generated_output *)xo);
484
513
 
485
514
  return error;
486
515
  }
487
516
 
488
- static int diff_patch_from_sources(
489
- diff_patch_with_delta *pd,
517
+ static int patch_generated_from_sources(
518
+ patch_generated_with_delta *pd,
490
519
  git_xdiff_output *xo,
491
520
  git_diff_file_content_src *oldsrc,
492
521
  git_diff_file_content_src *newsrc,
@@ -499,7 +528,7 @@ static int diff_patch_from_sources(
499
528
  git_diff_file *lfile = &pd->delta.old_file, *rfile = &pd->delta.new_file;
500
529
  git_diff_file_content *ldata = &pd->patch.ofile, *rdata = &pd->patch.nfile;
501
530
 
502
- if ((error = diff_patch_normalize_options(&pd->patch.diff_opts, opts)) < 0)
531
+ if ((error = patch_generated_normalize_options(&pd->patch.base.diff_opts, opts)) < 0)
503
532
  return error;
504
533
 
505
534
  if (opts && (opts->flags & GIT_DIFF_REVERSE) != 0) {
@@ -507,7 +536,7 @@ static int diff_patch_from_sources(
507
536
  tmp = ldata; ldata = rdata; rdata = tmp;
508
537
  }
509
538
 
510
- pd->patch.delta = &pd->delta;
539
+ pd->patch.base.delta = &pd->delta;
511
540
 
512
541
  if (!oldsrc->as_path) {
513
542
  if (newsrc->as_path)
@@ -530,12 +559,12 @@ static int diff_patch_from_sources(
530
559
  return diff_single_generate(pd, xo);
531
560
  }
532
561
 
533
- static int diff_patch_with_delta_alloc(
534
- diff_patch_with_delta **out,
562
+ static int patch_generated_with_delta_alloc(
563
+ patch_generated_with_delta **out,
535
564
  const char **old_path,
536
565
  const char **new_path)
537
566
  {
538
- diff_patch_with_delta *pd;
567
+ patch_generated_with_delta *pd;
539
568
  size_t old_len = *old_path ? strlen(*old_path) : 0;
540
569
  size_t new_len = *new_path ? strlen(*new_path) : 0;
541
570
  size_t alloc_len;
@@ -547,7 +576,7 @@ static int diff_patch_with_delta_alloc(
547
576
  *out = pd = git__calloc(1, alloc_len);
548
577
  GITERR_CHECK_ALLOC(pd);
549
578
 
550
- pd->patch.flags = GIT_DIFF_PATCH_ALLOCATED;
579
+ pd->patch.flags = GIT_PATCH_GENERATED_ALLOCATED;
551
580
 
552
581
  if (*old_path) {
553
582
  memcpy(&pd->paths[0], *old_path, old_len);
@@ -575,7 +604,7 @@ static int diff_from_sources(
575
604
  void *payload)
576
605
  {
577
606
  int error = 0;
578
- diff_patch_with_delta pd;
607
+ patch_generated_with_delta pd;
579
608
  git_xdiff_output xo;
580
609
 
581
610
  memset(&xo, 0, sizeof(xo));
@@ -585,9 +614,9 @@ static int diff_from_sources(
585
614
 
586
615
  memset(&pd, 0, sizeof(pd));
587
616
 
588
- error = diff_patch_from_sources(&pd, &xo, oldsrc, newsrc, opts);
617
+ error = patch_generated_from_sources(&pd, &xo, oldsrc, newsrc, opts);
589
618
 
590
- git_patch_free(&pd.patch);
619
+ git_patch_free(&pd.patch.base);
591
620
 
592
621
  return error;
593
622
  }
@@ -599,13 +628,13 @@ static int patch_from_sources(
599
628
  const git_diff_options *opts)
600
629
  {
601
630
  int error = 0;
602
- diff_patch_with_delta *pd;
631
+ patch_generated_with_delta *pd;
603
632
  git_xdiff_output xo;
604
633
 
605
634
  assert(out);
606
635
  *out = NULL;
607
636
 
608
- if ((error = diff_patch_with_delta_alloc(
637
+ if ((error = patch_generated_with_delta_alloc(
609
638
  &pd, &oldsrc->as_path, &newsrc->as_path)) < 0)
610
639
  return error;
611
640
 
@@ -613,7 +642,7 @@ static int patch_from_sources(
613
642
  diff_output_to_patch(&xo.output, &pd->patch);
614
643
  git_xdiff_init(&xo, opts);
615
644
 
616
- if (!(error = diff_patch_from_sources(pd, &xo, oldsrc, newsrc, opts)))
645
+ if (!(error = patch_generated_from_sources(pd, &xo, oldsrc, newsrc, opts)))
617
646
  *out = (git_patch *)pd;
618
647
  else
619
648
  git_patch_free((git_patch *)pd);
@@ -732,13 +761,13 @@ int git_patch_from_buffers(
732
761
  return patch_from_sources(out, &osrc, &nsrc, opts);
733
762
  }
734
763
 
735
- int git_patch_from_diff(
764
+ int git_patch_generated_from_diff(
736
765
  git_patch **patch_ptr, git_diff *diff, size_t idx)
737
766
  {
738
767
  int error = 0;
739
768
  git_xdiff_output xo;
740
769
  git_diff_delta *delta = NULL;
741
- git_patch *patch = NULL;
770
+ git_patch_generated *patch = NULL;
742
771
 
743
772
  if (patch_ptr) *patch_ptr = NULL;
744
773
 
@@ -760,17 +789,17 @@ int git_patch_from_diff(
760
789
  (diff->opts.flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0))
761
790
  return 0;
762
791
 
763
- if ((error = diff_patch_alloc_from_diff(&patch, diff, idx)) < 0)
792
+ if ((error = patch_generated_alloc_from_diff(&patch, diff, idx)) < 0)
764
793
  return error;
765
794
 
766
795
  memset(&xo, 0, sizeof(xo));
767
796
  diff_output_to_patch(&xo.output, patch);
768
797
  git_xdiff_init(&xo, &diff->opts);
769
798
 
770
- error = diff_patch_invoke_file_callback(patch, &xo.output);
799
+ error = patch_generated_invoke_file_callback(patch, &xo.output);
771
800
 
772
801
  if (!error)
773
- error = diff_patch_generate(patch, &xo.output);
802
+ error = patch_generated_create(patch, &xo.output);
774
803
 
775
804
  if (!error) {
776
805
  /* TODO: if cumulative diff size is < 0.5 total size, flatten patch */
@@ -778,237 +807,34 @@ int git_patch_from_diff(
778
807
  }
779
808
 
780
809
  if (error || !patch_ptr)
781
- git_patch_free(patch);
810
+ git_patch_free(&patch->base);
782
811
  else
783
- *patch_ptr = patch;
812
+ *patch_ptr = &patch->base;
784
813
 
785
814
  return error;
786
815
  }
787
816
 
788
- void git_patch_free(git_patch *patch)
789
- {
790
- if (patch)
791
- GIT_REFCOUNT_DEC(patch, diff_patch_free);
792
- }
793
-
794
- const git_diff_delta *git_patch_get_delta(const git_patch *patch)
795
- {
796
- assert(patch);
797
- return patch->delta;
798
- }
799
-
800
- size_t git_patch_num_hunks(const git_patch *patch)
801
- {
802
- assert(patch);
803
- return git_array_size(patch->hunks);
804
- }
805
-
806
- int git_patch_line_stats(
807
- size_t *total_ctxt,
808
- size_t *total_adds,
809
- size_t *total_dels,
810
- const git_patch *patch)
811
- {
812
- size_t totals[3], idx;
813
-
814
- memset(totals, 0, sizeof(totals));
815
-
816
- for (idx = 0; idx < git_array_size(patch->lines); ++idx) {
817
- git_diff_line *line = git_array_get(patch->lines, idx);
818
- if (!line)
819
- continue;
820
-
821
- switch (line->origin) {
822
- case GIT_DIFF_LINE_CONTEXT: totals[0]++; break;
823
- case GIT_DIFF_LINE_ADDITION: totals[1]++; break;
824
- case GIT_DIFF_LINE_DELETION: totals[2]++; break;
825
- default:
826
- /* diff --stat and --numstat don't count EOFNL marks because
827
- * they will always be paired with a ADDITION or DELETION line.
828
- */
829
- break;
830
- }
831
- }
832
-
833
- if (total_ctxt)
834
- *total_ctxt = totals[0];
835
- if (total_adds)
836
- *total_adds = totals[1];
837
- if (total_dels)
838
- *total_dels = totals[2];
839
-
840
- return 0;
841
- }
842
-
843
- static int diff_error_outofrange(const char *thing)
844
- {
845
- giterr_set(GITERR_INVALID, "Diff patch %s index out of range", thing);
846
- return GIT_ENOTFOUND;
847
- }
848
-
849
- int git_patch_get_hunk(
850
- const git_diff_hunk **out,
851
- size_t *lines_in_hunk,
852
- git_patch *patch,
853
- size_t hunk_idx)
854
- {
855
- diff_patch_hunk *hunk;
856
- assert(patch);
857
-
858
- hunk = git_array_get(patch->hunks, hunk_idx);
859
-
860
- if (!hunk) {
861
- if (out) *out = NULL;
862
- if (lines_in_hunk) *lines_in_hunk = 0;
863
- return diff_error_outofrange("hunk");
864
- }
865
-
866
- if (out) *out = &hunk->hunk;
867
- if (lines_in_hunk) *lines_in_hunk = hunk->line_count;
868
- return 0;
869
- }
870
-
871
- int git_patch_num_lines_in_hunk(const git_patch *patch, size_t hunk_idx)
872
- {
873
- diff_patch_hunk *hunk;
874
- assert(patch);
875
-
876
- if (!(hunk = git_array_get(patch->hunks, hunk_idx)))
877
- return diff_error_outofrange("hunk");
878
- return (int)hunk->line_count;
879
- }
880
-
881
- int git_patch_get_line_in_hunk(
882
- const git_diff_line **out,
883
- git_patch *patch,
884
- size_t hunk_idx,
885
- size_t line_of_hunk)
886
- {
887
- diff_patch_hunk *hunk;
888
- git_diff_line *line;
889
-
890
- assert(patch);
891
-
892
- if (!(hunk = git_array_get(patch->hunks, hunk_idx))) {
893
- if (out) *out = NULL;
894
- return diff_error_outofrange("hunk");
895
- }
896
-
897
- if (line_of_hunk >= hunk->line_count ||
898
- !(line = git_array_get(
899
- patch->lines, hunk->line_start + line_of_hunk))) {
900
- if (out) *out = NULL;
901
- return diff_error_outofrange("line");
902
- }
903
-
904
- if (out) *out = line;
905
- return 0;
906
- }
907
-
908
- size_t git_patch_size(
909
- git_patch *patch,
910
- int include_context,
911
- int include_hunk_headers,
912
- int include_file_headers)
913
- {
914
- size_t out;
915
-
916
- assert(patch);
917
-
918
- out = patch->content_size;
919
-
920
- if (!include_context)
921
- out -= patch->context_size;
922
-
923
- if (include_hunk_headers)
924
- out += patch->header_size;
925
-
926
- if (include_file_headers) {
927
- git_buf file_header = GIT_BUF_INIT;
928
-
929
- if (git_diff_delta__format_file_header(
930
- &file_header, patch->delta, NULL, NULL, 0) < 0)
931
- giterr_clear();
932
- else
933
- out += git_buf_len(&file_header);
934
-
935
- git_buf_free(&file_header);
936
- }
937
-
938
- return out;
939
- }
940
-
941
- git_diff *git_patch__diff(git_patch *patch)
942
- {
943
- return patch->diff;
944
- }
945
-
946
- git_diff_driver *git_patch__driver(git_patch *patch)
817
+ git_diff_driver *git_patch_generated_driver(git_patch_generated *patch)
947
818
  {
948
819
  /* ofile driver is representative for whole patch */
949
820
  return patch->ofile.driver;
950
821
  }
951
822
 
952
- void git_patch__old_data(
953
- char **ptr, size_t *len, git_patch *patch)
823
+ void git_patch_generated_old_data(
824
+ char **ptr, size_t *len, git_patch_generated *patch)
954
825
  {
955
826
  *ptr = patch->ofile.map.data;
956
827
  *len = patch->ofile.map.len;
957
828
  }
958
829
 
959
- void git_patch__new_data(
960
- char **ptr, size_t *len, git_patch *patch)
830
+ void git_patch_generated_new_data(
831
+ char **ptr, size_t *len, git_patch_generated *patch)
961
832
  {
962
833
  *ptr = patch->nfile.map.data;
963
834
  *len = patch->nfile.map.len;
964
835
  }
965
836
 
966
- int git_patch__invoke_callbacks(
967
- git_patch *patch,
968
- git_diff_file_cb file_cb,
969
- git_diff_binary_cb binary_cb,
970
- git_diff_hunk_cb hunk_cb,
971
- git_diff_line_cb line_cb,
972
- void *payload)
973
- {
974
- int error = 0;
975
- uint32_t i, j;
976
-
977
- if (file_cb)
978
- error = file_cb(patch->delta, 0, payload);
979
-
980
- if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0) {
981
- if (binary_cb)
982
- error = binary_cb(patch->delta, &patch->binary, payload);
983
-
984
- return error;
985
- }
986
-
987
- if (!hunk_cb && !line_cb)
988
- return error;
989
-
990
- for (i = 0; !error && i < git_array_size(patch->hunks); ++i) {
991
- diff_patch_hunk *h = git_array_get(patch->hunks, i);
992
-
993
- if (hunk_cb)
994
- error = hunk_cb(patch->delta, &h->hunk, payload);
995
-
996
- if (!line_cb)
997
- continue;
998
-
999
- for (j = 0; !error && j < h->line_count; ++j) {
1000
- git_diff_line *l =
1001
- git_array_get(patch->lines, h->line_start + j);
1002
-
1003
- error = line_cb(patch->delta, &h->hunk, l, payload);
1004
- }
1005
- }
1006
-
1007
- return error;
1008
- }
1009
-
1010
-
1011
- static int diff_patch_file_cb(
837
+ static int patch_generated_file_cb(
1012
838
  const git_diff_delta *delta,
1013
839
  float progress,
1014
840
  void *payload)
@@ -1017,7 +843,7 @@ static int diff_patch_file_cb(
1017
843
  return 0;
1018
844
  }
1019
845
 
1020
- static int diff_patch_binary_cb(
846
+ static int patch_generated_binary_cb(
1021
847
  const git_diff_delta *delta,
1022
848
  const git_diff_binary *binary,
1023
849
  void *payload)
@@ -1047,62 +873,62 @@ static int diff_patch_binary_cb(
1047
873
  return 0;
1048
874
  }
1049
875
 
1050
- static int diff_patch_hunk_cb(
876
+ static int git_patch_hunk_cb(
1051
877
  const git_diff_delta *delta,
1052
878
  const git_diff_hunk *hunk_,
1053
879
  void *payload)
1054
880
  {
1055
- git_patch *patch = payload;
1056
- diff_patch_hunk *hunk;
881
+ git_patch_generated *patch = payload;
882
+ git_patch_hunk *hunk;
1057
883
 
1058
884
  GIT_UNUSED(delta);
1059
885
 
1060
- hunk = git_array_alloc(patch->hunks);
886
+ hunk = git_array_alloc(patch->base.hunks);
1061
887
  GITERR_CHECK_ALLOC(hunk);
1062
888
 
1063
889
  memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk));
1064
890
 
1065
- patch->header_size += hunk_->header_len;
891
+ patch->base.header_size += hunk_->header_len;
1066
892
 
1067
- hunk->line_start = git_array_size(patch->lines);
893
+ hunk->line_start = git_array_size(patch->base.lines);
1068
894
  hunk->line_count = 0;
1069
895
 
1070
896
  return 0;
1071
897
  }
1072
898
 
1073
- static int diff_patch_line_cb(
899
+ static int patch_generated_line_cb(
1074
900
  const git_diff_delta *delta,
1075
901
  const git_diff_hunk *hunk_,
1076
902
  const git_diff_line *line_,
1077
903
  void *payload)
1078
904
  {
1079
- git_patch *patch = payload;
1080
- diff_patch_hunk *hunk;
905
+ git_patch_generated *patch = payload;
906
+ git_patch_hunk *hunk;
1081
907
  git_diff_line *line;
1082
908
 
1083
909
  GIT_UNUSED(delta);
1084
910
  GIT_UNUSED(hunk_);
1085
911
 
1086
- hunk = git_array_last(patch->hunks);
912
+ hunk = git_array_last(patch->base.hunks);
1087
913
  assert(hunk); /* programmer error if no hunk is available */
1088
914
 
1089
- line = git_array_alloc(patch->lines);
915
+ line = git_array_alloc(patch->base.lines);
1090
916
  GITERR_CHECK_ALLOC(line);
1091
917
 
1092
918
  memcpy(line, line_, sizeof(*line));
1093
919
 
1094
920
  /* do some bookkeeping so we can provide old/new line numbers */
1095
921
 
1096
- patch->content_size += line->content_len;
922
+ patch->base.content_size += line->content_len;
1097
923
 
1098
924
  if (line->origin == GIT_DIFF_LINE_ADDITION ||
1099
925
  line->origin == GIT_DIFF_LINE_DELETION)
1100
- patch->content_size += 1;
926
+ patch->base.content_size += 1;
1101
927
  else if (line->origin == GIT_DIFF_LINE_CONTEXT) {
1102
- patch->content_size += 1;
1103
- patch->context_size += line->content_len + 1;
928
+ patch->base.content_size += 1;
929
+ patch->base.context_size += line->content_len + 1;
1104
930
  } else if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
1105
- patch->context_size += line->content_len;
931
+ patch->base.context_size += line->content_len;
1106
932
 
1107
933
  hunk->line_count++;
1108
934
 
@@ -1110,7 +936,7 @@ static int diff_patch_line_cb(
1110
936
  }
1111
937
 
1112
938
  static void diff_output_init(
1113
- git_diff_output *out,
939
+ git_patch_generated_output *out,
1114
940
  const git_diff_options *opts,
1115
941
  git_diff_file_cb file_cb,
1116
942
  git_diff_binary_cb binary_cb,
@@ -1129,14 +955,15 @@ static void diff_output_init(
1129
955
  out->payload = payload;
1130
956
  }
1131
957
 
1132
- static void diff_output_to_patch(git_diff_output *out, git_patch *patch)
958
+ static void diff_output_to_patch(
959
+ git_patch_generated_output *out, git_patch_generated *patch)
1133
960
  {
1134
961
  diff_output_init(
1135
962
  out,
1136
963
  NULL,
1137
- diff_patch_file_cb,
1138
- diff_patch_binary_cb,
1139
- diff_patch_hunk_cb,
1140
- diff_patch_line_cb,
964
+ patch_generated_file_cb,
965
+ patch_generated_binary_cb,
966
+ git_patch_hunk_cb,
967
+ patch_generated_line_cb,
1141
968
  patch);
1142
969
  }