# [PATCH] Support ref logs for refs/*

3 messages from 2009-01-08 to 2009-01-08. Participants: Neil Macneale, Nanako Shiraishi, mac4-git@theory.org.
Thread: https://gitlist.dev/t/17044

## Neil Macneale, 2009-01-08 08:28

Subject: [PATCH] Support ref logs for refs/*
Message-ID: <20090108082827.GA6177@tesla.theory.org>
URL: https://gitlist.dev/e/20090108082827.GA6177%40tesla.theory.org

```
The documentation for git update-ref seems to imply that logging of ref
updates should be done for anything in refs/, though the code looks like it
restricts changes to heads and remotes. Any reason not so support arbitrary
refs?

I don't see much point in logging for tags, so the patch ignores refs/tags.

Thanks,
Neil

Signed-off-by: Neil Macneale <mac4-git@theory.org>
---
 refs.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 33ced65..cfff22b 100644
--- a/refs.c
+++ b/refs.c
@@ -1154,9 +1154,9 @@ static int log_ref_write(const char *ref_name, const
unsigned char *old_sha1,
        git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
 
        if (log_all_ref_updates &&
-           (!prefixcmp(ref_name, "refs/heads/") ||
-            !prefixcmp(ref_name, "refs/remotes/") ||
-            !strcmp(ref_name, "HEAD"))) {
+           (!prefixcmp(ref_name, "refs/") ||
+            !strcmp(ref_name, "HEAD")) &&
+           prefixcmp(ref_name, "refs/tags/")) {
                if (safe_create_leading_directories(log_file) < 0)
                        return error("unable to create directory for %s",
                                     log_file);
-- 
1.6.1.141.gfe98e.dirty

```

## Nanako Shiraishi, 2009-01-08 09:08

Subject: Re: [PATCH] Support ref logs for refs/*
Message-ID: <20090108180857.6117@nanako3.lavabit.com>
URL: https://gitlist.dev/e/20090108180857.6117%40nanako3.lavabit.com
In-Reply-To: <20090108082827.GA6177@tesla.theory.org>

```
Quoting Neil Macneale <mac4-git@theory.org>:

> The documentation for git update-ref seems to imply that logging of ref
> updates should be done for anything in refs/...

The documementation for git-update-ref is part of git, and git does not use anything outside of refs/{heads,tags,remotes}/ for its normal operation. 

I think it is generally assumed that there is nothing of interest outside of these areas that deserves the automated creation of reflogs, and the code you are touching is about that. Once you have reflog for any ref you are interested outside of these areas, your actions will be logged regardless. 

Most notably, refs/stash itself is exempt from this code path and it makes sure that reflog exists without relying on log_all_ref_updates configuration. 

Also the documentation for the configuration variable explicitly says it is about the branch heads.

core.logAllRefUpdates::
	Enable the reflog. Updates to a ref <ref> is logged to the file
	"$GIT_DIR/logs/<ref>", by appending the new and old
	SHA1, the date/time and the reason of the update, but
	only when the file exists.  If this configuration
	variable is set to true, missing "$GIT_DIR/logs/<ref>"
	file is automatically created for branch heads.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

```

## mac4-git@theory.org, 2009-01-08 16:52

Subject: Re: [PATCH] Support ref logs for refs/*
Message-ID: <20090108165240.GA22815@tesla.theory.org>
URL: https://gitlist.dev/e/20090108165240.GA22815%40tesla.theory.org
In-Reply-To: <20090108180857.6117@nanako3.lavabit.com>

```
On Thursday, January 08, 2009, the wise Nanako Shiraishi wrote:
>Quoting Neil Macneale <mac4-git@theory.org>:
>
>> The documentation for git update-ref seems to imply that logging of ref
>> updates should be done for anything in refs/...
>
>The documementation for git-update-ref is part of git, and git does not use anything outside of refs/{heads,tags,remotes}/ for its normal operation. 
>
>I think it is generally assumed that there is nothing of interest outside of these areas that deserves the automated creation of reflogs, and the code you are touching is about that. Once you have reflog for any ref you are interested outside of these areas, your actions will be logged regardless. 

Why is that generally assumed? I can fetch to arbitrary refs and git prune
doesn't clean objects references from argitrary refs, so it seems like
there is implicit support for these references. A little extra logging
never hurt anyone.

>Most notably, refs/stash itself is exempt from this code path and it makes sure that reflog exists without relying on log_all_ref_updates configuration. 

Why not? I'd like like have logs for stash actions. Makes the case when
someone runs git stash clear by mistake a little easier to recover from.

The alternative is for me to touch a file in .git/logs/refs prior to any
use of git update-ref.  It seems like most git commands go to great
lengths to prevent you from ever needing to get into the .git dir, so maybe
an alternative would be an option to force git update-ref to create a log
file automatically. I thought thats what the "all" in core.logallrefupdates
meant. Silly me. 

A command line option for git update-ref is not ideal because when I run
git fetch remote refs/whatever:refs/whatever, I still want a log entry. 
Thus, I still need to be mucking with the .git dir when I shouldn't need
to.

Whats the harm in a little more logging? The space wasted is pretty much
nothing. I'd much rather be able to look at a ref log in the event that I
mess somthing up than run git fsck.

Cheers,
Neil

>
>-- 
>Nanako Shiraishi
>http://ivory.ap.teacup.com/nanako3/
>
>--
>To unsubscribe from this list: send the line "unsubscribe git" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

```
