summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2008-12-17 12:38:11 -0800
committerShawn O. Pearce <sop@google.com>2008-12-17 13:42:17 -0800
commit637e12bdc6c8312537c87485b3d465e913f91b75 (patch)
tree32195b934cc11138beabd013a73026577352d317 /webapp
parent79de1e48ca0093d7dad1c277ea5123bb3c7304ea (diff)
Add ancestor revision update to PatchSetImporter
These are necessary for new PatchSet entities, where none of the parent links are in the database. But we can update them too when we build an update for an existing patch set. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'webapp')
-rw-r--r--webapp/src/com/google/gerrit/client/reviewdb/PatchSetAncestor.java7
-rw-r--r--webapp/src/com/google/gerrit/git/PatchSetImporter.java33
2 files changed, 37 insertions, 3 deletions
diff --git a/webapp/src/com/google/gerrit/client/reviewdb/PatchSetAncestor.java b/webapp/src/com/google/gerrit/client/reviewdb/PatchSetAncestor.java
index d22d6f96f9..62e9d72388 100644
--- a/webapp/src/com/google/gerrit/client/reviewdb/PatchSetAncestor.java
+++ b/webapp/src/com/google/gerrit/client/reviewdb/PatchSetAncestor.java
@@ -55,9 +55,8 @@ public final class PatchSetAncestor {
protected PatchSetAncestor() {
}
- public PatchSetAncestor(final PatchSetAncestor.Key k, final RevId rev) {
+ public PatchSetAncestor(final PatchSetAncestor.Key k) {
key = k;
- ancestorRevision = rev;
}
public PatchSetAncestor.Key getKey() {
@@ -75,4 +74,8 @@ public final class PatchSetAncestor {
public RevId getAncestorRevision() {
return ancestorRevision;
}
+
+ public void setAncestorRevision(final RevId id) {
+ ancestorRevision = id;
+ }
}
diff --git a/webapp/src/com/google/gerrit/git/PatchSetImporter.java b/webapp/src/com/google/gerrit/git/PatchSetImporter.java
index ef8ebb11ee..36a83bbd87 100644
--- a/webapp/src/com/google/gerrit/git/PatchSetImporter.java
+++ b/webapp/src/com/google/gerrit/git/PatchSetImporter.java
@@ -17,6 +17,7 @@ package com.google.gerrit.git;
import com.google.gerrit.client.reviewdb.Patch;
import com.google.gerrit.client.reviewdb.PatchContent;
import com.google.gerrit.client.reviewdb.PatchSet;
+import com.google.gerrit.client.reviewdb.PatchSetAncestor;
import com.google.gerrit.client.reviewdb.PatchSetInfo;
import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb;
@@ -66,6 +67,13 @@ public class PatchSetImporter {
private final Map<PatchContent.Key, String> content =
new HashMap<PatchContent.Key, String>();
+ private final Map<Integer, PatchSetAncestor> ancestorExisting =
+ new HashMap<Integer, PatchSetAncestor>();
+ private final List<PatchSetAncestor> ancestorInsert =
+ new ArrayList<PatchSetAncestor>();
+ private final List<PatchSetAncestor> ancestorUpdate =
+ new ArrayList<PatchSetAncestor>();
+
public PatchSetImporter(final ReviewDb dstDb, final Repository srcRepo,
final RevCommit srcCommit, final PatchSet dstPatchSet,
final boolean isNewPatchSet) {
@@ -79,7 +87,7 @@ public class PatchSetImporter {
public void run() throws IOException, OrmException {
gitpatch = readGitPatch();
- dst.setRevision(new RevId(src.getId().name()));
+ dst.setRevision(toRevId(src));
if (!isNew) {
// If we aren't a new patch set then we need to load the existing
@@ -89,6 +97,10 @@ public class PatchSetImporter {
for (final Patch p : db.patches().byPatchSet(dst.getKey())) {
patchExisting.put(p.getFileName(), p);
}
+ for (final PatchSetAncestor a : db.patchSetAncestors().ancestorsOf(
+ dst.getKey())) {
+ ancestorExisting.put(a.getPosition(), a);
+ }
}
importInfo();
@@ -110,9 +122,13 @@ public class PatchSetImporter {
db.patchSetInfo().update(Collections.singleton(info));
}
db.patches().insert(patchInsert, txn);
+ db.patchSetAncestors().insert(ancestorInsert, txn);
if (!isNew) {
db.patches().update(patchUpdate, txn);
db.patches().delete(patchExisting.values(), txn);
+
+ db.patchSetAncestors().update(ancestorUpdate, txn);
+ db.patchSetAncestors().delete(ancestorExisting.values(), txn);
}
txn.commit();
}
@@ -127,6 +143,17 @@ public class PatchSetImporter {
info.setMessage(src.getFullMessage());
info.setAuthor(toUserIdentity(src.getAuthorIdent()));
info.setCommitter(toUserIdentity(src.getCommitterIdent()));
+
+ for (int p = 0; p < src.getParentCount(); p++) {
+ PatchSetAncestor a = ancestorExisting.remove(p + 1);
+ if (a == null) {
+ a = new PatchSetAncestor(new PatchSetAncestor.Key(dst.getKey(), p + 1));
+ ancestorInsert.add(a);
+ } else {
+ ancestorUpdate.add(a);
+ }
+ a.setAncestorRevision(toRevId(src.getParent(p)));
+ }
}
private UserIdentity toUserIdentity(final PersonIdent who) {
@@ -227,6 +254,10 @@ public class PatchSetImporter {
}
}
+ private static RevId toRevId(final RevCommit src) {
+ return new RevId(src.getId().name());
+ }
+
private org.spearce.jgit.patch.Patch readGitPatch() throws IOException {
final List<String> args = new ArrayList<String>();
args.add("git");