2015-08-04 21:51:24 +08:00
|
|
|
/*
|
|
|
|
* Builtin "git am"
|
|
|
|
*
|
|
|
|
* Based on git-am.sh by Junio C Hamano.
|
|
|
|
*/
|
2019-01-24 16:29:12 +08:00
|
|
|
#define USE_THE_INDEX_COMPATIBILITY_MACROS
|
2015-08-04 21:51:24 +08:00
|
|
|
#include "cache.h"
|
2017-06-15 02:07:36 +08:00
|
|
|
#include "config.h"
|
2015-08-04 21:51:24 +08:00
|
|
|
#include "builtin.h"
|
2018-04-11 05:26:18 +08:00
|
|
|
#include "exec-cmd.h"
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
#include "parse-options.h"
|
|
|
|
#include "dir.h"
|
2015-08-04 21:51:26 +08:00
|
|
|
#include "run-command.h"
|
2015-08-04 21:51:28 +08:00
|
|
|
#include "quote.h"
|
2015-08-26 05:57:09 +08:00
|
|
|
#include "tempfile.h"
|
2015-08-04 21:51:29 +08:00
|
|
|
#include "lockfile.h"
|
2015-08-04 21:51:30 +08:00
|
|
|
#include "cache-tree.h"
|
|
|
|
#include "refs.h"
|
|
|
|
#include "commit.h"
|
2015-08-04 21:51:31 +08:00
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
2015-08-04 21:51:34 +08:00
|
|
|
#include "unpack-trees.h"
|
|
|
|
#include "branch.h"
|
2015-08-04 21:51:39 +08:00
|
|
|
#include "sequencer.h"
|
2015-08-04 21:51:41 +08:00
|
|
|
#include "revision.h"
|
|
|
|
#include "merge-recursive.h"
|
2015-08-04 21:51:43 +08:00
|
|
|
#include "log-tree.h"
|
2015-08-04 21:51:55 +08:00
|
|
|
#include "notes-utils.h"
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
#include "rerere.h"
|
2015-08-04 21:52:03 +08:00
|
|
|
#include "prompt.h"
|
2015-10-15 08:45:43 +08:00
|
|
|
#include "mailinfo.h"
|
2016-09-05 04:18:33 +08:00
|
|
|
#include "apply.h"
|
2016-08-31 03:36:42 +08:00
|
|
|
#include "string-list.h"
|
2017-08-19 06:20:21 +08:00
|
|
|
#include "packfile.h"
|
2018-06-29 09:21:56 +08:00
|
|
|
#include "repository.h"
|
2015-08-04 21:51:28 +08:00
|
|
|
|
2015-08-04 21:51:29 +08:00
|
|
|
/**
|
|
|
|
* Returns the length of the first line of msg.
|
|
|
|
*/
|
|
|
|
static int linelen(const char *msg)
|
|
|
|
{
|
|
|
|
return strchrnul(msg, '\n') - msg;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:00 +08:00
|
|
|
/**
|
|
|
|
* Returns true if `str` consists of only whitespace, false otherwise.
|
|
|
|
*/
|
|
|
|
static int str_isspace(const char *str)
|
|
|
|
{
|
|
|
|
for (; *str; str++)
|
|
|
|
if (!isspace(*str))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
enum patch_format {
|
|
|
|
PATCH_FORMAT_UNKNOWN = 0,
|
2015-08-04 21:52:00 +08:00
|
|
|
PATCH_FORMAT_MBOX,
|
2015-08-04 21:52:01 +08:00
|
|
|
PATCH_FORMAT_STGIT,
|
2015-08-04 21:52:02 +08:00
|
|
|
PATCH_FORMAT_STGIT_SERIES,
|
2016-06-05 12:46:41 +08:00
|
|
|
PATCH_FORMAT_HG,
|
|
|
|
PATCH_FORMAT_MBOXRD
|
2015-08-04 21:51:26 +08:00
|
|
|
};
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2015-08-04 21:51:46 +08:00
|
|
|
enum keep_type {
|
|
|
|
KEEP_FALSE = 0,
|
|
|
|
KEEP_TRUE, /* pass -k flag to git-mailinfo */
|
|
|
|
KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
|
|
|
|
};
|
|
|
|
|
2015-08-04 21:51:49 +08:00
|
|
|
enum scissors_type {
|
|
|
|
SCISSORS_UNSET = -1,
|
|
|
|
SCISSORS_FALSE = 0, /* pass --no-scissors to git-mailinfo */
|
|
|
|
SCISSORS_TRUE /* pass --scissors to git-mailinfo */
|
|
|
|
};
|
|
|
|
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
enum signoff_type {
|
|
|
|
SIGNOFF_FALSE = 0,
|
|
|
|
SIGNOFF_TRUE = 1,
|
|
|
|
SIGNOFF_EXPLICIT /* --signoff was set on the command-line */
|
|
|
|
};
|
|
|
|
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
enum show_patch_type {
|
|
|
|
SHOW_PATCH_RAW = 0,
|
2020-02-20 22:15:19 +08:00
|
|
|
SHOW_PATCH_DIFF = 1,
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
};
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
struct am_state {
|
|
|
|
/* state directory path */
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
/* current and last patch numbers, 1-indexed */
|
|
|
|
int cur;
|
|
|
|
int last;
|
2015-08-04 21:51:26 +08:00
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
/* commit metadata and message */
|
|
|
|
char *author_name;
|
|
|
|
char *author_email;
|
|
|
|
char *author_date;
|
|
|
|
char *msg;
|
|
|
|
size_t msg_len;
|
|
|
|
|
2015-08-04 21:51:54 +08:00
|
|
|
/* when --rebasing, records the original commit the patch came from */
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id orig_commit;
|
2015-08-04 21:51:54 +08:00
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
/* number of digits in patch filename */
|
|
|
|
int prec;
|
2015-08-04 21:51:37 +08:00
|
|
|
|
|
|
|
/* various operating modes and command line options */
|
2015-08-04 21:52:03 +08:00
|
|
|
int interactive;
|
2015-08-04 21:51:41 +08:00
|
|
|
int threeway;
|
2015-08-04 21:51:37 +08:00
|
|
|
int quiet;
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
int signoff; /* enum signoff_type */
|
2015-08-04 21:51:45 +08:00
|
|
|
int utf8;
|
2015-08-04 21:51:46 +08:00
|
|
|
int keep; /* enum keep_type */
|
2015-08-04 21:51:47 +08:00
|
|
|
int message_id;
|
2015-08-04 21:51:49 +08:00
|
|
|
int scissors; /* enum scissors_type */
|
2021-05-10 01:12:13 +08:00
|
|
|
int quoted_cr; /* enum quoted_cr_action */
|
2020-07-29 04:24:27 +08:00
|
|
|
struct strvec git_apply_opts;
|
2015-08-04 21:51:38 +08:00
|
|
|
const char *resolvemsg;
|
2015-08-04 21:51:52 +08:00
|
|
|
int committer_date_is_author_date;
|
2015-08-04 21:51:51 +08:00
|
|
|
int ignore_date;
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
int allow_rerere_autoupdate;
|
2015-08-04 21:51:53 +08:00
|
|
|
const char *sign_commit;
|
2015-08-04 21:51:42 +08:00
|
|
|
int rebasing;
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-21 05:09:35 +08:00
|
|
|
* Initializes am_state with the default values.
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
*/
|
2017-04-21 05:09:35 +08:00
|
|
|
static void am_state_init(struct am_state *state)
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
{
|
2015-08-04 21:51:53 +08:00
|
|
|
int gpgsign;
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
|
2017-04-21 05:09:35 +08:00
|
|
|
state->dir = git_pathdup("rebase-apply");
|
2015-08-04 21:51:26 +08:00
|
|
|
|
|
|
|
state->prec = 4;
|
2015-08-04 21:51:45 +08:00
|
|
|
|
2015-08-04 22:19:26 +08:00
|
|
|
git_config_get_bool("am.threeway", &state->threeway);
|
|
|
|
|
2015-08-04 21:51:45 +08:00
|
|
|
state->utf8 = 1;
|
2015-08-04 21:51:47 +08:00
|
|
|
|
|
|
|
git_config_get_bool("am.messageid", &state->message_id);
|
2015-08-04 21:51:49 +08:00
|
|
|
|
|
|
|
state->scissors = SCISSORS_UNSET;
|
2021-05-10 01:12:13 +08:00
|
|
|
state->quoted_cr = quoted_cr_unset;
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_init(&state->git_apply_opts);
|
2015-08-04 21:51:53 +08:00
|
|
|
|
|
|
|
if (!git_config_get_bool("commit.gpgsign", &gpgsign))
|
|
|
|
state->sign_commit = gpgsign ? "" : NULL;
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases memory allocated by an am_state.
|
|
|
|
*/
|
|
|
|
static void am_state_release(struct am_state *state)
|
|
|
|
{
|
|
|
|
free(state->dir);
|
2015-08-04 21:51:28 +08:00
|
|
|
free(state->author_name);
|
|
|
|
free(state->author_email);
|
|
|
|
free(state->author_date);
|
|
|
|
free(state->msg);
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_clear(&state->git_apply_opts);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 01:12:13 +08:00
|
|
|
static int am_option_parse_quoted_cr(const struct option *opt,
|
|
|
|
const char *arg, int unset)
|
|
|
|
{
|
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
|
|
|
if (mailinfo_parse_quoted_cr_action(arg, opt->value) != 0)
|
|
|
|
return error(_("bad action '%s' for '%s'"), arg, "--quoted-cr");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/**
|
|
|
|
* Returns path relative to the am_state directory.
|
|
|
|
*/
|
|
|
|
static inline const char *am_path(const struct am_state *state, const char *path)
|
|
|
|
{
|
|
|
|
return mkpath("%s/%s", state->dir, path);
|
|
|
|
}
|
|
|
|
|
2015-08-25 00:12:53 +08:00
|
|
|
/**
|
|
|
|
* For convenience to call write_file()
|
|
|
|
*/
|
2016-07-08 17:08:05 +08:00
|
|
|
static void write_state_text(const struct am_state *state,
|
|
|
|
const char *name, const char *string)
|
2015-08-25 00:12:53 +08:00
|
|
|
{
|
2016-07-08 17:08:05 +08:00
|
|
|
write_file(am_path(state, name), "%s", string);
|
2015-08-25 00:12:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-08 17:08:05 +08:00
|
|
|
static void write_state_count(const struct am_state *state,
|
|
|
|
const char *name, int value)
|
2015-08-25 00:12:53 +08:00
|
|
|
{
|
2016-07-08 17:08:05 +08:00
|
|
|
write_file(am_path(state, name), "%d", value);
|
2015-08-25 00:12:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-08 17:08:05 +08:00
|
|
|
static void write_state_bool(const struct am_state *state,
|
|
|
|
const char *name, int value)
|
2015-08-25 00:12:53 +08:00
|
|
|
{
|
2016-07-08 17:08:05 +08:00
|
|
|
write_state_text(state, name, value ? "t" : "f");
|
2015-08-25 00:12:53 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:37 +08:00
|
|
|
/**
|
|
|
|
* If state->quiet is false, calls fprintf(fp, fmt, ...), and appends a newline
|
|
|
|
* at the end.
|
|
|
|
*/
|
2021-07-13 16:05:18 +08:00
|
|
|
__attribute__((format (printf, 3, 4)))
|
2015-08-04 21:51:37 +08:00
|
|
|
static void say(const struct am_state *state, FILE *fp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (!state->quiet) {
|
|
|
|
vfprintf(fp, fmt, ap);
|
|
|
|
putc('\n', fp);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/**
|
|
|
|
* Returns 1 if there is an am session in progress, 0 otherwise.
|
|
|
|
*/
|
|
|
|
static int am_in_progress(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (lstat(state->dir, &st) < 0 || !S_ISDIR(st.st_mode))
|
|
|
|
return 0;
|
|
|
|
if (lstat(am_path(state, "last"), &st) || !S_ISREG(st.st_mode))
|
|
|
|
return 0;
|
|
|
|
if (lstat(am_path(state, "next"), &st) || !S_ISREG(st.st_mode))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the contents of `file` in the `state` directory into `sb`. Returns the
|
|
|
|
* number of bytes read on success, -1 if the file does not exist. If `trim` is
|
|
|
|
* set, trailing whitespace will be removed.
|
|
|
|
*/
|
|
|
|
static int read_state_file(struct strbuf *sb, const struct am_state *state,
|
|
|
|
const char *file, int trim)
|
|
|
|
{
|
|
|
|
strbuf_reset(sb);
|
|
|
|
|
|
|
|
if (strbuf_read_file(sb, am_path(state, file), 0) >= 0) {
|
|
|
|
if (trim)
|
|
|
|
strbuf_trim(sb);
|
|
|
|
|
|
|
|
return sb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno == ENOENT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
die_errno(_("could not read '%s'"), am_path(state, file));
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
/**
|
|
|
|
* Reads and parses the state directory's "author-script" file, and sets
|
|
|
|
* state->author_name, state->author_email and state->author_date accordingly.
|
|
|
|
* Returns 0 on success, -1 if the file could not be parsed.
|
|
|
|
*
|
|
|
|
* The author script is of the format:
|
|
|
|
*
|
|
|
|
* GIT_AUTHOR_NAME='$author_name'
|
|
|
|
* GIT_AUTHOR_EMAIL='$author_email'
|
|
|
|
* GIT_AUTHOR_DATE='$author_date'
|
|
|
|
*
|
|
|
|
* where $author_name, $author_email and $author_date are quoted. We are strict
|
|
|
|
* with our parsing, as the file was meant to be eval'd in the old git-am.sh
|
|
|
|
* script, and thus if the file differs from what this function expects, it is
|
|
|
|
* better to bail out than to do something that the user does not expect.
|
|
|
|
*/
|
2018-10-31 18:15:54 +08:00
|
|
|
static int read_am_author_script(struct am_state *state)
|
2015-08-04 21:51:28 +08:00
|
|
|
{
|
|
|
|
const char *filename = am_path(state, "author-script");
|
|
|
|
|
|
|
|
assert(!state->author_name);
|
|
|
|
assert(!state->author_email);
|
|
|
|
assert(!state->author_date);
|
|
|
|
|
2018-10-31 18:15:55 +08:00
|
|
|
return read_author_script(filename, &state->author_name,
|
|
|
|
&state->author_email, &state->author_date, 1);
|
2015-08-04 21:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves state->author_name, state->author_email and state->author_date in the
|
|
|
|
* state directory's "author-script" file.
|
|
|
|
*/
|
|
|
|
static void write_author_script(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addstr(&sb, "GIT_AUTHOR_NAME=");
|
|
|
|
sq_quote_buf(&sb, state->author_name);
|
|
|
|
strbuf_addch(&sb, '\n');
|
|
|
|
|
|
|
|
strbuf_addstr(&sb, "GIT_AUTHOR_EMAIL=");
|
|
|
|
sq_quote_buf(&sb, state->author_email);
|
|
|
|
strbuf_addch(&sb, '\n');
|
|
|
|
|
|
|
|
strbuf_addstr(&sb, "GIT_AUTHOR_DATE=");
|
|
|
|
sq_quote_buf(&sb, state->author_date);
|
|
|
|
strbuf_addch(&sb, '\n');
|
|
|
|
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "author-script", sb.buf);
|
2015-08-04 21:51:28 +08:00
|
|
|
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the commit message from the state directory's "final-commit" file,
|
|
|
|
* setting state->msg to its contents and state->msg_len to the length of its
|
|
|
|
* contents in bytes.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 if the file does not exist.
|
|
|
|
*/
|
|
|
|
static int read_commit_msg(struct am_state *state)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
assert(!state->msg);
|
|
|
|
|
|
|
|
if (read_state_file(&sb, state, "final-commit", 0) < 0) {
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->msg = strbuf_detach(&sb, &state->msg_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves state->msg in the state directory's "final-commit" file.
|
|
|
|
*/
|
|
|
|
static void write_commit_msg(const struct am_state *state)
|
|
|
|
{
|
|
|
|
const char *filename = am_path(state, "final-commit");
|
2016-07-08 17:12:55 +08:00
|
|
|
write_file_buf(filename, state->msg, state->msg_len);
|
2015-08-04 21:51:28 +08:00
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/**
|
|
|
|
* Loads state from disk.
|
|
|
|
*/
|
|
|
|
static void am_load(struct am_state *state)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (read_state_file(&sb, state, "next", 1) < 0)
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("state file 'next' does not exist");
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
state->cur = strtol(sb.buf, NULL, 10);
|
|
|
|
|
|
|
|
if (read_state_file(&sb, state, "last", 1) < 0)
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("state file 'last' does not exist");
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
state->last = strtol(sb.buf, NULL, 10);
|
|
|
|
|
2018-10-31 18:15:54 +08:00
|
|
|
if (read_am_author_script(state) < 0)
|
2015-08-04 21:51:28 +08:00
|
|
|
die(_("could not parse author script"));
|
|
|
|
|
|
|
|
read_commit_msg(state);
|
|
|
|
|
2015-08-04 21:51:54 +08:00
|
|
|
if (read_state_file(&sb, state, "original-commit", 1) < 0)
|
2016-09-06 04:08:09 +08:00
|
|
|
oidclr(&state->orig_commit);
|
|
|
|
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
|
2015-08-04 21:51:54 +08:00
|
|
|
die(_("could not parse %s"), am_path(state, "original-commit"));
|
|
|
|
|
2015-08-04 21:51:41 +08:00
|
|
|
read_state_file(&sb, state, "threeway", 1);
|
|
|
|
state->threeway = !strcmp(sb.buf, "t");
|
|
|
|
|
2015-08-04 21:51:37 +08:00
|
|
|
read_state_file(&sb, state, "quiet", 1);
|
|
|
|
state->quiet = !strcmp(sb.buf, "t");
|
|
|
|
|
2015-08-04 21:51:39 +08:00
|
|
|
read_state_file(&sb, state, "sign", 1);
|
|
|
|
state->signoff = !strcmp(sb.buf, "t");
|
|
|
|
|
2015-08-04 21:51:45 +08:00
|
|
|
read_state_file(&sb, state, "utf8", 1);
|
|
|
|
state->utf8 = !strcmp(sb.buf, "t");
|
|
|
|
|
2017-08-02 18:44:15 +08:00
|
|
|
if (file_exists(am_path(state, "rerere-autoupdate"))) {
|
|
|
|
read_state_file(&sb, state, "rerere-autoupdate", 1);
|
|
|
|
state->allow_rerere_autoupdate = strcmp(sb.buf, "t") ?
|
|
|
|
RERERE_NOAUTOUPDATE : RERERE_AUTOUPDATE;
|
|
|
|
} else {
|
|
|
|
state->allow_rerere_autoupdate = 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:46 +08:00
|
|
|
read_state_file(&sb, state, "keep", 1);
|
|
|
|
if (!strcmp(sb.buf, "t"))
|
|
|
|
state->keep = KEEP_TRUE;
|
|
|
|
else if (!strcmp(sb.buf, "b"))
|
|
|
|
state->keep = KEEP_NON_PATCH;
|
|
|
|
else
|
|
|
|
state->keep = KEEP_FALSE;
|
|
|
|
|
2015-08-04 21:51:47 +08:00
|
|
|
read_state_file(&sb, state, "messageid", 1);
|
|
|
|
state->message_id = !strcmp(sb.buf, "t");
|
|
|
|
|
2015-08-04 21:51:49 +08:00
|
|
|
read_state_file(&sb, state, "scissors", 1);
|
|
|
|
if (!strcmp(sb.buf, "t"))
|
|
|
|
state->scissors = SCISSORS_TRUE;
|
|
|
|
else if (!strcmp(sb.buf, "f"))
|
|
|
|
state->scissors = SCISSORS_FALSE;
|
|
|
|
else
|
|
|
|
state->scissors = SCISSORS_UNSET;
|
|
|
|
|
2021-05-10 01:12:13 +08:00
|
|
|
read_state_file(&sb, state, "quoted-cr", 1);
|
|
|
|
if (!*sb.buf)
|
|
|
|
state->quoted_cr = quoted_cr_unset;
|
|
|
|
else if (mailinfo_parse_quoted_cr_action(sb.buf, &state->quoted_cr) != 0)
|
|
|
|
die(_("could not parse %s"), am_path(state, "quoted-cr"));
|
|
|
|
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
read_state_file(&sb, state, "apply-opt", 1);
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_clear(&state->git_apply_opts);
|
2020-07-29 04:24:02 +08:00
|
|
|
if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0)
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
die(_("could not parse %s"), am_path(state, "apply-opt"));
|
|
|
|
|
2015-08-04 21:51:42 +08:00
|
|
|
state->rebasing = !!file_exists(am_path(state, "rebasing"));
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the am_state directory, forcefully terminating the current am
|
|
|
|
* session.
|
|
|
|
*/
|
|
|
|
static void am_destroy(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addstr(&sb, state->dir);
|
|
|
|
remove_dir_recursively(&sb, 0);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:56 +08:00
|
|
|
/**
|
|
|
|
* Runs applypatch-msg hook. Returns its exit code.
|
|
|
|
*/
|
|
|
|
static int run_applypatch_msg_hook(struct am_state *state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
assert(state->msg);
|
|
|
|
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
|
|
|
|
|
|
|
|
if (!ret) {
|
2017-06-16 07:15:46 +08:00
|
|
|
FREE_AND_NULL(state->msg);
|
2015-08-04 21:51:56 +08:00
|
|
|
if (read_commit_msg(state) < 0)
|
|
|
|
die(_("'%s' was deleted by the applypatch-msg hook"),
|
|
|
|
am_path(state, "final-commit"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:54 +08:00
|
|
|
/**
|
|
|
|
* Runs post-rewrite hook. Returns it exit code.
|
|
|
|
*/
|
|
|
|
static int run_post_rewrite_hook(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
const char *hook = find_hook("post-rewrite");
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!hook)
|
|
|
|
return 0;
|
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, hook);
|
|
|
|
strvec_push(&cp.args, "rebase");
|
2015-08-04 21:51:54 +08:00
|
|
|
|
|
|
|
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
|
|
|
|
cp.stdout_to_stderr = 1;
|
2019-02-23 06:25:06 +08:00
|
|
|
cp.trace2_hook_name = "post-rewrite";
|
2015-08-04 21:51:54 +08:00
|
|
|
|
|
|
|
ret = run_command(&cp);
|
|
|
|
|
|
|
|
close(cp.in);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:55 +08:00
|
|
|
/**
|
|
|
|
* Reads the state directory's "rewritten" file, and copies notes from the old
|
|
|
|
* commits listed in the file to their rewritten commits.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int copy_notes_for_rebase(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct notes_rewrite_cfg *c;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
const char *invalid_line = _("Malformed input line: '%s'.");
|
|
|
|
const char *msg = "Notes added by 'git rebase'";
|
|
|
|
FILE *fp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
assert(state->rebasing);
|
|
|
|
|
|
|
|
c = init_copy_notes_for_rewrite("rebase");
|
|
|
|
if (!c)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fp = xfopen(am_path(state, "rewritten"), "r");
|
|
|
|
|
2016-01-14 07:31:17 +08:00
|
|
|
while (!strbuf_getline_lf(&sb, fp)) {
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id from_obj, to_obj;
|
2019-02-19 08:05:07 +08:00
|
|
|
const char *p;
|
2015-08-04 21:51:55 +08:00
|
|
|
|
2019-02-19 08:05:07 +08:00
|
|
|
if (sb.len != the_hash_algo->hexsz * 2 + 1) {
|
2015-08-04 21:51:55 +08:00
|
|
|
ret = error(invalid_line, sb.buf);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2019-02-19 08:05:07 +08:00
|
|
|
if (parse_oid_hex(sb.buf, &from_obj, &p)) {
|
2015-08-04 21:51:55 +08:00
|
|
|
ret = error(invalid_line, sb.buf);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2019-02-19 08:05:07 +08:00
|
|
|
if (*p != ' ') {
|
2015-08-04 21:51:55 +08:00
|
|
|
ret = error(invalid_line, sb.buf);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2019-02-19 08:05:07 +08:00
|
|
|
if (get_oid_hex(p + 1, &to_obj)) {
|
2015-08-04 21:51:55 +08:00
|
|
|
ret = error(invalid_line, sb.buf);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:42 +08:00
|
|
|
if (copy_note_for_rewrite(c, &from_obj, &to_obj))
|
2015-08-04 21:51:55 +08:00
|
|
|
ret = error(_("Failed to copy notes from '%s' to '%s'"),
|
2016-09-06 04:08:09 +08:00
|
|
|
oid_to_hex(&from_obj), oid_to_hex(&to_obj));
|
2015-08-04 21:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
2019-01-12 10:13:23 +08:00
|
|
|
finish_copy_notes_for_rewrite(the_repository, c, msg);
|
2015-08-04 21:51:55 +08:00
|
|
|
fclose(fp);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:27 +08:00
|
|
|
/**
|
|
|
|
* Determines if the file looks like a piece of RFC2822 mail by grabbing all
|
|
|
|
* non-indented lines and checking if they look like they begin with valid
|
|
|
|
* header field names.
|
|
|
|
*
|
|
|
|
* Returns 1 if the file looks like a piece of mail, 0 otherwise.
|
|
|
|
*/
|
|
|
|
static int is_mail(FILE *fp)
|
|
|
|
{
|
|
|
|
const char *header_regex = "^[!-9;-~]+:";
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
regex_t regex;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
if (fseek(fp, 0L, SEEK_SET))
|
|
|
|
die_errno(_("fseek failed"));
|
|
|
|
|
|
|
|
if (regcomp(®ex, header_regex, REG_NOSUB | REG_EXTENDED))
|
|
|
|
die("invalid pattern: %s", header_regex);
|
|
|
|
|
2016-01-14 10:32:23 +08:00
|
|
|
while (!strbuf_getline(&sb, fp)) {
|
2015-08-04 21:51:27 +08:00
|
|
|
if (!sb.len)
|
|
|
|
break; /* End of header */
|
|
|
|
|
|
|
|
/* Ignore indented folded lines */
|
|
|
|
if (*sb.buf == '\t' || *sb.buf == ' ')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* It's a header if it matches header_regex */
|
|
|
|
if (regexec(®ex, sb.buf, 0, NULL, 0)) {
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
regfree(®ex);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to detect the patch_format of the patches contained in `paths`,
|
|
|
|
* returning the PATCH_FORMAT_* enum value. Returns PATCH_FORMAT_UNKNOWN if
|
|
|
|
* detection fails.
|
|
|
|
*/
|
|
|
|
static int detect_patch_format(const char **paths)
|
|
|
|
{
|
|
|
|
enum patch_format ret = PATCH_FORMAT_UNKNOWN;
|
|
|
|
struct strbuf l1 = STRBUF_INIT;
|
2015-08-04 21:52:00 +08:00
|
|
|
struct strbuf l2 = STRBUF_INIT;
|
|
|
|
struct strbuf l3 = STRBUF_INIT;
|
2015-08-04 21:51:27 +08:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We default to mbox format if input is from stdin and for directories
|
|
|
|
*/
|
|
|
|
if (!*paths || !strcmp(*paths, "-") || is_directory(*paths))
|
|
|
|
return PATCH_FORMAT_MBOX;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise, check the first few lines of the first patch, starting
|
|
|
|
* from the first non-blank line, to try to detect its format.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fp = xfopen(*paths, "r");
|
|
|
|
|
2016-01-14 10:32:23 +08:00
|
|
|
while (!strbuf_getline(&l1, fp)) {
|
2015-08-04 21:51:27 +08:00
|
|
|
if (l1.len)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (starts_with(l1.buf, "From ") || starts_with(l1.buf, "From: ")) {
|
|
|
|
ret = PATCH_FORMAT_MBOX;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:01 +08:00
|
|
|
if (starts_with(l1.buf, "# This series applies on GIT commit")) {
|
|
|
|
ret = PATCH_FORMAT_STGIT_SERIES;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:02 +08:00
|
|
|
if (!strcmp(l1.buf, "# HG changeset patch")) {
|
|
|
|
ret = PATCH_FORMAT_HG;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-01-14 10:32:23 +08:00
|
|
|
strbuf_getline(&l2, fp);
|
|
|
|
strbuf_getline(&l3, fp);
|
2015-08-04 21:52:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the second line is empty and the third is a From, Author or Date
|
|
|
|
* entry, this is likely an StGit patch.
|
|
|
|
*/
|
|
|
|
if (l1.len && !l2.len &&
|
|
|
|
(starts_with(l3.buf, "From:") ||
|
|
|
|
starts_with(l3.buf, "Author:") ||
|
|
|
|
starts_with(l3.buf, "Date:"))) {
|
|
|
|
ret = PATCH_FORMAT_STGIT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:27 +08:00
|
|
|
if (l1.len && is_mail(fp)) {
|
|
|
|
ret = PATCH_FORMAT_MBOX;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
fclose(fp);
|
|
|
|
strbuf_release(&l1);
|
2017-08-31 01:49:32 +08:00
|
|
|
strbuf_release(&l2);
|
|
|
|
strbuf_release(&l3);
|
2015-08-04 21:51:27 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
/**
|
|
|
|
* Splits out individual email patches from `paths`, where each path is either
|
|
|
|
* a mbox file or a Maildir. Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-06-05 12:46:41 +08:00
|
|
|
static int split_mail_mbox(struct am_state *state, const char **paths,
|
|
|
|
int keep_cr, int mboxrd)
|
2015-08-04 21:51:26 +08:00
|
|
|
{
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf last = STRBUF_INIT;
|
2017-12-08 04:20:19 +08:00
|
|
|
int ret;
|
2015-08-04 21:51:26 +08:00
|
|
|
|
|
|
|
cp.git_cmd = 1;
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, "mailsplit");
|
|
|
|
strvec_pushf(&cp.args, "-d%d", state->prec);
|
|
|
|
strvec_pushf(&cp.args, "-o%s", state->dir);
|
|
|
|
strvec_push(&cp.args, "-b");
|
2015-08-04 21:51:48 +08:00
|
|
|
if (keep_cr)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, "--keep-cr");
|
2016-06-05 12:46:41 +08:00
|
|
|
if (mboxrd)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, "--mboxrd");
|
|
|
|
strvec_push(&cp.args, "--");
|
|
|
|
strvec_pushv(&cp.args, paths);
|
2015-08-04 21:51:26 +08:00
|
|
|
|
2017-12-08 04:20:19 +08:00
|
|
|
ret = capture_command(&cp, &last, 8);
|
|
|
|
if (ret)
|
|
|
|
goto exit;
|
2015-08-04 21:51:26 +08:00
|
|
|
|
|
|
|
state->cur = 1;
|
|
|
|
state->last = strtol(last.buf, NULL, 10);
|
|
|
|
|
2017-12-08 04:20:19 +08:00
|
|
|
exit:
|
|
|
|
strbuf_release(&last);
|
|
|
|
return ret ? -1 : 0;
|
2015-08-04 21:51:26 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:00 +08:00
|
|
|
/**
|
|
|
|
* Callback signature for split_mail_conv(). The foreign patch should be
|
|
|
|
* read from `in`, and the converted patch (in RFC2822 mail format) should be
|
|
|
|
* written to `out`. Return 0 on success, or -1 on failure.
|
|
|
|
*/
|
|
|
|
typedef int (*mail_conv_fn)(FILE *out, FILE *in, int keep_cr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls `fn` for each file in `paths` to convert the foreign patch to the
|
|
|
|
* RFC2822 mail format suitable for parsing with git-mailinfo.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
|
|
|
|
const char **paths, int keep_cr)
|
|
|
|
{
|
|
|
|
static const char *stdin_only[] = {"-", NULL};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!*paths)
|
|
|
|
paths = stdin_only;
|
|
|
|
|
|
|
|
for (i = 0; *paths; paths++, i++) {
|
|
|
|
FILE *in, *out;
|
|
|
|
const char *mail;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!strcmp(*paths, "-"))
|
|
|
|
in = stdin;
|
|
|
|
else
|
|
|
|
in = fopen(*paths, "r");
|
|
|
|
|
|
|
|
if (!in)
|
2016-05-08 17:47:24 +08:00
|
|
|
return error_errno(_("could not open '%s' for reading"),
|
|
|
|
*paths);
|
2015-08-04 21:52:00 +08:00
|
|
|
|
|
|
|
mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
|
|
|
|
|
|
|
|
out = fopen(mail, "w");
|
2017-04-17 00:55:30 +08:00
|
|
|
if (!out) {
|
|
|
|
if (in != stdin)
|
|
|
|
fclose(in);
|
2016-05-08 17:47:24 +08:00
|
|
|
return error_errno(_("could not open '%s' for writing"),
|
|
|
|
mail);
|
2017-04-17 00:55:30 +08:00
|
|
|
}
|
2015-08-04 21:52:00 +08:00
|
|
|
|
|
|
|
ret = fn(out, in, keep_cr);
|
|
|
|
|
|
|
|
fclose(out);
|
2017-04-17 00:55:30 +08:00
|
|
|
if (in != stdin)
|
|
|
|
fclose(in);
|
2015-08-04 21:52:00 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return error(_("could not parse patch '%s'"), *paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->cur = 1;
|
|
|
|
state->last = i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A split_mail_conv() callback that converts an StGit patch to an RFC2822
|
|
|
|
* message suitable for parsing with git-mailinfo.
|
|
|
|
*/
|
|
|
|
static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
int subject_printed = 0;
|
|
|
|
|
2016-01-14 07:31:17 +08:00
|
|
|
while (!strbuf_getline_lf(&sb, in)) {
|
2015-08-04 21:52:00 +08:00
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (str_isspace(sb.buf))
|
|
|
|
continue;
|
|
|
|
else if (skip_prefix(sb.buf, "Author:", &str))
|
|
|
|
fprintf(out, "From:%s\n", str);
|
|
|
|
else if (starts_with(sb.buf, "From") || starts_with(sb.buf, "Date"))
|
|
|
|
fprintf(out, "%s\n", sb.buf);
|
|
|
|
else if (!subject_printed) {
|
|
|
|
fprintf(out, "Subject: %s\n", sb.buf);
|
|
|
|
subject_printed = 1;
|
|
|
|
} else {
|
|
|
|
fprintf(out, "\n%s\n", sb.buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
while (strbuf_fread(&sb, 8192, in) > 0) {
|
|
|
|
fwrite(sb.buf, 1, sb.len, out);
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:01 +08:00
|
|
|
/**
|
|
|
|
* This function only supports a single StGit series file in `paths`.
|
|
|
|
*
|
|
|
|
* Given an StGit series file, converts the StGit patches in the series into
|
|
|
|
* RFC2822 messages suitable for parsing with git-mailinfo, and queues them in
|
|
|
|
* the state directory.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int split_mail_stgit_series(struct am_state *state, const char **paths,
|
|
|
|
int keep_cr)
|
|
|
|
{
|
|
|
|
const char *series_dir;
|
|
|
|
char *series_dir_buf;
|
|
|
|
FILE *fp;
|
2020-07-29 04:24:27 +08:00
|
|
|
struct strvec patches = STRVEC_INIT;
|
2015-08-04 21:52:01 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!paths[0] || paths[1])
|
|
|
|
return error(_("Only one StGIT patch series can be applied at once"));
|
|
|
|
|
|
|
|
series_dir_buf = xstrdup(*paths);
|
|
|
|
series_dir = dirname(series_dir_buf);
|
|
|
|
|
|
|
|
fp = fopen(*paths, "r");
|
|
|
|
if (!fp)
|
2016-05-08 17:47:24 +08:00
|
|
|
return error_errno(_("could not open '%s' for reading"), *paths);
|
2015-08-04 21:52:01 +08:00
|
|
|
|
2016-01-14 07:31:17 +08:00
|
|
|
while (!strbuf_getline_lf(&sb, fp)) {
|
2015-08-04 21:52:01 +08:00
|
|
|
if (*sb.buf == '#')
|
|
|
|
continue; /* skip comment lines */
|
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&patches, mkpath("%s/%s", series_dir, sb.buf));
|
2015-08-04 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
free(series_dir_buf);
|
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
ret = split_mail_conv(stgit_patch_to_mail, state, patches.v, keep_cr);
|
2015-08-04 21:52:01 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_clear(&patches);
|
2015-08-04 21:52:01 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:02 +08:00
|
|
|
/**
|
|
|
|
* A split_patches_conv() callback that converts a mercurial patch to a RFC2822
|
|
|
|
* message suitable for parsing with git-mailinfo.
|
|
|
|
*/
|
|
|
|
static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2017-08-31 01:49:33 +08:00
|
|
|
int rc = 0;
|
2015-08-04 21:52:02 +08:00
|
|
|
|
2016-01-14 07:31:17 +08:00
|
|
|
while (!strbuf_getline_lf(&sb, in)) {
|
2015-08-04 21:52:02 +08:00
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (skip_prefix(sb.buf, "# User ", &str))
|
|
|
|
fprintf(out, "From: %s\n", str);
|
|
|
|
else if (skip_prefix(sb.buf, "# Date ", &str)) {
|
2017-04-27 03:29:31 +08:00
|
|
|
timestamp_t timestamp;
|
2015-08-04 21:52:02 +08:00
|
|
|
long tz, tz2;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
errno = 0;
|
2017-04-21 18:45:44 +08:00
|
|
|
timestamp = parse_timestamp(str, &end, 10);
|
2017-08-31 01:49:33 +08:00
|
|
|
if (errno) {
|
|
|
|
rc = error(_("invalid timestamp"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-08-04 21:52:02 +08:00
|
|
|
|
2017-08-31 01:49:33 +08:00
|
|
|
if (!skip_prefix(end, " ", &str)) {
|
|
|
|
rc = error(_("invalid Date line"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-08-04 21:52:02 +08:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
tz = strtol(str, &end, 10);
|
2017-08-31 01:49:33 +08:00
|
|
|
if (errno) {
|
|
|
|
rc = error(_("invalid timezone offset"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-08-04 21:52:02 +08:00
|
|
|
|
2017-08-31 01:49:33 +08:00
|
|
|
if (*end) {
|
|
|
|
rc = error(_("invalid Date line"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2015-08-04 21:52:02 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mercurial's timezone is in seconds west of UTC,
|
|
|
|
* however git's timezone is in hours + minutes east of
|
|
|
|
* UTC. Convert it.
|
|
|
|
*/
|
|
|
|
tz2 = labs(tz) / 3600 * 100 + labs(tz) % 3600 / 60;
|
|
|
|
if (tz > 0)
|
|
|
|
tz2 = -tz2;
|
|
|
|
|
|
|
|
fprintf(out, "Date: %s\n", show_date(timestamp, tz2, DATE_MODE(RFC2822)));
|
|
|
|
} else if (starts_with(sb.buf, "# ")) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
fprintf(out, "\n%s\n", sb.buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
while (strbuf_fread(&sb, 8192, in) > 0) {
|
|
|
|
fwrite(sb.buf, 1, sb.len, out);
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
}
|
2017-08-31 01:49:33 +08:00
|
|
|
exit:
|
2015-08-04 21:52:02 +08:00
|
|
|
strbuf_release(&sb);
|
2017-08-31 01:49:33 +08:00
|
|
|
return rc;
|
2015-08-04 21:52:02 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
/**
|
|
|
|
* Splits a list of files/directories into individual email patches. Each path
|
|
|
|
* in `paths` must be a file/directory that is formatted according to
|
|
|
|
* `patch_format`.
|
|
|
|
*
|
|
|
|
* Once split out, the individual email patches will be stored in the state
|
|
|
|
* directory, with each patch's filename being its index, padded to state->prec
|
|
|
|
* digits.
|
|
|
|
*
|
|
|
|
* state->cur will be set to the index of the first mail, and state->last will
|
|
|
|
* be set to the index of the last mail.
|
|
|
|
*
|
2015-08-04 21:51:48 +08:00
|
|
|
* Set keep_cr to 0 to convert all lines ending with \r\n to end with \n, 1
|
|
|
|
* to disable this behavior, -1 to use the default configured setting.
|
|
|
|
*
|
2015-08-04 21:51:26 +08:00
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int split_mail(struct am_state *state, enum patch_format patch_format,
|
2015-08-04 21:51:48 +08:00
|
|
|
const char **paths, int keep_cr)
|
2015-08-04 21:51:26 +08:00
|
|
|
{
|
2015-08-04 21:51:48 +08:00
|
|
|
if (keep_cr < 0) {
|
|
|
|
keep_cr = 0;
|
|
|
|
git_config_get_bool("am.keepcr", &keep_cr);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
switch (patch_format) {
|
|
|
|
case PATCH_FORMAT_MBOX:
|
2016-06-05 12:46:41 +08:00
|
|
|
return split_mail_mbox(state, paths, keep_cr, 0);
|
2015-08-04 21:52:00 +08:00
|
|
|
case PATCH_FORMAT_STGIT:
|
|
|
|
return split_mail_conv(stgit_patch_to_mail, state, paths, keep_cr);
|
2015-08-04 21:52:01 +08:00
|
|
|
case PATCH_FORMAT_STGIT_SERIES:
|
|
|
|
return split_mail_stgit_series(state, paths, keep_cr);
|
2015-08-04 21:52:02 +08:00
|
|
|
case PATCH_FORMAT_HG:
|
|
|
|
return split_mail_conv(hg_patch_to_mail, state, paths, keep_cr);
|
2016-06-05 12:46:41 +08:00
|
|
|
case PATCH_FORMAT_MBOXRD:
|
|
|
|
return split_mail_mbox(state, paths, keep_cr, 1);
|
2015-08-04 21:51:26 +08:00
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid patch_format");
|
2015-08-04 21:51:26 +08:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/**
|
|
|
|
* Setup a new am session for applying patches
|
|
|
|
*/
|
2015-08-04 21:51:26 +08:00
|
|
|
static void am_setup(struct am_state *state, enum patch_format patch_format,
|
2015-08-04 21:51:48 +08:00
|
|
|
const char **paths, int keep_cr)
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
{
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id curr_head;
|
2015-08-04 21:51:46 +08:00
|
|
|
const char *str;
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2015-08-04 21:51:35 +08:00
|
|
|
|
2015-08-04 21:51:27 +08:00
|
|
|
if (!patch_format)
|
|
|
|
patch_format = detect_patch_format(paths);
|
|
|
|
|
|
|
|
if (!patch_format) {
|
|
|
|
fprintf_ln(stderr, _("Patch format detection failed."));
|
|
|
|
exit(128);
|
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
if (mkdir(state->dir, 0777) < 0 && errno != EEXIST)
|
|
|
|
die_errno(_("failed to create directory '%s'"), state->dir);
|
2018-02-11 17:43:28 +08:00
|
|
|
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2015-08-04 21:51:48 +08:00
|
|
|
if (split_mail(state, patch_format, paths, keep_cr) < 0) {
|
2015-08-04 21:51:26 +08:00
|
|
|
am_destroy(state);
|
|
|
|
die(_("Failed to split patches."));
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:42 +08:00
|
|
|
if (state->rebasing)
|
|
|
|
state->threeway = 1;
|
|
|
|
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_bool(state, "threeway", state->threeway);
|
|
|
|
write_state_bool(state, "quiet", state->quiet);
|
|
|
|
write_state_bool(state, "sign", state->signoff);
|
|
|
|
write_state_bool(state, "utf8", state->utf8);
|
2015-08-04 21:51:45 +08:00
|
|
|
|
2017-08-02 18:44:15 +08:00
|
|
|
if (state->allow_rerere_autoupdate)
|
|
|
|
write_state_bool(state, "rerere-autoupdate",
|
|
|
|
state->allow_rerere_autoupdate == RERERE_AUTOUPDATE);
|
|
|
|
|
2015-08-04 21:51:46 +08:00
|
|
|
switch (state->keep) {
|
|
|
|
case KEEP_FALSE:
|
|
|
|
str = "f";
|
|
|
|
break;
|
|
|
|
case KEEP_TRUE:
|
|
|
|
str = "t";
|
|
|
|
break;
|
|
|
|
case KEEP_NON_PATCH:
|
|
|
|
str = "b";
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid value for state->keep");
|
2015-08-04 21:51:46 +08:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "keep", str);
|
|
|
|
write_state_bool(state, "messageid", state->message_id);
|
2015-08-04 21:51:47 +08:00
|
|
|
|
2015-08-04 21:51:49 +08:00
|
|
|
switch (state->scissors) {
|
|
|
|
case SCISSORS_UNSET:
|
|
|
|
str = "";
|
|
|
|
break;
|
|
|
|
case SCISSORS_FALSE:
|
|
|
|
str = "f";
|
|
|
|
break;
|
|
|
|
case SCISSORS_TRUE:
|
|
|
|
str = "t";
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid value for state->scissors");
|
2015-08-04 21:51:49 +08:00
|
|
|
}
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "scissors", str);
|
2015-08-04 21:51:49 +08:00
|
|
|
|
2021-05-10 01:12:13 +08:00
|
|
|
switch (state->quoted_cr) {
|
|
|
|
case quoted_cr_unset:
|
|
|
|
str = "";
|
|
|
|
break;
|
|
|
|
case quoted_cr_nowarn:
|
|
|
|
str = "nowarn";
|
|
|
|
break;
|
|
|
|
case quoted_cr_warn:
|
|
|
|
str = "warn";
|
|
|
|
break;
|
|
|
|
case quoted_cr_strip:
|
|
|
|
str = "strip";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG("invalid value for state->quoted_cr");
|
|
|
|
}
|
|
|
|
write_state_text(state, "quoted-cr", str);
|
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
sq_quote_argv(&sb, state->git_apply_opts.v);
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "apply-opt", sb.buf);
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
|
2015-08-04 21:51:42 +08:00
|
|
|
if (state->rebasing)
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "rebasing", "");
|
2015-08-04 21:51:42 +08:00
|
|
|
else
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "applying", "");
|
2015-08-04 21:51:42 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (!get_oid("HEAD", &curr_head)) {
|
|
|
|
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
|
2015-08-04 21:51:42 +08:00
|
|
|
if (!state->rebasing)
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
|
|
|
|
UPDATE_REFS_DIE_ON_ERR);
|
2015-08-04 21:51:35 +08:00
|
|
|
} else {
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "abort-safety", "");
|
2015-08-04 21:51:42 +08:00
|
|
|
if (!state->rebasing)
|
2017-02-21 09:10:32 +08:00
|
|
|
delete_ref(NULL, "ORIG_HEAD", NULL, 0);
|
2015-08-04 21:51:35 +08:00
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/*
|
|
|
|
* NOTE: Since the "next" and "last" files determine if an am_state
|
|
|
|
* session is in progress, they should be written last.
|
|
|
|
*/
|
|
|
|
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_count(state, "next", state->cur);
|
|
|
|
write_state_count(state, "last", state->last);
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
|
|
|
|
strbuf_release(&sb);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increments the patch pointer, and cleans am_state for the application of the
|
|
|
|
* next patch.
|
|
|
|
*/
|
|
|
|
static void am_next(struct am_state *state)
|
|
|
|
{
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id head;
|
2015-08-04 21:51:35 +08:00
|
|
|
|
2017-06-16 07:15:49 +08:00
|
|
|
FREE_AND_NULL(state->author_name);
|
|
|
|
FREE_AND_NULL(state->author_email);
|
|
|
|
FREE_AND_NULL(state->author_date);
|
|
|
|
FREE_AND_NULL(state->msg);
|
2015-08-04 21:51:28 +08:00
|
|
|
state->msg_len = 0;
|
|
|
|
|
|
|
|
unlink(am_path(state, "author-script"));
|
|
|
|
unlink(am_path(state, "final-commit"));
|
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
oidclr(&state->orig_commit);
|
2015-08-04 21:51:54 +08:00
|
|
|
unlink(am_path(state, "original-commit"));
|
2018-02-11 17:43:28 +08:00
|
|
|
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
|
2015-08-04 21:51:54 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (!get_oid("HEAD", &head))
|
|
|
|
write_state_text(state, "abort-safety", oid_to_hex(&head));
|
2015-08-04 21:51:35 +08:00
|
|
|
else
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_text(state, "abort-safety", "");
|
2015-08-04 21:51:35 +08:00
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
state->cur++;
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_count(state, "next", state->cur);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
/**
|
|
|
|
* Returns the filename of the current patch email.
|
|
|
|
*/
|
|
|
|
static const char *msgnum(const struct am_state *state)
|
|
|
|
{
|
|
|
|
static struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
strbuf_addf(&sb, "%0*d", state->prec, state->cur);
|
|
|
|
|
|
|
|
return sb.buf;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:38 +08:00
|
|
|
/**
|
|
|
|
* Dies with a user-friendly message on how to proceed after resolving the
|
|
|
|
* problem. This message can be overridden with state->resolvemsg.
|
|
|
|
*/
|
|
|
|
static void NORETURN die_user_resolve(const struct am_state *state)
|
|
|
|
{
|
|
|
|
if (state->resolvemsg) {
|
|
|
|
printf_ln("%s", state->resolvemsg);
|
|
|
|
} else {
|
2015-08-04 21:52:03 +08:00
|
|
|
const char *cmdline = state->interactive ? "git am -i" : "git am";
|
2015-08-04 21:51:38 +08:00
|
|
|
|
|
|
|
printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline);
|
|
|
|
printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline);
|
|
|
|
printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(128);
|
|
|
|
}
|
|
|
|
|
2017-04-15 22:41:02 +08:00
|
|
|
/**
|
|
|
|
* Appends signoff to the "msg" field of the am_state.
|
|
|
|
*/
|
|
|
|
static void am_append_signoff(struct am_state *state)
|
am: match --signoff to the original scripted version
Linus noticed that the recently reimplemented "git am -s" defines
the trailer block too rigidly, resulting in an unnecessary blank
line between the existing sign-offs and his new sign-off. An e-mail
submission sent to Linus in real life ends with mixture of sign-offs
and commentaries, e.g.
title here
message here
Signed-off-by: Original Author <original@auth.or>
[rv: tweaked frotz and nitfol]
Signed-off-by: Re Viewer <rv@ew.er>
Signed-off-by: Other Reviewer <other@rev.ewer>
---
patch here
Because the reimplementation reused append_signoff() helper that is
used by other codepaths, which is unaware that people intermix such
comments with their sign-offs in the trailer block, such a message
was judged to end with a non-trailer, resulting in an extra blank
line before adding a new sign-off.
The original scripted version of "git am" used a lot looser
definition, i.e. "if and only if there is no line that begins with
Signed-off-by:, add a blank line before adding a new sign-off". For
the upcoming release, stop using the append_signoff() in "git am"
and reimplement the looser definition used by the scripted version
to use only in "git am" to fix this regression in "am" while
avoiding new regressions to other users of append_signoff().
In the longer term, we should look into loosening append_signoff()
so that other codepaths that add a new sign-off behave the same way
as "git am -s", but that is a task for post-release.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-06 10:56:20 +08:00
|
|
|
{
|
2017-04-15 22:41:02 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
am: match --signoff to the original scripted version
Linus noticed that the recently reimplemented "git am -s" defines
the trailer block too rigidly, resulting in an unnecessary blank
line between the existing sign-offs and his new sign-off. An e-mail
submission sent to Linus in real life ends with mixture of sign-offs
and commentaries, e.g.
title here
message here
Signed-off-by: Original Author <original@auth.or>
[rv: tweaked frotz and nitfol]
Signed-off-by: Re Viewer <rv@ew.er>
Signed-off-by: Other Reviewer <other@rev.ewer>
---
patch here
Because the reimplementation reused append_signoff() helper that is
used by other codepaths, which is unaware that people intermix such
comments with their sign-offs in the trailer block, such a message
was judged to end with a non-trailer, resulting in an extra blank
line before adding a new sign-off.
The original scripted version of "git am" used a lot looser
definition, i.e. "if and only if there is no line that begins with
Signed-off-by:, add a blank line before adding a new sign-off". For
the upcoming release, stop using the append_signoff() in "git am"
and reimplement the looser definition used by the scripted version
to use only in "git am" to fix this regression in "am" while
avoiding new regressions to other users of append_signoff().
In the longer term, we should look into loosening append_signoff()
so that other codepaths that add a new sign-off behave the same way
as "git am -s", but that is a task for post-release.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-06 10:56:20 +08:00
|
|
|
|
2017-04-15 22:41:02 +08:00
|
|
|
strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len);
|
2017-08-08 18:25:33 +08:00
|
|
|
append_signoff(&sb, 0, 0);
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
state->msg = strbuf_detach(&sb, &state->msg_len);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
/**
|
|
|
|
* Parses `mail` using git-mailinfo, extracting its patch and authorship info.
|
|
|
|
* state->msg will be set to the patch message. state->author_name,
|
|
|
|
* state->author_email and state->author_date will be set to the patch author's
|
|
|
|
* name, email and date respectively. The patch body will be written to the
|
|
|
|
* state directory's "patch" file.
|
|
|
|
*
|
|
|
|
* Returns 1 if the patch should be skipped, 0 otherwise.
|
|
|
|
*/
|
|
|
|
static int parse_mail(struct am_state *state, const char *mail)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
struct strbuf author_name = STRBUF_INIT;
|
|
|
|
struct strbuf author_date = STRBUF_INIT;
|
|
|
|
struct strbuf author_email = STRBUF_INIT;
|
|
|
|
int ret = 0;
|
2015-10-15 08:45:43 +08:00
|
|
|
struct mailinfo mi;
|
2015-08-04 21:51:28 +08:00
|
|
|
|
2015-10-15 08:45:43 +08:00
|
|
|
setup_mailinfo(&mi);
|
2015-08-04 21:51:28 +08:00
|
|
|
|
2015-10-15 08:45:43 +08:00
|
|
|
if (state->utf8)
|
|
|
|
mi.metainfo_charset = get_commit_output_encoding();
|
|
|
|
else
|
|
|
|
mi.metainfo_charset = NULL;
|
2015-08-04 21:51:46 +08:00
|
|
|
|
|
|
|
switch (state->keep) {
|
|
|
|
case KEEP_FALSE:
|
|
|
|
break;
|
|
|
|
case KEEP_TRUE:
|
2015-10-15 08:45:43 +08:00
|
|
|
mi.keep_subject = 1;
|
2015-08-04 21:51:46 +08:00
|
|
|
break;
|
|
|
|
case KEEP_NON_PATCH:
|
2015-10-15 08:45:43 +08:00
|
|
|
mi.keep_non_patch_brackets_in_subject = 1;
|
2015-08-04 21:51:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid value for state->keep");
|
2015-08-04 21:51:46 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:47 +08:00
|
|
|
if (state->message_id)
|
2015-10-15 08:45:43 +08:00
|
|
|
mi.add_message_id = 1;
|
2015-08-04 21:51:47 +08:00
|
|
|
|
2015-08-04 21:51:49 +08:00
|
|
|
switch (state->scissors) {
|
|
|
|
case SCISSORS_UNSET:
|
|
|
|
break;
|
|
|
|
case SCISSORS_FALSE:
|
2015-10-15 08:45:43 +08:00
|
|
|
mi.use_scissors = 0;
|
2015-08-04 21:51:49 +08:00
|
|
|
break;
|
|
|
|
case SCISSORS_TRUE:
|
2015-10-15 08:45:43 +08:00
|
|
|
mi.use_scissors = 1;
|
2015-08-04 21:51:49 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid value for state->scissors");
|
2015-08-04 21:51:49 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 01:12:13 +08:00
|
|
|
switch (state->quoted_cr) {
|
|
|
|
case quoted_cr_unset:
|
|
|
|
break;
|
|
|
|
case quoted_cr_nowarn:
|
|
|
|
case quoted_cr_warn:
|
|
|
|
case quoted_cr_strip:
|
|
|
|
mi.quoted_cr = state->quoted_cr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG("invalid value for state->quoted_cr");
|
|
|
|
}
|
|
|
|
|
2017-05-03 18:16:46 +08:00
|
|
|
mi.input = xfopen(mail, "r");
|
|
|
|
mi.output = xfopen(am_path(state, "info"), "w");
|
2015-10-15 08:45:43 +08:00
|
|
|
if (mailinfo(&mi, am_path(state, "msg"), am_path(state, "patch")))
|
2015-08-04 21:51:28 +08:00
|
|
|
die("could not parse patch");
|
|
|
|
|
2015-10-15 08:45:43 +08:00
|
|
|
fclose(mi.input);
|
|
|
|
fclose(mi.output);
|
2015-08-04 21:51:28 +08:00
|
|
|
|
2018-08-26 05:50:32 +08:00
|
|
|
if (mi.format_flowed)
|
|
|
|
warning(_("Patch sent with format=flowed; "
|
|
|
|
"space at the end of lines might be lost."));
|
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
/* Extract message and author information */
|
|
|
|
fp = xfopen(am_path(state, "info"), "r");
|
2016-01-14 07:31:17 +08:00
|
|
|
while (!strbuf_getline_lf(&sb, fp)) {
|
2015-08-04 21:51:28 +08:00
|
|
|
const char *x;
|
|
|
|
|
|
|
|
if (skip_prefix(sb.buf, "Subject: ", &x)) {
|
|
|
|
if (msg.len)
|
|
|
|
strbuf_addch(&msg, '\n');
|
|
|
|
strbuf_addstr(&msg, x);
|
|
|
|
} else if (skip_prefix(sb.buf, "Author: ", &x))
|
|
|
|
strbuf_addstr(&author_name, x);
|
|
|
|
else if (skip_prefix(sb.buf, "Email: ", &x))
|
|
|
|
strbuf_addstr(&author_email, x);
|
|
|
|
else if (skip_prefix(sb.buf, "Date: ", &x))
|
|
|
|
strbuf_addstr(&author_date, x);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* Skip pine's internal folder data */
|
|
|
|
if (!strcmp(author_name.buf, "Mail System Internal Data")) {
|
|
|
|
ret = 1;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2019-01-02 23:38:32 +08:00
|
|
|
if (is_empty_or_missing_file(am_path(state, "patch"))) {
|
2017-05-11 20:06:32 +08:00
|
|
|
printf_ln(_("Patch is empty."));
|
2015-08-04 21:51:38 +08:00
|
|
|
die_user_resolve(state);
|
2015-08-04 21:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_addstr(&msg, "\n\n");
|
2015-10-15 08:45:43 +08:00
|
|
|
strbuf_addbuf(&msg, &mi.log_message);
|
2015-10-16 23:16:42 +08:00
|
|
|
strbuf_stripspace(&msg, 0);
|
2015-08-04 21:51:28 +08:00
|
|
|
|
|
|
|
assert(!state->author_name);
|
|
|
|
state->author_name = strbuf_detach(&author_name, NULL);
|
|
|
|
|
|
|
|
assert(!state->author_email);
|
|
|
|
state->author_email = strbuf_detach(&author_email, NULL);
|
|
|
|
|
|
|
|
assert(!state->author_date);
|
|
|
|
state->author_date = strbuf_detach(&author_date, NULL);
|
|
|
|
|
|
|
|
assert(!state->msg);
|
|
|
|
state->msg = strbuf_detach(&msg, &state->msg_len);
|
|
|
|
|
|
|
|
finish:
|
|
|
|
strbuf_release(&msg);
|
|
|
|
strbuf_release(&author_date);
|
|
|
|
strbuf_release(&author_email);
|
|
|
|
strbuf_release(&author_name);
|
|
|
|
strbuf_release(&sb);
|
2015-10-15 08:45:43 +08:00
|
|
|
clear_mailinfo(&mi);
|
2015-08-04 21:51:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:43 +08:00
|
|
|
/**
|
|
|
|
* Sets commit_id to the commit hash where the mail was generated from.
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-09-06 04:08:09 +08:00
|
|
|
static int get_mail_commit_oid(struct object_id *commit_id, const char *mail)
|
2015-08-04 21:51:43 +08:00
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
FILE *fp = xfopen(mail, "r");
|
|
|
|
const char *x;
|
2017-05-04 21:55:45 +08:00
|
|
|
int ret = 0;
|
2015-08-04 21:51:43 +08:00
|
|
|
|
2017-05-04 21:55:45 +08:00
|
|
|
if (strbuf_getline_lf(&sb, fp) ||
|
|
|
|
!skip_prefix(sb.buf, "From ", &x) ||
|
|
|
|
get_oid_hex(x, commit_id) < 0)
|
|
|
|
ret = -1;
|
2015-08-04 21:51:43 +08:00
|
|
|
|
|
|
|
strbuf_release(&sb);
|
|
|
|
fclose(fp);
|
2017-05-04 21:55:45 +08:00
|
|
|
return ret;
|
2015-08-04 21:51:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets state->msg, state->author_name, state->author_email, state->author_date
|
|
|
|
* to the commit's respective info.
|
|
|
|
*/
|
|
|
|
static void get_commit_info(struct am_state *state, struct commit *commit)
|
|
|
|
{
|
2017-04-27 11:27:17 +08:00
|
|
|
const char *buffer, *ident_line, *msg;
|
2015-08-04 21:51:43 +08:00
|
|
|
size_t ident_len;
|
2017-04-27 11:28:31 +08:00
|
|
|
struct ident_split id;
|
2015-08-04 21:51:43 +08:00
|
|
|
|
|
|
|
buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
|
|
|
|
|
|
|
|
ident_line = find_commit_header(buffer, "author", &ident_len);
|
2019-09-06 06:50:31 +08:00
|
|
|
if (!ident_line)
|
|
|
|
die(_("missing author line in commit %s"),
|
|
|
|
oid_to_hex(&commit->object.oid));
|
2017-04-27 11:28:31 +08:00
|
|
|
if (split_ident_line(&id, ident_line, ident_len) < 0)
|
2017-04-27 11:27:17 +08:00
|
|
|
die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
|
2015-08-04 21:51:43 +08:00
|
|
|
|
|
|
|
assert(!state->author_name);
|
2017-04-27 11:28:31 +08:00
|
|
|
if (id.name_begin)
|
2017-04-27 11:27:17 +08:00
|
|
|
state->author_name =
|
2017-04-27 11:28:31 +08:00
|
|
|
xmemdupz(id.name_begin, id.name_end - id.name_begin);
|
|
|
|
else
|
2015-08-04 21:51:43 +08:00
|
|
|
state->author_name = xstrdup("");
|
|
|
|
|
|
|
|
assert(!state->author_email);
|
2017-04-27 11:28:31 +08:00
|
|
|
if (id.mail_begin)
|
2017-04-27 11:27:17 +08:00
|
|
|
state->author_email =
|
2017-04-27 11:28:31 +08:00
|
|
|
xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
|
|
|
|
else
|
2015-08-04 21:51:43 +08:00
|
|
|
state->author_email = xstrdup("");
|
|
|
|
|
|
|
|
assert(!state->author_date);
|
2017-04-27 11:28:31 +08:00
|
|
|
state->author_date = xstrdup(show_ident_date(&id, DATE_MODE(NORMAL)));
|
2015-08-04 21:51:43 +08:00
|
|
|
|
|
|
|
assert(!state->msg);
|
|
|
|
msg = strstr(buffer, "\n\n");
|
|
|
|
if (!msg)
|
2015-11-10 10:22:28 +08:00
|
|
|
die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
|
2015-08-04 21:51:43 +08:00
|
|
|
state->msg = xstrdup(msg + 2);
|
|
|
|
state->msg_len = strlen(state->msg);
|
2017-04-27 11:25:55 +08:00
|
|
|
unuse_commit_buffer(commit, buffer);
|
2015-08-04 21:51:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes `commit` as a patch to the state directory's "patch" file.
|
|
|
|
*/
|
|
|
|
static void write_commit_patch(const struct am_state *state, struct commit *commit)
|
|
|
|
{
|
|
|
|
struct rev_info rev_info;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = xfopen(am_path(state, "patch"), "w");
|
2018-09-21 23:57:38 +08:00
|
|
|
repo_init_revisions(the_repository, &rev_info, NULL);
|
2015-08-04 21:51:43 +08:00
|
|
|
rev_info.diff = 1;
|
|
|
|
rev_info.abbrev = 0;
|
|
|
|
rev_info.disable_stdin = 1;
|
|
|
|
rev_info.show_root_diff = 1;
|
|
|
|
rev_info.diffopt.output_format = DIFF_FORMAT_PATCH;
|
|
|
|
rev_info.no_commit_id = 1;
|
2017-11-01 02:19:11 +08:00
|
|
|
rev_info.diffopt.flags.binary = 1;
|
|
|
|
rev_info.diffopt.flags.full_index = 1;
|
2015-08-04 21:51:43 +08:00
|
|
|
rev_info.diffopt.use_color = 0;
|
|
|
|
rev_info.diffopt.file = fp;
|
|
|
|
rev_info.diffopt.close_file = 1;
|
|
|
|
add_pending_object(&rev_info, &commit->object, "");
|
|
|
|
diff_setup_done(&rev_info.diffopt);
|
|
|
|
log_tree_commit(&rev_info, commit);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:03 +08:00
|
|
|
/**
|
|
|
|
* Writes the diff of the index against HEAD as a patch to the state
|
|
|
|
* directory's "patch" file.
|
|
|
|
*/
|
|
|
|
static void write_index_patch(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct tree *tree;
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id head;
|
2015-08-04 21:52:03 +08:00
|
|
|
struct rev_info rev_info;
|
|
|
|
FILE *fp;
|
|
|
|
|
am: fix --interactive HEAD tree resolution
In --interactive mode, "git am --resolved" will try to generate a patch
based on what is in the index, so that it can prompt "apply this
patch?". To do so it needs the tree of HEAD, which it tries to get with
get_oid_tree(). However, this doesn't yield a tree object; the "tree"
part just means "if you must disambiguate short oids, then prefer trees"
(and we do not need to disambiguate at all, since we are feeding a ref).
Instead, we must parse the oid as a commit (which should always be true
in a non-corrupt repository), and access its tree pointer manually.
This has been broken since the conversion to C in 7ff2683253
(builtin-am: implement -i/--interactive, 2015-08-04), but there was no
test coverage because of interactive-mode's insistence on having a tty.
That was lifted in the previous commit, so we can now add a test for
this case.
Note that before this patch, the test would result in a BUG() which
comes from 3506dc9445 (has_uncommitted_changes(): fall back to empty
tree, 2018-07-11). But before that, we'd have simply segfaulted (and in
fact this is the exact type of case the BUG() added there was trying to
catch!).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-24 14:46:27 +08:00
|
|
|
if (!get_oid("HEAD", &head)) {
|
|
|
|
struct commit *commit = lookup_commit_or_die(&head, "HEAD");
|
|
|
|
tree = get_commit_tree(commit);
|
|
|
|
} else
|
2018-06-29 09:21:56 +08:00
|
|
|
tree = lookup_tree(the_repository,
|
|
|
|
the_repository->hash_algo->empty_tree);
|
2015-08-04 21:52:03 +08:00
|
|
|
|
|
|
|
fp = xfopen(am_path(state, "patch"), "w");
|
2018-09-21 23:57:38 +08:00
|
|
|
repo_init_revisions(the_repository, &rev_info, NULL);
|
2015-08-04 21:52:03 +08:00
|
|
|
rev_info.diff = 1;
|
|
|
|
rev_info.disable_stdin = 1;
|
|
|
|
rev_info.no_commit_id = 1;
|
|
|
|
rev_info.diffopt.output_format = DIFF_FORMAT_PATCH;
|
|
|
|
rev_info.diffopt.use_color = 0;
|
|
|
|
rev_info.diffopt.file = fp;
|
|
|
|
rev_info.diffopt.close_file = 1;
|
|
|
|
add_pending_object(&rev_info, &tree->object, "");
|
|
|
|
diff_setup_done(&rev_info.diffopt);
|
|
|
|
run_diff_index(&rev_info, 1);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:43 +08:00
|
|
|
/**
|
|
|
|
* Like parse_mail(), but parses the mail by looking up its commit ID
|
|
|
|
* directly. This is used in --rebasing mode to bypass git-mailinfo's munging
|
|
|
|
* of patches.
|
|
|
|
*
|
2015-08-04 21:51:54 +08:00
|
|
|
* state->orig_commit will be set to the original commit ID.
|
|
|
|
*
|
2015-08-04 21:51:43 +08:00
|
|
|
* Will always return 0 as the patch should never be skipped.
|
|
|
|
*/
|
|
|
|
static int parse_mail_rebase(struct am_state *state, const char *mail)
|
|
|
|
{
|
|
|
|
struct commit *commit;
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id commit_oid;
|
2015-08-04 21:51:43 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (get_mail_commit_oid(&commit_oid, mail) < 0)
|
2015-08-04 21:51:43 +08:00
|
|
|
die(_("could not parse %s"), mail);
|
|
|
|
|
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.
Introduce a temporary in parse_object buffer in order to convert this
function. This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted. Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.
parse_object_buffer will lose this temporary in a later patch.
This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)
@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference(&E1)
@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)
@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit(&E1)
@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:10 +08:00
|
|
|
commit = lookup_commit_or_die(&commit_oid, mail);
|
2015-08-04 21:51:43 +08:00
|
|
|
|
|
|
|
get_commit_info(state, commit);
|
|
|
|
|
|
|
|
write_commit_patch(state, commit);
|
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
oidcpy(&state->orig_commit, &commit_oid);
|
|
|
|
write_state_text(state, "original-commit", oid_to_hex(&commit_oid));
|
2018-02-11 17:43:28 +08:00
|
|
|
update_ref("am", "REBASE_HEAD", &commit_oid,
|
|
|
|
NULL, REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
|
2015-08-04 21:51:54 +08:00
|
|
|
|
2015-08-04 21:51:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:29 +08:00
|
|
|
/**
|
2015-08-04 21:51:41 +08:00
|
|
|
* Applies current patch with git-apply. Returns 0 on success, -1 otherwise. If
|
|
|
|
* `index_file` is not NULL, the patch will be applied to that index.
|
2015-08-04 21:51:29 +08:00
|
|
|
*/
|
2015-08-04 21:51:41 +08:00
|
|
|
static int run_apply(const struct am_state *state, const char *index_file)
|
2015-08-04 21:51:29 +08:00
|
|
|
{
|
2020-07-29 04:24:27 +08:00
|
|
|
struct strvec apply_paths = STRVEC_INIT;
|
|
|
|
struct strvec apply_opts = STRVEC_INIT;
|
2016-09-05 04:18:33 +08:00
|
|
|
struct apply_state apply_state;
|
|
|
|
int res, opts_left;
|
|
|
|
int force_apply = 0;
|
|
|
|
int options = 0;
|
|
|
|
|
2018-08-14 00:14:39 +08:00
|
|
|
if (init_apply_state(&apply_state, the_repository, NULL))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("init_apply_state() failed");
|
2016-09-05 04:18:33 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&apply_opts, "apply");
|
2020-07-29 08:37:20 +08:00
|
|
|
strvec_pushv(&apply_opts, state->git_apply_opts.v);
|
2016-09-05 04:18:33 +08:00
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
opts_left = apply_parse_options(apply_opts.nr, apply_opts.v,
|
2016-09-05 04:18:33 +08:00
|
|
|
&apply_state, &force_apply, &options,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (opts_left != 0)
|
|
|
|
die("unknown option passed through to git apply");
|
|
|
|
|
|
|
|
if (index_file) {
|
|
|
|
apply_state.index_file = index_file;
|
|
|
|
apply_state.cached = 1;
|
|
|
|
} else
|
|
|
|
apply_state.check_index = 1;
|
2015-08-04 21:51:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are allowed to fall back on 3-way merge, don't give false
|
|
|
|
* errors during the initial attempt.
|
|
|
|
*/
|
2016-09-05 04:18:33 +08:00
|
|
|
if (state->threeway && !index_file)
|
|
|
|
apply_state.apply_verbosity = verbosity_silent;
|
2015-08-04 21:51:41 +08:00
|
|
|
|
2016-09-05 04:18:33 +08:00
|
|
|
if (check_apply_state(&apply_state, force_apply))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("check_apply_state() failed");
|
2015-08-04 21:51:41 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&apply_paths, am_path(state, "patch"));
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
res = apply_all_patches(&apply_state, apply_paths.nr, apply_paths.v, options);
|
2015-08-04 21:51:41 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_clear(&apply_paths);
|
|
|
|
strvec_clear(&apply_opts);
|
2016-09-05 04:18:33 +08:00
|
|
|
clear_apply_state(&apply_state);
|
2015-08-04 21:51:29 +08:00
|
|
|
|
2016-09-05 04:18:33 +08:00
|
|
|
if (res)
|
|
|
|
return res;
|
2015-08-04 21:51:29 +08:00
|
|
|
|
2016-09-05 04:18:33 +08:00
|
|
|
if (index_file) {
|
|
|
|
/* Reload index as apply_all_patches() will have modified it. */
|
|
|
|
discard_cache();
|
|
|
|
read_cache_from(index_file);
|
|
|
|
}
|
2015-08-04 21:51:41 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds an index that contains just the blobs needed for a 3way merge.
|
|
|
|
*/
|
|
|
|
static int build_fake_ancestor(const struct am_state *state, const char *index_file)
|
|
|
|
{
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
cp.git_cmd = 1;
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, "apply");
|
2020-07-29 08:37:20 +08:00
|
|
|
strvec_pushv(&cp.args, state->git_apply_opts.v);
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
|
|
|
|
strvec_push(&cp.args, am_path(state, "patch"));
|
2015-08-04 21:51:41 +08:00
|
|
|
|
|
|
|
if (run_command(&cp))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt a threeway merge, using index_path as the temporary index.
|
|
|
|
*/
|
|
|
|
static int fall_back_threeway(const struct am_state *state, const char *index_path)
|
|
|
|
{
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
struct object_id orig_tree, their_tree, our_tree;
|
|
|
|
const struct object_id *bases[1] = { &orig_tree };
|
|
|
|
struct merge_options o;
|
|
|
|
struct commit *result;
|
|
|
|
char *their_tree_name;
|
2015-08-04 21:51:41 +08:00
|
|
|
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
if (get_oid("HEAD", &our_tree) < 0)
|
2018-05-02 08:25:55 +08:00
|
|
|
oidcpy(&our_tree, the_hash_algo->empty_tree);
|
2015-08-04 21:51:41 +08:00
|
|
|
|
|
|
|
if (build_fake_ancestor(state, index_path))
|
|
|
|
return error("could not build fake ancestor");
|
|
|
|
|
|
|
|
discard_cache();
|
|
|
|
read_cache_from(index_path);
|
|
|
|
|
2018-03-12 10:27:23 +08:00
|
|
|
if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
|
2015-08-04 21:51:41 +08:00
|
|
|
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
|
|
|
|
|
|
|
|
say(state, stdout, _("Using index info to reconstruct a base tree..."));
|
|
|
|
|
|
|
|
if (!state->quiet) {
|
|
|
|
/*
|
|
|
|
* List paths that needed 3-way fallback, so that the user can
|
|
|
|
* review them with extra care to spot mismerges.
|
|
|
|
*/
|
|
|
|
struct rev_info rev_info;
|
|
|
|
|
2018-09-21 23:57:38 +08:00
|
|
|
repo_init_revisions(the_repository, &rev_info, NULL);
|
2015-08-04 21:51:41 +08:00
|
|
|
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
|
2019-03-24 16:20:14 +08:00
|
|
|
rev_info.diffopt.filter |= diff_filter_bit('A');
|
|
|
|
rev_info.diffopt.filter |= diff_filter_bit('M');
|
2017-05-07 06:10:26 +08:00
|
|
|
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
|
2015-08-04 21:51:41 +08:00
|
|
|
diff_setup_done(&rev_info.diffopt);
|
|
|
|
run_diff_index(&rev_info, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (run_apply(state, index_path))
|
|
|
|
return error(_("Did you hand edit your patch?\n"
|
|
|
|
"It does not apply to blobs recorded in its index."));
|
|
|
|
|
2018-03-12 10:27:23 +08:00
|
|
|
if (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))
|
2015-08-04 21:51:41 +08:00
|
|
|
return error("could not write tree");
|
|
|
|
|
|
|
|
say(state, stdout, _("Falling back to patching base and 3-way merge..."));
|
|
|
|
|
2015-08-04 21:51:29 +08:00
|
|
|
discard_cache();
|
|
|
|
read_cache();
|
|
|
|
|
2015-08-04 21:51:41 +08:00
|
|
|
/*
|
|
|
|
* This is not so wrong. Depending on which base we picked, orig_tree
|
2016-07-08 15:17:34 +08:00
|
|
|
* may be wildly different from ours, but their_tree has the same set of
|
2015-08-04 21:51:41 +08:00
|
|
|
* wildly different changes in parts the patch did not touch, so
|
|
|
|
* recursive ends up canceling them, saying that we reverted all those
|
|
|
|
* changes.
|
|
|
|
*/
|
|
|
|
|
2019-01-12 10:13:29 +08:00
|
|
|
init_merge_options(&o, the_repository);
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
|
|
|
|
o.branch1 = "HEAD";
|
|
|
|
their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
|
|
|
|
o.branch2 = their_tree_name;
|
2019-08-18 02:41:25 +08:00
|
|
|
o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE;
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
|
|
|
|
if (state->quiet)
|
|
|
|
o.verbosity = 0;
|
|
|
|
|
|
|
|
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
|
2018-09-21 23:57:32 +08:00
|
|
|
repo_rerere(the_repository, state->allow_rerere_autoupdate);
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
free(their_tree_name);
|
2015-08-04 21:51:41 +08:00
|
|
|
return error(_("Failed to merge in the changes."));
|
|
|
|
}
|
|
|
|
|
am -3: use merge_recursive() directly again
Last October, we had to change this code to run `git merge-recursive`
in a child process: git-am wants to print some helpful advice when the
merge failed, but the code in question was not prepared to return, it
die()d instead.
We are finally at a point when the code *is* prepared to return errors,
and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from
completing the error codepath, 2015-10-09), with the necessary changes
to adjust for the fact that Git's source code changed in the meantime
(such as: using OIDs instead of hashes in the recursive merge, and a
removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike
merge_trees() and merge_recursive(), this function returns 0 upon success,
as most of Git's functions. Therefore, the error value -1 naturally is
handled correctly, and we do not have to take care of it specifically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 00:06:30 +08:00
|
|
|
free(their_tree_name);
|
2015-08-04 21:51:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:30 +08:00
|
|
|
/**
|
|
|
|
* Commits the current index with state->msg as the commit message and
|
|
|
|
* state->author_name, state->author_email and state->author_date as the author
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
static void do_commit(const struct am_state *state)
|
|
|
|
{
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id tree, parent, commit;
|
|
|
|
const struct object_id *old_oid;
|
2015-08-04 21:51:30 +08:00
|
|
|
struct commit_list *parents = NULL;
|
2020-08-18 01:40:01 +08:00
|
|
|
const char *reflog_msg, *author, *committer = NULL;
|
2015-08-04 21:51:30 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
2015-08-04 21:51:57 +08:00
|
|
|
if (run_hook_le(NULL, "pre-applypatch", NULL))
|
|
|
|
exit(1);
|
|
|
|
|
2018-03-12 10:27:23 +08:00
|
|
|
if (write_cache_as_tree(&tree, 0, NULL))
|
2015-08-04 21:51:30 +08:00
|
|
|
die(_("git write-tree failed to write a tree"));
|
|
|
|
|
sha1_name: convert get_sha1* to get_oid*
Now that all the callers of get_sha1 directly or indirectly use struct
object_id, rename the functions starting with get_sha1 to start with
get_oid. Convert the internals in sha1_name.c to use struct object_id
as well, and eliminate explicit length checks where possible. Convert a
use of 40 in get_oid_basic to GIT_SHA1_HEXSZ.
Outside of sha1_name.c and cache.h, this transition was made with the
following semantic patch:
@@
expression E1, E2;
@@
- get_sha1(E1, E2.hash)
+ get_oid(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1(E1, E2->hash)
+ get_oid(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2.hash)
+ get_oid_committish(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2->hash)
+ get_oid_committish(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2.hash)
+ get_oid_treeish(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2->hash)
+ get_oid_treeish(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2.hash)
+ get_oid_commit(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2->hash)
+ get_oid_commit(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2.hash)
+ get_oid_tree(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2->hash)
+ get_oid_tree(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2.hash)
+ get_oid_blob(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2->hash)
+ get_oid_blob(E1, E2)
@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3.hash, E4)
+ get_oid_with_context(E1, E2, &E3, E4)
@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3->hash, E4)
+ get_oid_with_context(E1, E2, E3, E4)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-14 07:49:28 +08:00
|
|
|
if (!get_oid_commit("HEAD", &parent)) {
|
2016-09-06 04:08:09 +08:00
|
|
|
old_oid = &parent;
|
2018-06-29 09:21:59 +08:00
|
|
|
commit_list_insert(lookup_commit(the_repository, &parent),
|
|
|
|
&parents);
|
2015-08-04 21:51:30 +08:00
|
|
|
} else {
|
2016-09-06 04:08:09 +08:00
|
|
|
old_oid = NULL;
|
2015-08-04 21:51:37 +08:00
|
|
|
say(state, stderr, _("applying to an empty history"));
|
2015-08-04 21:51:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
author = fmt_ident(state->author_name, state->author_email,
|
2019-02-05 02:48:50 +08:00
|
|
|
WANT_AUTHOR_IDENT,
|
2015-08-04 21:51:51 +08:00
|
|
|
state->ignore_date ? NULL : state->author_date,
|
|
|
|
IDENT_STRICT);
|
2015-08-04 21:51:30 +08:00
|
|
|
|
2015-08-04 21:51:52 +08:00
|
|
|
if (state->committer_date_is_author_date)
|
2020-10-23 15:26:30 +08:00
|
|
|
committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
|
|
|
|
getenv("GIT_COMMITTER_EMAIL"),
|
|
|
|
WANT_COMMITTER_IDENT,
|
2020-08-18 01:40:01 +08:00
|
|
|
state->ignore_date ? NULL
|
|
|
|
: state->author_date,
|
|
|
|
IDENT_STRICT);
|
|
|
|
|
|
|
|
if (commit_tree_extended(state->msg, state->msg_len, &tree, parents,
|
|
|
|
&commit, author, committer, state->sign_commit,
|
|
|
|
NULL))
|
2015-08-04 21:51:30 +08:00
|
|
|
die(_("failed to write commit object"));
|
|
|
|
|
|
|
|
reflog_msg = getenv("GIT_REFLOG_ACTION");
|
|
|
|
if (!reflog_msg)
|
|
|
|
reflog_msg = "am";
|
|
|
|
|
|
|
|
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
|
|
|
|
state->msg);
|
|
|
|
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
|
|
|
|
UPDATE_REFS_DIE_ON_ERR);
|
2015-08-04 21:51:30 +08:00
|
|
|
|
2015-08-04 21:51:54 +08:00
|
|
|
if (state->rebasing) {
|
|
|
|
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
|
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
assert(!is_null_oid(&state->orig_commit));
|
|
|
|
fprintf(fp, "%s ", oid_to_hex(&state->orig_commit));
|
|
|
|
fprintf(fp, "%s\n", oid_to_hex(&commit));
|
2015-08-04 21:51:54 +08:00
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:58 +08:00
|
|
|
run_hook_le(NULL, "post-applypatch", NULL);
|
|
|
|
|
2015-08-04 21:51:30 +08:00
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:32 +08:00
|
|
|
/**
|
|
|
|
* Validates the am_state for resuming -- the "msg" and authorship fields must
|
|
|
|
* be filled up.
|
|
|
|
*/
|
|
|
|
static void validate_resume_state(const struct am_state *state)
|
|
|
|
{
|
|
|
|
if (!state->msg)
|
|
|
|
die(_("cannot resume: %s does not exist."),
|
|
|
|
am_path(state, "final-commit"));
|
|
|
|
|
|
|
|
if (!state->author_name || !state->author_email || !state->author_date)
|
|
|
|
die(_("cannot resume: %s does not exist."),
|
|
|
|
am_path(state, "author-script"));
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:03 +08:00
|
|
|
/**
|
|
|
|
* Interactively prompt the user on whether the current patch should be
|
|
|
|
* applied.
|
|
|
|
*
|
|
|
|
* Returns 0 if the user chooses to apply the patch, 1 if the user chooses to
|
|
|
|
* skip it.
|
|
|
|
*/
|
|
|
|
static int do_interactive(struct am_state *state)
|
|
|
|
{
|
|
|
|
assert(state->msg);
|
|
|
|
|
|
|
|
for (;;) {
|
2019-05-20 20:09:26 +08:00
|
|
|
char reply[64];
|
2015-08-04 21:52:03 +08:00
|
|
|
|
|
|
|
puts(_("Commit Body is:"));
|
|
|
|
puts("--------------------------");
|
|
|
|
printf("%s", state->msg);
|
|
|
|
puts("--------------------------");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a]
|
|
|
|
* in your translation. The program will only accept English
|
|
|
|
* input at this point.
|
|
|
|
*/
|
2019-05-20 20:09:26 +08:00
|
|
|
printf(_("Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all: "));
|
|
|
|
if (!fgets(reply, sizeof(reply), stdin))
|
|
|
|
die("unable to read from stdin; aborting");
|
2015-08-04 21:52:03 +08:00
|
|
|
|
2019-05-20 20:07:15 +08:00
|
|
|
if (*reply == 'y' || *reply == 'Y') {
|
2015-08-04 21:52:03 +08:00
|
|
|
return 0;
|
|
|
|
} else if (*reply == 'a' || *reply == 'A') {
|
|
|
|
state->interactive = 0;
|
|
|
|
return 0;
|
|
|
|
} else if (*reply == 'n' || *reply == 'N') {
|
|
|
|
return 1;
|
|
|
|
} else if (*reply == 'e' || *reply == 'E') {
|
|
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (!launch_editor(am_path(state, "final-commit"), &msg, NULL)) {
|
|
|
|
free(state->msg);
|
|
|
|
state->msg = strbuf_detach(&msg, &state->msg_len);
|
|
|
|
}
|
|
|
|
strbuf_release(&msg);
|
|
|
|
} else if (*reply == 'v' || *reply == 'V') {
|
|
|
|
const char *pager = git_pager(1);
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
if (!pager)
|
|
|
|
pager = "cat";
|
2016-02-17 06:46:39 +08:00
|
|
|
prepare_pager_args(&cp, pager);
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&cp.args, am_path(state, "patch"));
|
2015-08-04 21:52:03 +08:00
|
|
|
run_command(&cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
/**
|
|
|
|
* Applies all queued mail.
|
2015-08-04 21:51:33 +08:00
|
|
|
*
|
|
|
|
* If `resume` is true, we are "resuming". The "msg" and authorship fields, as
|
|
|
|
* well as the state directory's "patch" file is used as-is for applying the
|
|
|
|
* patch and committing it.
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
*/
|
2015-08-04 21:51:33 +08:00
|
|
|
static void am_run(struct am_state *state, int resume)
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
{
|
2015-08-04 21:51:31 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2015-08-04 21:51:30 +08:00
|
|
|
|
2015-08-04 21:51:35 +08:00
|
|
|
unlink(am_path(state, "dirtyindex"));
|
|
|
|
|
2019-09-12 02:20:25 +08:00
|
|
|
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0)
|
|
|
|
die(_("unable to write index file"));
|
2015-08-04 21:51:29 +08:00
|
|
|
|
2019-01-12 10:13:31 +08:00
|
|
|
if (repo_index_has_changes(the_repository, NULL, &sb)) {
|
2015-08-25 00:12:53 +08:00
|
|
|
write_state_bool(state, "dirtyindex", 1);
|
2015-08-04 21:51:31 +08:00
|
|
|
die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf);
|
2015-08-04 21:51:35 +08:00
|
|
|
}
|
2015-08-04 21:51:31 +08:00
|
|
|
|
|
|
|
strbuf_release(&sb);
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
while (state->cur <= state->last) {
|
2015-08-04 21:51:28 +08:00
|
|
|
const char *mail = am_path(state, msgnum(state));
|
2015-08-04 21:51:41 +08:00
|
|
|
int apply_status;
|
2015-08-04 21:51:28 +08:00
|
|
|
|
am: reset cached ident date for each patch
When we compute the date to go in author/committer lines of
commits, or tagger lines of tags, we get the current date
once and then cache it for the rest of the program. This is
a good thing in some cases, like "git commit", because it
means we do not racily assign different times to the
author/committer fields of a single commit object.
But as more programs start to make many commits in a single
process (e.g., the recently builtin "git am"), it means that
you'll get long strings of commits with identical committer
timestamps (whereas before, we invoked "git commit" many
times and got true timestamps).
This patch addresses it by letting callers reset the cached
time, which means they'll get a fresh time on their next
call to git_committer_info() or git_author_info(). The first
caller to do so is "git am", which resets the time for each
patch it applies.
It would be nice if we could just do this automatically
before filling in the ident fields of commit and tag
objects. Unfortunately, it's hard to know where a particular
logical operation begins and ends.
For instance, if commit_tree_extended() were to call
reset_ident_date() before getting the committer/author
ident, that doesn't quite work; sometimes the author info is
passed in to us as a parameter, and it may or may not have
come from a previous call to ident_default_date(). So in
those cases, we lose the property that the committer and the
author timestamp always match.
You could similarly put a date-reset at the end of
commit_tree_extended(). That actually works in the current
code base, but it's fragile. It makes the assumption that
after commit_tree_extended() finishes, the caller has no
other operations that would logically want to fall into the
same timestamp.
So instead we provide the tool to easily do the reset, and
let the high-level callers use it to annotate their own
logical operations.
There's no automated test, because it would be inherently
racy (it depends on whether the program takes multiple
seconds to run). But you can see the effect with something
like:
# make a fake 100-patch series
top=$(git rev-parse HEAD)
bottom=$(git rev-list --first-parent -100 HEAD | tail -n 1)
git log --format=email --reverse --first-parent \
--binary -m -p $bottom..$top >patch
# now apply it; this presumably takes multiple seconds
git checkout --detach $bottom
git am <patch
# now count the number of distinct committer times;
# prior to this patch, there would only be one, but
# now we'd typically see several.
git log --format=%ct $bottom.. | sort -u
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Helped-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-08-02 03:37:00 +08:00
|
|
|
reset_ident_date();
|
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
if (!file_exists(mail))
|
|
|
|
goto next;
|
|
|
|
|
2015-08-04 21:51:33 +08:00
|
|
|
if (resume) {
|
|
|
|
validate_resume_state(state);
|
|
|
|
} else {
|
2015-08-04 21:51:43 +08:00
|
|
|
int skip;
|
|
|
|
|
|
|
|
if (state->rebasing)
|
|
|
|
skip = parse_mail_rebase(state, mail);
|
|
|
|
else
|
|
|
|
skip = parse_mail(state, mail);
|
|
|
|
|
|
|
|
if (skip)
|
2015-08-04 21:51:33 +08:00
|
|
|
goto next; /* mail should be skipped */
|
2015-08-04 21:51:28 +08:00
|
|
|
|
2017-04-15 22:41:01 +08:00
|
|
|
if (state->signoff)
|
|
|
|
am_append_signoff(state);
|
|
|
|
|
2015-08-04 21:51:33 +08:00
|
|
|
write_author_script(state);
|
|
|
|
write_commit_msg(state);
|
|
|
|
}
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2015-08-04 21:52:03 +08:00
|
|
|
if (state->interactive && do_interactive(state))
|
|
|
|
goto next;
|
|
|
|
|
2015-08-04 21:51:56 +08:00
|
|
|
if (run_applypatch_msg_hook(state))
|
|
|
|
exit(1);
|
|
|
|
|
2015-08-04 21:51:37 +08:00
|
|
|
say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
|
2015-08-04 21:51:29 +08:00
|
|
|
|
2015-08-04 21:51:41 +08:00
|
|
|
apply_status = run_apply(state, NULL);
|
|
|
|
|
|
|
|
if (apply_status && state->threeway) {
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addstr(&sb, am_path(state, "patch-merge-index"));
|
|
|
|
apply_status = fall_back_threeway(state, sb.buf);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Applying the patch to an earlier tree and merging
|
|
|
|
* the result may have produced the same tree as ours.
|
|
|
|
*/
|
2018-07-01 09:25:00 +08:00
|
|
|
if (!apply_status &&
|
2019-01-12 10:13:31 +08:00
|
|
|
!repo_index_has_changes(the_repository, NULL, NULL)) {
|
2015-08-04 21:51:41 +08:00
|
|
|
say(state, stdout, _("No changes -- Patch already applied."));
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apply_status) {
|
2015-08-04 21:51:29 +08:00
|
|
|
printf_ln(_("Patch failed at %s %.*s"), msgnum(state),
|
|
|
|
linelen(state->msg), state->msg);
|
|
|
|
|
|
|
|
if (advice_amworkdir)
|
2020-02-20 22:15:19 +08:00
|
|
|
advise(_("Use 'git am --show-current-patch=diff' to see the failed patch"));
|
2015-08-04 21:51:29 +08:00
|
|
|
|
2015-08-04 21:51:38 +08:00
|
|
|
die_user_resolve(state);
|
2015-08-04 21:51:29 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:30 +08:00
|
|
|
do_commit(state);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2015-08-04 21:51:28 +08:00
|
|
|
next:
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
am_next(state);
|
2015-08-04 22:08:50 +08:00
|
|
|
|
|
|
|
if (resume)
|
|
|
|
am_load(state);
|
|
|
|
resume = 0;
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
|
|
|
|
2019-01-02 23:38:32 +08:00
|
|
|
if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
|
2015-08-04 21:51:54 +08:00
|
|
|
assert(state->rebasing);
|
2015-08-04 21:51:55 +08:00
|
|
|
copy_notes_for_rebase(state);
|
2015-08-04 21:51:54 +08:00
|
|
|
run_post_rewrite_hook(state);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:42 +08:00
|
|
|
/*
|
|
|
|
* In rebasing mode, it's up to the caller to take care of
|
|
|
|
* housekeeping.
|
|
|
|
*/
|
|
|
|
if (!state->rebasing) {
|
|
|
|
am_destroy(state);
|
2019-05-18 02:41:49 +08:00
|
|
|
close_object_store(the_repository->objects);
|
2020-09-18 02:11:44 +08:00
|
|
|
run_auto_maintenance(state->quiet);
|
2015-08-04 21:51:42 +08:00
|
|
|
}
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
}
|
2015-08-04 21:51:24 +08:00
|
|
|
|
2015-08-04 21:51:32 +08:00
|
|
|
/**
|
|
|
|
* Resume the current am session after patch application failure. The user did
|
|
|
|
* all the hard work, and we do not have to do any patch application. Just
|
|
|
|
* trust and commit what the user has in the index and working tree.
|
|
|
|
*/
|
|
|
|
static void am_resolve(struct am_state *state)
|
|
|
|
{
|
|
|
|
validate_resume_state(state);
|
|
|
|
|
2015-08-04 21:51:37 +08:00
|
|
|
say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
|
2015-08-04 21:51:32 +08:00
|
|
|
|
2019-01-12 10:13:31 +08:00
|
|
|
if (!repo_index_has_changes(the_repository, NULL, NULL)) {
|
2015-08-04 21:51:32 +08:00
|
|
|
printf_ln(_("No changes - did you forget to use 'git add'?\n"
|
|
|
|
"If there is nothing left to stage, chances are that something else\n"
|
|
|
|
"already introduced the same changes; you might want to skip this patch."));
|
2015-08-04 21:51:38 +08:00
|
|
|
die_user_resolve(state);
|
2015-08-04 21:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unmerged_cache()) {
|
|
|
|
printf_ln(_("You still have unmerged paths in your index.\n"
|
2017-05-11 20:06:32 +08:00
|
|
|
"You should 'git add' each file with resolved conflicts to mark them as such.\n"
|
|
|
|
"You might run `git rm` on a file to accept \"deleted by them\" for it."));
|
2015-08-04 21:51:38 +08:00
|
|
|
die_user_resolve(state);
|
2015-08-04 21:51:32 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:52:03 +08:00
|
|
|
if (state->interactive) {
|
|
|
|
write_index_patch(state);
|
|
|
|
if (do_interactive(state))
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:57:32 +08:00
|
|
|
repo_rerere(the_repository, 0);
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
|
2015-08-04 21:51:32 +08:00
|
|
|
do_commit(state);
|
|
|
|
|
2015-08-04 21:52:03 +08:00
|
|
|
next:
|
2015-08-04 21:51:32 +08:00
|
|
|
am_next(state);
|
2015-08-04 22:08:50 +08:00
|
|
|
am_load(state);
|
2015-08-04 21:51:33 +08:00
|
|
|
am_run(state, 0);
|
2015-08-04 21:51:32 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:34 +08:00
|
|
|
/**
|
|
|
|
* Performs a checkout fast-forward from `head` to `remote`. If `reset` is
|
|
|
|
* true, any unmerged entries will be discarded. Returns 0 on success, -1 on
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
|
|
|
|
{
|
2017-10-06 04:32:04 +08:00
|
|
|
struct lock_file lock_file = LOCK_INIT;
|
2015-08-04 21:51:34 +08:00
|
|
|
struct unpack_trees_options opts;
|
|
|
|
struct tree_desc t[2];
|
|
|
|
|
|
|
|
if (parse_tree(head) || parse_tree(remote))
|
|
|
|
return -1;
|
|
|
|
|
2017-10-06 04:32:04 +08:00
|
|
|
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
|
2015-08-04 21:51:34 +08:00
|
|
|
|
|
|
|
refresh_cache(REFRESH_QUIET);
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.head_idx = 1;
|
|
|
|
opts.src_index = &the_index;
|
|
|
|
opts.dst_index = &the_index;
|
|
|
|
opts.update = 1;
|
|
|
|
opts.merge = 1;
|
|
|
|
opts.reset = reset;
|
|
|
|
opts.fn = twoway_merge;
|
|
|
|
init_tree_desc(&t[0], head->buffer, head->size);
|
|
|
|
init_tree_desc(&t[1], remote->buffer, remote->size);
|
|
|
|
|
|
|
|
if (unpack_trees(2, t, &opts)) {
|
2017-10-06 04:32:04 +08:00
|
|
|
rollback_lock_file(&lock_file);
|
2015-08-04 21:51:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 04:32:04 +08:00
|
|
|
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
|
2015-08-04 21:51:34 +08:00
|
|
|
die(_("unable to write new index file"));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-19 16:22:22 +08:00
|
|
|
/**
|
|
|
|
* Merges a tree into the index. The index's stat info will take precedence
|
|
|
|
* over the merged tree's. Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int merge_tree(struct tree *tree)
|
|
|
|
{
|
2017-10-06 04:32:04 +08:00
|
|
|
struct lock_file lock_file = LOCK_INIT;
|
2015-08-19 16:22:22 +08:00
|
|
|
struct unpack_trees_options opts;
|
|
|
|
struct tree_desc t[1];
|
|
|
|
|
|
|
|
if (parse_tree(tree))
|
|
|
|
return -1;
|
|
|
|
|
2017-10-06 04:32:04 +08:00
|
|
|
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
|
2015-08-19 16:22:22 +08:00
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.head_idx = 1;
|
|
|
|
opts.src_index = &the_index;
|
|
|
|
opts.dst_index = &the_index;
|
|
|
|
opts.merge = 1;
|
|
|
|
opts.fn = oneway_merge;
|
|
|
|
init_tree_desc(&t[0], tree->buffer, tree->size);
|
|
|
|
|
|
|
|
if (unpack_trees(1, t, &opts)) {
|
2017-10-06 04:32:04 +08:00
|
|
|
rollback_lock_file(&lock_file);
|
2015-08-19 16:22:22 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 04:32:04 +08:00
|
|
|
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
|
2015-08-19 16:22:22 +08:00
|
|
|
die(_("unable to write new index file"));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:34 +08:00
|
|
|
/**
|
|
|
|
* Clean the index without touching entries that are not modified between
|
|
|
|
* `head` and `remote`.
|
|
|
|
*/
|
2016-09-06 04:08:09 +08:00
|
|
|
static int clean_index(const struct object_id *head, const struct object_id *remote)
|
2015-08-04 21:51:34 +08:00
|
|
|
{
|
|
|
|
struct tree *head_tree, *remote_tree, *index_tree;
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id index;
|
2015-08-04 21:51:34 +08:00
|
|
|
|
2017-05-07 06:10:37 +08:00
|
|
|
head_tree = parse_tree_indirect(head);
|
2015-08-04 21:51:34 +08:00
|
|
|
if (!head_tree)
|
2016-09-06 04:08:09 +08:00
|
|
|
return error(_("Could not parse object '%s'."), oid_to_hex(head));
|
2015-08-04 21:51:34 +08:00
|
|
|
|
2017-05-07 06:10:37 +08:00
|
|
|
remote_tree = parse_tree_indirect(remote);
|
2015-08-04 21:51:34 +08:00
|
|
|
if (!remote_tree)
|
2016-09-06 04:08:09 +08:00
|
|
|
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
|
2015-08-04 21:51:34 +08:00
|
|
|
|
|
|
|
read_cache_unmerged();
|
|
|
|
|
|
|
|
if (fast_forward_to(head_tree, head_tree, 1))
|
|
|
|
return -1;
|
|
|
|
|
2018-03-12 10:27:23 +08:00
|
|
|
if (write_cache_as_tree(&index, 0, NULL))
|
2015-08-04 21:51:34 +08:00
|
|
|
return -1;
|
|
|
|
|
2017-05-07 06:10:37 +08:00
|
|
|
index_tree = parse_tree_indirect(&index);
|
2015-08-04 21:51:34 +08:00
|
|
|
if (!index_tree)
|
2016-09-06 04:08:09 +08:00
|
|
|
return error(_("Could not parse object '%s'."), oid_to_hex(&index));
|
2015-08-04 21:51:34 +08:00
|
|
|
|
|
|
|
if (fast_forward_to(index_tree, remote_tree, 0))
|
|
|
|
return -1;
|
|
|
|
|
2015-08-19 16:22:22 +08:00
|
|
|
if (merge_tree(remote_tree))
|
2015-08-04 21:51:34 +08:00
|
|
|
return -1;
|
|
|
|
|
2019-03-29 18:38:59 +08:00
|
|
|
remove_branch_state(the_repository, 0);
|
2015-08-04 21:51:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
/**
|
|
|
|
* Resets rerere's merge resolution metadata.
|
|
|
|
*/
|
|
|
|
static void am_rerere_clear(void)
|
|
|
|
{
|
|
|
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
2018-11-10 13:49:09 +08:00
|
|
|
rerere_clear(the_repository, &merge_rr);
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
string_list_clear(&merge_rr, 1);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:34 +08:00
|
|
|
/**
|
|
|
|
* Resume the current am session by skipping the current patch.
|
|
|
|
*/
|
|
|
|
static void am_skip(struct am_state *state)
|
|
|
|
{
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id head;
|
2015-08-04 21:51:34 +08:00
|
|
|
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
am_rerere_clear();
|
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (get_oid("HEAD", &head))
|
2018-05-02 08:25:55 +08:00
|
|
|
oidcpy(&head, the_hash_algo->empty_tree);
|
2015-08-04 21:51:34 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (clean_index(&head, &head))
|
2015-08-04 21:51:34 +08:00
|
|
|
die(_("failed to clean index"));
|
|
|
|
|
2018-12-12 00:11:35 +08:00
|
|
|
if (state->rebasing) {
|
|
|
|
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
|
|
|
|
|
|
|
|
assert(!is_null_oid(&state->orig_commit));
|
|
|
|
fprintf(fp, "%s ", oid_to_hex(&state->orig_commit));
|
|
|
|
fprintf(fp, "%s\n", oid_to_hex(&head));
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:34 +08:00
|
|
|
am_next(state);
|
2015-08-04 22:08:50 +08:00
|
|
|
am_load(state);
|
2015-08-04 21:51:34 +08:00
|
|
|
am_run(state, 0);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:35 +08:00
|
|
|
/**
|
|
|
|
* Returns true if it is safe to reset HEAD to the ORIG_HEAD, false otherwise.
|
|
|
|
*
|
|
|
|
* It is not safe to reset HEAD when:
|
|
|
|
* 1. git-am previously failed because the index was dirty.
|
|
|
|
* 2. HEAD has moved since git-am previously failed.
|
|
|
|
*/
|
|
|
|
static int safe_to_abort(const struct am_state *state)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id abort_safety, head;
|
2015-08-04 21:51:35 +08:00
|
|
|
|
|
|
|
if (file_exists(am_path(state, "dirtyindex")))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (read_state_file(&sb, state, "abort-safety", 1) > 0) {
|
2016-09-06 04:08:09 +08:00
|
|
|
if (get_oid_hex(sb.buf, &abort_safety))
|
2016-12-08 05:51:29 +08:00
|
|
|
die(_("could not parse %s"), am_path(state, "abort-safety"));
|
2015-08-04 21:51:35 +08:00
|
|
|
} else
|
2016-09-06 04:08:09 +08:00
|
|
|
oidclr(&abort_safety);
|
2017-08-31 01:49:34 +08:00
|
|
|
strbuf_release(&sb);
|
2015-08-04 21:51:35 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
if (get_oid("HEAD", &head))
|
|
|
|
oidclr(&head);
|
2015-08-04 21:51:35 +08:00
|
|
|
|
convert "oidcmp() == 0" to oideq()
Using the more restrictive oideq() should, in the long run,
give the compiler more opportunities to optimize these
callsites. For now, this conversion should be a complete
noop with respect to the generated code.
The result is also perhaps a little more readable, as it
avoids the "zero is equal" idiom. Since it's so prevalent in
C, I think seasoned programmers tend not to even notice it
anymore, but it can sometimes make for awkward double
negations (e.g., we can drop a few !!oidcmp() instances
here).
This patch was generated almost entirely by the included
coccinelle patch. This mechanical conversion should be
completely safe, because we check explicitly for cases where
oidcmp() is compared to 0, which is what oideq() is doing
under the hood. Note that we don't have to catch "!oidcmp()"
separately; coccinelle's standard isomorphisms make sure the
two are treated equivalently.
I say "almost" because I did hand-edit the coccinelle output
to fix up a few style violations (it mostly keeps the
original formatting, but sometimes unwraps long lines).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-29 05:22:40 +08:00
|
|
|
if (oideq(&head, &abort_safety))
|
2015-08-04 21:51:35 +08:00
|
|
|
return 1;
|
|
|
|
|
2016-12-08 05:51:30 +08:00
|
|
|
warning(_("You seem to have moved HEAD since the last 'am' failure.\n"
|
2015-08-04 21:51:35 +08:00
|
|
|
"Not rewinding to ORIG_HEAD"));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aborts the current am session if it is safe to do so.
|
|
|
|
*/
|
|
|
|
static void am_abort(struct am_state *state)
|
|
|
|
{
|
2016-09-06 04:08:09 +08:00
|
|
|
struct object_id curr_head, orig_head;
|
2015-08-04 21:51:35 +08:00
|
|
|
int has_curr_head, has_orig_head;
|
|
|
|
char *curr_branch;
|
|
|
|
|
|
|
|
if (!safe_to_abort(state)) {
|
|
|
|
am_destroy(state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
am_rerere_clear();
|
|
|
|
|
refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
All of the callers already pass the hash member of struct object_id, so
update them to pass a pointer to the struct directly,
This transformation was done with an update to declaration and
definition and the following semantic patch:
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3.hash, E4)
+ resolve_refdup(E1, E2, &E3, E4)
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3->hash, E4)
+ resolve_refdup(E1, E2, E3, E4)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-16 06:06:55 +08:00
|
|
|
curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
|
2017-05-07 01:13:56 +08:00
|
|
|
has_curr_head = curr_branch && !is_null_oid(&curr_head);
|
2015-08-04 21:51:35 +08:00
|
|
|
if (!has_curr_head)
|
2018-05-02 08:25:55 +08:00
|
|
|
oidcpy(&curr_head, the_hash_algo->empty_tree);
|
2015-08-04 21:51:35 +08:00
|
|
|
|
2016-09-06 04:08:09 +08:00
|
|
|
has_orig_head = !get_oid("ORIG_HEAD", &orig_head);
|
2015-08-04 21:51:35 +08:00
|
|
|
if (!has_orig_head)
|
2018-05-02 08:25:55 +08:00
|
|
|
oidcpy(&orig_head, the_hash_algo->empty_tree);
|
2015-08-04 21:51:35 +08:00
|
|
|
|
2021-09-10 18:31:16 +08:00
|
|
|
if (clean_index(&curr_head, &orig_head))
|
|
|
|
die(_("failed to clean index"));
|
2015-08-04 21:51:35 +08:00
|
|
|
|
|
|
|
if (has_orig_head)
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref("am --abort", "HEAD", &orig_head,
|
|
|
|
has_curr_head ? &curr_head : NULL, 0,
|
|
|
|
UPDATE_REFS_DIE_ON_ERR);
|
2015-08-04 21:51:35 +08:00
|
|
|
else if (curr_branch)
|
2017-11-05 16:42:06 +08:00
|
|
|
delete_ref(NULL, curr_branch, NULL, REF_NO_DEREF);
|
2015-08-04 21:51:35 +08:00
|
|
|
|
|
|
|
free(curr_branch);
|
|
|
|
am_destroy(state);
|
|
|
|
}
|
|
|
|
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
|
2018-02-11 17:43:26 +08:00
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
const char *patch_path;
|
|
|
|
int len;
|
|
|
|
|
2018-02-11 17:43:27 +08:00
|
|
|
if (!is_null_oid(&state->orig_commit)) {
|
|
|
|
const char *av[4] = { "show", NULL, "--", NULL };
|
|
|
|
char *new_oid_str;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
|
|
|
|
ret = run_command_v_opt(av, RUN_GIT_CMD);
|
|
|
|
free(new_oid_str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
switch (sub_mode) {
|
|
|
|
case SHOW_PATCH_RAW:
|
|
|
|
patch_path = am_path(state, msgnum(state));
|
|
|
|
break;
|
2020-02-20 22:15:19 +08:00
|
|
|
case SHOW_PATCH_DIFF:
|
|
|
|
patch_path = am_path(state, "patch");
|
|
|
|
break;
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
default:
|
|
|
|
BUG("invalid mode for --show-current-patch");
|
|
|
|
}
|
|
|
|
|
2018-02-11 17:43:26 +08:00
|
|
|
len = strbuf_read_file(&sb, patch_path, 0);
|
|
|
|
if (len < 0)
|
|
|
|
die_errno(_("failed to read '%s'"), patch_path);
|
|
|
|
|
|
|
|
setup_pager();
|
|
|
|
write_in_full(1, sb.buf, sb.len);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
/**
|
|
|
|
* parse_options() callback that validates and sets opt->value to the
|
|
|
|
* PATCH_FORMAT_* enum value corresponding to `arg`.
|
|
|
|
*/
|
|
|
|
static int parse_opt_patchformat(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
int *opt_value = opt->value;
|
|
|
|
|
2018-11-05 14:38:39 +08:00
|
|
|
if (unset)
|
|
|
|
*opt_value = PATCH_FORMAT_UNKNOWN;
|
|
|
|
else if (!strcmp(arg, "mbox"))
|
2015-08-04 21:51:26 +08:00
|
|
|
*opt_value = PATCH_FORMAT_MBOX;
|
2015-08-04 21:52:00 +08:00
|
|
|
else if (!strcmp(arg, "stgit"))
|
|
|
|
*opt_value = PATCH_FORMAT_STGIT;
|
2015-08-04 21:52:01 +08:00
|
|
|
else if (!strcmp(arg, "stgit-series"))
|
|
|
|
*opt_value = PATCH_FORMAT_STGIT_SERIES;
|
2015-08-04 21:52:02 +08:00
|
|
|
else if (!strcmp(arg, "hg"))
|
|
|
|
*opt_value = PATCH_FORMAT_HG;
|
2016-06-05 12:46:41 +08:00
|
|
|
else if (!strcmp(arg, "mboxrd"))
|
|
|
|
*opt_value = PATCH_FORMAT_MBOXRD;
|
2019-02-16 19:24:41 +08:00
|
|
|
/*
|
|
|
|
* Please update $__git_patchformat in git-completion.bash
|
|
|
|
* when you add new options
|
|
|
|
*/
|
2015-08-04 21:51:26 +08:00
|
|
|
else
|
|
|
|
return error(_("Invalid value for --patch-format: %s"), arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-20 22:15:17 +08:00
|
|
|
enum resume_type {
|
2015-08-04 21:51:32 +08:00
|
|
|
RESUME_FALSE = 0,
|
2015-08-04 21:51:33 +08:00
|
|
|
RESUME_APPLY,
|
2015-08-04 21:51:34 +08:00
|
|
|
RESUME_RESOLVED,
|
2015-08-04 21:51:35 +08:00
|
|
|
RESUME_SKIP,
|
2018-02-14 19:16:06 +08:00
|
|
|
RESUME_ABORT,
|
2018-03-07 06:54:02 +08:00
|
|
|
RESUME_QUIT,
|
2018-02-11 17:43:26 +08:00
|
|
|
RESUME_SHOW_PATCH
|
2015-08-04 21:51:32 +08:00
|
|
|
};
|
|
|
|
|
2020-02-20 22:15:17 +08:00
|
|
|
struct resume_mode {
|
|
|
|
enum resume_type mode;
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
enum show_patch_type sub_mode;
|
2020-02-20 22:15:17 +08:00
|
|
|
};
|
|
|
|
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
static int parse_opt_show_current_patch(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
int *opt_value = opt->value;
|
|
|
|
struct resume_mode *resume = container_of(opt_value, struct resume_mode, mode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Please update $__git_showcurrentpatch in git-completion.bash
|
|
|
|
* when you add new options
|
|
|
|
*/
|
|
|
|
const char *valid_modes[] = {
|
2020-02-20 22:15:19 +08:00
|
|
|
[SHOW_PATCH_DIFF] = "diff",
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
[SHOW_PATCH_RAW] = "raw"
|
|
|
|
};
|
|
|
|
int new_value = SHOW_PATCH_RAW;
|
|
|
|
|
2020-09-30 20:29:02 +08:00
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
if (arg) {
|
|
|
|
for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
|
|
|
|
if (!strcmp(arg, valid_modes[new_value]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (new_value >= ARRAY_SIZE(valid_modes))
|
|
|
|
return error(_("Invalid value for --show-current-patch: %s"), arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resume->mode == RESUME_SHOW_PATCH && new_value != resume->sub_mode)
|
|
|
|
return error(_("--show-current-patch=%s is incompatible with "
|
|
|
|
"--show-current-patch=%s"),
|
|
|
|
arg, valid_modes[resume->sub_mode]);
|
|
|
|
|
|
|
|
resume->mode = RESUME_SHOW_PATCH;
|
|
|
|
resume->sub_mode = new_value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-01 01:49:44 +08:00
|
|
|
static int git_am_config(const char *k, const char *v, void *cb)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = git_gpg_config(k, v, NULL);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return git_default_config(k, v, NULL);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:51:24 +08:00
|
|
|
int cmd_am(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
struct am_state state;
|
builtin-am: implement legacy -b/--binary option
The -b/--binary option was initially implemented in 087b674 (git-am:
--binary; document --resume and --binary., 2005-11-16). The option will
pass the --binary flag to git-apply to allow it to apply binary patches.
However, in 2b6eef9 (Make apply --binary a no-op., 2006-09-06), --binary
was been made a no-op in git-apply. Following that, since cb3a160
(git-am: ignore --binary option, 2008-08-09), the --binary option in
git-am is ignored as well.
In 6c15a1c (am: officially deprecate -b/--binary option, 2012-03-13),
the --binary option was tweaked to its present behavior: when set, the
message:
The -b/--binary option has been a no-op for long time, and it
will be removed. Please do not use it anymore.
will be printed.
Re-implement this in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:52:04 +08:00
|
|
|
int binary = -1;
|
2015-08-04 21:51:48 +08:00
|
|
|
int keep_cr = -1;
|
2015-08-04 21:51:26 +08:00
|
|
|
int patch_format = PATCH_FORMAT_UNKNOWN;
|
2020-02-20 22:15:17 +08:00
|
|
|
struct resume_mode resume = { .mode = RESUME_FALSE };
|
2015-08-04 22:08:50 +08:00
|
|
|
int in_progress;
|
2018-02-11 17:43:26 +08:00
|
|
|
int ret = 0;
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
|
|
|
const char * const usage[] = {
|
2016-09-08 12:33:08 +08:00
|
|
|
N_("git am [<options>] [(<mbox> | <Maildir>)...]"),
|
2015-10-17 01:09:57 +08:00
|
|
|
N_("git am [<options>] (--continue | --skip | --abort)"),
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct option options[] = {
|
2015-08-04 21:52:03 +08:00
|
|
|
OPT_BOOL('i', "interactive", &state.interactive,
|
|
|
|
N_("run interactively")),
|
builtin-am: implement legacy -b/--binary option
The -b/--binary option was initially implemented in 087b674 (git-am:
--binary; document --resume and --binary., 2005-11-16). The option will
pass the --binary flag to git-apply to allow it to apply binary patches.
However, in 2b6eef9 (Make apply --binary a no-op., 2006-09-06), --binary
was been made a no-op in git-apply. Following that, since cb3a160
(git-am: ignore --binary option, 2008-08-09), the --binary option in
git-am is ignored as well.
In 6c15a1c (am: officially deprecate -b/--binary option, 2012-03-13),
the --binary option was tweaked to its present behavior: when set, the
message:
The -b/--binary option has been a no-op for long time, and it
will be removed. Please do not use it anymore.
will be printed.
Re-implement this in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:52:04 +08:00
|
|
|
OPT_HIDDEN_BOOL('b', "binary", &binary,
|
2015-08-26 23:51:19 +08:00
|
|
|
N_("historical option -- no-op")),
|
2015-08-04 21:51:41 +08:00
|
|
|
OPT_BOOL('3', "3way", &state.threeway,
|
|
|
|
N_("allow fall back on 3way merging if needed")),
|
2015-08-04 21:51:37 +08:00
|
|
|
OPT__QUIET(&state.quiet, N_("be quiet")),
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
OPT_SET_INT('s', "signoff", &state.signoff,
|
Documentation: stylistically normalize references to Signed-off-by:
Ted reported an old typo in the git-commit.txt and merge-options.txt.
Namely, the phrase "Signed-off-by line" was used without either a
definite nor indefinite article.
Upon examination, it seems that the documentation (including items in
Documentation/, but also option help strings) have been quite
inconsistent on usage when referring to `Signed-off-by`.
First, very few places used a definite or indefinite article with the
phrase "Signed-off-by line", but that was the initial typo that led
to this investigation. So, normalize using either an indefinite or
definite article consistently.
The original phrasing, in Commit 3f971fc425b (Documentation updates,
2005-08-14), is "Add Signed-off-by line". Commit 6f855371a53 (Add
--signoff, --check, and long option-names. 2005-12-09) switched to
using "Add `Signed-off-by:` line", but didn't normalize the former
commit to match. Later commits seem to have cut and pasted from one
or the other, which is likely how the usage became so inconsistent.
Junio stated on the git mailing list in
<xmqqy2k1dfoh.fsf@gitster.c.googlers.com> a preference to leave off
the colon. Thus, prefer `Signed-off-by` (with backticks) for the
documentation files and Signed-off-by (without backticks) for option
help strings.
Additionally, Junio argued that "trailer" is now the standard term to
refer to `Signed-off-by`, saying that "becomes plenty clear that we
are not talking about any random line in the log message". As such,
prefer "trailer" over "line" anywhere the former word fits.
However, leave alone those few places in documentation that use
Signed-off-by to refer to the process (rather than the specific
trailer), or in places where mail headers are generally discussed in
comparison with Signed-off-by.
Reported-by: "Theodore Y. Ts'o" <tytso@mit.edu>
Signed-off-by: Bradley M. Kuhn <bkuhn@sfconservancy.org>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-20 09:03:55 +08:00
|
|
|
N_("add a Signed-off-by trailer to the commit message"),
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
SIGNOFF_EXPLICIT),
|
2015-08-04 21:51:45 +08:00
|
|
|
OPT_BOOL('u', "utf8", &state.utf8,
|
|
|
|
N_("recode into utf8 (default)")),
|
2015-08-04 21:51:46 +08:00
|
|
|
OPT_SET_INT('k', "keep", &state.keep,
|
|
|
|
N_("pass -k flag to git-mailinfo"), KEEP_TRUE),
|
|
|
|
OPT_SET_INT(0, "keep-non-patch", &state.keep,
|
|
|
|
N_("pass -b flag to git-mailinfo"), KEEP_NON_PATCH),
|
2015-08-04 21:51:47 +08:00
|
|
|
OPT_BOOL('m', "message-id", &state.message_id,
|
|
|
|
N_("pass -m flag to git-mailinfo")),
|
2018-05-20 23:42:58 +08:00
|
|
|
OPT_SET_INT_F(0, "keep-cr", &keep_cr,
|
|
|
|
N_("pass --keep-cr flag to git-mailsplit for mbox format"),
|
|
|
|
1, PARSE_OPT_NONEG),
|
|
|
|
OPT_SET_INT_F(0, "no-keep-cr", &keep_cr,
|
|
|
|
N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
|
|
|
|
0, PARSE_OPT_NONEG),
|
2015-08-04 21:51:49 +08:00
|
|
|
OPT_BOOL('c', "scissors", &state.scissors,
|
|
|
|
N_("strip everything before a scissors line")),
|
2021-05-10 01:12:13 +08:00
|
|
|
OPT_CALLBACK_F(0, "quoted-cr", &state.quoted_cr, N_("action"),
|
|
|
|
N_("pass it through git-mailinfo"),
|
|
|
|
PARSE_OPT_NONEG, am_option_parse_quoted_cr),
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
OPT_PASSTHRU_ARGV(0, "whitespace", &state.git_apply_opts, N_("action"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
|
|
|
OPT_PASSTHRU_ARGV(0, "ignore-space-change", &state.git_apply_opts, NULL,
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
PARSE_OPT_NOARG),
|
|
|
|
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &state.git_apply_opts, NULL,
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
PARSE_OPT_NOARG),
|
|
|
|
OPT_PASSTHRU_ARGV(0, "directory", &state.git_apply_opts, N_("root"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
|
|
|
OPT_PASSTHRU_ARGV(0, "exclude", &state.git_apply_opts, N_("path"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
|
|
|
OPT_PASSTHRU_ARGV(0, "include", &state.git_apply_opts, N_("path"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
|
|
|
OPT_PASSTHRU_ARGV('C', NULL, &state.git_apply_opts, N_("n"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
|
|
|
OPT_PASSTHRU_ARGV('p', NULL, &state.git_apply_opts, N_("num"),
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
0),
|
2015-08-04 21:51:26 +08:00
|
|
|
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
|
|
|
|
N_("format the patch(es) are in"),
|
|
|
|
parse_opt_patchformat),
|
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to
git-apply:
* --whitespace, since 8c31cb8 (git-am: --whitespace=x option.,
2006-02-28)
* -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08)
* -p, since 2092a1f (Teach git-am to pass -p option down to git-apply,
2007-02-11)
* --directory, since b47dfe9 (git-am: add --directory=<dir> option,
2009-01-11)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
* --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply:
option to ignore whitespace differences, 2009-08-04)
* --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03)
* --include, since 58725ef (am: support --include option, 2012-03-28)
* --reject, since b80da42 (git-am: implement --reject option passed to
git-apply, 2009-01-23)
Re-implement support for these options in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:50 +08:00
|
|
|
OPT_PASSTHRU_ARGV(0, "reject", &state.git_apply_opts, NULL,
|
|
|
|
N_("pass it through git-apply"),
|
|
|
|
PARSE_OPT_NOARG),
|
2015-08-04 21:51:38 +08:00
|
|
|
OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
|
|
|
|
N_("override error message when patch failure occurs")),
|
2020-02-20 22:15:17 +08:00
|
|
|
OPT_CMDMODE(0, "continue", &resume.mode,
|
2015-08-04 21:51:32 +08:00
|
|
|
N_("continue applying patches after resolving a conflict"),
|
|
|
|
RESUME_RESOLVED),
|
2020-02-20 22:15:17 +08:00
|
|
|
OPT_CMDMODE('r', "resolved", &resume.mode,
|
2015-08-04 21:51:32 +08:00
|
|
|
N_("synonyms for --continue"),
|
|
|
|
RESUME_RESOLVED),
|
2020-02-20 22:15:17 +08:00
|
|
|
OPT_CMDMODE(0, "skip", &resume.mode,
|
2015-08-04 21:51:34 +08:00
|
|
|
N_("skip the current patch"),
|
|
|
|
RESUME_SKIP),
|
2020-02-20 22:15:17 +08:00
|
|
|
OPT_CMDMODE(0, "abort", &resume.mode,
|
2021-01-06 22:44:03 +08:00
|
|
|
N_("restore the original branch and abort the patching operation"),
|
2015-08-04 21:51:35 +08:00
|
|
|
RESUME_ABORT),
|
2020-02-20 22:15:17 +08:00
|
|
|
OPT_CMDMODE(0, "quit", &resume.mode,
|
2021-01-06 22:44:03 +08:00
|
|
|
N_("abort the patching operation but keep HEAD where it is"),
|
2018-02-14 19:16:06 +08:00
|
|
|
RESUME_QUIT),
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
{ OPTION_CALLBACK, 0, "show-current-patch", &resume.mode,
|
2020-02-20 22:15:19 +08:00
|
|
|
"(diff|raw)",
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
N_("show the patch being applied"),
|
|
|
|
PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
|
|
|
|
parse_opt_show_current_patch, RESUME_SHOW_PATCH },
|
2015-08-04 21:51:52 +08:00
|
|
|
OPT_BOOL(0, "committer-date-is-author-date",
|
|
|
|
&state.committer_date_is_author_date,
|
|
|
|
N_("lie about committer date")),
|
2015-08-04 21:51:51 +08:00
|
|
|
OPT_BOOL(0, "ignore-date", &state.ignore_date,
|
|
|
|
N_("use current timestamp for author date")),
|
builtin-am: rerere support
git-am.sh will call git-rerere at the following events:
* "git rerere" when a three-way merge fails to record the conflicted
automerge results. Since 8389b52 (git-rerere: reuse recorded resolve.,
2006-01-28)
* Since cb6020b (Teach --[no-]rerere-autoupdate option to merge,
revert and friends, 2009-12-04), git-am.sh supports the
--[no-]rerere-autoupdate option as well, and would pass it to
git-rerere.
* "git rerere" when --resolved, to record the hand resolution. Since
f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or
aborted rebase/am, 2006-12-08)
* "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or
avoid misrecording) resolved, skipped or aborted rebase/am,
2006-12-08)
* "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort,
2008-07-16)
Re-implement the above in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:59 +08:00
|
|
|
OPT_RERERE_AUTOUPDATE(&state.allow_rerere_autoupdate),
|
2015-08-04 21:51:53 +08:00
|
|
|
{ OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
|
|
|
|
N_("GPG-sign commits"),
|
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
|
2015-08-04 21:51:42 +08:00
|
|
|
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
|
|
|
|
N_("(internal use for git-rebase)")),
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
2015-08-04 21:51:24 +08:00
|
|
|
|
am: handle "-h" argument earlier
If the user provides "-h" on the command line, then our
parse_options() invocation will show a usage message and
quit. But if "-h" is the only argument, the git wrapper
behaves specially: it ignores our RUN_SETUP flag and calls
cmd_am() without having done repository setup at all. This
is due to 99caeed05 (Let 'git <command> -h' show usage
without a git dir, 2009-11-09).
Before cmd_am() calls parse_options(), though, it runs a few
other setup functions. One of these is am_state_init(),
which uses git_pathdup() to set up the default rebase-apply
path. But calling git_pathdup() when we haven't done
repository setup will fall back to using ".git". That's
mostly harmless (since we won't use the value anyway), but
is forbidden since b1ef400eec ("setup_git_env: avoid blind
fall-back to ".git"", 2016-10-20), and we now BUG().
We can't easily move that setup to after the parse_options()
call; the point is to set up defaults that are overwritten
by the option parsing. Instead, we'll detect the "-h" case
early and show the usage then. This matches the behavior of
other builtins which have a similar setup-ordering issue
(e.g., git-branch).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-30 13:11:23 +08:00
|
|
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
|
|
|
usage_with_options(usage, options);
|
|
|
|
|
2015-10-01 01:49:44 +08:00
|
|
|
git_config(git_am_config, NULL);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2017-04-21 05:09:35 +08:00
|
|
|
am_state_init(&state);
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2015-08-04 22:08:50 +08:00
|
|
|
in_progress = am_in_progress(&state);
|
|
|
|
if (in_progress)
|
|
|
|
am_load(&state);
|
|
|
|
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
|
|
|
|
builtin-am: implement legacy -b/--binary option
The -b/--binary option was initially implemented in 087b674 (git-am:
--binary; document --resume and --binary., 2005-11-16). The option will
pass the --binary flag to git-apply to allow it to apply binary patches.
However, in 2b6eef9 (Make apply --binary a no-op., 2006-09-06), --binary
was been made a no-op in git-apply. Following that, since cb3a160
(git-am: ignore --binary option, 2008-08-09), the --binary option in
git-am is ignored as well.
In 6c15a1c (am: officially deprecate -b/--binary option, 2012-03-13),
the --binary option was tweaked to its present behavior: when set, the
message:
The -b/--binary option has been a no-op for long time, and it
will be removed. Please do not use it anymore.
will be printed.
Re-implement this in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:52:04 +08:00
|
|
|
if (binary >= 0)
|
|
|
|
fprintf_ln(stderr, _("The -b/--binary option has been a no-op for long time, and\n"
|
|
|
|
"it will be removed. Please do not use it anymore."));
|
|
|
|
|
builtin-am: check for valid committer ident
When commit_tree() is called, if the user does not have an explicit
committer ident configured, it will attempt to construct a default
committer ident based on the user's and system's info (e.g. gecos field,
hostname etc.) However, if a default committer ident is unable to be
constructed, commit_tree() will die(), but at this point of git-am's
execution, there will already be changes made to the index and work
tree.
This can be confusing to new users, and as such since d64e6b0 (Keep
Porcelainish from failing by broken ident after making changes.,
2006-02-18) git-am.sh will check to see if the committer ident has been
configured, or a default one can be constructed, before even starting to
apply patches.
Re-implement this in builtin/am.c.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:52:05 +08:00
|
|
|
/* Ensure a valid committer ident can be constructed */
|
|
|
|
git_committer_info(IDENT_STRICT);
|
|
|
|
|
2019-01-12 10:13:26 +08:00
|
|
|
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
|
2015-08-04 21:51:29 +08:00
|
|
|
die(_("failed to read the index"));
|
|
|
|
|
2015-08-04 22:08:50 +08:00
|
|
|
if (in_progress) {
|
2015-08-04 21:51:36 +08:00
|
|
|
/*
|
|
|
|
* Catch user error to feed us patches when there is a session
|
|
|
|
* in progress:
|
|
|
|
*
|
|
|
|
* 1. mbox path(s) are provided on the command-line.
|
|
|
|
* 2. stdin is not a tty: the user is trying to feed us a patch
|
|
|
|
* from standard input. This is somewhat unreliable -- stdin
|
|
|
|
* could be /dev/null for example and the caller did not
|
|
|
|
* intend to feed us a patch but wanted to continue
|
|
|
|
* unattended.
|
|
|
|
*/
|
2020-02-20 22:15:17 +08:00
|
|
|
if (argc || (resume.mode == RESUME_FALSE && !isatty(0)))
|
2015-08-04 21:51:36 +08:00
|
|
|
die(_("previous rebase directory %s still exists but mbox given."),
|
|
|
|
state.dir);
|
|
|
|
|
2020-02-20 22:15:17 +08:00
|
|
|
if (resume.mode == RESUME_FALSE)
|
|
|
|
resume.mode = RESUME_APPLY;
|
am: let --signoff override --no-signoff
After resolving a conflicting patch, a user may wish to sign off the
patch to declare that the patch has been modified. As such, the user
will expect that running "git am --signoff --continue" will append the
signoff to the commit message.
However, the --signoff option is only taken into account during the
mail-parsing stage. If the --signoff option is set, then the signoff
will be appended to the commit message. Since the mail-parsing stage
comes before the patch application stage, the --signoff option, if
provided on the command-line when resuming, will have no effect at all.
We cannot move the append_signoff() call to the patch application stage
as the applypatch-msg hook and interactive mode, which run before patch
application, may expect the signoff to be there.
Fix this by taking note if the user explictly set the --signoff option
on the command-line, and append the signoff to the commit message when
resuming if so.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 22:08:51 +08:00
|
|
|
|
|
|
|
if (state.signoff == SIGNOFF_EXPLICIT)
|
|
|
|
am_append_signoff(&state);
|
2015-08-04 21:51:33 +08:00
|
|
|
} else {
|
2020-07-29 04:24:27 +08:00
|
|
|
struct strvec paths = STRVEC_INIT;
|
2015-08-04 21:51:26 +08:00
|
|
|
int i;
|
|
|
|
|
2015-08-04 21:51:44 +08:00
|
|
|
/*
|
|
|
|
* Handle stray state directory in the independent-run case. In
|
|
|
|
* the --rebasing case, it is up to the caller to take care of
|
|
|
|
* stray directories.
|
|
|
|
*/
|
|
|
|
if (file_exists(state.dir) && !state.rebasing) {
|
2020-02-20 22:15:17 +08:00
|
|
|
if (resume.mode == RESUME_ABORT || resume.mode == RESUME_QUIT) {
|
2015-08-04 21:51:44 +08:00
|
|
|
am_destroy(&state);
|
|
|
|
am_state_release(&state);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
die(_("Stray %s directory found.\n"
|
|
|
|
"Use \"git am --abort\" to remove it."),
|
|
|
|
state.dir);
|
|
|
|
}
|
|
|
|
|
2020-02-20 22:15:17 +08:00
|
|
|
if (resume.mode)
|
2015-08-04 21:51:32 +08:00
|
|
|
die(_("Resolve operation not in progress, we are not resuming."));
|
|
|
|
|
2015-08-04 21:51:26 +08:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
if (is_absolute_path(argv[i]) || !prefix)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&paths, argv[i]);
|
2015-08-04 21:51:26 +08:00
|
|
|
else
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&paths, mkpath("%s/%s", prefix, argv[i]));
|
2015-08-04 21:51:26 +08:00
|
|
|
}
|
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
if (state.interactive && !paths.nr)
|
2019-05-20 20:11:13 +08:00
|
|
|
die(_("interactive mode requires patches on the command line"));
|
|
|
|
|
2020-07-29 08:37:20 +08:00
|
|
|
am_setup(&state, patch_format, paths.v, keep_cr);
|
2015-08-04 21:51:26 +08:00
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_clear(&paths);
|
2015-08-04 21:51:26 +08:00
|
|
|
}
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
2020-02-20 22:15:17 +08:00
|
|
|
switch (resume.mode) {
|
2015-08-04 21:51:32 +08:00
|
|
|
case RESUME_FALSE:
|
2015-08-04 21:51:33 +08:00
|
|
|
am_run(&state, 0);
|
|
|
|
break;
|
|
|
|
case RESUME_APPLY:
|
|
|
|
am_run(&state, 1);
|
2015-08-04 21:51:32 +08:00
|
|
|
break;
|
|
|
|
case RESUME_RESOLVED:
|
|
|
|
am_resolve(&state);
|
|
|
|
break;
|
2015-08-04 21:51:34 +08:00
|
|
|
case RESUME_SKIP:
|
|
|
|
am_skip(&state);
|
|
|
|
break;
|
2015-08-04 21:51:35 +08:00
|
|
|
case RESUME_ABORT:
|
|
|
|
am_abort(&state);
|
|
|
|
break;
|
2018-02-14 19:16:06 +08:00
|
|
|
case RESUME_QUIT:
|
|
|
|
am_rerere_clear();
|
|
|
|
am_destroy(&state);
|
|
|
|
break;
|
2018-02-11 17:43:26 +08:00
|
|
|
case RESUME_SHOW_PATCH:
|
am: support --show-current-patch=raw as a synonym for--show-current-patch
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable or
base64. To simplify worktree operations and to avoid that users poke into
.git, it would be better if "git am" also provided a mode that copies
.git/rebase-merge/patch to stdout.
One possibility could be to have completely separate options, introducing
for example --show-current-message (for .git/rebase-apply/NNNN)
and --show-current-diff (for .git/rebase-apply/patch), while possibly
deprecating --show-current-patch.
That would even remove the need for the first two patches in the series.
However, the long common prefix would have prevented using an abbreviated
option such as "--show". Therefore, I chose instead to add a string
argument to --show-current-patch. The new argument is optional, so that
"git am --show-current-patch"'s behavior remains backwards-compatible.
The next choice to make is how to handle multiple --show-current-patch
options. Right now, something like "git am --abort --show-current-patch"
is rejected, and the previous suggestion would likewise have naturally
rejected a command line like
git am --show-current-message --show-current-diff
Therefore, I decided to also reject for example
git am --show-current-patch=diff --show-current-patch=raw
In other words the whole of --show-current-patch=xxx (including the
optional argument) is treated as the command mode. I found this to be
more consistent and intuitive, even though it differs from the usual
"last one wins" semantics of the git command line.
Add the code to parse submodes based on the above design, where for now
"raw" is the only valid submode. "raw" prints the full e-mail message
just like "git am --show-current-patch".
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-20 22:15:18 +08:00
|
|
|
ret = show_patch(&state, resume.sub_mode);
|
2018-02-11 17:43:26 +08:00
|
|
|
break;
|
2015-08-04 21:51:32 +08:00
|
|
|
default:
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("invalid resume value");
|
2015-08-04 21:51:32 +08:00
|
|
|
}
|
builtin-am: implement patch queue mechanism
git-am applies a series of patches. If the process terminates
abnormally, we want to be able to resume applying the series of patches.
This requires the session state to be saved in a persistent location.
Implement the mechanism of a "patch queue", represented by 2 integers --
the index of the current patch we are applying and the index of the last
patch, as well as its lifecycle through the following functions:
* am_setup(), which will set up the state directory
$GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
the last-known state will still persist.
* am_load(), which is called if there is an am session in
progress, to load the last known state from the state directory so we
can resume applying patches.
* am_run(), which will do the actual patch application. After applying a
patch, it calls am_next() to increment the current patch index. The
logic for applying and committing a patch is not implemented yet.
* am_destroy(), which is finally called when we successfully applied all
the patches in the queue, to clean up by removing the state directory
and its contents.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Stefan Beller <sbeller@google.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-04 21:51:25 +08:00
|
|
|
|
|
|
|
am_state_release(&state);
|
|
|
|
|
2018-02-11 17:43:26 +08:00
|
|
|
return ret;
|
2015-08-04 21:51:24 +08:00
|
|
|
}
|