Update to JGit 0.8.4.240-g8e9cc82

Change-Id: Id43a1846b31bb1aad40ca0ae295a268fcacd162f
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-08-05 17:57:35 -07:00
parent 91c1532130
commit 5f11b2954c
26 changed files with 255 additions and 118 deletions

View File

@@ -1313,6 +1313,32 @@ Common examples:
safe = true safe = true
---- ----
[[pack]]Section pack
~~~~~~~~~~~~~~~~~~~~
Global settings controlling how Gerrit Code Review creates pack
streams for Git clients running clone, fetch, or pull. Most of these
variables are per-client request, and thus should be carefully set
given the expected concurrent request load and available CPU and
memory resources.
[[pack.deltacompression]]pack.deltacompression::
+
If true, delta compression between objects is enabled. This may
result in a smaller overall transfer for the client, but requires
more server memory and CPU time.
+
False (off) by default, matching Gerrit Code Review 2.1.4.
[[pack.threads]]pack.threads::
+
Maximum number of threads to use for delta compression (if enabled).
This is per-client request. If set to 0 then the number of CPUs is
auto-detected and one thread per CPU is used, per client request.
+
By default, 1.
[[repository]]Section repository [[repository]]Section repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Repositories in this sense are the same as projects. Repositories in this sense are the same as projects.

View File

@@ -23,6 +23,7 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.CanonicalWebUrl; import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ReceiveCommits; import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.server.git.VisibleRefFilter; import com.google.gerrit.server.git.VisibleRefFilter;
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;
@@ -40,6 +41,7 @@ import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.http.server.resolver.UploadPackFactory; import org.eclipse.jgit.http.server.resolver.UploadPackFactory;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.pack.PackConfig;
import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.UploadPack;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -175,10 +177,12 @@ public class ProjectServlet extends GitServlet {
static class Upload implements UploadPackFactory { static class Upload implements UploadPackFactory {
private final Provider<ReviewDb> db; private final Provider<ReviewDb> db;
private final PackConfig packConfig;
@Inject @Inject
Upload(final Provider<ReviewDb> db) { Upload(final Provider<ReviewDb> db, final TransferConfig tc) {
this.db = db; this.db = db;
this.packConfig = tc.getPackConfig();
} }
@Override @Override
@@ -188,6 +192,7 @@ public class ProjectServlet extends GitServlet {
// //
ProjectControl pc = getProjectControl(req); ProjectControl pc = getProjectControl(req);
UploadPack up = new UploadPack(repo); UploadPack up = new UploadPack(repo);
up.setPackConfig(packConfig);
if (!pc.allRefsAreVisible()) { if (!pc.allRefsAreVisible()) {
up.setRefFilter(new VisibleRefFilter(repo, pc, db.get())); up.setRefFilter(new VisibleRefFilter(repo, pc, db.get()));
} }

View File

@@ -33,14 +33,16 @@ import eu.medsea.mimeutil.MimeType;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.NB;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.security.MessageDigest; import java.security.MessageDigest;
@@ -162,7 +164,7 @@ public class CatServlet extends HttpServlet {
return; return;
} }
final byte[] blobData; final ObjectLoader blobLoader;
final RevCommit fromCommit; final RevCommit fromCommit;
final String suffix; final String suffix;
final String path = patchKey.getFileName(); final String path = patchKey.getFileName();
@@ -196,7 +198,7 @@ public class CatServlet extends HttpServlet {
} }
if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) { if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) {
blobData = repo.openBlob(tw.getObjectId(0)).getCachedBytes(); blobLoader = repo.open(tw.getObjectId(0), Constants.OBJ_BLOB);
} else { } else {
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@@ -214,14 +216,20 @@ public class CatServlet extends HttpServlet {
repo.close(); repo.close();
} }
final byte[] raw =
blobLoader.isLarge() ? null : blobLoader.getCachedBytes();
final long when = fromCommit.getCommitTime() * 1000L; final long when = fromCommit.getCommitTime() * 1000L;
MimeType contentType = registry.getMimeType(path, blobData);
final byte[] outData;
if (registry.isSafeInline(contentType)) { rsp.setDateHeader("Last-Modified", when);
outData = blobData; rsp.setDateHeader("Expires", 0L);
rsp.setHeader("Pragma", "no-cache");
rsp.setHeader("Cache-Control", "no-cache, must-revalidate");
} else { OutputStream out;
ZipOutputStream zo;
final MimeType contentType = registry.getMimeType(path, raw);
if (!registry.isSafeInline(contentType)) {
// The content may not be safe to transmit inline, as a browser might // The content may not be safe to transmit inline, as a browser might
// interpret it as HTML or JavaScript hosted by this site. Such code // interpret it as HTML or JavaScript hosted by this site. Such code
// might then run in the site's security domain, and may be able to use // might then run in the site's security domain, and may be able to use
@@ -230,31 +238,51 @@ public class CatServlet extends HttpServlet {
// Usually, wrapping the content into a ZIP file forces the browser to // Usually, wrapping the content into a ZIP file forces the browser to
// save the content to the local system instead. // save the content to the local system instead.
// //
final ByteArrayOutputStream zip = new ByteArrayOutputStream();
final ZipOutputStream zo = new ZipOutputStream(zip);
final ZipEntry e = new ZipEntry(safeFileName(path, rand(req, suffix)));
e.setComment(fromCommit.name() + ":" + path);
e.setSize(blobData.length);
e.setTime(when);
zo.putNextEntry(e);
zo.write(blobData);
zo.closeEntry();
zo.close();
outData = zip.toByteArray();
contentType = ZIP;
rsp.setContentType(ZIP.toString());
rsp.setHeader("Content-Disposition", "attachment; filename=\"" rsp.setHeader("Content-Disposition", "attachment; filename=\""
+ safeFileName(path, suffix) + ".zip" + "\""); + safeFileName(path, suffix) + ".zip" + "\"");
zo = new ZipOutputStream(rsp.getOutputStream());
final ZipEntry e = new ZipEntry(safeFileName(path, rand(req, suffix)));
e.setComment(fromCommit.name() + ":" + path);
e.setSize(blobLoader.getSize());
e.setTime(when);
zo.putNextEntry(e);
out = zo;
} else {
rsp.setContentType(contentType.toString());
rsp.setHeader("Content-Length", "" + blobLoader.getSize());
out = rsp.getOutputStream();
zo = null;
} }
rsp.setContentType(contentType.toString()); if (raw != null) {
rsp.setContentLength(outData.length); out.write(raw);
rsp.setDateHeader("Last-Modified", when); } else {
rsp.setDateHeader("Expires", 0L); InputStream in = blobLoader.openStream();
rsp.setHeader("Pragma", "no-cache"); try {
rsp.setHeader("Cache-Control", "no-cache, must-revalidate"); byte[] buf = new byte[8192];
rsp.getOutputStream().write(outData); for (;;) {
int n = in.read(buf);
if (0 < n) {
out.write(buf, 0, n);
} else {
break;
}
}
} finally {
in.close();
}
}
if (zo != null) {
zo.closeEntry();
}
out.close();
} }
private static String safeFileName(String fileName, final String suffix) { private static String safeFileName(String fileName, final String suffix) {

View File

@@ -40,7 +40,6 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
@@ -377,14 +376,7 @@ class PatchScriptBuilder {
srcContent = other.srcContent; srcContent = other.srcContent;
} else if (mode.getObjectType() == Constants.OBJ_BLOB) { } else if (mode.getObjectType() == Constants.OBJ_BLOB) {
final ObjectLoader ldr = db.openObject(id); srcContent = Text.asByteArray(db.open(id, Constants.OBJ_BLOB));
if (ldr == null) {
throw new MissingObjectException(id, Constants.TYPE_BLOB);
}
srcContent = ldr.getCachedBytes();
if (ldr.getType() != Constants.OBJ_BLOB) {
throw new IncorrectObjectTypeException(id, Constants.TYPE_BLOB);
}
} else { } else {
srcContent = Text.NO_BYTES; srcContent = Text.NO_BYTES;

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package org.eclipse.jgit.lib; package org.eclipse.jgit.storage.file;
// Hack to obtain visibility to package level methods only. // Hack to obtain visibility to package level methods only.
// These aren't yet part of the public JGit API. // These aren't yet part of the public JGit API.

View File

@@ -19,7 +19,8 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import java.io.IOException; import java.io.IOException;
@@ -40,8 +41,8 @@ public class InitFlags {
@Inject @Inject
InitFlags(final SitePaths site) throws IOException, ConfigInvalidException { InitFlags(final SitePaths site) throws IOException, ConfigInvalidException {
cfg = new FileBasedConfig(site.gerrit_config); cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
sec = new FileBasedConfig(site.secure_config); sec = new FileBasedConfig(site.secure_config, FS.DETECTED);
cfg.load(); cfg.load();
sec.load(); sec.load();

View File

@@ -17,15 +17,16 @@ package com.google.gerrit.pgm.init;
import com.google.gerrit.pgm.util.Die; import com.google.gerrit.pgm.util.Die;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.lib.LockFile; import org.eclipse.jgit.storage.file.LockFile;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
import java.io.OutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@@ -48,7 +49,7 @@ class InitUtil {
static void saveSecure(final FileBasedConfig sec) throws IOException { static void saveSecure(final FileBasedConfig sec) throws IOException {
final byte[] out = Constants.encode(sec.toText()); final byte[] out = Constants.encode(sec.toText());
final File path = sec.getFile(); final File path = sec.getFile();
final LockFile lf = new LockFile(path); final LockFile lf = new LockFile(path, FS.DETECTED);
if (!lf.lock()) { if (!lf.lock()) {
throw new IOException("Cannot lock " + path); throw new IOException("Cannot lock " + path);
} }
@@ -169,7 +170,7 @@ class InitUtil {
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {
try { try {
dst.getParentFile().mkdirs(); dst.getParentFile().mkdirs();
LockFile lf = new LockFile(dst); LockFile lf = new LockFile(dst, FS.DETECTED);
if (!lf.lock()) { if (!lf.lock()) {
throw new IOException("Cannot lock " + dst); throw new IOException("Cannot lock " + dst);
} }

View File

@@ -26,7 +26,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@@ -21,6 +21,6 @@ import java.io.IOException;
public abstract class InitTestCase extends LocalDiskRepositoryTestCase { public abstract class InitTestCase extends LocalDiskRepositoryTestCase {
protected File newSitePath() throws IOException { protected File newSitePath() throws IOException {
return new File(createWorkRepository().getWorkDir(), "test_site"); return new File(createWorkRepository().getWorkTree(), "test_site");
} }
} }

View File

@@ -24,7 +24,8 @@ import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.config.SitePaths;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import java.io.File; import java.io.File;
@@ -50,7 +51,9 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
} }
} }
FileBasedConfig old = new FileBasedConfig(new File(p, "gerrit.config")); FileBasedConfig old =
new FileBasedConfig(new File(p, "gerrit.config"), FS.DETECTED);
old.setString("ldap", null, "username", "ldap.user"); old.setString("ldap", null, "username", "ldap.user");
old.setString("ldap", null, "password", "ldap.s3kr3t"); old.setString("ldap", null, "password", "ldap.s3kr3t");
@@ -84,8 +87,8 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
new String(IO.readFully(new File(site.etc_dir, n)), "UTF-8")); new String(IO.readFully(new File(site.etc_dir, n)), "UTF-8"));
} }
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config); FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
FileBasedConfig sec = new FileBasedConfig(site.secure_config); FileBasedConfig sec = new FileBasedConfig(site.secure_config, FS.DETECTED);
cfg.load(); cfg.load();
sec.load(); sec.load();

View File

@@ -46,6 +46,7 @@ import com.google.gerrit.server.git.PushAllProjectsOp;
import com.google.gerrit.server.git.PushReplication; import com.google.gerrit.server.git.PushReplication;
import com.google.gerrit.server.git.ReloadSubmitQueueOp; import com.google.gerrit.server.git.ReloadSubmitQueueOp;
import com.google.gerrit.server.git.ReplicationQueue; import com.google.gerrit.server.git.ReplicationQueue;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.server.git.WorkQueue; import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.mail.EmailSender; import com.google.gerrit.server.mail.EmailSender;
import com.google.gerrit.server.mail.FromAddressGenerator; import com.google.gerrit.server.mail.FromAddressGenerator;
@@ -123,6 +124,7 @@ public class GerritGlobalModule extends FactoryModule {
bind(WorkQueue.class); bind(WorkQueue.class);
bind(ToolsCatalog.class); bind(ToolsCatalog.class);
bind(EventFactory.class); bind(EventFactory.class);
bind(TransferConfig.class);
bind(ReplicationQueue.class).to(PushReplication.class).in(SINGLETON); bind(ReplicationQueue.class).to(PushReplication.class).in(SINGLETON);
factory(PushAllProjectsOp.Factory.class); factory(PushAllProjectsOp.Factory.class);

View File

@@ -20,7 +20,8 @@ import com.google.inject.ProvisionException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ class GerritServerConfigProvider implements Provider<Config> {
@Override @Override
public Config get() { public Config get() {
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config); FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
if (!cfg.getFile().exists()) { if (!cfg.getFile().exists()) {
log.info("No " + site.gerrit_config.getAbsolutePath() log.info("No " + site.gerrit_config.getAbsolutePath()
@@ -57,7 +58,7 @@ class GerritServerConfigProvider implements Provider<Config> {
} }
if (site.secure_config.exists()) { if (site.secure_config.exists()) {
cfg = new FileBasedConfig(cfg, site.secure_config); cfg = new FileBasedConfig(cfg, site.secure_config, FS.DETECTED);
try { try {
cfg.load(); cfg.load();
} catch (IOException e) { } catch (IOException e) {

View File

@@ -23,12 +23,12 @@ import com.google.inject.Singleton;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.WindowCache;
import org.eclipse.jgit.lib.WindowCacheConfig;
import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.LockFile;
import org.eclipse.jgit.storage.file.WindowCache;
import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
@@ -164,7 +164,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
final LockFile f; final LockFile f;
e = openRepository(name); e = openRepository(name);
f = new LockFile(new File(e.getDirectory(), "description")); f = new LockFile(new File(e.getDirectory(), "description"), FS.DETECTED);
if (f.lock()) { if (f.lock()) {
String d = description; String d = description;
if (d != null) { if (d != null) {

View File

@@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Commit; import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
@@ -76,6 +77,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -267,7 +269,7 @@ public class MergeOp {
branchTip = null; branchTip = null;
} }
for (final Ref r : rw.getRepository().getAllRefs().values()) { for (final Ref r : db.getAllRefs().values()) {
if (r.getName().startsWith(Constants.R_HEADS) if (r.getName().startsWith(Constants.R_HEADS)
|| r.getName().startsWith(Constants.R_TAGS)) { || r.getName().startsWith(Constants.R_TAGS)) {
try { try {
@@ -554,8 +556,7 @@ public class MergeOp {
mergeCommit.setCommitter(myIdent); mergeCommit.setCommitter(myIdent);
mergeCommit.setMessage(msgbuf.toString()); mergeCommit.setMessage(msgbuf.toString());
final ObjectId id = m.getObjectWriter().writeCommit(mergeCommit); mergeTip = (CodeReviewCommit) rw.parseCommit(commit(m, mergeCommit));
mergeTip = (CodeReviewCommit) rw.parseCommit(id);
} }
private void markCleanMerges() throws MergeException { private void markCleanMerges() throws MergeException {
@@ -796,7 +797,7 @@ public class MergeOp {
mergeCommit.setCommitter(toCommitterIdent(submitAudit)); mergeCommit.setCommitter(toCommitterIdent(submitAudit));
mergeCommit.setMessage(msgbuf.toString()); mergeCommit.setMessage(msgbuf.toString());
final ObjectId id = m.getObjectWriter().writeCommit(mergeCommit); final ObjectId id = commit(m, mergeCommit);
final CodeReviewCommit newCommit = (CodeReviewCommit) rw.parseCommit(id); final CodeReviewCommit newCommit = (CodeReviewCommit) rw.parseCommit(id);
newCommit.copyFrom(n); newCommit.copyFrom(n);
newCommit.statusCode = CommitMergeStatus.CLEAN_PICK; newCommit.statusCode = CommitMergeStatus.CLEAN_PICK;
@@ -806,6 +807,18 @@ public class MergeOp {
setRefLogIdent(submitAudit); setRefLogIdent(submitAudit);
} }
private ObjectId commit(final Merger m, final Commit mergeCommit)
throws IOException, UnsupportedEncodingException {
ObjectInserter oi = m.getObjectInserter();
try {
ObjectId id = oi.insert(Constants.OBJ_COMMIT, oi.format(mergeCommit));
oi.flush();
return id;
} finally {
oi.release();
}
}
private boolean contains(List<FooterLine> footers, FooterKey key, String val) { private boolean contains(List<FooterLine> footers, FooterKey key, String val) {
for (final FooterLine line : footers) { for (final FooterLine line : footers) {
if (line.matches(key) && val.equals(line.getValue())) { if (line.matches(key) && val.equals(line.getValue())) {

View File

@@ -37,7 +37,7 @@ import com.jcraft.jsch.Session;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.transport.OpenSshConfig; import org.eclipse.jgit.transport.OpenSshConfig;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
@@ -129,7 +129,8 @@ public class PushReplication implements ReplicationQueue {
private List<ReplicationConfig> allConfigs(final SitePaths site) private List<ReplicationConfig> allConfigs(final SitePaths site)
throws ConfigInvalidException, IOException { throws ConfigInvalidException, IOException {
final FileBasedConfig cfg = new FileBasedConfig(site.replication_config); final FileBasedConfig cfg =
new FileBasedConfig(site.replication_config, FS.DETECTED);
if (!cfg.getFile().exists()) { if (!cfg.getFile().exists()) {
log.warn("No " + cfg.getFile() + "; not replicating"); log.warn("No " + cfg.getFile() + "; not replicating");

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package com.google.gerrit.sshd; package com.google.gerrit.server.git;
import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.GerritServerConfig;
@@ -20,21 +20,32 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.pack.PackConfig;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Singleton @Singleton
public class TransferConfig { public class TransferConfig {
private final int timeout; private final int timeout;
private final PackConfig packConfig;
@Inject @Inject
TransferConfig(@GerritServerConfig final Config cfg) { TransferConfig(@GerritServerConfig final Config cfg) {
timeout = (int) ConfigUtil.getTimeUnit(cfg, "transfer", null, "timeout", // timeout = (int) ConfigUtil.getTimeUnit(cfg, "transfer", null, "timeout", //
0, TimeUnit.SECONDS); 0, TimeUnit.SECONDS);
packConfig = new PackConfig();
packConfig.setDeltaCompress(false);
packConfig.setThreads(1);
packConfig.fromConfig(cfg);
} }
/** @return configured timeout, in seconds. 0 if the timeout is infinite. */ /** @return configured timeout, in seconds. 0 if the timeout is infinite. */
public int getTimeout() { public int getTimeout() {
return timeout; return timeout;
} }
public PackConfig getPackConfig() {
return packConfig;
}
} }

View File

@@ -23,7 +23,6 @@ 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;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
@@ -105,11 +104,6 @@ public class PatchFile {
if (tw.getFileMode(0).getObjectType() != Constants.OBJ_BLOB) { if (tw.getFileMode(0).getObjectType() != Constants.OBJ_BLOB) {
return Text.EMPTY; return Text.EMPTY;
} }
final ObjectId id = tw.getObjectId(0); return new Text(repo.open(tw.getObjectId(0), Constants.OBJ_BLOB));
final ObjectLoader ldr = repo.openObject(id);
if (ldr == null) {
throw new MissingObjectException(id, Constants.TYPE_BLOB);
}
return new Text(ldr.getCachedBytes());
} }
} }

View File

@@ -87,13 +87,14 @@ import org.eclipse.jgit.diff.RawTextIgnoreTrailingWhitespace;
import org.eclipse.jgit.diff.RawTextIgnoreWhitespaceChange; import org.eclipse.jgit.diff.RawTextIgnoreWhitespaceChange;
import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.diff.RenameDetector;
import org.eclipse.jgit.diff.ReplaceEdit; import org.eclipse.jgit.diff.ReplaceEdit;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.patch.FileHeader; import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.FileHeader.PatchType; import org.eclipse.jgit.patch.FileHeader.PatchType;
@@ -271,8 +272,8 @@ public class PatchListCacheImpl implements PatchListCache {
if (e.getType() == Edit.Type.REPLACE) { if (e.getType() == Edit.Type.REPLACE) {
if (aContent == null) { if (aContent == null) {
edits = new ArrayList<Edit>(edits); edits = new ArrayList<Edit>(edits);
aContent = read(repo, fileHeader.getOldName(), aTree); aContent = read(repo, fileHeader.getOldPath(), aTree);
bContent = read(repo, fileHeader.getNewName(), bTree); bContent = read(repo, fileHeader.getNewPath(), bTree);
combineLineEdits(edits, aContent, bContent); combineLineEdits(edits, aContent, bContent);
i = -1; // restart the entire scan after combining lines. i = -1; // restart the entire scan after combining lines.
continue; continue;
@@ -535,8 +536,10 @@ public class PatchListCacheImpl implements PatchListCache {
if (tw == null || tw.getFileMode(0).getObjectType() != Constants.OBJ_BLOB) { if (tw == null || tw.getFileMode(0).getObjectType() != Constants.OBJ_BLOB) {
return Text.EMPTY; return Text.EMPTY;
} }
ObjectLoader ldr = repo.openObject(tw.getObjectId(0)); ObjectLoader ldr;
if (ldr == null) { try {
ldr = repo.open(tw.getObjectId(0), Constants.OBJ_BLOB);
} catch (MissingObjectException notFound) {
return Text.EMPTY; return Text.EMPTY;
} }
return new Text(ldr.getCachedBytes()); return new Text(ldr.getCachedBytes());
@@ -560,7 +563,14 @@ public class PatchListCacheImpl implements PatchListCache {
} }
private static ObjectId emptyTree(final Repository repo) throws IOException { private static ObjectId emptyTree(final Repository repo) throws IOException {
return new ObjectWriter(repo).writeCanonicalTree(new byte[0]); ObjectInserter oi = repo.newObjectInserter();
try {
ObjectId id = oi.insert(Constants.OBJ_TREE, new byte[] {});
oi.flush();
return id;
} finally {
oi.release();
}
} }
} }
} }

View File

@@ -67,19 +67,19 @@ public class PatchListEntry {
switch (changeType) { switch (changeType) {
case DELETED: case DELETED:
oldName = null; oldName = null;
newName = hdr.getOldName(); newName = hdr.getOldPath();
break; break;
case ADDED: case ADDED:
case MODIFIED: case MODIFIED:
oldName = null; oldName = null;
newName = hdr.getNewName(); newName = hdr.getNewPath();
break; break;
case COPIED: case COPIED:
case RENAMED: case RENAMED:
oldName = hdr.getOldName(); oldName = hdr.getOldPath();
newName = hdr.getNewName(); newName = hdr.getNewPath();
break; break;
default: default:

View File

@@ -15,11 +15,17 @@
package com.google.gerrit.server.patch; package com.google.gerrit.server.patch;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
import org.mozilla.universalchardet.UniversalDetector; import org.mozilla.universalchardet.UniversalDetector;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@@ -27,6 +33,7 @@ import java.nio.charset.UnsupportedCharsetException;
public class Text extends RawText { public class Text extends RawText {
private static final Logger log = LoggerFactory.getLogger(Text.class); private static final Logger log = LoggerFactory.getLogger(Text.class);
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
private static final int bigFileThreshold = 10 * 1024 * 1024;
public static final byte[] NO_BYTES = {}; public static final byte[] NO_BYTES = {};
public static final Text EMPTY = new Text(NO_BYTES); public static final Text EMPTY = new Text(NO_BYTES);
@@ -35,6 +42,36 @@ public class Text extends RawText {
return new String(content, charset(content, encoding)); return new String(content, charset(content, encoding));
} }
public static byte[] asByteArray(ObjectLoader ldr)
throws MissingObjectException, LargeObjectException, IOException {
if (!ldr.isLarge()) {
return ldr.getCachedBytes();
}
long sz = ldr.getSize();
if (sz > bigFileThreshold || sz > Integer.MAX_VALUE)
throw new LargeObjectException();
byte[] buf;
try {
buf = new byte[(int) sz];
} catch (OutOfMemoryError noMemory) {
LargeObjectException e;
e = new LargeObjectException();
e.initCause(noMemory);
throw e;
}
InputStream in = ldr.openStream();
try {
IO.readFully(in, buf, 0, buf.length);
} finally {
in.close();
}
return buf;
}
private static Charset charset(byte[] content, String encoding) { private static Charset charset(byte[] content, String encoding) {
if (encoding == null) { if (encoding == null) {
UniversalDetector d = new UniversalDetector(null); UniversalDetector d = new UniversalDetector(null);
@@ -64,6 +101,11 @@ public class Text extends RawText {
super(r); super(r);
} }
public Text(ObjectLoader ldr) throws MissingObjectException,
LargeObjectException, IOException {
this(asByteArray(ldr));
}
public byte[] getContent() { public byte[] getContent() {
return content; return content;
} }

View File

@@ -23,7 +23,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter; import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
@@ -144,7 +144,7 @@ public class CommitMsgHookTest extends HookTestCase {
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",// "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
call("a\n")); call("a\n"));
final DirCacheBuilder builder = DirCache.lock(repository).builder(); final DirCacheBuilder builder = repository.lockDirCache().builder();
builder.add(file("A")); builder.add(file("A"));
assertTrue(builder.commit()); assertTrue(builder.commit());
@@ -386,20 +386,27 @@ public class CommitMsgHookTest extends HookTestCase {
} }
private DirCacheEntry file(final String name) throws IOException { private DirCacheEntry file(final String name) throws IOException {
final ObjectInserter oi = repository.newObjectInserter();
try {
final DirCacheEntry e = new DirCacheEntry(name); final DirCacheEntry e = new DirCacheEntry(name);
e.setFileMode(FileMode.REGULAR_FILE); e.setFileMode(FileMode.REGULAR_FILE);
e.setObjectId(writer().writeBlob(Constants.encode(name))); e.setObjectId(oi.insert(Constants.OBJ_BLOB, Constants.encode(name)));
oi.flush();
return e; return e;
} finally {
oi.release();
}
} }
private void setHEAD() throws Exception { private void setHEAD() throws Exception {
final ObjectWriter ow = writer(); final ObjectInserter oi = repository.newObjectInserter();
try {
final Commit commit = new Commit(repository); final Commit commit = new Commit(repository);
commit.setTreeId(DirCache.newInCore().writeTree(ow)); commit.setTreeId(DirCache.newInCore().writeTree(oi));
commit.setAuthor(author); commit.setAuthor(author);
commit.setCommitter(committer); commit.setCommitter(committer);
commit.setMessage("test\n"); commit.setMessage("test\n");
final ObjectId commitId = ow.writeCommit(commit); ObjectId commitId = oi.insert(Constants.OBJ_COMMIT, oi.format(commit));
final RefUpdate ref = repository.updateRef(Constants.HEAD); final RefUpdate ref = repository.updateRef(Constants.HEAD);
ref.setNewObjectId(commitId); ref.setNewObjectId(commitId);
@@ -412,9 +419,8 @@ public class CommitMsgHookTest extends HookTestCase {
default: default:
fail(Constants.HEAD + " did not change: " + ref.getResult()); fail(Constants.HEAD + " did not change: " + ref.getResult());
} }
} finally {
oi.release();
} }
private ObjectWriter writer() {
return new ObjectWriter(repository);
} }
} }

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.server.PeerDaemonUser;
import com.google.gerrit.server.RemotePeer; import com.google.gerrit.server.RemotePeer;
import com.google.gerrit.server.config.FactoryModule; import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.config.GerritRequestModule; import com.google.gerrit.server.config.GerritRequestModule;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.server.git.WorkQueue; import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.ssh.SshInfo; import com.google.gerrit.server.ssh.SshInfo;
@@ -77,7 +78,6 @@ public class SshModule extends FactoryModule {
bind(PublickeyAuthenticator.class).to(DatabasePubKeyAuth.class); bind(PublickeyAuthenticator.class).to(DatabasePubKeyAuth.class);
bind(KeyPairProvider.class).toProvider(HostKeyProvider.class).in(SINGLETON); bind(KeyPairProvider.class).toProvider(HostKeyProvider.class).in(SINGLETON);
bind(TransferConfig.class);
install(new DefaultCommandModule()); install(new DefaultCommandModule());

View File

@@ -21,7 +21,7 @@ import net.sf.ehcache.Statistics;
import net.sf.ehcache.config.CacheConfiguration; import net.sf.ehcache.config.CacheConfiguration;
import org.apache.sshd.server.Environment; import org.apache.sshd.server.Environment;
import org.eclipse.jgit.lib.WindowCacheStatAccessor; import org.eclipse.jgit.storage.file.WindowCacheStatAccessor;
import java.io.PrintWriter; import java.io.PrintWriter;

View File

@@ -17,8 +17,8 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.reviewdb.Account; import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.ReceiveCommits; import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.sshd.AbstractGitCommand; import com.google.gerrit.sshd.AbstractGitCommand;
import com.google.gerrit.sshd.TransferConfig;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.ReceivePack;

View File

@@ -15,9 +15,9 @@
package com.google.gerrit.sshd.commands; package com.google.gerrit.sshd.commands;
import com.google.gerrit.reviewdb.ReviewDb; import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.server.git.VisibleRefFilter; import com.google.gerrit.server.git.VisibleRefFilter;
import com.google.gerrit.sshd.AbstractGitCommand; import com.google.gerrit.sshd.AbstractGitCommand;
import com.google.gerrit.sshd.TransferConfig;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@@ -40,6 +40,7 @@ final class Upload extends AbstractGitCommand {
if (!projectControl.allRefsAreVisible()) { if (!projectControl.allRefsAreVisible()) {
up.setRefFilter(new VisibleRefFilter(repo, projectControl, db.get())); up.setRefFilter(new VisibleRefFilter(repo, projectControl, db.get()));
} }
up.setPackConfig(config.getPackConfig());
up.setTimeout(config.getTimeout()); up.setTimeout(config.getTimeout());
try { try {
up.upload(in, out, err); up.upload(in, out, err);

View File

@@ -46,7 +46,7 @@ limitations under the License.
</issueManagement> </issueManagement>
<properties> <properties>
<jgitVersion>0.8.4.88-ge64cb03</jgitVersion> <jgitVersion>0.8.4.240-g8e9cc82</jgitVersion>
<gwtormVersion>1.1.4</gwtormVersion> <gwtormVersion>1.1.4</gwtormVersion>
<gwtjsonrpcVersion>1.2.2</gwtjsonrpcVersion> <gwtjsonrpcVersion>1.2.2</gwtjsonrpcVersion>
<gwtexpuiVersion>1.2.1</gwtexpuiVersion> <gwtexpuiVersion>1.2.1</gwtexpuiVersion>