Skip to contentSkip to conversation

Log ref updates to logs/refs/<ref>

RFC In review Shawn Pearce 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

RFC 4/5 Log ref updates to logs/refs/<ref>

If config parameter core.logAllRefUpdates is true or the log file already exists then append a line to ".git/logs/refs/<ref>" whenever git-update-ref <ref> is executed. Each log line contains the following information:

oldsha1 <SP> newsha1 <SP> committer <LF>

where committer is the current user, date, time and timezone in the standard GIT ident format. If the caller is unable to append to the log file then git-update-ref will fail without updating <ref>.

An optional message may be included in the log line with the -m flag.

---

 Documentation/config.txt         |    8 +++
 Documentation/git-update-ref.txt |   26 +++++++++
 cache.h                          |    1 
 config.c                         |    5 ++
 environment.c                    |    1 
 refs.c                           |   56 +++++++++++++++++++
 refs.h                           |    1 
 t/t1400-update-ref.sh            |  112 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 210 insertions(+), 0 deletions(-)
 create mode 100644 t/t1400-update-ref.sh

1b91f255386d1120bdcb434603993156c9fdde71

Documentation/config.txt +8 -0
index d1a4bec..e178ee2 100644
@@ -70,6 +70,14 @@ core.preferSymlinkRefs::
 	This is sometimes needed to work with old scripts that
 	expect HEAD to be a symbolic link.
 
+core.logAllRefUpdates::
+	If true, `git-update-ref` will append a line to
+	"$GIT_DIR/logs/<ref>" listing the new SHA1 and the date/time
+	of the update.	If the file does not exist it will be
+	created automatically.	This information can be used to
+	determine what commit was the tip of a branch "2 days ago".
+	This value is false by default (no logging).
+
 core.repositoryFormatVersion::
 	Internal variable identifying the repository format and layout
 	version.
Documentation/git-update-ref.txt +26 -0
index f0e710a..dfbd886 100644
@@ -49,6 +49,32 @@ for reading but not for writing (so we'l
 ref symlink to some other tree, if you have copied a whole
 archive by creating a symlink tree).
 
+Logging Updates
+---------------
+If config parameter "core.logAllRefUpdates" is true or the file
+"$GIT_DIR/logs/<ref>" exists then `git-update-ref` will append
+a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all
+symbolic refs before creating the log name) describing the change
+in ref value.  Log lines are formatted as:
+
+    . oldsha1 SP newsha1 SP committer LF
++
+Where "oldsha1" is the 40 character hexadecimal value previously
+stored in <ref>, "newsha1" is the 40 character hexadecimal value of
+<newvalue> and "committer" is the committer's name, email address
+and date in the standard GIT committer ident format.
+
+Optionally with -m:
+
+    . oldsha1 SP newsha1 SP committer TAB message LF
++
+Where all fields are as described above and "message" is the
+value supplied to the -m option.
+
+An update will fail (without changing <ref>) if the current user is
+unable to create a new log file, append to the existing log file
+or does not have committer information available.
+
 Author
 ------
 Written by Linus Torvalds <[email protected]>.
cache.h +1 -0
index b1300cd..82adbba 100644
@@ -171,6 +171,7 @@ extern void rollback_index_file(struct c
 extern int trust_executable_bit;
 extern int assume_unchanged;
 extern int prefer_symlink_refs;
+extern int log_all_ref_updates;
 extern int warn_ambiguous_refs;
 extern int diff_rename_limit_default;
 extern int shared_repository;
config.c +5 -0
index 0248c6d..2ae6153 100644
@@ -269,6 +269,11 @@ int git_default_config(const char *var, 
 		return 0;
 	}
 
+	if (!strcmp(var, "core.logallrefupdates")) {
+		log_all_ref_updates = git_config_bool(var, value);
+		return 0;
+	}
+
 	if (!strcmp(var, "core.warnambiguousrefs")) {
 		warn_ambiguous_refs = git_config_bool(var, value);
 		return 0;
environment.c +1 -0
index 444c99e..2e79eab 100644
@@ -14,6 +14,7 @@ char git_default_name[MAX_GITNAME];
 int trust_executable_bit = 1;
 int assume_unchanged = 0;
 int prefer_symlink_refs = 0;
+int log_all_ref_updates = 0;
 int warn_ambiguous_refs = 1;
 int repository_format_version = 0;
 char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
refs.c +56 -0

77 lines not on this page · raw message

refs.h +1 -0
index b7e9df2..43831e9 100644
@@ -4,6 +4,7 @@ #define REFS_H
 struct ref_lock {
 	char *ref_file;
 	char *lock_file;
+	char *log_file;
 	unsigned char old_sha1[20];
 	int lock_fd;
 };
t/t1400-update-ref.sh new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
1.3.2.g7278