/** * 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(); }
/** @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 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."); } }
@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); } } } }