FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Introduce `git_email_create`; deprecate `git_diff_format_email` by ethomson · Pull Request #6061 · libgit2/libgit2 · GitHub

1 change: 1 addition & 0 deletions include/git2.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "git2/deprecated.h"
#include "git2/describe.h"
#include "git2/diff.h"
#include "git2/email.h"
#include "git2/errors.h"
#include "git2/filter.h"
#include "git2/global.h"
Expand Down
96 changes: 96 additions & 0 deletions include/git2/deprecated.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,102 @@ typedef git_configmap git_cvar_map;

/**@}*/

/** @name Deprecated Diff Functions and Constants
*
* These functions and enumeration values are retained for backward
* compatibility. The newer versions of these functions and values
* should be preferred in all new code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/

/**
* Formatting options for diff e-mail generation
*/
typedef enum {
/** Normal patch, the default */
GIT_DIFF_FORMAT_EMAIL_NONE = 0,

/** Don't insert "[PATCH]" in the subject header*/
GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),

} git_diff_format_email_flags_t;

/**
* Options for controlling the formatting of the generated e-mail.
*/
typedef struct {
unsigned int version;

/** see `git_diff_format_email_flags_t` above */
uint32_t flags;

/** This patch number */
size_t patch_no;

/** Total number of patches in this series */
size_t total_patches;

/** id to use for the commit */
const git_oid *id;

/** Summary of the change */
const char *summary;

/** Commit message's body */
const char *body;

/** Author of the change */
const git_signature *author;
} git_diff_format_email_options;

#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL}

/**
* Create an e-mail ready patch from a diff.
*
* @deprecated git_email_create_from_diff
* @see git_email_create_from_diff
*/
GIT_EXTERN(int) git_diff_format_email(
git_buf *out,
git_diff *diff,
const git_diff_format_email_options *opts);

/**
* Create an e-mail ready patch for a commit.
*
* @deprecated git_email_create_from_commit
* @see git_email_create_from_commit
*/
GIT_EXTERN(int) git_diff_commit_as_email(
git_buf *out,
git_repository *repo,
git_commit *commit,
size_t patch_no,
size_t total_patches,
uint32_t flags,
const git_diff_options *diff_opts);

/**
* Initialize git_diff_format_email_options structure
*
* Initializes a `git_diff_format_email_options` with default values. Equivalent
* to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
*
* @param opts The `git_blame_options` struct to initialize.
* @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_diff_format_email_options_init(
git_diff_format_email_options *opts,
unsigned int version);

/**@}*/

/** @name Deprecated Error Functions and Constants
*
* These functions and enumeration values are retained for backward
Expand Down
93 changes: 0 additions & 93 deletions include/git2/diff.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1376,99 +1376,6 @@ GIT_EXTERN(int) git_diff_stats_to_buf(
*/
GIT_EXTERN(void) git_diff_stats_free(git_diff_stats *stats);

/**
* Formatting options for diff e-mail generation
*/
typedef enum {
/** Normal patch, the default */
GIT_DIFF_FORMAT_EMAIL_NONE = 0,

/** Don't insert "[PATCH]" in the subject header*/
GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),

} git_diff_format_email_flags_t;

/**
* Options for controlling the formatting of the generated e-mail.
*/
typedef struct {
unsigned int version;

/** see `git_diff_format_email_flags_t` above */
uint32_t flags;

/** This patch number */
size_t patch_no;

/** Total number of patches in this series */
size_t total_patches;

/** id to use for the commit */
const git_oid *id;

/** Summary of the change */
const char *summary;

/** Commit message's body */
const char *body;

/** Author of the change */
const git_signature *author;
} git_diff_format_email_options;

#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL}

/**
* Create an e-mail ready patch from a diff.
*
* @param out buffer to store the e-mail patch in
* @param diff containing the commit
* @param opts structure with options to influence content and formatting.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_diff_format_email(
git_buf *out,
git_diff *diff,
const git_diff_format_email_options *opts);

/**
* Create an e-mail ready patch for a commit.
*
* Does not support creating patches for merge commits (yet).
*
* @param out buffer to store the e-mail patch in
* @param repo containing the commit
* @param commit pointer to up commit
* @param patch_no patch number of the commit
* @param total_patches total number of patches in the patch set
* @param flags determines the formatting of the e-mail
* @param diff_opts structure with options to influence diff or NULL for defaults.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_diff_commit_as_email(
git_buf *out,
git_repository *repo,
git_commit *commit,
size_t patch_no,
size_t total_patches,
uint32_t flags,
const git_diff_options *diff_opts);

/**
* Initialize git_diff_format_email_options structure
*
* Initializes a `git_diff_format_email_options` with default values. Equivalent
* to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
*
* @param opts The `git_blame_options` struct to initialize.
* @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_diff_format_email_options_init(
git_diff_format_email_options *opts,
unsigned int version);

/**
* Patch ID options structure
*
Expand Down
127 changes: 127 additions & 0 deletions include/git2/email.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_email_h__
#define INCLUDE_git_email_h__

#include "common.h"

/**
* @file git2/email.h
* @brief Git email formatting and application routines.
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL

/**
* Formatting options for diff e-mail generation
*/
typedef enum {
/** Normal patch, the default */
GIT_EMAIL_CREATE_DEFAULT = 0,

/** Do not include patch numbers in the subject prefix. */
GIT_EMAIL_CREATE_OMIT_NUMBERS = (1u << 0),

/**
* Include numbers in the subject prefix even when the
* patch is for a single commit (1/1).
*/
GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1),

/** Do not perform rename or similarity detection. */
GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2),
} git_email_create_flags_t;

/**
* Options for controlling the formatting of the generated e-mail.
*/
typedef struct {
unsigned int version;

/** see `git_email_create_flags_t` above */
uint32_t flags;

/** Options to use when creating diffs */
git_diff_options diff_opts;

/** Options for finding similarities within diffs */
git_diff_find_options diff_find_opts;

/**
* The subject prefix, by default "PATCH". If set to an empty
* string ("") then only the patch numbers will be shown in the
* prefix. If the subject_prefix is empty and patch numbers
* are not being shown, the prefix will be omitted entirely.
*/
const char *subject_prefix;

/**
* The starting patch number; this cannot be 0. By default,
* this is 1.
*/
size_t start_number;

/** The "re-roll" number. By default, there is no re-roll. */
size_t reroll_number;
} git_email_create_options;

/*
* By default, our options include rename detection and binary
* diffs to match `git format-patch`.
*/
#define GIT_EMAIL_CREATE_OPTIONS_VERSION 1
#define GIT_EMAIL_CREATE_OPTIONS_INIT \
{ \
GIT_EMAIL_CREATE_OPTIONS_VERSION, \
GIT_EMAIL_CREATE_DEFAULT, \
{ GIT_DIFF_OPTIONS_VERSION, GIT_DIFF_SHOW_BINARY, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3 }, \
GIT_DIFF_FIND_OPTIONS_INIT \
}

/**
* Create a diff for a commit in mbox format for sending via email.
*
* @param out buffer to store the e-mail patch in
* @param diff the changes to include in the email
* @param patch_idx the patch index
* @param patch_count the total number of patches that will be included
* @param commit_id the commit id for this change
* @param summary the commit message for this change
* @param body optional text to include above the diffstat
* @param author the person who authored this commit
* @param opts email creation options
*/
GIT_EXTERN(int) git_email_create_from_diff(
git_buf *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
const git_oid *commit_id,
const char *summary,
const char *body,
const git_signature *author,
const git_email_create_options *opts);

/**
* Create a diff for a commit in mbox format for sending via email.
* The commit must not be a merge commit.
*
* @param out buffer to store the e-mail patch in
* @param commit commit to create a patch for
* @param opts email creation options
*/
GIT_EXTERN(int) git_email_create_from_commit(
git_buf *out,
git_commit *commit,
const git_email_create_options *opts);

GIT_END_DECL

/** @} */

#endif
45 changes: 45 additions & 0 deletions include/git2/sys/email.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_email_h__
#define INCLUDE_sys_git_email_h__

/**
* @file git2/sys/email.h
* @brief Advanced git email creation routines
* @defgroup git_email Advanced git email creation routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL

/**
* Create a diff for a commit in mbox format for sending via email.
*
* @param out buffer to store the e-mail patch in
* @param diff the changes to include in the email
* @param patch_idx the patch index
* @param patch_count the total number of patches that will be included
* @param commit_id the commit id for this change
* @param summary the commit message for this change
* @param body optional text to include above the diffstat
* @param author the person who authored this commit
* @param opts email creation options
*/
GIT_EXTERN(int) git_email_create_from_diff(
git_buf *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
const git_oid *commit_id,
const char *summary,
const char *body,
const git_signature *author,
const git_email_create_options *opts);

/** @} */
GIT_END_DECL
#endif
7 changes: 7 additions & 0 deletions src/buffer.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ void git_buf_shorten(git_buf *buf, size_t amount)
git_buf_clear(buf);
}

void git_buf_truncate_at_char(git_buf *buf, char separator)
{
ssize_t idx = git_buf_find(buf, separator);
if (idx >= 0)
git_buf_truncate(buf, (size_t)idx);
}

void git_buf_rtruncate_at_char(git_buf *buf, char separator)
{
ssize_t idx = git_buf_rfind_next(buf, separator);
Expand Down
Loading

Back | FazBrowse Home | New Git URL