コード例 #1
0
ファイル: GeoGitTest.java プロジェクト: ryantxu/jeo-contrib
  @Before
  public void setUp() throws IOException {
    Injector i =
        Guice.createInjector(Modules.override(new GeogitModule()).with(new JEStorageModule()));

    GeoGIT gg = new GeoGIT(i, Tests.newTmpDir("geogit", "tmp"));

    Repository repo = gg.getOrCreateRepository();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.name")
        .setValue("Wile E Coyote")
        .call();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.email")
        .setValue("*****@*****.**")
        .call();

    addShp(TestData.states(), repo);
    addShp(TestData.point(), repo);
    addShp(TestData.line(), repo);
    addShp(TestData.polygon(), repo);

    repo.command(BranchCreateOp.class).setName("scratch").call();
    ws = new GeoGitWorkspace(gg, null);
  }
コード例 #2
0
ファイル: GeoGitTest.java プロジェクト: hjanetzek/jeo
  void addShp(VectorDataset data, Repository repo) throws IOException {
    String name = data.getName();
    repo.getWorkingTree()
        .insert(
            name, GT.iterator(data.cursor(new Query())), new NullProgressListener(), null, null);
    data.close();

    AddOp add = repo.command(AddOp.class);
    add.call();

    CommitOp commit = repo.command(CommitOp.class);
    commit.setMessage("initial commit of " + name);
    commit.call();
  }
コード例 #3
0
  /**
   * This function takes all of the changes introduced by a commit on the sparse repository and
   * creates a new commit on the full repository with those changes.
   *
   * @param commitId the commit id of commit from the sparse repository
   * @param from the sparse repository
   * @param to the full repository
   */
  protected void pushSparseCommit(ObjectId commitId) {
    Repository from = localRepository;
    Repository to = remoteGeoGit.getRepository();
    Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId).call();
    if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
      RevCommit commit = (RevCommit) object.get();
      ObjectId parent = ObjectId.NULL;
      List<ObjectId> newParents = new LinkedList<ObjectId>();
      for (int i = 0; i < commit.getParentIds().size(); i++) {
        ObjectId parentId = commit.getParentIds().get(i);
        if (i != 0) {
          Optional<ObjectId> commonAncestor =
              from.getGraphDatabase()
                  .findLowestCommonAncestor(commit.getParentIds().get(0), parentId);
          if (commonAncestor.isPresent()) {
            if (from.getGraphDatabase().isSparsePath(parentId, commonAncestor.get())) {
              // This should be the base commit to preserve the sparse changes that
              // were filtered
              // out.
              newParents.add(0, from.getGraphDatabase().getMapping(parentId));
              continue;
            }
          }
        }
        newParents.add(from.getGraphDatabase().getMapping(parentId));
      }
      if (newParents.size() > 0) {
        parent = from.getGraphDatabase().getMapping(newParents.get(0));
      }
      Iterator<DiffEntry> diffIter =
          from.command(DiffOp.class)
              .setNewVersion(commitId)
              .setOldVersion(parent)
              .setReportTrees(true)
              .call();

      LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to);

      RevTree rootTree = RevTree.EMPTY;

      if (newParents.size() > 0) {
        ObjectId mappedCommit = newParents.get(0);

        Optional<ObjectId> treeId =
            to.command(ResolveTreeish.class).setTreeish(mappedCommit).call();
        if (treeId.isPresent()) {
          rootTree = to.getTree(treeId.get());
        }
      }

      // Create new commit
      ObjectId newTreeId =
          to.command(WriteTree.class)
              .setOldRoot(Suppliers.ofInstance(rootTree))
              .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes))
              .call();

      CommitBuilder builder = new CommitBuilder(commit);
      builder.setParentIds(newParents);
      builder.setTreeId(newTreeId);

      RevCommit mapped = builder.build();
      to.getObjectDatabase().put(mapped);

      from.getGraphDatabase().map(commit.getId(), mapped.getId());
      from.getGraphDatabase().map(mapped.getId(), commit.getId());
    }
  }
コード例 #4
0
ファイル: RepositoryTestCase.java プロジェクト: dwins/GeoGig
  protected final void doSetUp() throws IOException, SchemaException, ParseException, Exception {
    envHome = repositoryTempFolder.getRoot();

    injector = createInjector();

    geogit = new GeoGIT(injector, envHome);
    repo = geogit.getOrCreateRepository();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.name")
        .setValue("Gabriel Roldan")
        .call();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.email")
        .setValue("*****@*****.**")
        .call();

    pointsType = DataUtilities.createType(pointsNs, pointsName, pointsTypeSpec);
    modifiedPointsType = DataUtilities.createType(pointsNs, pointsName, modifiedPointsTypeSpec);

    points1 = feature(pointsType, idP1, "StringProp1_1", new Integer(1000), "POINT(1 1)");
    points1_modified = feature(pointsType, idP1, "StringProp1_1a", new Integer(1001), "POINT(1 2)");
    points1B =
        feature(
            modifiedPointsType,
            idP1,
            "StringProp1_1",
            new Integer(1000),
            "POINT(1 1)",
            "ExtraString");

    points1B_modified =
        feature(
            modifiedPointsType,
            idP1,
            "StringProp1_1a",
            new Integer(1001),
            "POINT(1 2)",
            "ExtraStringB");

    points2 = feature(pointsType, idP2, "StringProp1_2", new Integer(2000), "POINT(2 2)");
    points3 = feature(pointsType, idP3, "StringProp1_3", new Integer(3000), "POINT(3 3)");

    linesType = DataUtilities.createType(linesNs, linesName, linesTypeSpec);

    lines1 = feature(linesType, idL1, "StringProp2_1", new Integer(1000), "LINESTRING (1 1, 2 2)");
    lines2 = feature(linesType, idL2, "StringProp2_2", new Integer(2000), "LINESTRING (3 3, 4 4)");
    lines3 = feature(linesType, idL3, "StringProp2_3", new Integer(3000), "LINESTRING (5 5, 6 6)");

    polyType = DataUtilities.createType(polyNs, polyName, polyTypeSpec);

    poly1 =
        feature(
            polyType,
            idPG1,
            "StringProp3_1",
            new Integer(1000),
            "POLYGON ((1 1, 2 2, 3 3, 4 4, 1 1))");
    poly2 =
        feature(
            polyType,
            idPG2,
            "StringProp3_2",
            new Integer(2000),
            "POLYGON ((6 6, 7 7, 8 8, 9 9, 6 6))");
    poly3 =
        feature(
            polyType,
            idPG3,
            "StringProp3_3",
            new Integer(3000),
            "POLYGON ((11 11, 12 12, 13 13, 14 14, 11 11))");

    setUpInternal();
  }