create-project: Bring back --permissions-only flag
If a project is permissions only, assign HEAD to point to refs/meta/config. This way gitweb view of the project shows the permissions history by default, and clients that clone the project are able to get a detached HEAD pointing to the current permission state, rather than an empty repository. Change-Id: I194bfef1af9d00268de9c503ea986879f1fbaff9
This commit is contained in:
@@ -13,6 +13,7 @@ SYNOPSIS
|
||||
[--branch <REF>] \
|
||||
[\--owner <GROUP> ...] \
|
||||
[\--parent <NAME>] \
|
||||
[\--permissions-only] \
|
||||
[\--description <DESC>] \
|
||||
[\--submit-type <TYPE>] \
|
||||
[\--use-content-merge] \
|
||||
@@ -70,6 +71,11 @@ repository.*.createGroup will be used. If they don't exist,
|
||||
through. If not specified, the parent is set to the default
|
||||
project `\-- All Projects \--`.
|
||||
|
||||
\--permissions-only::
|
||||
Create the project only to serve as a parent for other
|
||||
projects. The new project's Git repository will be
|
||||
initialized to have 'HEAD' point to 'refs/meta/config'.
|
||||
|
||||
\--description::
|
||||
Initial description of the project. If not specified,
|
||||
no description is stored.
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
/** A version of the database schema. */
|
||||
public abstract class SchemaVersion {
|
||||
/** The current schema version. */
|
||||
private static final Class<? extends SchemaVersion> C = Schema_55.class;
|
||||
private static final Class<? extends SchemaVersion> C = Schema_56.class;
|
||||
|
||||
public static class Module extends AbstractModule {
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Schema_56 extends SchemaVersion {
|
||||
private final LocalDiskRepositoryManager mgr;
|
||||
private final Set<String> keysOne;
|
||||
private final Set<String> keysTwo;
|
||||
|
||||
@Inject
|
||||
Schema_56(Provider<Schema_55> prior, LocalDiskRepositoryManager mgr) {
|
||||
super(prior);
|
||||
this.mgr = mgr;
|
||||
|
||||
keysOne = new HashSet<String>();
|
||||
keysTwo = new HashSet<String>();
|
||||
|
||||
keysOne.add(GitRepositoryManager.REF_CONFIG);
|
||||
keysTwo.add(GitRepositoryManager.REF_CONFIG);
|
||||
keysTwo.add(Constants.HEAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void migrateData(ReviewDb db, UpdateUI ui) {
|
||||
for (Project.NameKey name : mgr.list()) {
|
||||
Repository git;
|
||||
try {
|
||||
git = mgr.openRepository(name);
|
||||
} catch (RepositoryNotFoundException e) {
|
||||
ui.message("warning: Cannot open " + name.get());
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Map<String, Ref> all = git.getAllRefs();
|
||||
if (all.keySet().equals(keysOne) || all.keySet().equals(keysTwo)) {
|
||||
try {
|
||||
RefUpdate update = git.updateRef(Constants.HEAD);
|
||||
update.disableRefLog();
|
||||
update.link(GitRepositoryManager.REF_CONFIG);
|
||||
} catch (IOException err) {
|
||||
ui.message("warning: " + name.get() + ": Cannot update HEAD to "
|
||||
+ GitRepositoryManager.REF_CONFIG + ": " + err.getMessage());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
git.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,9 @@ final class CreateProject extends BaseCommand {
|
||||
@Option(name = "--parent", aliases = {"-p"}, metaVar = "NAME", usage = "parent project")
|
||||
private ProjectControl newParent;
|
||||
|
||||
@Option(name = "--permissions-only", usage = "create project for use only as parent")
|
||||
private boolean permissionsOnly;
|
||||
|
||||
@Option(name = "--description", aliases = {"-d"}, metaVar = "DESC", usage = "description of project")
|
||||
private String projectDescription = "";
|
||||
|
||||
@@ -141,20 +144,21 @@ final class CreateProject extends BaseCommand {
|
||||
validateParameters();
|
||||
nameKey = new Project.NameKey(projectName);
|
||||
|
||||
String head = permissionsOnly ? GitRepositoryManager.REF_CONFIG : branch;
|
||||
final Repository repo = repoManager.createRepository(nameKey);
|
||||
try {
|
||||
RefUpdate u = repo.updateRef(Constants.HEAD);
|
||||
u.disableRefLog();
|
||||
u.link(branch);
|
||||
u.link(head);
|
||||
|
||||
createProject();
|
||||
repoManager.setProjectDescription(nameKey, projectDescription);
|
||||
|
||||
if (createEmptyCommit) {
|
||||
if (!permissionsOnly && createEmptyCommit) {
|
||||
createEmptyCommit(repo, nameKey, branch);
|
||||
}
|
||||
|
||||
rq.replicateNewProject(nameKey, branch);
|
||||
rq.replicateNewProject(nameKey, head);
|
||||
} finally {
|
||||
repo.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user