Remove the branches table from the database
This table is actually unnecessary, and causes some confusion when setting up a new Gerrit installation, or a new project. Bug: issue 299 Change-Id: If19f3474a7b5e3adba3b09c470a01927fe46cb58 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -47,10 +47,7 @@ protocol, don't forget to create a `git-daemon-export-ok` file:
|
|||||||
Register Project
|
Register Project
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
At least two inserts are needed to register a project with Gerrit:
|
One insert is needed to register a project with Gerrit.
|
||||||
one to define the project exists, and another to define a branch
|
|
||||||
that changes can be uploaded to for code review. Additional branches
|
|
||||||
may be defined if desired.
|
|
||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
Note that the `.git` suffix is not typically included in the
|
Note that the `.git` suffix is not typically included in the
|
||||||
@@ -69,13 +66,6 @@ for a project named `project`.
|
|||||||
,'N'
|
,'N'
|
||||||
,'M'
|
,'M'
|
||||||
,'new/project');
|
,'new/project');
|
||||||
|
|
||||||
INSERT INTO branches
|
|
||||||
(branch_name
|
|
||||||
,project_name)
|
|
||||||
VALUES
|
|
||||||
('refs/heads/master'
|
|
||||||
,'new/project');
|
|
||||||
====
|
====
|
||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package com.google.gerrit.client.reviewdb;
|
|||||||
import com.google.gwtorm.client.Column;
|
import com.google.gwtorm.client.Column;
|
||||||
import com.google.gwtorm.client.StringKey;
|
import com.google.gwtorm.client.StringKey;
|
||||||
|
|
||||||
/** Registered line of development within a {@link Project}. */
|
/** Line of development within a {@link Project}. */
|
||||||
public final class Branch {
|
public final class Branch {
|
||||||
public static final String R_HEADS = "refs/heads/";
|
public static final String R_HEADS = "refs/heads/";
|
||||||
public static final String R_REFS = "refs/";
|
public static final String R_REFS = "refs/";
|
||||||
@@ -69,8 +69,8 @@ public final class Branch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(name = Column.NONE)
|
|
||||||
protected NameKey name;
|
protected NameKey name;
|
||||||
|
protected RevId revision;
|
||||||
|
|
||||||
protected Branch() {
|
protected Branch() {
|
||||||
}
|
}
|
||||||
@@ -90,4 +90,12 @@ public final class Branch {
|
|||||||
public String getShortName() {
|
public String getShortName() {
|
||||||
return name.getShortName();
|
return name.getShortName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RevId getRevision() {
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRevision(final RevId id) {
|
||||||
|
revision = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2008 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.client.reviewdb;
|
|
||||||
|
|
||||||
import com.google.gwtorm.client.Access;
|
|
||||||
import com.google.gwtorm.client.OrmException;
|
|
||||||
import com.google.gwtorm.client.PrimaryKey;
|
|
||||||
import com.google.gwtorm.client.Query;
|
|
||||||
import com.google.gwtorm.client.ResultSet;
|
|
||||||
|
|
||||||
public interface BranchAccess extends Access<Branch, Branch.NameKey> {
|
|
||||||
@PrimaryKey("name")
|
|
||||||
Branch get(Branch.NameKey name) throws OrmException;
|
|
||||||
|
|
||||||
@Query("WHERE name.projectName = ? ORDER BY name.branchName")
|
|
||||||
ResultSet<Branch> byProject(Project.NameKey key) throws OrmException;
|
|
||||||
}
|
|
||||||
@@ -87,9 +87,6 @@ public interface ReviewDb extends Schema {
|
|||||||
@Relation
|
@Relation
|
||||||
ProjectRightAccess projectRights();
|
ProjectRightAccess projectRights();
|
||||||
|
|
||||||
@Relation
|
|
||||||
BranchAccess branches();
|
|
||||||
|
|
||||||
@Relation
|
@Relation
|
||||||
ChangeAccess changes();
|
ChangeAccess changes();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.rpc.project;
|
|||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.Branch;
|
import com.google.gerrit.client.reviewdb.Branch;
|
||||||
import com.google.gerrit.client.reviewdb.Project;
|
import com.google.gerrit.client.reviewdb.Project;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
|
||||||
import com.google.gerrit.client.rpc.InvalidNameException;
|
import com.google.gerrit.client.rpc.InvalidNameException;
|
||||||
import com.google.gerrit.client.rpc.InvalidRevisionException;
|
import com.google.gerrit.client.rpc.InvalidRevisionException;
|
||||||
import com.google.gerrit.git.GitRepositoryManager;
|
import com.google.gerrit.git.GitRepositoryManager;
|
||||||
@@ -25,12 +24,9 @@ import com.google.gerrit.server.IdentifiedUser;
|
|||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.rpc.Handler;
|
import com.google.gerrit.server.rpc.Handler;
|
||||||
import com.google.gwtorm.client.OrmException;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
@@ -40,9 +36,10 @@ import org.eclipse.jgit.lib.RefUpdate;
|
|||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.revwalk.ObjectWalk;
|
import org.eclipse.jgit.revwalk.ObjectWalk;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class AddBranch extends Handler<List<Branch>> {
|
class AddBranch extends Handler<List<Branch>> {
|
||||||
@@ -59,7 +56,6 @@ class AddBranch extends Handler<List<Branch>> {
|
|||||||
private final IdentifiedUser identifiedUser;
|
private final IdentifiedUser identifiedUser;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final ReplicationQueue replication;
|
private final ReplicationQueue replication;
|
||||||
private final ReviewDb db;
|
|
||||||
|
|
||||||
private final Project.NameKey projectName;
|
private final Project.NameKey projectName;
|
||||||
private final String branchName;
|
private final String branchName;
|
||||||
@@ -69,7 +65,7 @@ class AddBranch extends Handler<List<Branch>> {
|
|||||||
AddBranch(final ProjectControl.Factory projectControlFactory,
|
AddBranch(final ProjectControl.Factory projectControlFactory,
|
||||||
final ListBranches.Factory listBranchesFactory,
|
final ListBranches.Factory listBranchesFactory,
|
||||||
final IdentifiedUser identifiedUser, final GitRepositoryManager repoManager,
|
final IdentifiedUser identifiedUser, final GitRepositoryManager repoManager,
|
||||||
final ReplicationQueue replication, final ReviewDb db,
|
final ReplicationQueue replication,
|
||||||
|
|
||||||
@Assisted Project.NameKey projectName,
|
@Assisted Project.NameKey projectName,
|
||||||
@Assisted("branchName") String branchName,
|
@Assisted("branchName") String branchName,
|
||||||
@@ -79,7 +75,6 @@ class AddBranch extends Handler<List<Branch>> {
|
|||||||
this.identifiedUser = identifiedUser;
|
this.identifiedUser = identifiedUser;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.replication = replication;
|
this.replication = replication;
|
||||||
this.db = db;
|
|
||||||
|
|
||||||
this.projectName = projectName;
|
this.projectName = projectName;
|
||||||
this.branchName = branchName;
|
this.branchName = branchName;
|
||||||
@@ -87,7 +82,7 @@ class AddBranch extends Handler<List<Branch>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Branch> call() throws NoSuchProjectException, OrmException,
|
public List<Branch> call() throws NoSuchProjectException,
|
||||||
InvalidNameException, InvalidRevisionException, IOException {
|
InvalidNameException, InvalidRevisionException, IOException {
|
||||||
final ProjectControl projectControl =
|
final ProjectControl projectControl =
|
||||||
projectControlFactory.validateFor(projectName, ProjectControl.OWNER
|
projectControlFactory.validateFor(projectName, ProjectControl.OWNER
|
||||||
@@ -141,9 +136,6 @@ class AddBranch extends Handler<List<Branch>> {
|
|||||||
repo.close();
|
repo.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Branch newBranch = new Branch(name);
|
|
||||||
db.branches().insert(Collections.singleton(newBranch));
|
|
||||||
|
|
||||||
return listBranchesFactory.create(projectName).call();
|
return listBranchesFactory.create(projectName).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,24 +16,21 @@ package com.google.gerrit.server.rpc.project;
|
|||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.Branch;
|
import com.google.gerrit.client.reviewdb.Branch;
|
||||||
import com.google.gerrit.client.reviewdb.Project;
|
import com.google.gerrit.client.reviewdb.Project;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
|
||||||
import com.google.gerrit.git.GitRepositoryManager;
|
import com.google.gerrit.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.git.ReplicationQueue;
|
import com.google.gerrit.git.ReplicationQueue;
|
||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.rpc.Handler;
|
import com.google.gerrit.server.rpc.Handler;
|
||||||
import com.google.gwtorm.client.OrmException;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
import org.eclipse.jgit.lib.RefUpdate;
|
import org.eclipse.jgit.lib.RefUpdate;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -49,21 +46,19 @@ class DeleteBranches extends Handler<Set<Branch.NameKey>> {
|
|||||||
private final ProjectControl.Factory projectControlFactory;
|
private final ProjectControl.Factory projectControlFactory;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final ReplicationQueue replication;
|
private final ReplicationQueue replication;
|
||||||
private final ReviewDb db;
|
|
||||||
|
|
||||||
private final Project.NameKey projectName;
|
private final Project.NameKey projectName;
|
||||||
private final Set<Branch.NameKey> toRemove;
|
private final Set<Branch.NameKey> toRemove;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DeleteBranches(final ProjectControl.Factory projectControlFactory,
|
DeleteBranches(final ProjectControl.Factory projectControlFactory,
|
||||||
final GitRepositoryManager repoManager, final ReplicationQueue replication,
|
final GitRepositoryManager repoManager,
|
||||||
final ReviewDb db,
|
final ReplicationQueue replication,
|
||||||
|
|
||||||
@Assisted Project.NameKey name, @Assisted Set<Branch.NameKey> toRemove) {
|
@Assisted Project.NameKey name, @Assisted Set<Branch.NameKey> toRemove) {
|
||||||
this.projectControlFactory = projectControlFactory;
|
this.projectControlFactory = projectControlFactory;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.replication = replication;
|
this.replication = replication;
|
||||||
this.db = db;
|
|
||||||
|
|
||||||
this.projectName = name;
|
this.projectName = name;
|
||||||
this.toRemove = toRemove;
|
this.toRemove = toRemove;
|
||||||
@@ -71,7 +66,7 @@ class DeleteBranches extends Handler<Set<Branch.NameKey>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Branch.NameKey> call() throws NoSuchProjectException,
|
public Set<Branch.NameKey> call() throws NoSuchProjectException,
|
||||||
RepositoryNotFoundException, OrmException {
|
RepositoryNotFoundException {
|
||||||
final ProjectControl projectControl =
|
final ProjectControl projectControl =
|
||||||
projectControlFactory.validateFor(projectName, ProjectControl.OWNER
|
projectControlFactory.validateFor(projectName, ProjectControl.OWNER
|
||||||
| ProjectControl.VISIBLE);
|
| ProjectControl.VISIBLE);
|
||||||
@@ -89,14 +84,10 @@ class DeleteBranches extends Handler<Set<Branch.NameKey>> {
|
|||||||
final Repository r = repoManager.openRepository(projectName.get());
|
final Repository r = repoManager.openRepository(projectName.get());
|
||||||
try {
|
try {
|
||||||
for (final Branch.NameKey branchKey : toRemove) {
|
for (final Branch.NameKey branchKey : toRemove) {
|
||||||
final Branch b = db.branches().get(branchKey);
|
final String refname = branchKey.get();
|
||||||
if (b == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final RefUpdate.Result result;
|
final RefUpdate.Result result;
|
||||||
try {
|
try {
|
||||||
final RefUpdate u = r.updateRef(b.getName());
|
final RefUpdate u = r.updateRef(refname);
|
||||||
u.setForceUpdate(true);
|
u.setForceUpdate(true);
|
||||||
result = u.delete();
|
result = u.delete();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -109,9 +100,8 @@ class DeleteBranches extends Handler<Set<Branch.NameKey>> {
|
|||||||
case NO_CHANGE:
|
case NO_CHANGE:
|
||||||
case FAST_FORWARD:
|
case FAST_FORWARD:
|
||||||
case FORCED:
|
case FORCED:
|
||||||
db.branches().delete(Collections.singleton(b));
|
|
||||||
deleted.add(branchKey);
|
deleted.add(branchKey);
|
||||||
replication.scheduleUpdate(projectName, b.getName());
|
replication.scheduleUpdate(projectName, refname);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REJECTED_CURRENT_BRANCH:
|
case REJECTED_CURRENT_BRANCH:
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.ssh.commands;
|
|||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.AccountGroup;
|
import com.google.gerrit.client.reviewdb.AccountGroup;
|
||||||
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||||
import com.google.gerrit.client.reviewdb.Branch;
|
|
||||||
import com.google.gerrit.client.reviewdb.Project;
|
import com.google.gerrit.client.reviewdb.Project;
|
||||||
import com.google.gerrit.client.reviewdb.ProjectRight;
|
import com.google.gerrit.client.reviewdb.ProjectRight;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||||
@@ -30,9 +29,9 @@ import com.google.gwtorm.client.OrmException;
|
|||||||
import com.google.gwtorm.client.Transaction;
|
import com.google.gwtorm.client.Transaction;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Option;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.kohsuke.args4j.Option;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -130,10 +129,6 @@ final class AdminCreateProject extends BaseCommand {
|
|||||||
pr.setMaxValue((short) 1);
|
pr.setMaxValue((short) 1);
|
||||||
pr.setMinValue((short) 1);
|
pr.setMinValue((short) 1);
|
||||||
db.projectRights().insert(Collections.singleton(pr), txn);
|
db.projectRights().insert(Collections.singleton(pr), txn);
|
||||||
|
|
||||||
final Branch newBranch =
|
|
||||||
new Branch(new Branch.NameKey(newProjectNameKey, branch));
|
|
||||||
db.branches().insert(Collections.singleton(newBranch), txn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateParameters() throws Failure {
|
private void validateParameters() throws Failure {
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ import com.google.gwtorm.client.OrmRunnable;
|
|||||||
import com.google.gwtorm.client.Transaction;
|
import com.google.gwtorm.client.Transaction;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Option;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
@@ -81,6 +78,9 @@ import org.eclipse.jgit.transport.ReceiveCommand;
|
|||||||
import org.eclipse.jgit.transport.ReceivePack;
|
import org.eclipse.jgit.transport.ReceivePack;
|
||||||
import org.eclipse.jgit.transport.ReceiveCommand.Result;
|
import org.eclipse.jgit.transport.ReceiveCommand.Result;
|
||||||
import org.eclipse.jgit.transport.ReceiveCommand.Type;
|
import org.eclipse.jgit.transport.ReceiveCommand.Type;
|
||||||
|
import org.kohsuke.args4j.Option;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -168,7 +168,7 @@ final class Receive extends AbstractGitCommand {
|
|||||||
private ReceivePack rp;
|
private ReceivePack rp;
|
||||||
private PersonIdent refLogIdent;
|
private PersonIdent refLogIdent;
|
||||||
private ReceiveCommand newChange;
|
private ReceiveCommand newChange;
|
||||||
private Branch destBranch;
|
private Branch.NameKey destBranch;
|
||||||
|
|
||||||
private final List<Change.Id> allNewChanges = new ArrayList<Change.Id>();
|
private final List<Change.Id> allNewChanges = new ArrayList<Change.Id>();
|
||||||
private final Map<Change.Id, ReplaceRequest> replaceByChange =
|
private final Map<Change.Id, ReplaceRequest> replaceByChange =
|
||||||
@@ -223,11 +223,9 @@ final class Receive extends AbstractGitCommand {
|
|||||||
if (isHead(c)) {
|
if (isHead(c)) {
|
||||||
switch (c.getType()) {
|
switch (c.getType()) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
insertBranchEntity(c);
|
|
||||||
autoCloseChanges(c);
|
autoCloseChanges(c);
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
deleteBranchEntity(c);
|
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
case UPDATE_NONFASTFORWARD:
|
case UPDATE_NONFASTFORWARD:
|
||||||
@@ -541,15 +539,30 @@ final class Receive extends AbstractGitCommand {
|
|||||||
destBranchName = Constants.R_HEADS + destBranchName;
|
destBranchName = Constants.R_HEADS + destBranchName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rp.getAdvertisedRefs().containsKey(destBranchName)) {
|
||||||
|
// We advertised the branch to the client so we know
|
||||||
|
// the branch exists. Target this branch for the upload.
|
||||||
|
//
|
||||||
|
destBranch = new Branch.NameKey(project.getNameKey(), destBranchName);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// We didn't advertise the branch, because it doesn't exist yet.
|
||||||
|
// Allow it anyway if HEAD is a symbolic reference to the name.
|
||||||
|
//
|
||||||
|
final String head;
|
||||||
try {
|
try {
|
||||||
destBranch =
|
head = repo.getFullBranch();
|
||||||
db.branches().get(
|
} catch (IOException e) {
|
||||||
new Branch.NameKey(project.getNameKey(), destBranchName));
|
log.error("Cannot read HEAD symref", e);
|
||||||
} catch (OrmException e) {
|
reject(cmd, "internal error");
|
||||||
log.error("Cannot lookup branch " + project + " " + destBranchName, e);
|
|
||||||
reject(cmd, "database error");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (head.equals(destBranchName)) {
|
||||||
|
destBranch = new Branch.NameKey(project.getNameKey(), destBranchName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (destBranch == null) {
|
if (destBranch == null) {
|
||||||
String n = destBranchName;
|
String n = destBranchName;
|
||||||
if (n.startsWith(Constants.R_HEADS))
|
if (n.startsWith(Constants.R_HEADS))
|
||||||
@@ -797,8 +810,7 @@ final class Receive extends AbstractGitCommand {
|
|||||||
|
|
||||||
final Transaction txn = db.beginTransaction();
|
final Transaction txn = db.beginTransaction();
|
||||||
final Change change =
|
final Change change =
|
||||||
new Change(changeKey, new Change.Id(db.nextChangeId()), me, destBranch
|
new Change(changeKey, new Change.Id(db.nextChangeId()), me, destBranch);
|
||||||
.getNameKey());
|
|
||||||
final PatchSet ps = new PatchSet(change.newPatchSetId());
|
final PatchSet ps = new PatchSet(change.newPatchSetId());
|
||||||
ps.setCreatedOn(change.getCreatedOn());
|
ps.setCreatedOn(change.getCreatedOn());
|
||||||
ps.setUploader(me);
|
ps.setUploader(me);
|
||||||
@@ -1240,46 +1252,6 @@ final class Receive extends AbstractGitCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertBranchEntity(final ReceiveCommand c) {
|
|
||||||
try {
|
|
||||||
final Branch.NameKey nameKey =
|
|
||||||
new Branch.NameKey(project.getNameKey(), c.getRefName());
|
|
||||||
final Branch b = new Branch(nameKey);
|
|
||||||
db.branches().insert(Collections.singleton(b));
|
|
||||||
} catch (OrmException e) {
|
|
||||||
final String msg = "database failure creating " + c.getRefName();
|
|
||||||
log.error(msg, e);
|
|
||||||
|
|
||||||
try {
|
|
||||||
err.write(("remote error: " + msg + "\n").getBytes("UTF-8"));
|
|
||||||
err.flush();
|
|
||||||
} catch (IOException e2) {
|
|
||||||
// Ignore errors writing to the client
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteBranchEntity(final ReceiveCommand c) {
|
|
||||||
try {
|
|
||||||
final Branch.NameKey nameKey =
|
|
||||||
new Branch.NameKey(project.getNameKey(), c.getRefName());
|
|
||||||
final Branch b = db.branches().get(nameKey);
|
|
||||||
if (b != null) {
|
|
||||||
db.branches().delete(Collections.singleton(b));
|
|
||||||
}
|
|
||||||
} catch (OrmException e) {
|
|
||||||
final String msg = "database failure deleting " + c.getRefName();
|
|
||||||
log.error(msg, e);
|
|
||||||
|
|
||||||
try {
|
|
||||||
err.write(("remote error: " + msg + "\n").getBytes("UTF-8"));
|
|
||||||
err.flush();
|
|
||||||
} catch (IOException e2) {
|
|
||||||
// Ignore errors writing to the client
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void autoCloseChanges(final ReceiveCommand cmd) {
|
private void autoCloseChanges(final ReceiveCommand cmd) {
|
||||||
final RevWalk rw = rp.getRevWalk();
|
final RevWalk rw = rp.getRevWalk();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -29,4 +29,6 @@ UPDATE account_groups SET group_type = 'INTERNAL' WHERE group_type IS NULL;
|
|||||||
ALTER TABLE account_groups MODIFY group_type VARCHAR(8) NOT NULL;
|
ALTER TABLE account_groups MODIFY group_type VARCHAR(8) NOT NULL;
|
||||||
ALTER TABLE account_groups DROP automatic_membership;
|
ALTER TABLE account_groups DROP automatic_membership;
|
||||||
|
|
||||||
|
DROP TABLE branches;
|
||||||
|
|
||||||
UPDATE schema_version SET version_nbr = 19;
|
UPDATE schema_version SET version_nbr = 19;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ UPDATE account_groups SET group_type = 'INTERNAL' WHERE group_type IS NULL;
|
|||||||
ALTER TABLE account_groups ALTER group_type SET NOT NULL;
|
ALTER TABLE account_groups ALTER group_type SET NOT NULL;
|
||||||
ALTER TABLE account_groups DROP automatic_membership;
|
ALTER TABLE account_groups DROP automatic_membership;
|
||||||
|
|
||||||
|
DROP TABLE branches;
|
||||||
|
|
||||||
UPDATE schema_version SET version_nbr = 19;
|
UPDATE schema_version SET version_nbr = 19;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
Reference in New Issue
Block a user