]> source.dussan.org Git - jgit.git/commitdiff
Set config "extensions" option when converting ref storage format 38/154538/2
authorMatthias Sohn <matthias.sohn@sap.com>
Sat, 14 Dec 2019 21:45:09 +0000 (22:45 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 15 Dec 2019 09:15:46 +0000 (10:15 +0100)
When converting to reftable format the option extensions.refStorage must
be set to "reftable" [1]. When converting back to refdir format this
config option needs to be removed.

Introduce constants for refStorage config options, also for the
"reftree" format.

[1] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/master/Documentation/technical/reftable.md#Version-1

Change-Id: I190222fa5edc1ad7309daa9be17ca934ff7971e3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java

index 063600f4ea9923d24a4b14cec5e040e98c394934..da58bbcb06ad2cbeb87056a3b5b68d4b876a4cf0 100644 (file)
@@ -52,6 +52,7 @@ import java.util.List;
 import org.eclipse.jgit.internal.storage.reftree.RefTree;
 import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase;
 import org.eclipse.jgit.lib.CommitBuilder;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
 import org.eclipse.jgit.lib.ObjectReader;
@@ -133,8 +134,11 @@ class RebuildRefTree extends TextBuiltin {
 
                        if (enable && !(db.getRefDatabase() instanceof RefTreeDatabase)) {
                                StoredConfig cfg = db.getConfig();
-                               cfg.setInt("core", null, "repositoryformatversion", 1); //$NON-NLS-1$ //$NON-NLS-2$
-                               cfg.setString("extensions", null, "refStorage", "reftree"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                               cfg.setInt(ConfigConstants.CONFIG_CORE_SECTION, null,
+                                               ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 1);
+                               cfg.setString(ConfigConstants.CONFIG_EXTENSIONS_SECTION, null,
+                                               ConfigConstants.CONFIG_KEY_REFSTORAGE,
+                                               ConfigConstants.CONFIG_REFSTORAGE_REFTREE);
                                cfg.save();
                                errw.println("Enabled reftree."); //$NON-NLS-1$
                                errw.flush();
index 92d5d24d0b71d38c2dda9d2c9503179e5fd1a7ab..ff9b32c1cf2ad1eadebbd8b6e77c1559202409b0 100644 (file)
@@ -205,12 +205,15 @@ public class FileRepository extends Repository {
                                ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
 
                String reftype = repoConfig.getString(
-                               "extensions", null, "refStorage"); //$NON-NLS-1$ //$NON-NLS-2$
+                               ConfigConstants.CONFIG_EXTENSIONS_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_REFSTORAGE);
                if (repositoryFormatVersion >= 1 && reftype != null) {
-                       if (StringUtils.equalsIgnoreCase(reftype, "reftable")) { //$NON-NLS-1$
+                       if (StringUtils.equalsIgnoreCase(reftype,
+                                       ConfigConstants.CONFIG_REFSTORAGE_REFTABLE)) {
                                refs = new FileReftableDatabase(this,
                                                new File(getDirectory(), "refs")); //$NON-NLS-1$
-                       } else if (StringUtils.equalsIgnoreCase(reftype, "reftree")) { //$NON-NLS-1$
+                       } else if (StringUtils.equalsIgnoreCase(reftype,
+                                       ConfigConstants.CONFIG_REFSTORAGE_REFTREE)) {
                                refs = new RefTreeDatabase(this, new RefDirectory(this));
                        } else {
                                throw new IOException(JGitText.get().unknownRepositoryFormat);
@@ -721,6 +724,10 @@ public class FileRepository extends Repository {
                        FileUtils.delete(reftableDir,
                                        FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
                }
+
+               repoConfig.unset(ConfigConstants.CONFIG_EXTENSIONS_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_REFSTORAGE);
+               repoConfig.save();
        }
 
        @SuppressWarnings("nls")
@@ -774,6 +781,11 @@ public class FileRepository extends Repository {
 
                refs.close();
                refs = new FileReftableDatabase(this, refsFile);
+
+               repoConfig.setString(ConfigConstants.CONFIG_EXTENSIONS_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_REFSTORAGE,
+                               ConfigConstants.CONFIG_REFSTORAGE_REFTABLE);
+               repoConfig.save();
        }
 
        /**
index e0bd592194f809d429093ffd8bbb25a45cb84d6c..b6ffb8479650b7397a60f0759c4675f60e5ba851 100644 (file)
@@ -503,8 +503,31 @@ public final class ConfigConstants {
 
        /**
         * The "minRacyThreshold" key
-        *
         * @since 5.1.9
         */
        public static final String CONFIG_KEY_MIN_RACY_THRESHOLD = "minRacyThreshold";
+
+       /**
+        * The "extensions" section
+        * @since 5.7
+        */
+       public static final String CONFIG_EXTENSIONS_SECTION = "extensions";
+
+       /**
+        * The extensions.refStorage key
+        * @since 5.7
+        */
+       public static final String CONFIG_KEY_REFSTORAGE = "refStorage";
+
+       /**
+        * The "reftable" refStorage format
+        * @since 5.7
+        */
+       public static final String CONFIG_REFSTORAGE_REFTABLE = "reftable";
+
+       /**
+        * The "reftree" refStorage format
+        * @since 5.7
+        */
+       public static final String CONFIG_REFSTORAGE_REFTREE = "reftree";
 }