| 1 |
// SvnTest, a client program used to test SubversionSharp library |
|---|
| 2 |
#region Copyright (C) 2004 SOFTEC sa. |
|---|
| 3 |
// |
|---|
| 4 |
// SvnTest, a client program used to test SubversionSharp library |
|---|
| 5 |
// Copyright 2004 by SOFTEC sa |
|---|
| 6 |
// |
|---|
| 7 |
// This program is free software; you can redistribute it and/or |
|---|
| 8 |
// modify it under the terms of the GNU General Public License as |
|---|
| 9 |
// published by the Free Software Foundation; either version 2 of |
|---|
| 10 |
// the License, or (at your option) any later version. |
|---|
| 11 |
// |
|---|
| 12 |
// This program is distributed in the hope that it will be useful, |
|---|
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 15 |
// See the GNU General Public License for more details. |
|---|
| 16 |
// |
|---|
| 17 |
// You should have received a copy of the GNU General Public |
|---|
| 18 |
// License along with this program; if not, write to the Free Software |
|---|
| 19 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 |
// |
|---|
| 21 |
// Sources, support options and lastest version of the complete library |
|---|
| 22 |
// is available from: |
|---|
| 23 |
// http://www.softec.st/SubversionSharp |
|---|
| 24 |
// |
|---|
| 25 |
// |
|---|
| 26 |
// Initial authors : |
|---|
| 27 |
// Denis Gervalle |
|---|
| 28 |
// Olivier Desaive |
|---|
| 29 |
#endregion |
|---|
| 30 |
// |
|---|
| 31 |
using System; |
|---|
| 32 |
using System.Collections; |
|---|
| 33 |
using System.IO; |
|---|
| 34 |
using Mono.GetOptions; |
|---|
| 35 |
using Softec.AprSharp; |
|---|
| 36 |
using Softec.SubversionSharp; |
|---|
| 37 |
|
|---|
| 38 |
namespace Softec.SubversionSharp.Test { |
|---|
| 39 |
|
|---|
| 40 |
[SubCommand("status", "st", |
|---|
| 41 |
@"[PATH...] |
|---|
| 42 |
Print the status of working copy files and directories. |
|---|
| 43 |
With no args, print only locally modified items (no network access). |
|---|
| 44 |
With -u, add working revision and server out-of-date information. |
|---|
| 45 |
With -v, print full revision information on every item. |
|---|
| 46 |
|
|---|
| 47 |
The first five columns in the output are each one character wide: |
|---|
| 48 |
First column: Says if item was added, deleted, or otherwise changed |
|---|
| 49 |
' ' no modifications |
|---|
| 50 |
'A' Added |
|---|
| 51 |
'C' Conflicted |
|---|
| 52 |
'D' Deleted |
|---|
| 53 |
'G' Merged |
|---|
| 54 |
'I' Ignored |
|---|
| 55 |
'M' Modified |
|---|
| 56 |
'R' Replaced |
|---|
| 57 |
'X' item is unversioned, but is used by an externals definition |
|---|
| 58 |
'?' item is not under version control |
|---|
| 59 |
'!' item is missing (removed by non-svn command) or incomplete |
|---|
| 60 |
'~' versioned item obstructed by some item of a different kind |
|---|
| 61 |
Second column: Modifications of a file's or directory's properties |
|---|
| 62 |
' ' no modifications |
|---|
| 63 |
'C' Conflicted |
|---|
| 64 |
'M' Modified |
|---|
| 65 |
Third column: Whether the working copy directory is locked |
|---|
| 66 |
' ' not locked |
|---|
| 67 |
'L' locked |
|---|
| 68 |
Fourth column: Scheduled commit will contain addition-with-history |
|---|
| 69 |
' ' no history scheduled with commit |
|---|
| 70 |
'+' history scheduled with commit |
|---|
| 71 |
Fifth column: Whether the item is switched relative to its parent |
|---|
| 72 |
' ' normal |
|---|
| 73 |
'S' switched |
|---|
| 74 |
|
|---|
| 75 |
The out-of-date information appears in the eighth column (with -u): |
|---|
| 76 |
'*' a newer revision exists on the server |
|---|
| 77 |
' ' the working copy is up to date |
|---|
| 78 |
|
|---|
| 79 |
Remaining fields are variable width and delimited by spaces: |
|---|
| 80 |
The working revision (with -u or -v) |
|---|
| 81 |
The last committed revision and last committed author (with -v) |
|---|
| 82 |
The working copy path is always the final field, so it can |
|---|
| 83 |
include spaces. |
|---|
| 84 |
|
|---|
| 85 |
Example output: |
|---|
| 86 |
svn status wc |
|---|
| 87 |
M wc/bar.c |
|---|
| 88 |
A + wc/qax.c |
|---|
| 89 |
|
|---|
| 90 |
svn status -u wc |
|---|
| 91 |
M 965 wc/bar.c |
|---|
| 92 |
* 965 wc/foo.c |
|---|
| 93 |
A + 965 wc/qax.c |
|---|
| 94 |
Head revision: 981 |
|---|
| 95 |
|
|---|
| 96 |
svn status --show-updates --verbose wc |
|---|
| 97 |
M 965 938 kfogel wc/bar.c |
|---|
| 98 |
* 965 922 sussman wc/foo.c |
|---|
| 99 |
A + 965 687 joe wc/qax.c |
|---|
| 100 |
965 687 joe wc/zig.c |
|---|
| 101 |
Head revision: 981" |
|---|
| 102 |
)] |
|---|
| 103 |
class StatusCmd : CmdBaseWithAuth |
|---|
| 104 |
{ |
|---|
| 105 |
[Option("operate on single directory only", 'N', "non-recursive")] |
|---|
| 106 |
public bool oNoRecurse { |
|---|
| 107 |
set { oRecurse = !value; } |
|---|
| 108 |
} |
|---|
| 109 |
public bool oRecurse = true; |
|---|
| 110 |
|
|---|
| 111 |
[Option("display update information", 'u', "show-updates")] |
|---|
| 112 |
public bool oShowUpdates = false; |
|---|
| 113 |
|
|---|
| 114 |
[Option("print extra information", 'v', "verbose")] |
|---|
| 115 |
public bool oVerbose = false; |
|---|
| 116 |
|
|---|
| 117 |
[Option("disregard default and svn:ignore property ignores", "no-ignore")] |
|---|
| 118 |
public bool oNoIgnore = false; |
|---|
| 119 |
|
|---|
| 120 |
protected override int Execute() |
|---|
| 121 |
{ |
|---|
| 122 |
int nbPath = RemainingArguments.Length; |
|---|
| 123 |
|
|---|
| 124 |
if( nbPath == 1 ) |
|---|
| 125 |
{ |
|---|
| 126 |
client.Status(new SvnPath("", client.Pool), |
|---|
| 127 |
new SvnRevision(Svn.Revision.Head), |
|---|
| 128 |
new SvnWcStatus.Func(StatusCallback), IntPtr.Zero, |
|---|
| 129 |
oRecurse, oVerbose, oShowUpdates, oNoIgnore); |
|---|
| 130 |
} |
|---|
| 131 |
else |
|---|
| 132 |
{ |
|---|
| 133 |
for(int i=1; i<nbPath; i++) |
|---|
| 134 |
{ |
|---|
| 135 |
try |
|---|
| 136 |
{ |
|---|
| 137 |
client.Status(new SvnPath(RemainingArguments[i], client.Pool), |
|---|
| 138 |
new SvnRevision(Svn.Revision.Head), |
|---|
| 139 |
new SvnWcStatus.Func(StatusCallback), IntPtr.Zero, |
|---|
| 140 |
oRecurse, oVerbose, oShowUpdates, oNoIgnore); |
|---|
| 141 |
} |
|---|
| 142 |
catch( Exception e ) |
|---|
| 143 |
{ |
|---|
| 144 |
if( oDebug ) |
|---|
| 145 |
Console.WriteLine(e); |
|---|
| 146 |
else |
|---|
| 147 |
Console.WriteLine(e.Message); |
|---|
| 148 |
} |
|---|
| 149 |
client.Clear(); |
|---|
| 150 |
} |
|---|
| 151 |
} |
|---|
| 152 |
return(0); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
private void StatusCallback(IntPtr baton, SvnPath path, SvnWcStatus status) |
|---|
| 156 |
{ |
|---|
| 157 |
if (status.IsNull |
|---|
| 158 |
|| (oQuiet && status.Entry.IsNull) |
|---|
| 159 |
|| ((status.TextStatus == SvnWcStatus.Kind.None) |
|---|
| 160 |
&& (status.ReposTextStatus == SvnWcStatus.Kind.None))) |
|---|
| 161 |
{ |
|---|
| 162 |
return; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
string wrkRevNum = ""; |
|---|
| 166 |
string ciRevNum = ""; |
|---|
| 167 |
string ciAuthor = ""; |
|---|
| 168 |
char oodStatus = '@'; |
|---|
| 169 |
|
|---|
| 170 |
if (oShowUpdates || oVerbose) |
|---|
| 171 |
{ |
|---|
| 172 |
if( status.Entry.IsNull ) |
|---|
| 173 |
wrkRevNum = ""; |
|---|
| 174 |
else if( status.Entry.Revision < 0 ) |
|---|
| 175 |
wrkRevNum = " ? "; |
|---|
| 176 |
else if( status.Copied ) |
|---|
| 177 |
wrkRevNum = "-"; |
|---|
| 178 |
else |
|---|
| 179 |
wrkRevNum = status.Entry.Revision.ToString(); |
|---|
| 180 |
|
|---|
| 181 |
if( status.ReposTextStatus != SvnWcStatus.Kind.None |
|---|
| 182 |
|| status.ReposPropStatus != SvnWcStatus.Kind.None ) |
|---|
| 183 |
oodStatus = '*'; |
|---|
| 184 |
else |
|---|
| 185 |
oodStatus = ' '; |
|---|
| 186 |
|
|---|
| 187 |
if( oVerbose ) |
|---|
| 188 |
{ |
|---|
| 189 |
if( status.Entry.IsNull ) |
|---|
| 190 |
ciRevNum = ""; |
|---|
| 191 |
else if( status.Entry.CommitRev < 0 ) |
|---|
| 192 |
ciRevNum = " ? "; |
|---|
| 193 |
else |
|---|
| 194 |
ciRevNum = status.Entry.CommitRev.ToString(); |
|---|
| 195 |
|
|---|
| 196 |
if( status.Entry.IsNull ) |
|---|
| 197 |
ciAuthor = ""; |
|---|
| 198 |
else if( status.Entry.CommitAuthor.IsNull ) |
|---|
| 199 |
ciAuthor = " ? "; |
|---|
| 200 |
else |
|---|
| 201 |
ciAuthor = status.Entry.CommitAuthor.ToString(); |
|---|
| 202 |
} |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
if(oVerbose) |
|---|
| 206 |
{ |
|---|
| 207 |
Console.WriteLine("{0}{1}{2}{3}{4} {5} {6,6} {7,6:X} {8,-12} {9}", |
|---|
| 208 |
WcStatusChar(status.TextStatus), |
|---|
| 209 |
WcStatusChar(status.PropStatus), |
|---|
| 210 |
status.Locked ? 'L' : ' ', |
|---|
| 211 |
status.Copied ? '+' : ' ', |
|---|
| 212 |
status.Switched ? 'S' : ' ', |
|---|
| 213 |
oodStatus, |
|---|
| 214 |
wrkRevNum, |
|---|
| 215 |
ciRevNum, |
|---|
| 216 |
ciAuthor, |
|---|
| 217 |
path); |
|---|
| 218 |
} |
|---|
| 219 |
else if (oShowUpdates) |
|---|
| 220 |
{ |
|---|
| 221 |
Console.WriteLine("{0}{1}{2}{3}{4} {5} {6,6} {7}", |
|---|
| 222 |
WcStatusChar(status.TextStatus), |
|---|
| 223 |
WcStatusChar(status.PropStatus), |
|---|
| 224 |
status.Locked ? 'L' : ' ', |
|---|
| 225 |
status.Copied ? '+' : ' ', |
|---|
| 226 |
status.Switched ? 'S' : ' ', |
|---|
| 227 |
oodStatus, |
|---|
| 228 |
wrkRevNum, |
|---|
| 229 |
path); |
|---|
| 230 |
} |
|---|
| 231 |
else |
|---|
| 232 |
{ |
|---|
| 233 |
Console.WriteLine("{0}{1}{2}{3}{4} {5}", |
|---|
| 234 |
WcStatusChar(status.TextStatus), |
|---|
| 235 |
WcStatusChar(status.PropStatus), |
|---|
| 236 |
status.Locked ? 'L' : ' ', |
|---|
| 237 |
status.Copied ? '+' : ' ', |
|---|
| 238 |
status.Switched ? 'S' : ' ', |
|---|
| 239 |
path); |
|---|
| 240 |
} |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
private char WcStatusChar(SvnWcStatus.Kind kind) |
|---|
| 244 |
{ |
|---|
| 245 |
switch( kind ) |
|---|
| 246 |
{ |
|---|
| 247 |
case SvnWcStatus.Kind.None : return ' '; |
|---|
| 248 |
case SvnWcStatus.Kind.Unversioned : return '?'; |
|---|
| 249 |
case SvnWcStatus.Kind.Normal : return ' '; |
|---|
| 250 |
case SvnWcStatus.Kind.Added : return 'A'; |
|---|
| 251 |
case SvnWcStatus.Kind.Missing : return '!'; |
|---|
| 252 |
case SvnWcStatus.Kind.Deleted : return 'D'; |
|---|
| 253 |
case SvnWcStatus.Kind.Replaced : return 'R'; |
|---|
| 254 |
case SvnWcStatus.Kind.Modified : return 'M'; |
|---|
| 255 |
case SvnWcStatus.Kind.Merged : return 'G'; |
|---|
| 256 |
case SvnWcStatus.Kind.Conflicted : return 'C'; |
|---|
| 257 |
case SvnWcStatus.Kind.Ignored : return 'I'; |
|---|
| 258 |
case SvnWcStatus.Kind.Obstructed : return '~'; |
|---|
| 259 |
case SvnWcStatus.Kind.External : return 'X'; |
|---|
| 260 |
case SvnWcStatus.Kind.Incomplete : return 'I'; |
|---|
| 261 |
} |
|---|
| 262 |
return '?'; |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
} |
|---|