Re: [PATCH/WIP v3 10/31] am: refresh the index at start

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Tan <pyokagan@xxxxxxxxx> writes:

> If a file is unchanged but stat-dirty, git-apply may erroneously fail to
> apply patches, thinking that they conflict with a dirty working tree.
>
> As such, since 2a6f08a (am: refresh the index at start and --resolved,
> 2011-08-15), git-am will refresh the index before applying patches.
> Re-implement this behavior.

Good.

I would actually have expected to see this as part of 08/31, though.

>
> Signed-off-by: Paul Tan <pyokagan@xxxxxxxxx>
> ---
>  builtin/am.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/builtin/am.c b/builtin/am.c
> index dfb6f7e..a7efe85 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -13,6 +13,7 @@
>  #include "cache-tree.h"
>  #include "refs.h"
>  #include "commit.h"
> +#include "lockfile.h"
>  
>  /**
>   * Returns 1 if the file is empty or does not exist, 0 otherwise.
> @@ -471,6 +472,20 @@ static const char *msgnum(const struct am_state *state)
>  }
>  
>  /**
> + * Refresh and write index.
> + */
> +static void refresh_and_write_cache(void)
> +{
> +	static struct lock_file lock_file;
> +
> +	hold_locked_index(&lock_file, 1);
> +	refresh_cache(REFRESH_QUIET);
> +	if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
> +		die(_("unable to write index file"));
> +	rollback_lock_file(&lock_file);
> +}
> +
> +/**
>   * Parses `patch` using git-mailinfo. state->msg will be set to the patch
>   * message. state->author_name, state->author_email, state->author_date will be
>   * set to the patch author's name, email and date respectively. The patch's
> @@ -607,6 +622,8 @@ static void do_commit(const struct am_state *state)
>   */
>  static void am_run(struct am_state *state)
>  {
> +	refresh_and_write_cache();
> +
>  	while (state->cur <= state->last) {
>  		const char *patch = am_path(state, msgnum(state));
>  
> @@ -696,6 +713,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
>  
>  	argc = parse_options(argc, argv, prefix, am_options, am_usage, 0);
>  
> +	if (read_index_preload(&the_index, NULL) < 0)
> +		die(_("failed to read the index"));
> +
>  	if (am_in_progress(&state))
>  		am_load(&state);
>  	else {
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]