01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html.
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.cli.command;
13:
14: import java.io.File;
15: import java.io.InputStream;
16: import java.io.PrintStream;
17:
18: import org.tmatesoft.svn.cli.SVNArgument;
19: import org.tmatesoft.svn.cli.SVNCommand;
20: import org.tmatesoft.svn.core.SVNException;
21: import org.tmatesoft.svn.core.SVNNodeKind;
22: import org.tmatesoft.svn.core.wc.SVNRevision;
23: import org.tmatesoft.svn.core.wc.admin.ISVNChangeEntryHandler;
24: import org.tmatesoft.svn.core.wc.admin.SVNChangeEntry;
25: import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
26:
27: /**
28: * @version 1.1.1
29: * @author TMate Software Ltd.
30: * @since 1.1.1
31: */
32: public class SVNLookChangedCommand extends SVNCommand implements
33: ISVNChangeEntryHandler {
34: private PrintStream myOut;
35:
36: public void run(PrintStream out, PrintStream err)
37: throws SVNException {
38: if (!getCommandLine().hasPaths()) {
39: SVNCommand.println(err,
40: "jsvnlook: Repository argument required");
41: System.exit(1);
42: }
43:
44: File reposRoot = new File(getCommandLine().getPathAt(0));
45: myOut = out;
46: SVNRevision revision = SVNRevision.HEAD;
47: SVNLookClient lookClient = getClientManager().getLookClient();
48: boolean isCopyInfoIncluded = getCommandLine().hasArgument(
49: SVNArgument.COPY_INFO);
50:
51: if (getCommandLine().hasArgument(SVNArgument.TRANSACTION)) {
52: String transactionName = (String) getCommandLine()
53: .getArgumentValue(SVNArgument.TRANSACTION);
54: lookClient.doGetChanged(reposRoot, transactionName, this ,
55: isCopyInfoIncluded);
56: return;
57: } else if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
58: revision = SVNRevision.parse((String) getCommandLine()
59: .getArgumentValue(SVNArgument.REVISION));
60: }
61:
62: lookClient.doGetChanged(reposRoot, revision, this ,
63: isCopyInfoIncluded);
64: }
65:
66: public void run(InputStream in, PrintStream out, PrintStream err)
67: throws SVNException {
68: run(out, err);
69: }
70:
71: public void handleEntry(SVNChangeEntry entry) throws SVNException {
72: String[] status = new String[3];
73: status[0] = entry.getType() == SVNChangeEntry.TYPE_UPDATED
74: && !entry.hasTextModifications() ? "_" : ""
75: + entry.getType();
76: status[1] = entry.hasPropertyModifications() ? ""
77: + SVNChangeEntry.TYPE_UPDATED : " ";
78: status[2] = entry.getCopyFromPath() != null ? "+" : " ";
79: String path = !entry.getPath().endsWith("/")
80: && entry.getKind() == SVNNodeKind.DIR ? entry.getPath()
81: + "/" : entry.getPath();
82: path = path.startsWith("/") ? path.substring(1) : path;
83: SVNCommand.println(myOut, status[0] + status[1] + status[2]
84: + " " + path);
85: if (entry.getCopyFromPath() != null) {
86: String copyFromPath = entry.getCopyFromPath();
87: if (copyFromPath.startsWith("/")) {
88: copyFromPath = copyFromPath.substring(1);
89: }
90: if (!copyFromPath.endsWith("/")
91: && entry.getKind() == SVNNodeKind.DIR) {
92: copyFromPath += "/";
93: }
94: SVNCommand.println(myOut, " (from " + copyFromPath
95: + ":r" + entry.getCopyFromRevision() + ")");
96: }
97: }
98:
99: }
|