git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Bert Wesarg <bert.wesarg@googlemail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>,
	Jakub Narebski <jnareb@gmail.com>,
	Finn Arne Gangstad <finnag@pvv.org>,
	"git@vger.kernel.org List" <git@vger.kernel.org>,
	Avery Pennarun <apenwarr@gmail.com>
Subject: Re: [PATCH 07/12] ll-merge: make flag easier to populate
Date: Thu, 5 Aug 2010 14:12:30 +0200	[thread overview]
Message-ID: <AANLkTi=9GwZgiQHpBLN_L14==Pir0Gs=DosZHF4wg9zi@mail.gmail.com> (raw)
In-Reply-To: <20100805111738.GI13779@burratino>

On Thu, Aug 5, 2010 at 13:17, Jonathan Nieder <jrnieder@gmail.com> wrote:
> ll_merge() takes its options in a flag word, which has a few
> advantages:
>
>  - options flags can be cheaply passed around in registers, while
>   an option struct passed by pointer cannot;
>
>  - callers can easily pass 0 without trouble for no options,
>   while an option struct passed by value would not allow that.
>
> The downside is that code to populate and access the flag word can be
> somewhat opaque.  Mitigate that with a few macros.
>
> Cc: Avery Pennarun <apenwarr@gmail.com>
> Cc: Bert Wesarg <bert.wesarg@googlemail.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
>  Documentation/technical/api-merge.txt |   11 +++++++----
>  ll-merge.c                            |    9 +++++----
>  ll-merge.h                            |   14 ++++++++++++++
>  merge-recursive.c                     |    3 ++-
>  4 files changed, 28 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/technical/api-merge.txt b/Documentation/technical/api-merge.txt
> index 01a89d6..a7e050b 100644
> --- a/Documentation/technical/api-merge.txt
> +++ b/Documentation/technical/api-merge.txt
> @@ -49,12 +49,15 @@ supports this.
>
>  The `flag` parameter is a bitfield:
>
> - - The least significant bit indicates whether this is an internal
> -   merge to consolidate ancestors for a recursive merge.
> + - The `LL_OPT_VIRTUAL_ANCESTOR` bit indicates whether this is an
> +   internal merge to consolidate ancestors for a recursive merge.
>
> - - The next two bits allow local conflicts to be automatically
> + - The `LL_OPT_FAVOR_MASK` bits allow local conflicts to be automatically
>    resolved in favor of one side or the other (as in 'git merge-file'
> -   `--ours`/`--theirs`/`--union` for 01, 10, and 11, respectively).
> +   `--ours`/`--theirs`/`--union`).
> +   They can be populated by `create_ll_flag`, whose argument can be
> +   `XDL_MERGE_FAVOR_OURS`, `XDL_MERGE_FAVOR_THEIRS`, or
> +   `XDL_MERGE_FAVOR_UNION`.
>
>  Everything else
>  ---------------
> diff --git a/ll-merge.c b/ll-merge.c
> index 5068fe0..290f764 100644
> --- a/ll-merge.c
> +++ b/ll-merge.c
> @@ -46,7 +46,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
>         * or common ancestor for an internal merge.  Still return
>         * "conflicted merge" status.
>         */
> -       mmfile_t *stolen = (flag & 01) ? orig : src1;
> +       mmfile_t *stolen = (flag & LL_OPT_VIRTUAL_ANCESTOR) ? orig : src1;
>
>        result->ptr = stolen->ptr;
>        result->size = stolen->size;
> @@ -79,7 +79,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
>
>        memset(&xmp, 0, sizeof(xmp));
>        xmp.level = XDL_MERGE_ZEALOUS;
> -       xmp.favor= (flag >> 1) & 03;
> +       xmp.favor = ll_opt_favor(flag);
>        if (git_xmerge_style >= 0)
>                xmp.style = git_xmerge_style;
>        if (marker_size > 0)
> @@ -99,7 +99,8 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
>                          int flag, int marker_size)
>  {
>        /* Use union favor */
> -       flag = (flag & 1) | (XDL_MERGE_FAVOR_UNION << 1);
> +       flag = (flag & LL_OPT_VIRTUAL_ANCESTOR) |
> +              create_ll_flag(XDL_MERGE_FAVOR_UNION);
>        return ll_xdl_merge(drv_unused, result, path_unused,
>                            orig, NULL, src1, NULL, src2, NULL,
>                            flag, marker_size);
> @@ -342,7 +343,7 @@ int ll_merge(mmbuffer_t *result_buf,
>        const char *ll_driver_name = NULL;
>        int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
>        const struct ll_merge_driver *driver;
> -       int virtual_ancestor = flag & 01;
> +       int virtual_ancestor = flag & LL_OPT_VIRTUAL_ANCESTOR;
>
>        if (merge_renormalize) {
>                normalize_file(ancestor, path);
> diff --git a/ll-merge.h b/ll-merge.h
> index 57754cc..5990271 100644
> --- a/ll-merge.h
> +++ b/ll-merge.h
> @@ -5,6 +5,20 @@
>  #ifndef LL_MERGE_H
>  #define LL_MERGE_H
>
> +#define LL_OPT_VIRTUAL_ANCESTOR        (1 << 0)
> +#define LL_OPT_FAVOR_MASK      ((1 << 1) | (1 << 2))
> +#define LL_OPT_FAVOR_SHIFT 1
> +
> +static inline int ll_opt_favor(int flag)
> +{
> +       return (flag & LL_OPT_FAVOR_MASK) >> LL_OPT_FAVOR_SHIFT;
> +}
> +
> +static inline int create_ll_flag(int favor)
> +{
> +       return ((favor << LL_OPT_FAVOR_SHIFT) & LL_OPT_FAVOR_MASK);
> +}
> +

These two function names do not suggests that these are symmetric. How
about get_ll_flavor() and create_ll_flavor()? Or flavor_to_ll_flag()
and ll_flag_to_flavor().

Regards,
Bert

>  int ll_merge(mmbuffer_t *result_buf,
>             const char *path,
>             mmfile_t *ancestor, const char *ancestor_label,
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 8a49844..c0c9f0c 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -647,7 +647,8 @@ static int merge_3way(struct merge_options *o,
>
>        merge_status = ll_merge(result_buf, a->path, &orig, base_name,
>                                &src1, name1, &src2, name2,
> -                               (!!o->call_depth) | (favor << 1));
> +                               ((o->call_depth ? LL_OPT_VIRTUAL_ANCESTOR : 0) |
> +                                create_ll_flag(favor)));
>
>        free(name1);
>        free(name2);
> --
> 1.7.2.1.544.ga752d.dirty
>
>

  reply	other threads:[~2010-08-05 12:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-02 19:20 [PATCH v6 0/3] Merge renormalization, config renamed Eyvind Bernhardsen
2010-07-02 19:20 ` [PATCH v6 1/3] Avoid conflicts when merging branches with mixed normalization Eyvind Bernhardsen
2010-07-02 19:20 ` [PATCH v6 2/3] Try normalizing files to avoid delete/modify conflicts when merging Eyvind Bernhardsen
2010-07-02 19:20 ` [PATCH v6 3/3] Don't expand CRLFs when normalizing text during merge Eyvind Bernhardsen
2010-07-02 22:46 ` [PATCH v6 0/3] Merge renormalization, config renamed Junio C Hamano
2010-08-04  3:19 ` [PATCH/RFC eb/double-convert-before-merge 0/6] merge -Xrenormalize Jonathan Nieder
2010-08-04  3:20   ` [PATCH 1/6] merge-trees: push choice to renormalize away from low level Jonathan Nieder
2010-08-04  3:21   ` [PATCH 2/6] merge-trees: let caller decide whether to renormalize Jonathan Nieder
2010-08-04  3:21   ` [PATCH 3/6] ll-merge: " Jonathan Nieder
2010-08-04 18:12     ` Junio C Hamano
2010-08-04  3:22   ` [PATCH 4/6] rerere: migrate to parse-options API Jonathan Nieder
2010-08-04  3:23   ` [PATCH 5/6] rerere: let caller decide whether to renormalize Jonathan Nieder
2010-08-04 18:12     ` Junio C Hamano
2010-08-05 11:08       ` [PATCH/RFC v2 0/12] " Jonathan Nieder
2010-08-05 11:09         ` [PATCH 01/12] t6038 (merge.renormalize): style nitpicks Jonathan Nieder
2010-08-05 11:41           ` Ævar Arnfjörð Bjarmason
2010-08-05 11:54             ` Jonathan Nieder
2010-08-05 11:11         ` [PATCH 02/12] t6038 (merge.renormalize): try checkout -m and cherry-pick Jonathan Nieder
2010-08-05 11:13         ` [PATCH 03/12] t6038 (merge.renormalize): check that it can be turned off Jonathan Nieder
2010-08-05 11:13         ` [PATCH 04/12] merge-trees: push choice to renormalize away from low level Jonathan Nieder
2010-08-05 11:15         ` [PATCH 05/12] merge-trees: let caller decide whether to renormalize Jonathan Nieder
2010-08-05 11:16         ` [PATCH 06/12] Documentation/technical: document ll_merge Jonathan Nieder
2010-08-05 11:17         ` [PATCH 07/12] ll-merge: make flag easier to populate Jonathan Nieder
2010-08-05 12:12           ` Bert Wesarg [this message]
2010-08-05 12:16             ` Jonathan Nieder
2010-08-05 13:05               ` Bert Wesarg
2010-08-05 13:11                 ` Jonathan Nieder
2010-08-05 11:24         ` [PATCH 08/12] ll-merge: let caller decide whether to renormalize Jonathan Nieder
2010-08-05 11:25         ` [PATCH 09/12] t4200 (rerere): modernize style Jonathan Nieder
2010-08-05 11:28         ` [PATCH 10/12] rerere: migrate to parse-options API Jonathan Nieder
2010-08-05 11:30         ` [PATCH 11/12] rerere: never renormalize Jonathan Nieder
2010-08-05 11:32         ` [PATCH 12/12] merge-recursive --renormalize Jonathan Nieder
2010-08-05 19:02         ` [PATCH/RFC v2 0/12] Re: rerere: let caller decide whether to renormalize Eyvind Bernhardsen
2010-08-04  3:29   ` [PATCH 6/6] merge-recursive: add -Xrenormalize option Jonathan Nieder
2010-08-04 18:10   ` [PATCH/RFC eb/double-convert-before-merge 0/6] merge -Xrenormalize Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=9GwZgiQHpBLN_L14==Pir0Gs=DosZHF4wg9zi@mail.gmail.com' \
    --to=bert.wesarg@googlemail.com \
    --cc=apenwarr@gmail.com \
    --cc=eyvind.bernhardsen@gmail.com \
    --cc=finnag@pvv.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).