Skip to content

Commit ba3595a

Browse files
committed
diff: deprecate diff_format_email
`git_diff_format_email` is deprecated in favor of `git_email_create`.
1 parent 67b1d01 commit ba3595a

File tree

4 files changed

+139
-116
lines changed

4 files changed

+139
-116
lines changed

include/git2/deprecated.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,102 @@ typedef git_configmap git_cvar_map;
294294

295295
/**@}*/
296296

297+
/** @name Deprecated Diff Functions and Constants
298+
*
299+
* These functions and enumeration values are retained for backward
300+
* compatibility. The newer versions of these functions and values
301+
* should be preferred in all new code.
302+
*
303+
* There is no plan to remove these backward compatibility values at
304+
* this time.
305+
*/
306+
/**@{*/
307+
308+
/**
309+
* Formatting options for diff e-mail generation
310+
*/
311+
typedef enum {
312+
/** Normal patch, the default */
313+
GIT_DIFF_FORMAT_EMAIL_NONE = 0,
314+
315+
/** Don't insert "[PATCH]" in the subject header*/
316+
GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),
317+
318+
} git_diff_format_email_flags_t;
319+
320+
/**
321+
* Options for controlling the formatting of the generated e-mail.
322+
*/
323+
typedef struct {
324+
unsigned int version;
325+
326+
/** see `git_diff_format_email_flags_t` above */
327+
uint32_t flags;
328+
329+
/** This patch number */
330+
size_t patch_no;
331+
332+
/** Total number of patches in this series */
333+
size_t total_patches;
334+
335+
/** id to use for the commit */
336+
const git_oid *id;
337+
338+
/** Summary of the change */
339+
const char *summary;
340+
341+
/** Commit message's body */
342+
const char *body;
343+
344+
/** Author of the change */
345+
const git_signature *author;
346+
} git_diff_format_email_options;
347+
348+
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
349+
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL}
350+
351+
/**
352+
* Create an e-mail ready patch from a diff.
353+
*
354+
* @deprecated git_email_create_from_diff
355+
* @see git_email_create_from_diff
356+
*/
357+
GIT_EXTERN(int) git_diff_format_email(
358+
git_buf *out,
359+
git_diff *diff,
360+
const git_diff_format_email_options *opts);
361+
362+
/**
363+
* Create an e-mail ready patch for a commit.
364+
*
365+
* @deprecated git_email_create_from_commit
366+
* @see git_email_create_from_commit
367+
*/
368+
GIT_EXTERN(int) git_diff_commit_as_email(
369+
git_buf *out,
370+
git_repository *repo,
371+
git_commit *commit,
372+
size_t patch_no,
373+
size_t total_patches,
374+
uint32_t flags,
375+
const git_diff_options *diff_opts);
376+
377+
/**
378+
* Initialize git_diff_format_email_options structure
379+
*
380+
* Initializes a `git_diff_format_email_options` with default values. Equivalent
381+
* to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
382+
*
383+
* @param opts The `git_blame_options` struct to initialize.
384+
* @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`.
385+
* @return Zero on success; -1 on failure.
386+
*/
387+
GIT_EXTERN(int) git_diff_format_email_options_init(
388+
git_diff_format_email_options *opts,
389+
unsigned int version);
390+
391+
/**@}*/
392+
297393
/** @name Deprecated Error Functions and Constants
298394
*
299395
* These functions and enumeration values are retained for backward

include/git2/diff.h

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,99 +1376,6 @@ GIT_EXTERN(int) git_diff_stats_to_buf(
13761376
*/
13771377
GIT_EXTERN(void) git_diff_stats_free(git_diff_stats *stats);
13781378

1379-
/**
1380-
* Formatting options for diff e-mail generation
1381-
*/
1382-
typedef enum {
1383-
/** Normal patch, the default */
1384-
GIT_DIFF_FORMAT_EMAIL_NONE = 0,
1385-
1386-
/** Don't insert "[PATCH]" in the subject header*/
1387-
GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),
1388-
1389-
} git_diff_format_email_flags_t;
1390-
1391-
/**
1392-
* Options for controlling the formatting of the generated e-mail.
1393-
*/
1394-
typedef struct {
1395-
unsigned int version;
1396-
1397-
/** see `git_diff_format_email_flags_t` above */
1398-
uint32_t flags;
1399-
1400-
/** This patch number */
1401-
size_t patch_no;
1402-
1403-
/** Total number of patches in this series */
1404-
size_t total_patches;
1405-
1406-
/** id to use for the commit */
1407-
const git_oid *id;
1408-
1409-
/** Summary of the change */
1410-
const char *summary;
1411-
1412-
/** Commit message's body */
1413-
const char *body;
1414-
1415-
/** Author of the change */
1416-
const git_signature *author;
1417-
} git_diff_format_email_options;
1418-
1419-
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
1420-
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL}
1421-
1422-
/**
1423-
* Create an e-mail ready patch from a diff.
1424-
*
1425-
* @param out buffer to store the e-mail patch in
1426-
* @param diff containing the commit
1427-
* @param opts structure with options to influence content and formatting.
1428-
* @return 0 or an error code
1429-
*/
1430-
GIT_EXTERN(int) git_diff_format_email(
1431-
git_buf *out,
1432-
git_diff *diff,
1433-
const git_diff_format_email_options *opts);
1434-
1435-
/**
1436-
* Create an e-mail ready patch for a commit.
1437-
*
1438-
* Does not support creating patches for merge commits (yet).
1439-
*
1440-
* @param out buffer to store the e-mail patch in
1441-
* @param repo containing the commit
1442-
* @param commit pointer to up commit
1443-
* @param patch_no patch number of the commit
1444-
* @param total_patches total number of patches in the patch set
1445-
* @param flags determines the formatting of the e-mail
1446-
* @param diff_opts structure with options to influence diff or NULL for defaults.
1447-
* @return 0 or an error code
1448-
*/
1449-
GIT_EXTERN(int) git_diff_commit_as_email(
1450-
git_buf *out,
1451-
git_repository *repo,
1452-
git_commit *commit,
1453-
size_t patch_no,
1454-
size_t total_patches,
1455-
uint32_t flags,
1456-
const git_diff_options *diff_opts);
1457-
1458-
/**
1459-
* Initialize git_diff_format_email_options structure
1460-
*
1461-
* Initializes a `git_diff_format_email_options` with default values. Equivalent
1462-
* to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
1463-
*
1464-
* @param opts The `git_blame_options` struct to initialize.
1465-
* @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`.
1466-
* @return Zero on success; -1 on failure.
1467-
*/
1468-
GIT_EXTERN(int) git_diff_format_email_options_init(
1469-
git_diff_format_email_options *opts,
1470-
unsigned int version);
1471-
14721379
/**
14731380
* Patch ID options structure
14741381
*

src/diff.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
#include "diff.h"
99

10-
#include "git2/version.h"
11-
#include "git2/email.h"
12-
#include "diff_generate.h"
10+
#include "common.h"
1311
#include "patch.h"
1412
#include "email.h"
1513
#include "commit.h"
1614
#include "index.h"
15+
#include "diff_generate.h"
16+
17+
#include "git2/version.h"
18+
#include "git2/email.h"
1719

1820
struct patch_id_args {
1921
git_hash_ctx ctx;
@@ -152,6 +154,8 @@ int git_diff_foreach(
152154
return error;
153155
}
154156

157+
#ifndef GIT_DEPRECATE_HARD
158+
155159
int git_diff_format_email(
156160
git_buf *out,
157161
git_diff *diff,
@@ -216,35 +220,16 @@ int git_diff_commit_as_email(
216220
return error;
217221
}
218222

219-
int git_diff_options_init(git_diff_options *opts, unsigned int version)
220-
{
221-
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
222-
opts, version, git_diff_options, GIT_DIFF_OPTIONS_INIT);
223-
return 0;
224-
}
225-
226-
#ifndef GIT_DEPRECATE_HARD
227223
int git_diff_init_options(git_diff_options *opts, unsigned int version)
228224
{
229225
return git_diff_options_init(opts, version);
230226
}
231-
#endif
232227

233-
int git_diff_find_options_init(
234-
git_diff_find_options *opts, unsigned int version)
235-
{
236-
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
237-
opts, version, git_diff_find_options, GIT_DIFF_FIND_OPTIONS_INIT);
238-
return 0;
239-
}
240-
241-
#ifndef GIT_DEPRECATE_HARD
242228
int git_diff_find_init_options(
243229
git_diff_find_options *opts, unsigned int version)
244230
{
245231
return git_diff_find_options_init(opts, version);
246232
}
247-
#endif
248233

249234
int git_diff_format_email_options_init(
250235
git_diff_format_email_options *opts, unsigned int version)
@@ -255,14 +240,29 @@ int git_diff_format_email_options_init(
255240
return 0;
256241
}
257242

258-
#ifndef GIT_DEPRECATE_HARD
259243
int git_diff_format_email_init_options(
260244
git_diff_format_email_options *opts, unsigned int version)
261245
{
262246
return git_diff_format_email_options_init(opts, version);
263247
}
248+
264249
#endif
265250

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+
266266
static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
267267
{
268268
git_oid hash;

0 commit comments

Comments
 (0)