Set the GIT_DIR/description file during gerrit create-project
Otherwise the initial description of the project won't appear in the gitweb description file, which may confuse users who rely on the local gitweb installation to examine repositories. Signed-off-by: Shawn O. Pearce <sop@google.com> CC: Ulrik Sjölin <ulrik.sjolin@gmail.com>
This commit is contained in:
@@ -21,8 +21,12 @@ import com.google.gerrit.server.config.SitePath;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spearce.jgit.errors.RepositoryNotFoundException;
|
import org.spearce.jgit.errors.RepositoryNotFoundException;
|
||||||
import org.spearce.jgit.lib.Config;
|
import org.spearce.jgit.lib.Config;
|
||||||
|
import org.spearce.jgit.lib.Constants;
|
||||||
|
import org.spearce.jgit.lib.LockFile;
|
||||||
import org.spearce.jgit.lib.PersonIdent;
|
import org.spearce.jgit.lib.PersonIdent;
|
||||||
import org.spearce.jgit.lib.Repository;
|
import org.spearce.jgit.lib.Repository;
|
||||||
import org.spearce.jgit.lib.RepositoryCache;
|
import org.spearce.jgit.lib.RepositoryCache;
|
||||||
@@ -35,6 +39,7 @@ import java.io.IOException;
|
|||||||
/** Global server-side state for Gerrit. */
|
/** Global server-side state for Gerrit. */
|
||||||
@Singleton
|
@Singleton
|
||||||
public class GerritServer {
|
public class GerritServer {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(GerritServer.class);
|
||||||
private final File sitePath;
|
private final File sitePath;
|
||||||
private final Config gerritConfigFile;
|
private final Config gerritConfigFile;
|
||||||
private final File basepath;
|
private final File basepath;
|
||||||
@@ -124,6 +129,45 @@ public class GerritServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@code GIT_DIR/description} file for gitweb.
|
||||||
|
* <p>
|
||||||
|
* NB: This code should really be in JGit, as a member of the Repostiory
|
||||||
|
* object. Until it moves there, its here.
|
||||||
|
*
|
||||||
|
* @param name the repository name, relative to the base directory.
|
||||||
|
* @param description new description text for the repository.
|
||||||
|
*/
|
||||||
|
public void setProjectDescription(final String name, final String description) {
|
||||||
|
// Update git's description file, in case gitweb is being used
|
||||||
|
//
|
||||||
|
try {
|
||||||
|
final Repository e;
|
||||||
|
final LockFile f;
|
||||||
|
|
||||||
|
e = openRepository(name);
|
||||||
|
f = new LockFile(new File(e.getDirectory(), "description"));
|
||||||
|
if (f.lock()) {
|
||||||
|
String d = description;
|
||||||
|
if (d != null) {
|
||||||
|
d = d.trim();
|
||||||
|
if (d.length() > 0) {
|
||||||
|
d += "\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
d = "";
|
||||||
|
}
|
||||||
|
f.write(Constants.encode(d));
|
||||||
|
f.commit();
|
||||||
|
}
|
||||||
|
e.close();
|
||||||
|
} catch (RepositoryNotFoundException e) {
|
||||||
|
log.error("Cannot update description for " + name, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Cannot update description for " + name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isUnreasonableName(final String name) {
|
private boolean isUnreasonableName(final String name) {
|
||||||
if (name.length() == 0) return true; // no empty paths
|
if (name.length() == 0) return true; // no empty paths
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import org.spearce.jgit.errors.IncorrectObjectTypeException;
|
|||||||
import org.spearce.jgit.errors.MissingObjectException;
|
import org.spearce.jgit.errors.MissingObjectException;
|
||||||
import org.spearce.jgit.errors.RepositoryNotFoundException;
|
import org.spearce.jgit.errors.RepositoryNotFoundException;
|
||||||
import org.spearce.jgit.lib.Constants;
|
import org.spearce.jgit.lib.Constants;
|
||||||
import org.spearce.jgit.lib.LockFile;
|
|
||||||
import org.spearce.jgit.lib.ObjectId;
|
import org.spearce.jgit.lib.ObjectId;
|
||||||
import org.spearce.jgit.lib.Ref;
|
import org.spearce.jgit.lib.Ref;
|
||||||
import org.spearce.jgit.lib.RefUpdate;
|
import org.spearce.jgit.lib.RefUpdate;
|
||||||
@@ -55,7 +54,6 @@ import org.spearce.jgit.lib.Repository;
|
|||||||
import org.spearce.jgit.revwalk.ObjectWalk;
|
import org.spearce.jgit.revwalk.ObjectWalk;
|
||||||
import org.spearce.jgit.revwalk.RevCommit;
|
import org.spearce.jgit.revwalk.RevCommit;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -155,33 +153,8 @@ class ProjectAdminServiceImpl extends BaseServiceImplementation implements
|
|||||||
projectCache.evict(proj);
|
projectCache.evict(proj);
|
||||||
|
|
||||||
if (!wildProject.equals(projectName)) {
|
if (!wildProject.equals(projectName)) {
|
||||||
// Update git's description file, in case gitweb is being used
|
server.setProjectDescription(projectName.get(), update
|
||||||
//
|
.getDescription());
|
||||||
try {
|
|
||||||
final Repository e;
|
|
||||||
final LockFile f;
|
|
||||||
|
|
||||||
e = server.openRepository(proj.getName());
|
|
||||||
f = new LockFile(new File(e.getDirectory(), "description"));
|
|
||||||
if (f.lock()) {
|
|
||||||
String d = proj.getDescription();
|
|
||||||
if (d != null) {
|
|
||||||
d = d.trim();
|
|
||||||
if (d.length() > 0) {
|
|
||||||
d += "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
d = "";
|
|
||||||
}
|
|
||||||
f.write(Constants.encode(d));
|
|
||||||
f.commit();
|
|
||||||
}
|
|
||||||
e.close();
|
|
||||||
} catch (RepositoryNotFoundException e) {
|
|
||||||
log.error("Cannot update description for " + proj.getName(), e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Cannot update description for " + proj.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ final class AdminCreateProject extends BaseCommand {
|
|||||||
|
|
||||||
Repository repo = gs.createRepository(projectName);
|
Repository repo = gs.createRepository(projectName);
|
||||||
repo.create(true);
|
repo.create(true);
|
||||||
|
gs.setProjectDescription(projectName, projectDescription);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user