List for cgit developers and users
 help / color / mirror / Atom feed
From: larsh at hjemli.net (larsh at hjemli.net)
Subject: [PATCH] guess default branch from HEAD
Date: Tue, 19 Jul 2011 07:08:45 +0000	[thread overview]
Message-ID: <20110719070845.GB7524@hjemli.net> (raw)
In-Reply-To: <20110713151037.GK5875@plenz.com>

On Wed, Jul 13, 2011 at 05:10:37PM +0200, Julius Plenz wrote:
> Hi!
> 
> * chris <jugg at hotmail.com> [2011-07-09 10:12]:
> > I've applied the following patch:
> > 
> > http://hjemli.net/git/cgit/patch/?id=795118d4042d53566d8375dcabe20515e9135351
> > 
> > ontop of:
> > 
> > http://hjemli.net/git/cgit/commit/?id=2a8f553163d642e60092ced20631e1020581273b
> > 
> > and the index page 'idle' times no longer show up (the idle column
> > is blank). Each project's summary page 'Age' column still works just
> > fine.
> 
[snip]
> 
> When Lars proposed the patch, I didn't actually try it out. Now,
> reading over it again, I see two ovious quirks: The first is trivial
> to fix: return "master" will return a stack address, but you have to
> allocate memory for that:
> 
> diff --git a/cgit.c b/cgit.c
> index d51885b..f9be05c 100644
> --- a/cgit.c
> +++ b/cgit.c
> @@ -427,7 +427,7 @@ static char *guess_defbranch(const char *repo_path)
>  
>         ref = resolve_ref("HEAD", sha1, 0, NULL);
>         if (!ref || prefixcmp(ref, "refs/heads/"))
> -               return "master";
> +               return xstrdup("master");
>         return xstrdup(ref + 11);
>  }
>  

No, string constants have static storage so this isn't needed.

> 
> Now, the second thing is a more severe thing. guess_defbranch will get
> the repo_path as an argument; however, it's not used. The reason why
> this works *once* (in my little program above) is that you explictly
> set GIT_DIR on the shell, or you are in a git repository already.
> 
> However, when iterating over multiple repositories, you change your
> gitdir. When writing the patch I discovered resolve_ref at some point,
> BUT it cannot be used in this case.

This is true if resolve_ref() is invoked during repository discovery,
but my patch only invokes resolve_ref() once (when a repository has
been selected as "active"). This works for all pages _except_ the index
page where repo.defbranch now has no default value, and a simple (albeit
imperfect) fix for this is just to check "master" if nothing else is
specified (see my response to Chris).

I think this is an ok compromise between performance and correctness;
the user can either rely on a 90% solution to get automatic "idle" info
on the index page or use the "agefile" option (and a git hook) to get
the correct "idle" time, cgit can rely on resolve_ref() to find the ref
pointed to by HEAD, and we avoid resolving the HEAD of every repo on
every page request.

> So, Lars, I propose to revert your patch and use my original one
> instead. I agree it would be nice to use as much functionality from
> libgit.a -- in this case, however, I can't see a way to do it properly.

If we wanted to run resolve_ref() on multiple repositories, we could
always fork() and pipe the result from resolve_ref() back to the
parent process. But I don't think we want to resolve the HEAD of every
repository.

--
larsh




  reply	other threads:[~2011-07-19  7:08 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-10 16:03 [PATCH 1/5] " plenz
2011-03-10 16:03 ` [PATCH 2/5] get_commit_date() obtains newest commit date plenz
2011-03-10 16:03 ` [PATCH 3/5] make enable-log-linecount independent of -filecount plenz
2011-03-10 17:25   ` hjemli
2011-03-26 14:43     ` hjemli
2011-03-10 16:03 ` [PATCH 4/5] fix two encoding bugs plenz
2011-03-10 17:29   ` hjemli
2011-03-10 16:03 ` [PATCH 5/5] Add advice about scan-path in cgitrc.5.txt plenz
2011-03-10 17:33   ` hjemli
2011-03-10 17:22 ` [PATCH 1/5] guess default branch from HEAD hjemli
2011-03-16 10:53   ` plenz
2011-03-26 10:08     ` hjemli
2011-03-30 16:00       ` [PATCH v2] " plenz
2011-04-07  9:44         ` hjemli
2011-04-07 10:49           ` plenz
2011-04-07 10:59             ` [PATCH] " plenz
2011-06-10  6:42               ` jugg
2011-06-13 10:16                 ` larsh
2011-06-13 10:16                   ` hjemli
2011-06-16 14:59                     ` plenz
2011-06-20 19:25                       ` hjemli
2011-07-09  8:09                         ` jugg
2011-07-13 15:10                           ` plenz
2011-07-19  7:08                             ` larsh [this message]
2011-07-19  9:40                             ` jugg
2011-07-19  6:30                           ` larsh
2011-07-19  9:35                             ` jugg
2011-07-19  9:56                               ` larsh
2011-07-19 10:13                                 ` jugg
2011-07-21 10:34                                   ` larsh
2011-04-07 11:05             ` [PATCH v2] " hjemli
2011-06-09  4:40               ` jugg

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

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

  git send-email \
    --in-reply-to=20110719070845.GB7524@hjemli.net \
    --to=cgit@lists.zx2c4.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.
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 NNTP newsgroup(s).