Write reflog for refs/meta/config changes

A reflog is currently only written for branches under refs/heads/.
The refs/meta/config branch has no reflog, but it contains important
information such as access rights, and hence it should have a reflog
as well.

A problem with getting a reflog for refs/meta/config is that JGit
(and also native Git) is not creating a reflog for this branch even
if core.logAllRefUpdates is set (see section 'core.logAllRefUpdates'
in [1]).

To make JGit write the reflog for the refs/meta/config branch the
reflog file for this branch must already exist. This is why the
LocalDiskRepositoryManager now creates an empty reflog file for
the refs/meta/config branch when a new repository is created.

In addition this change contains a schema migration that creates the
reflog file for the refs/meta/config branch in all existing
repositories, so that further updates get a reflog entry. This
migration is only possible if the repositories are stored on local
disk and is not executed if a GitRepositoryManager other than
LocalDiskRepositoryManager is used.

[1] https://www.kernel.org/pub/software/scm/git/docs/git-config.html#_variables

Change-Id: I9b6354cfa51263db10fb99e329b397b86f40156d
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-01-13 15:53:46 +01:00
parent b675732aaf
commit 5b5cad6522
4 changed files with 126 additions and 2 deletions

View File

@@ -45,7 +45,9 @@ import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.RawParseUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Objects;
/**
@@ -342,7 +344,12 @@ public abstract class VersionedMetaData {
RefUpdate ru = db.updateRef(refName);
ru.setExpectedOldObjectId(oldId);
ru.setNewObjectId(src);
ru.disableRefLog();
ru.setRefLogIdent(update.getCommitBuilder().getAuthor());
try (BufferedReader reader = new BufferedReader(
new StringReader(update.getCommitBuilder().getMessage()))) {
// read the subject line and use it as reflog message
ru.setRefLogMessage("commit: " + reader.readLine(), true);
}
inserter.flush();
RefUpdate.Result result = ru.update();
switch (result) {