git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] xdiff: rename "struct group" to "struct xdlgroup"

From
Stefan Beller <sbeller@google.com>
Date
Sep 27, 2016, 16:22 UTC
Message-ID
<CAGZ79kaeFWUAZ=oxxY2tqUMYL1NF8WBYk69AN1ncyuHyJh5HKg@mail.gmail.com>
In-Reply-To
<20160927043733.u3emlanbipu2cn5h@sigill.intra.peff.net>
On Mon, Sep 26, 2016 at 9:37 PM, Jeff King <peff@peff.net> wrote:
Show 15 quoted lines
> Commit e8adf23 (xdl_change_compact(): introduce the concept
> of a change group, 2016-08-22) added a "struct group" type
> to xdiff/xdiffi.c. But the POSIX system header "grp.h"
> already defines "struct group" (it is part of the getgrnam
> interface). This happens to work because the new type is
> local to xdiffi.c, and the xdiff code includes a relatively
> small set of system headers. But it will break compilation
> if xdiff ever switches to using git-compat-util.h.  It can
> also probably cause confusion with tools that look at the
> whole code base, like coccinelle or ctags.
>
> Let's resolve by giving the xdiff variant a scoped name,
> which is closer to other xdiff types anyway (e.g.,
> xdlfile_t, though note that xdiff is fond if typedefs when
> Git usually is not).
Makes sense!

Thanks, Stefan

Show 82 quoted lines
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I didn't rename the functions, which have no conflict, but that would
> also be closer to xdiff's usual style. I don't know how far it is worth
> going; maybe this patch is even already too far.
>
> I noticed because I have a patch series which switches xdiff
> to git-compat-util, to try to use the st_* macros there.
>
>  xdiff/xdiffi.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
> index 67c1ccc..760fbb6 100644
> --- a/xdiff/xdiffi.c
> +++ b/xdiff/xdiffi.c
> @@ -708,7 +708,7 @@ static int score_cmp(struct split_score *s1, struct split_score *s2)
>   * Note that loops that are testing for changed lines in xdf->rchg do not need
>   * index bounding since the array is prepared with a zero at position -1 and N.
>   */
> -struct group {
> +struct xdlgroup {
>         /*
>          * The index of the first changed line in the group, or the index of
>          * the unchanged line above which the (empty) group is located.
> @@ -725,7 +725,7 @@ struct group {
>  /*
>   * Initialize g to point at the first group in xdf.
>   */
> -static void group_init(xdfile_t *xdf, struct group *g)
> +static void group_init(xdfile_t *xdf, struct xdlgroup *g)
>  {
>         g->start = g->end = 0;
>         while (xdf->rchg[g->end])
> @@ -736,7 +736,7 @@ static void group_init(xdfile_t *xdf, struct group *g)
>   * Move g to describe the next (possibly empty) group in xdf and return 0. If g
>   * is already at the end of the file, do nothing and return -1.
>   */
> -static inline int group_next(xdfile_t *xdf, struct group *g)
> +static inline int group_next(xdfile_t *xdf, struct xdlgroup *g)
>  {
>         if (g->end == xdf->nrec)
>                 return -1;
> @@ -752,7 +752,7 @@ static inline int group_next(xdfile_t *xdf, struct group *g)
>   * Move g to describe the previous (possibly empty) group in xdf and return 0.
>   * If g is already at the beginning of the file, do nothing and return -1.
>   */
> -static inline int group_previous(xdfile_t *xdf, struct group *g)
> +static inline int group_previous(xdfile_t *xdf, struct xdlgroup *g)
>  {
>         if (g->start == 0)
>                 return -1;
> @@ -769,7 +769,7 @@ static inline int group_previous(xdfile_t *xdf, struct group *g)
>   * following group, expand this group to include it. Return 0 on success or -1
>   * if g cannot be slid down.
>   */
> -static int group_slide_down(xdfile_t *xdf, struct group *g, long flags)
> +static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g, long flags)
>  {
>         if (g->end < xdf->nrec &&
>             recs_match(xdf->recs[g->start], xdf->recs[g->end], flags)) {
> @@ -790,7 +790,7 @@ static int group_slide_down(xdfile_t *xdf, struct group *g, long flags)
>   * into a previous group, expand this group to include it. Return 0 on success
>   * or -1 if g cannot be slid up.
>   */
> -static int group_slide_up(xdfile_t *xdf, struct group *g, long flags)
> +static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g, long flags)
>  {
>         if (g->start > 0 &&
>             recs_match(xdf->recs[g->start - 1], xdf->recs[g->end - 1], flags)) {
> @@ -818,7 +818,7 @@ static void xdl_bug(const char *msg)
>   * size.
>   */
>  int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
> -       struct group g, go;
> +       struct xdlgroup g, go;
>         long earliest_end, end_matching_other;
>         long groupsize;
>         unsigned int blank_lines;
> --
> 2.10.0.492.g14f803f
Previous: Jeff King
Message 4 of 4 in “xdiff: rename "struct group" to "struct xdlgroup"”
  1. xdiff: rename "struct group" to "struct xdlgroup"Jeff King, Sep 27, 2016
  2. Michael HaggertySep 27, 2016
  3. Jeff KingSep 27, 2016
  4. Stefan BellerSep 27, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.