Ejemplo n.º 1
0
 @Override
 public void print(RevCommit commit) throws IOException {
   Ansi ansi = AnsiDecorator.newAnsi(useColor);
   ansi.fg(Color.YELLOW).a(getIdAsString(commit.getId())).reset();
   String message = Strings.nullToEmpty(commit.getMessage());
   String title = Splitter.on('\n').split(message).iterator().next();
   ansi.a(" ").a(title);
   console.println(ansi.toString());
 }
Ejemplo n.º 2
0
 @Override
 protected void print(RevCommit commit, Writer w) throws IOException {
   println(w, "tree\t", commit.getTreeId().toString());
   print(w, "parents\t");
   for (Iterator<ObjectId> it = commit.getParentIds().iterator(); it.hasNext(); ) {
     print(w, it.next().toString());
     if (it.hasNext()) {
       print(w, " ");
     }
   }
   println(w);
   printPerson(w, "author", commit.getAuthor());
   printPerson(w, "committer", commit.getCommitter());
   println(w, "message\t", Optional.fromNullable(commit.getMessage()).or(""));
   w.flush();
 }
Ejemplo n.º 3
0
  private void writeCSV(GeoGIT geogit, Writer out, Iterator<RevCommit> log) throws Exception {
    String response =
        "ChangeType,FeatureId,CommitId,Parent CommitIds,Author Name,Author Email,Author Commit Time,Committer Name,Committer Email,Committer Commit Time,Commit Message";
    out.write(response);
    response = "";
    String path = paths.get(0);
    // This is the feature type object
    Optional<NodeRef> ref =
        geogit
            .command(FindTreeChild.class)
            .setChildPath(path)
            .setParent(geogit.getRepository().workingTree().getTree())
            .call();
    Optional<RevObject> type = Optional.absent();
    if (ref.isPresent()) {
      type =
          geogit
              .command(RevObjectParse.class)
              .setRefSpec(ref.get().getMetadataId().toString())
              .call();
    } else {
      throw new CommandSpecException("Couldn't resolve the given path.");
    }
    if (type.isPresent() && type.get() instanceof RevFeatureType) {
      RevFeatureType featureType = (RevFeatureType) type.get();
      Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
      int attributeLength = attribs.size();
      for (PropertyDescriptor attrib : attribs) {
        response += "," + escapeCsv(attrib.getName().toString());
      }
      response += '\n';
      out.write(response);
      response = "";
      RevCommit commit = null;

      while (log.hasNext()) {
        commit = log.next();
        String parentId =
            commit.getParentIds().size() >= 1
                ? commit.getParentIds().get(0).toString()
                : ObjectId.NULL.toString();
        Iterator<DiffEntry> diff =
            geogit
                .command(DiffOp.class)
                .setOldVersion(parentId)
                .setNewVersion(commit.getId().toString())
                .setFilter(path)
                .call();
        while (diff.hasNext()) {
          DiffEntry entry = diff.next();
          response += entry.changeType().toString() + ",";
          String fid = "";
          if (entry.newPath() != null) {
            if (entry.oldPath() != null) {
              fid = entry.oldPath() + " -> " + entry.newPath();
            } else {
              fid = entry.newPath();
            }
          } else if (entry.oldPath() != null) {
            fid = entry.oldPath();
          }
          response += fid + ",";
          response += commit.getId().toString() + ",";
          response += parentId;
          if (commit.getParentIds().size() > 1) {
            for (int index = 1; index < commit.getParentIds().size(); index++) {
              response += " " + commit.getParentIds().get(index).toString();
            }
          }
          response += ",";
          if (commit.getAuthor().getName().isPresent()) {
            response += escapeCsv(commit.getAuthor().getName().get());
          }
          response += ",";
          if (commit.getAuthor().getEmail().isPresent()) {
            response += escapeCsv(commit.getAuthor().getEmail().get());
          }
          response +=
              ","
                  + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z")
                      .format(new Date(commit.getAuthor().getTimestamp()))
                  + ",";
          if (commit.getCommitter().getName().isPresent()) {
            response += escapeCsv(commit.getCommitter().getName().get());
          }
          response += ",";
          if (commit.getCommitter().getEmail().isPresent()) {
            response += escapeCsv(commit.getCommitter().getEmail().get());
          }
          response +=
              ","
                  + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z")
                      .format(new Date(commit.getCommitter().getTimestamp()))
                  + ",";
          String message = escapeCsv(commit.getMessage());
          response += message;
          if (entry.newObjectId() == ObjectId.NULL) {
            // Feature was removed so we need to fill out blank attribute values
            for (int index = 0; index < attributeLength; index++) {
              response += ",";
            }
          } else {
            // Feature was added or modified so we need to write out the
            // attribute
            // values from the feature
            Optional<RevObject> feature =
                geogit.command(RevObjectParse.class).setObjectId(entry.newObjectId()).call();
            RevFeature revFeature = (RevFeature) feature.get();
            List<Optional<Object>> values = revFeature.getValues();
            for (int index = 0; index < values.size(); index++) {
              Optional<Object> value = values.get(index);
              PropertyDescriptor attrib = (PropertyDescriptor) attribs.toArray()[index];
              String stringValue = "";
              if (value.isPresent()) {
                FieldType attributeType = FieldType.forBinding(attrib.getType().getBinding());
                switch (attributeType) {
                  case DATE:
                    stringValue =
                        new SimpleDateFormat("MM/dd/yyyy z").format((java.sql.Date) value.get());
                    break;
                  case DATETIME:
                    stringValue =
                        new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Date) value.get());
                    break;
                  case TIME:
                    stringValue = new SimpleDateFormat("HH:mm:ss z").format((Time) value.get());
                    break;
                  case TIMESTAMP:
                    stringValue =
                        new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z")
                            .format((Timestamp) value.get());
                    break;
                  default:
                    stringValue = escapeCsv(value.get().toString());
                }
                response += "," + stringValue;
              } else {
                response += ",";
              }
            }
          }
          response += '\n';
          out.write(response);
          response = "";
        }
      }
    } else {
      // Couldn't resolve FeatureType
      throw new CommandSpecException("Couldn't resolve the given path to a feature type.");
    }
  }
Ejemplo n.º 4
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);
          }
        }
      }
    }