rugged 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +1 -1
  4. data/vendor/libgit2/cmake/FindLibSSH2.cmake +13 -0
  5. data/vendor/libgit2/include/git2/attr.h +7 -1
  6. data/vendor/libgit2/include/git2/blob.h +7 -1
  7. data/vendor/libgit2/include/git2/clone.h +1 -1
  8. data/vendor/libgit2/include/git2/common.h +19 -1
  9. data/vendor/libgit2/include/git2/deprecated.h +120 -0
  10. data/vendor/libgit2/include/git2/diff.h +3 -97
  11. data/vendor/libgit2/include/git2/email.h +127 -0
  12. data/vendor/libgit2/include/git2/filter.h +7 -1
  13. data/vendor/libgit2/include/git2/notes.h +2 -2
  14. data/vendor/libgit2/include/git2/oidarray.h +5 -8
  15. data/vendor/libgit2/include/git2/remote.h +4 -4
  16. data/vendor/libgit2/include/git2/repository.h +12 -10
  17. data/vendor/libgit2/include/git2/stash.h +1 -1
  18. data/vendor/libgit2/include/git2/stdint.h +3 -3
  19. data/vendor/libgit2/include/git2/sys/email.h +45 -0
  20. data/vendor/libgit2/include/git2/version.h +3 -3
  21. data/vendor/libgit2/include/git2.h +1 -0
  22. data/vendor/libgit2/src/CMakeLists.txt +7 -0
  23. data/vendor/libgit2/src/attr.c +24 -9
  24. data/vendor/libgit2/src/attr_file.c +23 -15
  25. data/vendor/libgit2/src/attr_file.h +3 -3
  26. data/vendor/libgit2/src/blame.c +4 -4
  27. data/vendor/libgit2/src/blame_git.c +1 -1
  28. data/vendor/libgit2/src/blob.c +15 -9
  29. data/vendor/libgit2/src/buffer.c +16 -8
  30. data/vendor/libgit2/src/buffer.h +2 -1
  31. data/vendor/libgit2/src/cc-compat.h +1 -7
  32. data/vendor/libgit2/src/checkout.c +6 -7
  33. data/vendor/libgit2/src/clone.c +1 -1
  34. data/vendor/libgit2/src/commit_graph.c +1 -1
  35. data/vendor/libgit2/src/config.c +1 -1
  36. data/vendor/libgit2/src/config_file.c +2 -2
  37. data/vendor/libgit2/src/config_parse.c +1 -1
  38. data/vendor/libgit2/src/describe.c +1 -1
  39. data/vendor/libgit2/src/diff.c +41 -173
  40. data/vendor/libgit2/src/email.c +299 -0
  41. data/vendor/libgit2/src/email.h +25 -0
  42. data/vendor/libgit2/src/filter.c +7 -1
  43. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +8 -8
  44. data/vendor/libgit2/src/ignore.c +2 -2
  45. data/vendor/libgit2/src/indexer.c +37 -3
  46. data/vendor/libgit2/src/libgit2.c +23 -0
  47. data/vendor/libgit2/src/merge.c +7 -4
  48. data/vendor/libgit2/src/notes.c +31 -31
  49. data/vendor/libgit2/src/oidarray.c +10 -1
  50. data/vendor/libgit2/src/path.c +1 -1
  51. data/vendor/libgit2/src/path.h +1 -1
  52. data/vendor/libgit2/src/pathspec.c +1 -1
  53. data/vendor/libgit2/src/refdb_fs.c +1 -1
  54. data/vendor/libgit2/src/refs.c +2 -2
  55. data/vendor/libgit2/src/refspec.c +1 -1
  56. data/vendor/libgit2/src/remote.c +12 -5
  57. data/vendor/libgit2/src/repository.c +130 -19
  58. data/vendor/libgit2/src/repository.h +4 -0
  59. data/vendor/libgit2/src/reset.c +1 -1
  60. data/vendor/libgit2/src/revparse.c +4 -4
  61. data/vendor/libgit2/src/stash.c +1 -1
  62. data/vendor/libgit2/src/streams/openssl_legacy.c +1 -1
  63. data/vendor/libgit2/src/streams/openssl_legacy.h +1 -1
  64. data/vendor/libgit2/src/threadstate.c +2 -1
  65. data/vendor/libgit2/src/trailer.c +1 -1
  66. data/vendor/libgit2/src/transports/ssh.c +4 -4
  67. data/vendor/libgit2/src/transports/winhttp.c +1 -1
  68. data/vendor/libgit2/src/util.c +1 -1
  69. data/vendor/libgit2/src/util.h +1 -1
  70. data/vendor/libgit2/src/win32/findfile.c +1 -1
  71. data/vendor/libgit2/src/win32/posix.h +6 -6
  72. data/vendor/libgit2/src/win32/posix_w32.c +9 -6
  73. metadata +11 -6
@@ -7,11 +7,15 @@
7
7
 
8
8
  #include "diff.h"
9
9
 
10
- #include "git2/version.h"
11
- #include "diff_generate.h"
10
+ #include "common.h"
12
11
  #include "patch.h"
12
+ #include "email.h"
13
13
  #include "commit.h"
14
14
  #include "index.h"
15
+ #include "diff_generate.h"
16
+
17
+ #include "git2/version.h"
18
+ #include "git2/email.h"
15
19
 
16
20
  struct patch_id_args {
17
21
  git_hash_ctx ctx;
@@ -150,97 +154,14 @@ int git_diff_foreach(
150
154
  return error;
151
155
  }
152
156
 
153
- static int diff_format_email_append_header_tobuf(
154
- git_buf *out,
155
- const git_oid *id,
156
- const git_signature *author,
157
- const char *summary,
158
- const char *body,
159
- size_t patch_no,
160
- size_t total_patches,
161
- bool exclude_patchno_marker)
162
- {
163
- char idstr[GIT_OID_HEXSZ + 1];
164
- char date_str[GIT_DATE_RFC2822_SZ];
165
- int error = 0;
166
-
167
- git_oid_fmt(idstr, id);
168
- idstr[GIT_OID_HEXSZ] = '\0';
169
-
170
- if ((error = git__date_rfc2822_fmt(date_str, sizeof(date_str),
171
- &author->when)) < 0)
172
- return error;
173
-
174
- error = git_buf_printf(out,
175
- "From %s Mon Sep 17 00:00:00 2001\n" \
176
- "From: %s <%s>\n" \
177
- "Date: %s\n" \
178
- "Subject: ",
179
- idstr,
180
- author->name, author->email,
181
- date_str);
182
-
183
- if (error < 0)
184
- return error;
185
-
186
- if (!exclude_patchno_marker) {
187
- if (total_patches == 1) {
188
- error = git_buf_puts(out, "[PATCH] ");
189
- } else {
190
- error = git_buf_printf(out, "[PATCH %"PRIuZ"/%"PRIuZ"] ",
191
- patch_no, total_patches);
192
- }
193
-
194
- if (error < 0)
195
- return error;
196
- }
197
-
198
- error = git_buf_printf(out, "%s\n\n", summary);
199
-
200
- if (body) {
201
- git_buf_puts(out, body);
202
-
203
- if (out->ptr[out->size - 1] != '\n')
204
- git_buf_putc(out, '\n');
205
- }
206
-
207
- return error;
208
- }
209
-
210
- static int diff_format_email_append_patches_tobuf(
211
- git_buf *out,
212
- git_diff *diff)
213
- {
214
- size_t i, deltas;
215
- int error = 0;
216
-
217
- deltas = git_diff_num_deltas(diff);
218
-
219
- for (i = 0; i < deltas; ++i) {
220
- git_patch *patch = NULL;
221
-
222
- if ((error = git_patch_from_diff(&patch, diff, i)) >= 0)
223
- error = git_patch_to_buf(out, patch);
224
-
225
- git_patch_free(patch);
226
-
227
- if (error < 0)
228
- break;
229
- }
230
-
231
- return error;
232
- }
157
+ #ifndef GIT_DEPRECATE_HARD
233
158
 
234
159
  int git_diff_format_email(
235
160
  git_buf *out,
236
161
  git_diff *diff,
237
162
  const git_diff_format_email_options *opts)
238
163
  {
239
- git_diff_stats *stats = NULL;
240
- char *summary = NULL, *loc = NULL;
241
- bool ignore_marker;
242
- unsigned int format_flags = 0;
243
- size_t allocsize;
164
+ git_email_create_options email_create_opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
244
165
  int error;
245
166
 
246
167
  GIT_ASSERT_ARG(out);
@@ -251,64 +172,13 @@ int git_diff_format_email(
251
172
  GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
252
173
  "git_format_email_options");
253
174
 
254
- ignore_marker = (opts->flags &
255
- GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0;
256
-
257
- if (!ignore_marker) {
258
- if (opts->patch_no > opts->total_patches) {
259
- git_error_set(GIT_ERROR_INVALID,
260
- "patch %"PRIuZ" out of range. max %"PRIuZ,
261
- opts->patch_no, opts->total_patches);
262
- return -1;
263
- }
175
+ if ((opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0)
176
+ email_create_opts.subject_prefix = "";
264
177
 
265
- if (opts->patch_no == 0) {
266
- git_error_set(GIT_ERROR_INVALID,
267
- "invalid patch no %"PRIuZ". should be >0", opts->patch_no);
268
- return -1;
269
- }
270
- }
271
178
 
272
- /* the summary we receive may not be clean.
273
- * it could potentially contain new line characters
274
- * or not be set, sanitize, */
275
- if ((loc = strpbrk(opts->summary, "\r\n")) != NULL) {
276
- size_t offset = 0;
277
-
278
- if ((offset = (loc - opts->summary)) == 0) {
279
- git_error_set(GIT_ERROR_INVALID, "summary is empty");
280
- error = -1;
281
- goto on_error;
282
- }
283
-
284
- GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, offset, 1);
285
- summary = git__calloc(allocsize, sizeof(char));
286
- GIT_ERROR_CHECK_ALLOC(summary);
287
-
288
- strncpy(summary, opts->summary, offset);
289
- }
290
-
291
- error = diff_format_email_append_header_tobuf(out,
292
- opts->id, opts->author, summary == NULL ? opts->summary : summary,
293
- opts->body, opts->patch_no, opts->total_patches, ignore_marker);
294
-
295
- if (error < 0)
296
- goto on_error;
297
-
298
- format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;
299
-
300
- if ((error = git_buf_puts(out, "---\n")) < 0 ||
301
- (error = git_diff_get_stats(&stats, diff)) < 0 ||
302
- (error = git_diff_stats_to_buf(out, stats, format_flags, 0)) < 0 ||
303
- (error = git_buf_putc(out, '\n')) < 0 ||
304
- (error = diff_format_email_append_patches_tobuf(out, diff)) < 0)
305
- goto on_error;
306
-
307
- error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
308
-
309
- on_error:
310
- git__free(summary);
311
- git_diff_stats_free(stats);
179
+ error = git_email__append_from_diff(out, diff, opts->patch_no,
180
+ opts->total_patches, opts->id, opts->summary, opts->body,
181
+ opts->author, &email_create_opts);
312
182
 
313
183
  return error;
314
184
  }
@@ -323,60 +193,43 @@ int git_diff_commit_as_email(
323
193
  const git_diff_options *diff_opts)
324
194
  {
325
195
  git_diff *diff = NULL;
326
- git_diff_format_email_options opts =
327
- GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
196
+ git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
197
+ const git_oid *commit_id;
198
+ const char *summary, *body;
199
+ const git_signature *author;
328
200
  int error;
329
201
 
330
202
  GIT_ASSERT_ARG(out);
331
203
  GIT_ASSERT_ARG(repo);
332
204
  GIT_ASSERT_ARG(commit);
333
205
 
334
- opts.flags = flags;
335
- opts.patch_no = patch_no;
336
- opts.total_patches = total_patches;
337
- opts.id = git_commit_id(commit);
338
- opts.summary = git_commit_summary(commit);
339
- opts.body = git_commit_body(commit);
340
- opts.author = git_commit_author(commit);
206
+ commit_id = git_commit_id(commit);
207
+ summary = git_commit_summary(commit);
208
+ body = git_commit_body(commit);
209
+ author = git_commit_author(commit);
210
+
211
+ if ((flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0)
212
+ opts.subject_prefix = "";
341
213
 
342
214
  if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0)
343
215
  return error;
344
216
 
345
- error = git_diff_format_email(out, diff, &opts);
217
+ error = git_email_create_from_diff(out, diff, patch_no, total_patches, commit_id, summary, body, author, &opts);
346
218
 
347
219
  git_diff_free(diff);
348
220
  return error;
349
221
  }
350
222
 
351
- int git_diff_options_init(git_diff_options *opts, unsigned int version)
352
- {
353
- GIT_INIT_STRUCTURE_FROM_TEMPLATE(
354
- opts, version, git_diff_options, GIT_DIFF_OPTIONS_INIT);
355
- return 0;
356
- }
357
-
358
- #ifndef GIT_DEPRECATE_HARD
359
223
  int git_diff_init_options(git_diff_options *opts, unsigned int version)
360
224
  {
361
225
  return git_diff_options_init(opts, version);
362
226
  }
363
- #endif
364
227
 
365
- int git_diff_find_options_init(
366
- git_diff_find_options *opts, unsigned int version)
367
- {
368
- GIT_INIT_STRUCTURE_FROM_TEMPLATE(
369
- opts, version, git_diff_find_options, GIT_DIFF_FIND_OPTIONS_INIT);
370
- return 0;
371
- }
372
-
373
- #ifndef GIT_DEPRECATE_HARD
374
228
  int git_diff_find_init_options(
375
229
  git_diff_find_options *opts, unsigned int version)
376
230
  {
377
231
  return git_diff_find_options_init(opts, version);
378
232
  }
379
- #endif
380
233
 
381
234
  int git_diff_format_email_options_init(
382
235
  git_diff_format_email_options *opts, unsigned int version)
@@ -387,14 +240,29 @@ int git_diff_format_email_options_init(
387
240
  return 0;
388
241
  }
389
242
 
390
- #ifndef GIT_DEPRECATE_HARD
391
243
  int git_diff_format_email_init_options(
392
244
  git_diff_format_email_options *opts, unsigned int version)
393
245
  {
394
246
  return git_diff_format_email_options_init(opts, version);
395
247
  }
248
+
396
249
  #endif
397
250
 
251
+ int git_diff_options_init(git_diff_options *opts, unsigned int version)
252
+ {
253
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
254
+ opts, version, git_diff_options, GIT_DIFF_OPTIONS_INIT);
255
+ return 0;
256
+ }
257
+
258
+ int git_diff_find_options_init(
259
+ git_diff_find_options *opts, unsigned int version)
260
+ {
261
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
262
+ opts, version, git_diff_find_options, GIT_DIFF_FIND_OPTIONS_INIT);
263
+ return 0;
264
+ }
265
+
398
266
  static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
399
267
  {
400
268
  git_oid hash;
@@ -0,0 +1,299 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "email.h"
9
+
10
+ #include "buffer.h"
11
+ #include "common.h"
12
+ #include "diff_generate.h"
13
+
14
+ #include "git2/email.h"
15
+ #include "git2/patch.h"
16
+ #include "git2/version.h"
17
+
18
+ /*
19
+ * Git uses a "magic" timestamp to indicate that an email message
20
+ * is from `git format-patch` (or our equivalent).
21
+ */
22
+ #define EMAIL_TIMESTAMP "Mon Sep 17 00:00:00 2001"
23
+
24
+ GIT_INLINE(int) include_prefix(
25
+ size_t patch_count,
26
+ git_email_create_options *opts)
27
+ {
28
+ return ((!opts->subject_prefix || *opts->subject_prefix) ||
29
+ (opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 ||
30
+ opts->reroll_number ||
31
+ (patch_count > 1 && !(opts->flags & GIT_EMAIL_CREATE_OMIT_NUMBERS)));
32
+ }
33
+
34
+ static int append_prefix(
35
+ git_buf *out,
36
+ size_t patch_idx,
37
+ size_t patch_count,
38
+ git_email_create_options *opts)
39
+ {
40
+ const char *subject_prefix = opts->subject_prefix ?
41
+ opts->subject_prefix : "PATCH";
42
+
43
+ git_buf_putc(out, '[');
44
+
45
+ if (*subject_prefix)
46
+ git_buf_puts(out, subject_prefix);
47
+
48
+ if (opts->reroll_number) {
49
+ if (*subject_prefix)
50
+ git_buf_putc(out, ' ');
51
+
52
+ git_buf_printf(out, "v%" PRIuZ, opts->reroll_number);
53
+ }
54
+
55
+ if ((opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 ||
56
+ (patch_count > 1 && !(opts->flags & GIT_EMAIL_CREATE_OMIT_NUMBERS))) {
57
+ size_t start_number = opts->start_number ?
58
+ opts->start_number : 1;
59
+
60
+ if (*subject_prefix || opts->reroll_number)
61
+ git_buf_putc(out, ' ');
62
+
63
+ git_buf_printf(out, "%" PRIuZ "/%" PRIuZ,
64
+ patch_idx + (start_number - 1),
65
+ patch_count + (start_number - 1));
66
+ }
67
+
68
+ git_buf_puts(out, "]");
69
+
70
+ return git_buf_oom(out) ? -1 : 0;
71
+ }
72
+
73
+ static int append_subject(
74
+ git_buf *out,
75
+ size_t patch_idx,
76
+ size_t patch_count,
77
+ const char *summary,
78
+ git_email_create_options *opts)
79
+ {
80
+ bool prefix = include_prefix(patch_count, opts);
81
+ size_t summary_len = summary ? strlen(summary) : 0;
82
+ int error;
83
+
84
+ if (summary_len) {
85
+ const char *nl = strchr(summary, '\n');
86
+
87
+ if (nl)
88
+ summary_len = (nl - summary);
89
+ }
90
+
91
+ if ((error = git_buf_puts(out, "Subject: ")) < 0)
92
+ return error;
93
+
94
+ if (prefix &&
95
+ (error = append_prefix(out, patch_idx, patch_count, opts)) < 0)
96
+ return error;
97
+
98
+ if (prefix && summary_len && (error = git_buf_putc(out, ' ')) < 0)
99
+ return error;
100
+
101
+ if (summary_len &&
102
+ (error = git_buf_put(out, summary, summary_len)) < 0)
103
+ return error;
104
+
105
+ return git_buf_putc(out, '\n');
106
+ }
107
+
108
+ static int append_header(
109
+ git_buf *out,
110
+ size_t patch_idx,
111
+ size_t patch_count,
112
+ const git_oid *commit_id,
113
+ const char *summary,
114
+ const git_signature *author,
115
+ git_email_create_options *opts)
116
+ {
117
+ char id[GIT_OID_HEXSZ];
118
+ char date[GIT_DATE_RFC2822_SZ];
119
+ int error;
120
+
121
+ if ((error = git_oid_fmt(id, commit_id)) < 0 ||
122
+ (error = git_buf_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
123
+ (error = git_buf_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
124
+ (error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
125
+ (error = git_buf_printf(out, "Date: %s\n", date)) < 0 ||
126
+ (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
127
+ return error;
128
+
129
+ if ((error = git_buf_putc(out, '\n')) < 0)
130
+ return error;
131
+
132
+ return 0;
133
+ }
134
+
135
+ static int append_body(git_buf *out, const char *body)
136
+ {
137
+ size_t body_len;
138
+ int error;
139
+
140
+ if (!body)
141
+ return 0;
142
+
143
+ body_len = strlen(body);
144
+
145
+ if ((error = git_buf_puts(out, body)) < 0)
146
+ return error;
147
+
148
+ if (body_len && body[body_len - 1] != '\n')
149
+ error = git_buf_putc(out, '\n');
150
+
151
+ return error;
152
+ }
153
+
154
+ static int append_diffstat(git_buf *out, git_diff *diff)
155
+ {
156
+ git_diff_stats *stats = NULL;
157
+ unsigned int format_flags;
158
+ int error;
159
+
160
+ format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;
161
+
162
+ if ((error = git_diff_get_stats(&stats, diff)) == 0 &&
163
+ (error = git_diff_stats_to_buf(out, stats, format_flags, 0)) == 0)
164
+ error = git_buf_putc(out, '\n');
165
+
166
+ git_diff_stats_free(stats);
167
+ return error;
168
+ }
169
+
170
+ static int append_patches(git_buf *out, git_diff *diff)
171
+ {
172
+ size_t i, deltas;
173
+ int error = 0;
174
+
175
+ deltas = git_diff_num_deltas(diff);
176
+
177
+ for (i = 0; i < deltas; ++i) {
178
+ git_patch *patch = NULL;
179
+
180
+ if ((error = git_patch_from_diff(&patch, diff, i)) >= 0)
181
+ error = git_patch_to_buf(out, patch);
182
+
183
+ git_patch_free(patch);
184
+
185
+ if (error < 0)
186
+ break;
187
+ }
188
+
189
+ return error;
190
+ }
191
+
192
+ int git_email__append_from_diff(
193
+ git_buf *out,
194
+ git_diff *diff,
195
+ size_t patch_idx,
196
+ size_t patch_count,
197
+ const git_oid *commit_id,
198
+ const char *summary,
199
+ const char *body,
200
+ const git_signature *author,
201
+ const git_email_create_options *given_opts)
202
+ {
203
+ git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
204
+ int error;
205
+
206
+ GIT_ASSERT_ARG(out);
207
+ GIT_ASSERT_ARG(diff);
208
+ GIT_ASSERT_ARG(!patch_idx || patch_idx <= patch_count);
209
+ GIT_ASSERT_ARG(commit_id);
210
+ GIT_ASSERT_ARG(author);
211
+
212
+ GIT_ERROR_CHECK_VERSION(given_opts,
213
+ GIT_EMAIL_CREATE_OPTIONS_VERSION,
214
+ "git_email_create_options");
215
+
216
+ if (given_opts)
217
+ memcpy(&opts, given_opts, sizeof(git_email_create_options));
218
+
219
+ git_buf_sanitize(out);
220
+
221
+ if ((error = append_header(out, patch_idx, patch_count, commit_id, summary, author, &opts)) == 0 &&
222
+ (error = append_body(out, body)) == 0 &&
223
+ (error = git_buf_puts(out, "---\n")) == 0 &&
224
+ (error = append_diffstat(out, diff)) == 0 &&
225
+ (error = append_patches(out, diff)) == 0)
226
+ error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
227
+
228
+ return error;
229
+ }
230
+
231
+ int git_email_create_from_diff(
232
+ git_buf *out,
233
+ git_diff *diff,
234
+ size_t patch_idx,
235
+ size_t patch_count,
236
+ const git_oid *commit_id,
237
+ const char *summary,
238
+ const char *body,
239
+ const git_signature *author,
240
+ const git_email_create_options *given_opts)
241
+ {
242
+ int error;
243
+
244
+ git_buf_sanitize(out);
245
+ git_buf_clear(out);
246
+
247
+ error = git_email__append_from_diff(out, diff, patch_idx,
248
+ patch_count, commit_id, summary, body, author,
249
+ given_opts);
250
+
251
+ return error;
252
+ }
253
+
254
+ int git_email_create_from_commit(
255
+ git_buf *out,
256
+ git_commit *commit,
257
+ const git_email_create_options *given_opts)
258
+ {
259
+ git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
260
+ git_diff *diff = NULL;
261
+ git_repository *repo;
262
+ git_diff_options *diff_opts;
263
+ git_diff_find_options *find_opts;
264
+ const git_signature *author;
265
+ const char *summary, *body;
266
+ const git_oid *commit_id;
267
+ int error = -1;
268
+
269
+ GIT_ASSERT_ARG(out);
270
+ GIT_ASSERT_ARG(commit);
271
+
272
+ GIT_ERROR_CHECK_VERSION(given_opts,
273
+ GIT_EMAIL_CREATE_OPTIONS_VERSION,
274
+ "git_email_create_options");
275
+
276
+ if (given_opts)
277
+ memcpy(&opts, given_opts, sizeof(git_email_create_options));
278
+
279
+ repo = git_commit_owner(commit);
280
+ author = git_commit_author(commit);
281
+ summary = git_commit_summary(commit);
282
+ body = git_commit_body(commit);
283
+ commit_id = git_commit_id(commit);
284
+ diff_opts = &opts.diff_opts;
285
+ find_opts = &opts.diff_find_opts;
286
+
287
+ if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0)
288
+ goto done;
289
+
290
+ if ((opts.flags & GIT_EMAIL_CREATE_NO_RENAMES) == 0 &&
291
+ (error = git_diff_find_similar(diff, find_opts)) < 0)
292
+ goto done;
293
+
294
+ error = git_email_create_from_diff(out, diff, 1, 1, commit_id, summary, body, author, &opts);
295
+
296
+ done:
297
+ git_diff_free(diff);
298
+ return error;
299
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_email_h__
8
+ #define INCLUDE_email_h__
9
+
10
+ #include "common.h"
11
+
12
+ #include "git2/email.h"
13
+
14
+ extern int git_email__append_from_diff(
15
+ git_buf *out,
16
+ git_diff *diff,
17
+ size_t patch_idx,
18
+ size_t patch_count,
19
+ const git_oid *commit_id,
20
+ const char *summary,
21
+ const char *body,
22
+ const git_signature *author,
23
+ const git_email_create_options *given_opts);
24
+
25
+ #endif
@@ -446,7 +446,13 @@ static int filter_list_check_attributes(
446
446
 
447
447
  if ((src->options.flags & GIT_FILTER_ATTRIBUTES_FROM_COMMIT) != 0) {
448
448
  attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_COMMIT;
449
- attr_opts.commit_id = src->options.commit_id;
449
+
450
+ #ifndef GIT_DEPRECATE_HARD
451
+ if (src->options.commit_id)
452
+ git_oid_cpy(&attr_opts.attr_commit_id, src->options.commit_id);
453
+ else
454
+ #endif
455
+ git_oid_cpy(&attr_opts.attr_commit_id, &src->options.attr_commit_id);
450
456
  }
451
457
 
452
458
  error = git_attr_get_many_with_session(
@@ -1710,7 +1710,7 @@ static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t i
1710
1710
 
1711
1711
 
1712
1712
 
1713
- static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
1713
+ static void sha1_process(SHA1_CTX *ctx, const uint32_t block[16])
1714
1714
  {
1715
1715
  unsigned i, j;
1716
1716
  uint32_t ubc_dv_mask[DVMASKSIZE] = { 0xFFFFFFFF };
@@ -1762,7 +1762,7 @@ static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
1762
1762
  }
1763
1763
  }
1764
1764
 
1765
- void SHA1DCInit(SHA1_CTX* ctx)
1765
+ void SHA1DCInit(SHA1_CTX *ctx)
1766
1766
  {
1767
1767
  ctx->total = 0;
1768
1768
  ctx->ihv[0] = 0x67452301;
@@ -1778,7 +1778,7 @@ void SHA1DCInit(SHA1_CTX* ctx)
1778
1778
  ctx->callback = NULL;
1779
1779
  }
1780
1780
 
1781
- void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
1781
+ void SHA1DCSetSafeHash(SHA1_CTX *ctx, int safehash)
1782
1782
  {
1783
1783
  if (safehash)
1784
1784
  ctx->safe_hash = 1;
@@ -1787,7 +1787,7 @@ void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
1787
1787
  }
1788
1788
 
1789
1789
 
1790
- void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
1790
+ void SHA1DCSetUseUBC(SHA1_CTX *ctx, int ubc_check)
1791
1791
  {
1792
1792
  if (ubc_check)
1793
1793
  ctx->ubc_check = 1;
@@ -1795,7 +1795,7 @@ void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
1795
1795
  ctx->ubc_check = 0;
1796
1796
  }
1797
1797
 
1798
- void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
1798
+ void SHA1DCSetUseDetectColl(SHA1_CTX *ctx, int detect_coll)
1799
1799
  {
1800
1800
  if (detect_coll)
1801
1801
  ctx->detect_coll = 1;
@@ -1803,7 +1803,7 @@ void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
1803
1803
  ctx->detect_coll = 0;
1804
1804
  }
1805
1805
 
1806
- void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
1806
+ void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *ctx, int reduced_round_coll)
1807
1807
  {
1808
1808
  if (reduced_round_coll)
1809
1809
  ctx->reduced_round_coll = 1;
@@ -1811,12 +1811,12 @@ void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
1811
1811
  ctx->reduced_round_coll = 0;
1812
1812
  }
1813
1813
 
1814
- void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback)
1814
+ void SHA1DCSetCallback(SHA1_CTX *ctx, collision_block_callback callback)
1815
1815
  {
1816
1816
  ctx->callback = callback;
1817
1817
  }
1818
1818
 
1819
- void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, size_t len)
1819
+ void SHA1DCUpdate(SHA1_CTX *ctx, const char *buf, size_t len)
1820
1820
  {
1821
1821
  unsigned left, fill;
1822
1822
 
@@ -468,7 +468,7 @@ int git_ignore__lookup(
468
468
  *out = GIT_IGNORE_NOTFOUND;
469
469
 
470
470
  if (git_attr_path__init(
471
- &path, ignores->repo, pathname, git_repository_workdir(ignores->repo), dir_flag) < 0)
471
+ &path, pathname, git_repository_workdir(ignores->repo), dir_flag) < 0)
472
472
  return -1;
473
473
 
474
474
  /* first process builtins - success means path was found */
@@ -552,7 +552,7 @@ int git_ignore_path_is_ignored(
552
552
  else if (git_repository_is_bare(repo))
553
553
  dir_flag = GIT_DIR_FLAG_FALSE;
554
554
 
555
- if ((error = git_attr_path__init(&path, repo, pathname, workdir, dir_flag)) < 0 ||
555
+ if ((error = git_attr_path__init(&path, pathname, workdir, dir_flag)) < 0 ||
556
556
  (error = git_ignore__for_path(repo, path.path, &ignores)) < 0)
557
557
  goto cleanup;
558
558