001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.cli;
013:
014: import java.io.PrintStream;
015:
016: import org.tmatesoft.svn.core.SVNNodeKind;
017: import org.tmatesoft.svn.core.internal.util.SVNFormatUtil;
018: import org.tmatesoft.svn.core.wc.ISVNStatusHandler;
019: import org.tmatesoft.svn.core.wc.SVNStatus;
020: import org.tmatesoft.svn.core.wc.SVNStatusType;
021:
022: /**
023: *
024: * @version 1.1.1
025: * @author TMate Software Ltd.
026: */
027: public class SVNCommandStatusHandler implements ISVNStatusHandler {
028:
029: private PrintStream myOut;
030: private boolean myDetailed;
031: private boolean myShowLastCommitted;
032: private boolean mySkipUnrecognized;
033: private boolean myShowReposLocks;
034:
035: public SVNCommandStatusHandler(PrintStream out, boolean detailed,
036: boolean showLastCommitted, boolean skipUnrecognized,
037: boolean showReposLocks) {
038: myOut = out;
039: myDetailed = detailed;
040: myShowLastCommitted = showLastCommitted;
041: mySkipUnrecognized = skipUnrecognized;
042: myShowReposLocks = showReposLocks;
043: }
044:
045: public void handleStatus(SVNStatus status) {
046: if (status == null
047: || (mySkipUnrecognized && status.getURL() == null)
048: || (status.getContentsStatus() == SVNStatusType.STATUS_NONE && status
049: .getRemoteContentsStatus() == SVNStatusType.STATUS_NONE)) {
050: return;
051: }
052: StringBuffer result = new StringBuffer();
053: if (!myDetailed) {
054: result.append(getStatusChar(status.getContentsStatus()));
055: result.append(getStatusChar(status.getPropertiesStatus()));
056: result.append(status.isLocked() ? 'L' : ' ');
057: result.append(status.isCopied() ? '+' : ' ');
058: result.append(status.isSwitched() ? 'S' : ' ');
059: result.append(status.getLocalLock() != null ? 'K' : ' ');
060: result.append(" ");
061: result.append(SVNFormatUtil.formatPath(status.getFile()));
062: } else {
063: String wcRevision;
064: char remoteStatus;
065: if (status.getURL() == null) {
066: wcRevision = "";
067: } else if (!status.getRevision().isValid()) {
068: wcRevision = " ? ";
069: } else if (status.isCopied()) {
070: wcRevision = "-";
071: } else {
072: wcRevision = Long.toString(status.getRevision()
073: .getNumber());
074: if (status.getKind() == SVNNodeKind.DIR
075: && status.getContentsStatus() == SVNStatusType.STATUS_MISSING) {
076: wcRevision = " ? ";
077: }
078: }
079: if (status.getRemotePropertiesStatus() != SVNStatusType.STATUS_NONE
080: || status.getRemoteContentsStatus() != SVNStatusType.STATUS_NONE) {
081: remoteStatus = '*';
082: } else {
083: remoteStatus = ' ';
084: }
085: char lockStatus;
086: if (myShowReposLocks) {
087: if (status.getRemoteLock() != null) {
088: if (status.getLocalLock() != null) {
089: lockStatus = status.getLocalLock().getID()
090: .equals(status.getRemoteLock().getID()) ? 'K'
091: : 'T';
092: } else {
093: lockStatus = 'O';
094: }
095: } else if (status.getLocalLock() != null) {
096: lockStatus = 'B';
097: } else {
098: lockStatus = ' ';
099: }
100: } else {
101: lockStatus = status.getLocalLock() != null ? 'K' : ' ';
102: }
103: if (myShowLastCommitted) {
104: String commitRevision = "";
105: String commitAuthor = "";
106:
107: if (status.getURL() != null
108: && status.getCommittedRevision().isValid()) {
109: commitRevision = status.getCommittedRevision()
110: .toString();
111: } else if (status.getURL() != null) {
112: commitRevision = " ? ";
113: }
114: if (status.getURL() != null
115: && status.getAuthor() != null) {
116: commitAuthor = status.getAuthor();
117: } else if (status.getURL() != null) {
118: commitAuthor = " ? ";
119: }
120: result
121: .append(getStatusChar(status
122: .getContentsStatus()));
123: result.append(getStatusChar(status
124: .getPropertiesStatus()));
125: result.append(status.isLocked() ? 'L' : ' ');
126: result.append(status.isCopied() ? '+' : ' ');
127: result.append(status.isSwitched() ? 'S' : ' ');
128: result.append(lockStatus);
129: result.append(" ");
130: result.append(remoteStatus);
131: result.append(" ");
132: result.append(SVNCommand.formatString(wcRevision, 6,
133: false)); // 6 chars
134: result.append(" ");
135: result.append(SVNCommand.formatString(commitRevision,
136: 6, false)); // 6 chars
137: result.append(" ");
138: result.append(SVNCommand.formatString(commitAuthor, 12,
139: true)); // 12 chars
140: result.append(" ");
141: result.append(SVNFormatUtil
142: .formatPath(status.getFile()));
143: } else {
144: result
145: .append(getStatusChar(status
146: .getContentsStatus()));
147: result.append(getStatusChar(status
148: .getPropertiesStatus()));
149: result.append(status.isLocked() ? 'L' : ' ');
150: result.append(status.isCopied() ? '+' : ' ');
151: result.append(status.isSwitched() ? 'S' : ' ');
152: result.append(lockStatus);
153: result.append(" ");
154: result.append(remoteStatus);
155: result.append(" ");
156: result.append(SVNCommand.formatString(wcRevision, 6,
157: false)); // 6 chars
158: result.append(" ");
159: result.append(SVNFormatUtil
160: .formatPath(status.getFile()));
161: }
162: }
163: myOut.println(result.toString());
164:
165: }
166:
167: private static char getStatusChar(SVNStatusType type) {
168: if (type == SVNStatusType.STATUS_NONE) {
169: return ' ';
170: } else if (type == SVNStatusType.STATUS_NORMAL) {
171: return ' ';
172: } else if (type == SVNStatusType.STATUS_ADDED) {
173: return 'A';
174: } else if (type == SVNStatusType.STATUS_MISSING) {
175: return '!';
176: } else if (type == SVNStatusType.STATUS_INCOMPLETE) {
177: return '!';
178: } else if (type == SVNStatusType.STATUS_DELETED) {
179: return 'D';
180: } else if (type == SVNStatusType.STATUS_REPLACED) {
181: return 'R';
182: } else if (type == SVNStatusType.STATUS_MODIFIED) {
183: return 'M';
184: } else if (type == SVNStatusType.STATUS_CONFLICTED) {
185: return 'C';
186: } else if (type == SVNStatusType.STATUS_OBSTRUCTED) {
187: return '~';
188: } else if (type == SVNStatusType.STATUS_IGNORED) {
189: return 'I';
190: } else if (type == SVNStatusType.STATUS_EXTERNAL) {
191: return 'X';
192: } else if (type == SVNStatusType.STATUS_UNVERSIONED) {
193: return '?';
194: }
195: return '?';
196: }
197: }
|