Beispiel #1
0
  /** Executes the map command using the provided options. */
  @Override
  protected void runInternal(GeogitCLI cli) throws IOException {

    if (args == null || args.isEmpty() || args.size() != 1) {
      printUsage(cli);
      throw new CommandFailedException();
    }

    String path = args.get(0);

    geogit = cli.getGeogit();

    ObjectId oldTreeId = geogit.getRepository().workingTree().getTree().getId();

    ObjectId newTreeId = geogit.command(OSMUnmapOp.class).setPath(path).call().getId();

    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
      console.println(
          "No differences were found after unmapping.\n"
              + "No changes have been made to the working tree");
    } else {
      // print something?
    }
  }
Beispiel #2
0
  // two features with different content should point to different objects
  public void testInsertNonEqualObjects() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);

    ObjectId oId2 = insertAndAdd(points2);
    assertNotNull(oId1);
    assertNotNull(oId2);
    assertFalse(oId1.equals(oId2));
  }
    protected Node parseNodeLine(String line) {
      List<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line));
      Preconditions.checkArgument(tokens.size() == 6, "Wrong tree element definition: %s", line);
      TYPE type = TYPE.valueOf(tokens.get(1));
      String name = tokens.get(2);
      ObjectId id = ObjectId.valueOf(tokens.get(3));
      ObjectId metadataId = ObjectId.valueOf(tokens.get(4));
      Envelope bbox = parseBBox(tokens.get(5));

      org.geogit.api.Node ref = org.geogit.api.Node.create(name, id, metadataId, type, bbox);

      return ref;
    }
Beispiel #4
0
  /**
   * Returns an Id as a string, decorating or abbreviating it if needed
   *
   * @param id
   * @return
   */
  private String getIdAsString(ObjectId id) {
    StringBuilder sb = new StringBuilder();
    if (args.abbrev) {
      sb.append(id.toString().substring(0, 7));
    } else {
      sb.append(id.toString());
    }
    if (refs.containsKey(id)) {
      sb.append(" (");
      sb.append(refs.get(id));
      sb.append(")");
    }

    return sb.toString();
  }
Beispiel #5
0
 private RevTree getTree(ObjectId treeId) {
   if (treeId.isNull()) {
     return RevTree.EMPTY;
   }
   RevTree revTree = targetdb.getTree(treeId);
   return revTree;
 }
  /** @see org.geogit.storage.ObjectDatabase#getRaw(org.geogit.api.ObjectId) */
  @Override
  protected InputStream getRawInternal(final ObjectId id) throws IOException {
    Preconditions.checkNotNull(id, "id");
    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();

    final LockMode lockMode = LockMode.READ_COMMITTED;
    Transaction transaction = txn.getTransaction();
    OperationStatus operationStatus = objectDb.get(transaction, key, data, lockMode);
    if (NOTFOUND.equals(operationStatus)) {
      throw new IllegalArgumentException("Object does not exist: " + id.toString());
    }
    final byte[] cData = data.getData();

    return new ByteArrayInputStream(cData);
  }
  @Override
  public boolean delete(final ObjectId id) {
    final byte[] rawKey = id.getRawValue();
    final DatabaseEntry key = new DatabaseEntry(rawKey);

    final OperationStatus status = objectDb.delete(txn.getTransaction(), key);

    return SUCCESS.equals(status);
  }
 @Override
 protected RevTag read(ObjectId id, BufferedReader reader, TYPE type) throws IOException {
   Preconditions.checkArgument(TYPE.TAG.equals(type), "Wrong type: %s", type.name());
   String name = parseLine(requireLine(reader), "name");
   String message = parseLine(requireLine(reader), "message");
   String commitId = parseLine(requireLine(reader), "commitid");
   RevPerson tagger = parsePerson(requireLine(reader));
   RevTag tag = new RevTagImpl(id, name, ObjectId.valueOf(commitId), message, tagger);
   return tag;
 }
Beispiel #9
0
  @Override
  public void runInternal(GeogitCLI cli) throws IOException {
    ImmutableList<ObjectId> updatedObjects = cli.getGeogit().command(RebuildGraphOp.class).call();

    final ConsoleReader console = cli.getConsole();
    if (updatedObjects.size() > 0) {
      if (quiet) {
        console.println(updatedObjects.size() + " graph elements (commits) were fixed.");
      } else {
        console.println(
            "The following graph elements (commits) were incomplete or missing and have been fixed:");
        for (ObjectId object : updatedObjects) {
          console.println(object.toString());
        }
      }
    } else {
      console.println("No missing or incomplete graph elements (commits) were found.");
    }
  }
  /** @see org.geogit.storage.ObjectDatabase#exists(org.geogit.api.ObjectId) */
  @Override
  public boolean exists(final ObjectId id) {
    Preconditions.checkNotNull(id, "id");

    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();
    // tell db not to retrieve data
    data.setPartial(0, 0, true);

    final LockMode lockMode = LockMode.DEFAULT;
    CurrentTransaction.getInstance(env);
    OperationStatus status = objectDb.get(txn.getTransaction(), key, data, lockMode);
    return SUCCESS == status;
  }
 @Override
 public T read(ObjectId id, InputStream rawData) throws IllegalArgumentException {
   try {
     BufferedReader reader;
     reader = new BufferedReader(new InputStreamReader(rawData, "UTF-8"));
     TYPE type = RevObject.TYPE.valueOf(requireLine(reader).trim());
     T parsed = read(id, reader, type);
     Preconditions.checkState(parsed != null, "parsed to null");
     if (id != null) {
       Preconditions.checkState(
           id.equals(parsed.getId()),
           "Expected and parsed object ids don't match: %s %s",
           id,
           parsed.getId());
     }
     return parsed;
   } catch (Exception e) {
     throw Throwables.propagate(e);
   }
 }
        @Override
        protected RevTree read(ObjectId id, BufferedReader reader, TYPE type) throws IOException {
          Preconditions.checkArgument(TYPE.TREE.equals(type), "Wrong type: %s", type.name());
          Builder<Node> features = ImmutableList.builder();
          Builder<Node> trees = ImmutableList.builder();
          TreeMap<Integer, Bucket> subtrees = Maps.newTreeMap();
          long size = Long.parseLong(parseLine(requireLine(reader), "size"));
          int numTrees = Integer.parseInt(parseLine(requireLine(reader), "numtrees"));
          String line;
          while ((line = reader.readLine()) != null) {
            Preconditions.checkArgument(!line.isEmpty(), "Empty tree element definition");
            ArrayList<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line));
            String nodeType = tokens.get(0);
            if (nodeType.equals(TextWriter.TreeNode.REF.name())) {
              Node entryRef = parseNodeLine(line);
              if (entryRef.getType().equals(TYPE.TREE)) {
                trees.add(entryRef);
              } else {
                features.add(entryRef);
              }
            } else if (nodeType.equals(TextWriter.TreeNode.BUCKET.name())) {
              Preconditions.checkArgument(tokens.size() == 4, "Wrong bucket definition: %s", line);
              Integer idx = Integer.parseInt(tokens.get(1));
              ObjectId bucketId = ObjectId.valueOf(tokens.get(2));
              Envelope bounds = parseBBox(tokens.get(3));
              Bucket bucket = Bucket.create(bucketId, bounds);
              subtrees.put(idx, bucket);
            } else {
              throw new IllegalArgumentException("Wrong tree element definition: " + line);
            }
          }

          RevTree tree;
          if (subtrees.isEmpty()) {
            tree = RevTreeImpl.createLeafTree(id, size, features.build(), trees.build());
          } else {
            tree = RevTreeImpl.createNodeTree(id, size, numTrees, subtrees);
          }
          return tree;
        }
        @Override
        protected RevCommit read(ObjectId id, BufferedReader reader, TYPE type) throws IOException {
          Preconditions.checkArgument(TYPE.COMMIT.equals(type), "Wrong type: %s", type.name());
          String tree = parseLine(requireLine(reader), "tree");
          List<String> parents =
              Lists.newArrayList(
                  Splitter.on(' ')
                      .omitEmptyStrings()
                      .split(parseLine(requireLine(reader), "parents")));
          RevPerson author = parsePerson(requireLine(reader), "author");
          RevPerson committer = parsePerson(requireLine(reader), "committer");
          String message = parseMessage(reader);

          CommitBuilder builder = new CommitBuilder();
          builder.setAuthor(author.getName().orNull());
          builder.setAuthorEmail(author.getEmail().orNull());
          builder.setAuthorTimestamp(author.getTimestamp());
          builder.setAuthorTimeZoneOffset(author.getTimeZoneOffset());
          builder.setCommitter(committer.getName().orNull());
          builder.setCommitterEmail(committer.getEmail().orNull());
          builder.setCommitterTimestamp(committer.getTimestamp());
          builder.setCommitterTimeZoneOffset(committer.getTimeZoneOffset());
          builder.setMessage(message);
          List<ObjectId> parentIds =
              Lists.newArrayList(
                  Iterators.transform(
                      parents.iterator(),
                      new Function<String, ObjectId>() {

                        @Override
                        public ObjectId apply(String input) {
                          ObjectId objectId = ObjectId.valueOf(input);
                          return objectId;
                        }
                      }));
          builder.setParentIds(parentIds);
          builder.setTreeId(ObjectId.valueOf(tree));
          RevCommit commit = builder.build();
          return commit;
        }
Beispiel #14
0
  @Override
  public Resource findTarget(Request request, Response response) {

    if (request.getAttributes().containsKey("id")) {
      final Optional<GeoGIT> ggit = getGeogit(request);
      Preconditions.checkState(ggit.isPresent());

      final String id = (String) request.getAttributes().get("id");
      final ObjectId oid = ObjectId.valueOf(id);

      GeoGIT geogit = ggit.get();
      Repository repository = geogit.getRepository();
      boolean blobExists = repository.blobExists(oid);
      if (blobExists) {
        ObjectResource objectResource = new ObjectResource(oid, geogit);
        objectResource.init(getContext(), request, response);
        return objectResource;
      }
    }

    return super.findTarget(request, response);
  }
  /** @see org.geogit.storage.ObjectDatabase#put(org.geogit.storage.ObjectWriter) */
  @Override
  protected boolean putInternal(final ObjectId id, final byte[] rawData, final boolean override)
      throws IOException {
    final byte[] rawKey = id.getRawValue();
    DatabaseEntry key = new DatabaseEntry(rawKey);
    DatabaseEntry data = new DatabaseEntry(rawData);

    OperationStatus status;
    if (override) {
      status = objectDb.put(txn.getTransaction(), key, data);
    } else {
      status = objectDb.putNoOverwrite(txn.getTransaction(), key, data);
    }
    final boolean didntExist = SUCCESS.equals(status);

    if (LOGGER.isLoggable(Level.FINER)) {
      if (didntExist) {
        LOGGER.finer("Key already exists in blob store, blob reused for id: " + id);
      }
    }
    return didntExist;
  }
Beispiel #16
0
    @Override
    public void print(RevCommit commit) throws IOException {
      Ansi ansi = AnsiDecorator.newAnsi(useColor);

      ansi.a("Commit:  ").fg(Color.YELLOW).a(getIdAsString(commit.getId())).reset().newline();
      if (commit.getParentIds().size() > 1) {
        ansi.a("Merge: ");
        for (ObjectId parent : commit.getParentIds()) {
          ansi.a(parent.toString().substring(0, 7)).a(" ");
        }
        ansi.newline();
      }
      ansi.a("Author:  ").fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();

      final long timestamp = commit.getAuthor().getTimestamp();
      final int timeZoneOffset = commit.getAuthor().getTimeZoneOffset();

      String friendlyString = estimateSince(now, timestamp);
      DATE_FORMAT.getCalendar().getTimeZone().setRawOffset(timeZoneOffset);
      String formattedDate = DATE_FORMAT.format(timestamp);

      ansi.a("Date:    (")
          .fg(Color.RED)
          .a(friendlyString)
          .reset()
          .a(") ")
          .a(formattedDate)
          .newline();
      ansi.a("Subject: ").a(commit.getMessage()).newline();
      if ((detail.equals(LOG_DETAIL.NAMES_ONLY)) && commit.getParentIds().size() == 1) {
        ansi.a("Affected paths:").newline();
        Iterator<DiffEntry> diff =
            geogit
                .command(DiffOp.class)
                .setOldVersion(commit.parentN(0).get())
                .setNewVersion(commit.getId())
                .call();
        DiffEntry diffEntry;
        while (diff.hasNext()) {
          diffEntry = diff.next();
          ansi.a("\t" + diffEntry.newPath()).newline();
        }
      }
      if (detail.equals(LOG_DETAIL.STATS) && commit.getParentIds().size() == 1) {

        Iterator<DiffEntry> diff =
            geogit
                .command(DiffOp.class)
                .setOldVersion(commit.parentN(0).get())
                .setNewVersion(commit.getId())
                .call();
        int adds = 0, deletes = 0, changes = 0;
        DiffEntry diffEntry;
        while (diff.hasNext()) {
          diffEntry = diff.next();
          switch (diffEntry.changeType()) {
            case ADDED:
              ++adds;
              break;
            case REMOVED:
              ++deletes;
              break;
            case MODIFIED:
              ++changes;
              break;
          }
        }

        ansi.a("Changes:");
        ansi.fg(Color.GREEN)
            .a(adds)
            .reset()
            .a(" features added, ")
            .fg(Color.YELLOW)
            .a(changes)
            .reset()
            .a(" changed, ")
            .fg(Color.RED)
            .a(deletes)
            .reset()
            .a(" deleted.")
            .reset()
            .newline();
      }

      console.println(ansi.toString());
      if (detail.equals(LOG_DETAIL.SUMMARY) && commit.getParentIds().size() == 1) {
        ansi.a("Changes:").newline();
        Iterator<DiffEntry> diff =
            geogit
                .command(DiffOp.class)
                .setOldVersion(commit.parentN(0).get())
                .setNewVersion(commit.getId())
                .call();
        DiffEntry diffEntry;
        while (diff.hasNext()) {
          diffEntry = diff.next();
          if (detail.equals(LOG_DETAIL.SUMMARY)) {
            new FullDiffPrinter(true, false).print(geogit, console, diffEntry);
          }
        }
      }
    }