matthiasblaesing commented on pull request #3423:
URL: https://github.com/apache/netbeans/pull/3423#issuecomment-1006962968
`cnd-asf` looks sane to me. This is what I tried to describe. If you merge
`master` into `cnd`, it should look identical, just not resulting in a new
branch.
As indicated I had a look at two commits that contain the donated code and
all looks good to me (not to surprising given, that @lahodaj had plenty of
experience from the first donations). If anyone wants to have a look, this is
my approach:
- check the two commits, that brought in the donations:
7c9326139ffcd06e4e65130153e4a8a233eb6398 and
17624e153c7979d69f14207a588987e7bd48c1c6
- ensure that the commits have either exactly one parent (normal commit with
new files) or no parent (orphan branch)
- ensure that only files were added
- ensure that all added files can be found either in donation4 or donation4.5
<details>
<summary>I decided to write that down in java using jgit, feel free to use
`CheckApacheNetBeansDonation.java` (Expand to see)</summary>
```java
package jgit;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
public class CheckApacheNetBeansDonation {
private static final String[] commits = new String[]{
"7c9326139ffcd06e4e65130153e4a8a233eb6398",
"17624e153c7979d69f14207a588987e7bd48c1c6"
};
public static void main(String[] args) throws Exception {
Repository repository = new
FileRepository("/home/matthias/src/netbeans/.git");
for (String commitId : commits) {
System.out.println("Commit: " + commitId);
try ( RevWalk walk = new RevWalk(repository); ObjectReader or =
repository.newObjectReader(); DonationZips dz = new DonationZips()) {
dz.addDonationZip("/home/matthias/archiv/netbeans/ApacheDonation4.zip",
"ApacheDonation4/");
dz.addDonationZip("/home/matthias/archiv/netbeans/ApacheDonation4.5.zip",
"ApacheDonation4.5/");
RevCommit commit =
walk.parseCommit(ObjectId.fromString(commitId));
RevCommit parent = null;
if (commit.getParentCount() == 1) {
parent = commit.getParent(0);
} else if (commit.getParentCount() != 0) {
throw new IllegalStateException("Only non-merge commits are
supported!");
}
AbstractTreeIterator commitTree =
getCanonicalTreeParser(repository, commit);
AbstractTreeIterator parentTree = null;
if (parent != null) {
parentTree = getCanonicalTreeParser(repository, parent);
} else {
parentTree = new EmptyTreeIterator();
}
try ( TreeWalk tw = new TreeWalk(repository)) {
tw.setRecursive(true);
tw.addTree(parentTree);
tw.addTree(commitTree);
while (tw.next()) {
ObjectId parentObjectId = tw.getObjectId(0);
ObjectId commitObjectId = tw.getObjectId(1);
if (parentObjectId.equals(ObjectId.zeroId())) {
checkContentsInDonationZip(or, commitObjectId,
tw.getPathString(), dz);
} else if (commitObjectId.equals(ObjectId.zeroId())) {
//System.out.println("Removed: " +
tw.getPathString());
throw new IllegalStateException("Found Removal");
} else if (!parentObjectId.equals(commitObjectId)) {
//System.out.println("Modified: " +
tw.getPathString());
throw new IllegalStateException("Found
Modification");
}
}
}
}
}
}
private static void checkContentsInDonationZip(ObjectReader or, ObjectId
objectId, String path, DonationZips dz) throws IOException {
byte[] donatedData = dz.getData(path);
if(donatedData == null) {
throw new IOException("Not found in donation: " + path);
}
ObjectLoader ol = or.open(objectId);
if(! Arrays.equals(donatedData, ol.getBytes())) {
throw new IOException("Donated data not identical to repository: "
+ path);
}
}
private static CanonicalTreeParser getCanonicalTreeParser(Repository
repository, ObjectId commitId) throws IOException {
try ( RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(commitId);
ObjectId treeId = commit.getTree().getId();
try ( ObjectReader reader = repository.newObjectReader()) {
return new CanonicalTreeParser(null, reader, treeId);
}
}
}
private static class DonationZips implements Closeable {
private final List<DonationZip> zips = new ArrayList<>();
public DonationZips() {
}
public void addDonationZip(String pathToZip, String infilePrefix)
throws IOException {
this.zips.add(new DonationZip(new File(pathToZip), infilePrefix));
}
public byte[] getData(String path) throws IOException {
for (DonationZip dz : zips) {
byte[] result = dz.getData(path);
if (result != null) {
return result;
}
}
return null;
}
public void close() throws IOException {
List<IOException> exceptions = new ArrayList<>();
for (DonationZip dz : zips) {
}
if (!exceptions.isEmpty()) {
IOException ex = new IOException("Failed to close some ZIPs");
for (IOException ex2 : exceptions) {
ex.addSuppressed(ex2);
}
throw ex;
}
}
}
private static class DonationZip implements Closeable {
private final ZipFile zipFile;
private final String infilePrefix;
public DonationZip(File pathToZip, String infilePrefix) throws
IOException {
this.zipFile = new ZipFile(pathToZip);
this.infilePrefix = infilePrefix;
}
public byte[] getData(String path) throws IOException {
String fullpath = infilePrefix + path;
ZipEntry ze = this.zipFile.getEntry(fullpath);
if (ze == null) {
return null;
}
try ( InputStream is = this.zipFile.getInputStream(ze)) {
return is.readAllBytes();
}
}
@Override
public void close() throws IOException {
this.zipFile.close();
}
}
}
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists