Browse Source

Set commit time to ZipArchiveEntry

Archived zip files for a same commit have different MD5 hash because
mdate and mdate in the header of zip entries are not specified. In
this case, Commons Compress sets an archived time.

In the original git implementation, it's set a commit time:
e2b2d6a172/archive.c (L378)

By this fix, archive command sets the commit time to ZipArchiveEntry
when RevCommit is given as an archiving target.

Change-Id: I30dd8710e910cdf42d57742f8709e9803930a123
Signed-off-by: Naoki Takezoe <takezoe@gmail.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.7
Naoki Takezoe 8 years ago committed by Matthias Sohn
parent
commit
1448ec37f9
  1. 1
      org.eclipse.jgit.archive/META-INF/MANIFEST.MF
  2. 13
      org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
  3. 15
      org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
  4. 15
      org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
  5. 15
      org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
  6. 20
      org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
  7. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
  8. 8
      org.eclipse.jgit/.settings/.api_filters
  9. 37
      org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java

1
org.eclipse.jgit.archive/META-INF/MANIFEST.MF

@ -15,6 +15,7 @@ Import-Package: org.apache.commons.compress.archivers;version="[1.4,2.0)",
org.eclipse.jgit.api;version="[4.7.0,4.8.0)", org.eclipse.jgit.api;version="[4.7.0,4.8.0)",
org.eclipse.jgit.lib;version="[4.7.0,4.8.0)", org.eclipse.jgit.lib;version="[4.7.0,4.8.0)",
org.eclipse.jgit.nls;version="[4.7.0,4.8.0)", org.eclipse.jgit.nls;version="[4.7.0,4.8.0)",
org.eclipse.jgit.revwalk;version="[4.7.0,4.8.0)",
org.eclipse.jgit.util;version="[4.7.0,4.8.0)", org.eclipse.jgit.util;version="[4.7.0,4.8.0)",
org.osgi.framework;version="[1.3.0,2.0.0)" org.osgi.framework;version="[1.3.0,2.0.0)"
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy

13
org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java

@ -57,6 +57,7 @@ import org.apache.commons.compress.archivers.tar.TarConstants;
import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.archive.internal.ArchiveText; import org.eclipse.jgit.archive.internal.ArchiveText;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
/** /**
@ -84,9 +85,21 @@ public final class TarFormat extends BaseFormat implements
return applyFormatOptions(out, o); return applyFormatOptions(out, o);
} }
@Deprecated
@Override
public void putEntry(ArchiveOutputStream out, public void putEntry(ArchiveOutputStream out,
String path, FileMode mode, ObjectLoader loader) String path, FileMode mode, ObjectLoader loader)
throws IOException { throws IOException {
putEntry(out, null, path, mode,loader);
}
/**
* @since 4.7
*/
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
throws IOException {
if (mode == FileMode.SYMLINK) { if (mode == FileMode.SYMLINK) {
final TarArchiveEntry entry = new TarArchiveEntry( final TarArchiveEntry entry = new TarArchiveEntry(
path, TarConstants.LF_SYMLINK); path, TarConstants.LF_SYMLINK);

15
org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java

@ -53,6 +53,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
/** /**
@ -80,10 +81,22 @@ public final class Tbz2Format extends BaseFormat implements
return tarFormat.createArchiveOutputStream(out, o); return tarFormat.createArchiveOutputStream(out, o);
} }
@Deprecated
@Override
public void putEntry(ArchiveOutputStream out, public void putEntry(ArchiveOutputStream out,
String path, FileMode mode, ObjectLoader loader) String path, FileMode mode, ObjectLoader loader)
throws IOException { throws IOException {
tarFormat.putEntry(out, path, mode, loader); putEntry(out, null, path, mode,loader);
}
/**
* @since 4.7
*/
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
throws IOException {
tarFormat.putEntry(out, tree, path, mode, loader);
} }
public Iterable<String> suffixes() { public Iterable<String> suffixes() {

15
org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java

@ -53,6 +53,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
/** /**
@ -80,10 +81,22 @@ public final class TgzFormat extends BaseFormat implements
return tarFormat.createArchiveOutputStream(out, o); return tarFormat.createArchiveOutputStream(out, o);
} }
@Deprecated
@Override
public void putEntry(ArchiveOutputStream out, public void putEntry(ArchiveOutputStream out,
String path, FileMode mode, ObjectLoader loader) String path, FileMode mode, ObjectLoader loader)
throws IOException { throws IOException {
tarFormat.putEntry(out, path, mode, loader); putEntry(out, null, path, mode,loader);
}
/**
* @since 4.7
*/
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
throws IOException {
tarFormat.putEntry(out, tree, path, mode, loader);
} }
public Iterable<String> suffixes() { public Iterable<String> suffixes() {

15
org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java

@ -53,6 +53,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
/** /**
@ -80,10 +81,22 @@ public final class TxzFormat extends BaseFormat implements
return tarFormat.createArchiveOutputStream(out, o); return tarFormat.createArchiveOutputStream(out, o);
} }
@Deprecated
@Override
public void putEntry(ArchiveOutputStream out, public void putEntry(ArchiveOutputStream out,
String path, FileMode mode, ObjectLoader loader) String path, FileMode mode, ObjectLoader loader)
throws IOException { throws IOException {
tarFormat.putEntry(out, path, mode, loader); putEntry(out, null, path, mode,loader);
}
/**
* @since 4.7
*/
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
throws IOException {
tarFormat.putEntry(out, tree, path, mode, loader);
} }
public Iterable<String> suffixes() { public Iterable<String> suffixes() {

20
org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java

@ -56,7 +56,9 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.archive.internal.ArchiveText; import org.eclipse.jgit.archive.internal.ArchiveText;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.revwalk.RevCommit;
/** /**
* PKWARE's ZIP format. * PKWARE's ZIP format.
@ -80,9 +82,21 @@ public final class ZipFormat extends BaseFormat implements
return applyFormatOptions(new ZipArchiveOutputStream(s), o); return applyFormatOptions(new ZipArchiveOutputStream(s), o);
} }
@Deprecated
@Override
public void putEntry(ArchiveOutputStream out, public void putEntry(ArchiveOutputStream out,
String path, FileMode mode, ObjectLoader loader) String path, FileMode mode, ObjectLoader loader)
throws IOException { throws IOException {
putEntry(out, null, path, mode,loader);
}
/**
* @since 4.7
*/
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
throws IOException {
// ZipArchiveEntry detects directories by checking // ZipArchiveEntry detects directories by checking
// for '/' at the end of the filename. // for '/' at the end of the filename.
if (path.endsWith("/") && mode != FileMode.TREE) //$NON-NLS-1$ if (path.endsWith("/") && mode != FileMode.TREE) //$NON-NLS-1$
@ -92,6 +106,12 @@ public final class ZipFormat extends BaseFormat implements
path = path + "/"; //$NON-NLS-1$ path = path + "/"; //$NON-NLS-1$
final ZipArchiveEntry entry = new ZipArchiveEntry(path); final ZipArchiveEntry entry = new ZipArchiveEntry(path);
if(tree instanceof RevCommit){
long commitTime = ((RevCommit) tree).getCommitTime();
entry.setTime(commitTime);
}
if (mode == FileMode.TREE) { if (mode == FileMode.TREE) {
out.putArchiveEntry(entry); out.putArchiveEntry(entry);
out.closeArchiveEntry(); out.closeArchiveEntry();

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java

@ -57,6 +57,7 @@ import java.util.Map;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.util.StringUtils; import org.eclipse.jgit.util.StringUtils;
@ -203,12 +204,14 @@ public class ArchiveCommandTest extends RepositoryTestCase {
private final List<String> SUFFIXES = Collections private final List<String> SUFFIXES = Collections
.unmodifiableList(Arrays.asList(".mck")); .unmodifiableList(Arrays.asList(".mck"));
@Override
public MockOutputStream createArchiveOutputStream(OutputStream s) public MockOutputStream createArchiveOutputStream(OutputStream s)
throws IOException { throws IOException {
return createArchiveOutputStream(s, return createArchiveOutputStream(s,
Collections.<String, Object> emptyMap()); Collections.<String, Object> emptyMap());
} }
@Override
public MockOutputStream createArchiveOutputStream(OutputStream s, public MockOutputStream createArchiveOutputStream(OutputStream s,
Map<String, Object> o) throws IOException { Map<String, Object> o) throws IOException {
for (Map.Entry<String, Object> p : o.entrySet()) { for (Map.Entry<String, Object> p : o.entrySet()) {
@ -224,11 +227,18 @@ public class ArchiveCommandTest extends RepositoryTestCase {
return new MockOutputStream(); return new MockOutputStream();
} }
@Override
public void putEntry(MockOutputStream out, String path, FileMode mode, ObjectLoader loader) { public void putEntry(MockOutputStream out, String path, FileMode mode, ObjectLoader loader) {
putEntry(out, null, path, mode, loader);
}
@Override
public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) {
String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null; String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null;
entries.put(path, content); entries.put(path, content);
} }
@Override
public Iterable<String> suffixes() { public Iterable<String> suffixes() {
return SUFFIXES; return SUFFIXES;
} }

8
org.eclipse.jgit/.settings/.api_filters

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jgit" version="2"> <component id="org.eclipse.jgit" version="2">
<resource path="src/org/eclipse/jgit/api/ArchiveCommand.java" type="org.eclipse.jgit.api.ArchiveCommand$Format">
<filter comment="OSGi semver allows to break implementors in minor releases" id="403804204">
<message_arguments>
<message_argument value="org.eclipse.jgit.api.ArchiveCommand.Format"/>
<message_argument value="putEntry(T, ObjectId, String, FileMode, ObjectLoader)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/jgit/transport/http/HttpConnection.java" type="org.eclipse.jgit.transport.http.HttpConnection"> <resource path="src/org/eclipse/jgit/transport/http/HttpConnection.java" type="org.eclipse.jgit.transport.http.HttpConnection">
<filter comment="OSGi semantic versioning rules allow to break implementors in minor releases" id="403767336"> <filter comment="OSGi semantic versioning rules allow to break implementors in minor releases" id="403767336">
<message_arguments> <message_arguments>

37
org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java

@ -162,8 +162,8 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
* @param out * @param out
* archive object from createArchiveOutputStream * archive object from createArchiveOutputStream
* @param path * @param path
* full filename relative to the root of the archive * full filename relative to the root of the archive (with
* (with trailing '/' for directories) * trailing '/' for directories)
* @param mode * @param mode
* mode (for example FileMode.REGULAR_FILE or * mode (for example FileMode.REGULAR_FILE or
* FileMode.SYMLINK) * FileMode.SYMLINK)
@ -171,9 +171,36 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
* blob object with data for this entry (null for * blob object with data for this entry (null for
* directories) * directories)
* @throws IOException * @throws IOException
* thrown by the underlying output stream for I/O errors * thrown by the underlying output stream for I/O errors
* @deprecated use
* {@link #putEntry(Closeable, ObjectId, String, FileMode, ObjectLoader)}
* instead
*/ */
@Deprecated
void putEntry(T out, String path, FileMode mode, void putEntry(T out, String path, FileMode mode,
ObjectLoader loader) throws IOException;
/**
* Write an entry to an archive.
*
* @param out
* archive object from createArchiveOutputStream
* @param tree
* the tag, commit, or tree object to produce an archive for
* @param path
* full filename relative to the root of the archive (with
* trailing '/' for directories)
* @param mode
* mode (for example FileMode.REGULAR_FILE or
* FileMode.SYMLINK)
* @param loader
* blob object with data for this entry (null for
* directories)
* @throws IOException
* thrown by the underlying output stream for I/O errors
* @since 4.7
*/
void putEntry(T out, ObjectId tree, String path, FileMode mode,
ObjectLoader loader) throws IOException; ObjectLoader loader) throws IOException;
/** /**
@ -389,11 +416,11 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
mode = FileMode.TREE; mode = FileMode.TREE;
if (mode == FileMode.TREE) { if (mode == FileMode.TREE) {
fmt.putEntry(outa, name + "/", mode, null); //$NON-NLS-1$ fmt.putEntry(outa, tree, name + "/", mode, null); //$NON-NLS-1$
continue; continue;
} }
walk.getObjectId(idBuf, 0); walk.getObjectId(idBuf, 0);
fmt.putEntry(outa, name, mode, reader.open(idBuf)); fmt.putEntry(outa, tree, name, mode, reader.open(idBuf));
} }
outa.close(); outa.close();
return out; return out;

Loading…
Cancel
Save