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

Re: [PATCH] pack-refs: remove newly empty directories

From
Greg Price <price@ksplice.com>
Date
Jul 6, 2010, 03:25 UTC
Message-ID
<AANLkTilDcpdekvsw9b4TN8QNpubs6wkpibXdzz2AkTf-@mail.gmail.com>
In-Reply-To
<7vsk3x5n35.fsf@alter.siamese.dyndns.org>
On Mon, Jul 5, 2010 at 11:02 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> Will this keep refs/heads/p/q that is empty after packing p/q/r/s branch
> that happens to be the only branch whose name begins with p/?
>
> I do not want a careless loop that will remove refs/heads after packing
> "master" that happens to be the only local branch, but still...
It will.  I could fix that with something like this (untested):
/* Remove empty parents, but spare refs/ and immediate subdirs.
   Note, munges *name. */
static void try_remove_empty_parents(char *name)
{
  char *p, *q;
  int i;
  p = name;
  for (i = 0; i < 2; i++) { /* refs/{heads,tags,...}/ */
    while (*p && *p != '/')
      p++;
    if (*p)
      p++;
  }
  for (q = p; *q; q++)
    ;
  while (1) {
    for ( ; q > p && *q != '/'; q--)
      ;
    if (q == p)
      break;
    *q = '\0';
    if (rmdir(git_path("%s", name)))
      break;
  }
}
and then
      if (lock) {
              unlink_or_warn(git_path("%s", r->name));
              unlock_ref(lock);
+              try_remove_empty_parents(r->name);
      }
Sound reasonable?
Greg
Previous: Junio C HamanoNext: Greg Price
Message 3 of 8 in “pack-refs: remove newly empty directories”
  1. pack-refs: remove newly empty directoriesGreg Price, Jul 5, 2010
  2. Junio C HamanoJul 6, 2010
  3. Greg PriceJul 6, 2010
  4. pack-refs: remove newly empty directoriesGreg Price, Jul 6, 2010
  5. Johannes SixtJul 6, 2010
  6. Junio C HamanoJul 6, 2010
  7. Andreas SchwabJul 6, 2010
  8. Greg PriceJul 6, 2010

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.