Example usage for org.eclipse.jgit.util QuotedString GIT_PATH

List of usage examples for org.eclipse.jgit.util QuotedString GIT_PATH

Introduction

In this page you can find the example usage for org.eclipse.jgit.util QuotedString GIT_PATH.

Prototype

GitPathStyle GIT_PATH

To view the source code for org.eclipse.jgit.util QuotedString GIT_PATH.

Click Source Link

Document

Quoting style that obeys the rules Git applies to file names

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private static String quotePath(String name) {
    return QuotedString.GIT_PATH.quote(name);
}

From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java

License:Apache License

private static String parseFilename(byte[] note, MutableInteger curr, Change.Id changeId, Charset enc)
        throws ConfigInvalidException {
    checkHeaderLineFormat(note, curr, FILE, enc, changeId);
    int startOfFileName = RawParseUtils.endOfFooterLineKey(note, curr.value) + 2;
    int endOfLine = RawParseUtils.nextLF(note, curr.value);
    curr.value = endOfLine;//from w ww.  j  a  v a  2  s.co  m
    curr.value = RawParseUtils.nextLF(note, curr.value);
    return QuotedString.GIT_PATH.dequote(RawParseUtils.decode(enc, note, startOfFileName, endOfLine - 1));
}

From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java

License:Apache License

/**
 * Build a note that contains the metadata for and the contents of all of the
 * comments in the given list of comments.
 *
 * @param comments//from w ww .  j a  va2  s  .co m
 *            A list of the comments to be written to the returned note
 *            byte array.
 *            All of the comments in this list must have the same side and
 *            must share the same PatchSet.Id.
 *            This list must not be empty because we cannot build a note
 *            for no comments.
 * @return the note. Null if there are no comments in the list.
 */
public byte[] buildNote(List<PatchLineComment> comments) {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    OutputStreamWriter streamWriter = new OutputStreamWriter(buf, UTF_8);
    try (PrintWriter writer = new PrintWriter(streamWriter)) {
        PatchLineComment first = comments.get(0);

        short side = first.getSide();
        PatchSet.Id psId = PatchLineCommentsUtil.getCommentPsId(first);
        appendHeaderField(writer, side == 0 ? BASE_PATCH_SET : PATCH_SET, Integer.toString(psId.get()));
        appendHeaderField(writer, REVISION, first.getRevId().get());

        String currentFilename = null;

        for (PatchLineComment c : comments) {
            PatchSet.Id currentPsId = PatchLineCommentsUtil.getCommentPsId(c);
            checkArgument(psId.equals(currentPsId),
                    "All comments being added must all have the same PatchSet.Id. The"
                            + "comment below does not have the same PatchSet.Id as the others " + "(%s).\n%s",
                    psId.toString(), c.toString());
            checkArgument(side == c.getSide(),
                    "All comments being added must all have the same side. The"
                            + "comment below does not have the same side as the others " + "(%s).\n%s",
                    side, c.toString());
            String commentFilename = QuotedString.GIT_PATH.quote(c.getKey().getParentKey().getFileName());

            if (!commentFilename.equals(currentFilename)) {
                currentFilename = commentFilename;
                writer.print("File: ");
                writer.print(commentFilename);
                writer.print("\n\n");
            }

            // The CommentRange field for a comment is allowed to be null.
            // If it is indeed null, then in the first line, we simply use the line
            // number field for a comment instead. If it isn't null, we write the
            // comment range itself.
            CommentRange range = c.getRange();
            if (range != null) {
                writer.print(range.getStartLine());
                writer.print(':');
                writer.print(range.getStartCharacter());
                writer.print('-');
                writer.print(range.getEndLine());
                writer.print(':');
                writer.print(range.getEndCharacter());
            } else {
                writer.print(c.getLine());
            }
            writer.print("\n");

            writer.print(formatTime(serverIdent, c.getWrittenOn()));
            writer.print("\n");

            PersonIdent ident = newIdent(accountCache.get(c.getAuthor()).getAccount(), c.getWrittenOn());
            String nameString = ident.getName() + " <" + ident.getEmailAddress() + ">";
            appendHeaderField(writer, AUTHOR, nameString);

            String parent = c.getParentUuid();
            if (parent != null) {
                appendHeaderField(writer, PARENT, parent);
            }

            appendHeaderField(writer, UUID, c.getKey().get());

            byte[] messageBytes = c.getMessage().getBytes(UTF_8);
            appendHeaderField(writer, LENGTH, Integer.toString(messageBytes.length));

            writer.print(c.getMessage());
            writer.print("\n\n");
        }
    }
    return buf.toByteArray();
}

From source file:com.madgag.agit.diff.LineContextDiffer.java

License:Open Source License

private static String quotePath(String name) {
    String q = QuotedString.GIT_PATH.quote(name);
    return ('"' + name + '"').equals(q) ? name : q;
}

From source file:org.eclipse.ptp.rdt.sync.git.core.GitRemoteSyncConnection.java

License:Open Source License

private void getRemoteFileStatus(Set<String> filesToAdd, Set<String> filesToDelete, IProgressMonitor monitor,
        boolean includeUntrackedFiles) throws IOException, RemoteExecutionException, RemoteSyncException {
    SubMonitor subMon = SubMonitor.convert(monitor, 10);
    subMon.subTask(Messages.GitRemoteSyncConnection_getting_remote_file_status);
    try {/* w w w  .j av  a  2s  .c o  m*/
        final String command;
        if (includeUntrackedFiles) {
            command = gitCommand + " ls-files -t --modified --others --deleted"; //$NON-NLS-1$
        } else {
            command = gitCommand + " ls-files -t --modified --deleted"; //$NON-NLS-1$
        }
        CommandResults commandResults = null;

        try {
            commandResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory,
                    subMon.newChild(10));
        } catch (final InterruptedException e) {
            throw new RemoteExecutionException(e);
        } catch (RemoteConnectionException e) {
            throw new RemoteExecutionException(e);
        }
        if (commandResults.getExitCode() != 0) {
            throw new RemoteExecutionException(Messages.GRSC_GitLsFilesFailure + commandResults.getStdout());
        }

        BufferedReader statusReader = new BufferedReader(new StringReader(commandResults.getStdout()));
        String line = null;
        while ((line = statusReader.readLine()) != null) {
            if (line.charAt(0) == ' ' || line.charAt(1) != ' ') {
                continue;
            }
            char status = line.charAt(0);
            String fn = line.substring(2);
            fn = QuotedString.GIT_PATH.dequote(fn);
            if (status == 'R') {
                filesToDelete.add(fn);
            } else if (!(fileFilter.shouldIgnore(fn))) {
                filesToAdd.add(fn);
            }
        }
        statusReader.close();
    } finally {
        if (monitor != null) {
            monitor.done();
        }
    }
}