My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#include "usvn.h"

bool CheckSvn()
{
String h;
if(Sys("svn", h) >= 0)
return true;
#ifdef PLATFORM_WIN32
Exclamation("Unable to execute svn.exe!&"
"You can download svn client here: [^http://www.sliksvn.com/en/download^ http://www.sliksvn.com/en/download]");
#else
Exclamation("Unable to execute 'svn' binary!&Please install svn client.");
#endif
return false;
}

SvnSync::SvnSync()
{
CtrlLayoutOKCancel(*this, "SvnSynchronize SVN repositories");
list.AddIndex();
list.AddIndex();
list.AddColumn("Action");
list.AddColumn("Path");
list.AddColumn("Changes");
list.ColumnWidths("220 500 100");
list.NoCursor().EvenRowColor();
list.SetLineCy(max(Draw::GetStdFontCy(), 20));
list.WhenLeftClick = THISBACK(Diff);
Sizeable().Zoomable();
setup <<= THISBACK(Setup);
BackPaint();
}

void SvnSync::Setup()
{
works.Execute();
SyncList();
}

int CharFilterSvnMsg(int c)
{
return c >= 32 && c < 128 && c != '\"' ? c : 0;
}

void SvnSync::SyncList()
{
list.Clear();
for(int i = 0; i < works.GetCount(); i++) {
SvnWork w = works[i];
String path = GetFullPath(w.working);
list.Add(REPOSITORY, path,
AttrText("Working directory").SetFont(StdFont().Bold()).Ink(White).Paper(Blue),
AttrText(path).SetFont(Arial(20).Bold()).Paper(Blue).Ink(White),
AttrText("").SetFont(Arial(20).Bold()).Paper(Blue).Ink(White));
list.SetLineCy(list.GetCount() - 1, 26);
Vector<String> ln = Split(Sys("svn status " + path), CharFilterCrLf);
bool actions = false;
for(int pass = 0; pass < 2; pass++)
for(int i = 0; i < ln.GetCount(); i++) {
String h = ln[i];
if(h.GetCount() > 7) {
String file = GetFullPath(TrimLeft(h.Mid(7)));
if(IsFullPath(file)) {
actions = true;
h.Trim(7);
bool simple = h.Mid(1, 6) == " ";
int action = simple ? String("MC?!~").Find(h[0]) : SVN_IGNORE;
if(h == " S ")
action = REPLACE;
String an;
Color color;
if(action == SVN_IGNORE) {
color = Black;
if(simple && h[0] == 'A') {
an = "svn add";
action = SVN_ACTION;
}
else
if(simple && h[0] == 'D') {
an = "svn delete";
action = SVN_ACTION;
}
else {
an = h.Mid(0, 7);
color = Gray;
}
}
else {
int q = file.ReverseFind('.');
if(action == ADD && q >= 0 && (file.Mid(q + 1) == "mine" ||
file[q + 1] == 'r' && IsDigit(file[q + 2]))
&& FileExists(file.Mid(0, q))) {
action = DELETEC;
an = "Delete (conflict resolved)";
color = Black;
}
else {
static const char *as[] = {
"Modify", "Resolved", "Add", "Remove", "Replace"
};
static Color c[] = { LtBlue, Magenta, Green, LtRed, LtMagenta };
an = as[action];
color = c[action];
}
}
if(pass == action < 0) {
int ii = list.GetCount();
list.Add(action, file,
action < 0 ? Value(AttrText(an).Ink(color)) : Value(true),
AttrText(" " + file.Mid(path.GetCount() + 1)).Ink(color));
if(action >= 0) {
list.SetCtrl(ii, 0, revert.Add().SetLabel("Revert\n" + an + "\nSkip").NoWantFocus());
Ctrl& b = diff.Add().SetLabel("Changes..").SizePos().NoWantFocus();
b <<= THISBACK1(DoDiff, ii);
list.SetCtrl(ii, 2, b);
}
}
}
}
}
if(actions) {
list.Add(MESSAGE, Null, AttrText("Commit message:").SetFont(StdFont().Bold()));
list.SetLineCy(list.GetCount() - 1, (3 * EditField::GetStdHeight()) + 4);
list.SetCtrl(list.GetCount() - 1, 1, message.Add().SetFilter(CharFilterSvnMsg).VSizePos(2, 2).HSizePos());
int q = msgmap.Find(w.working);
if(q >= 0) {
message.Top() <<= msgmap[q];
msgmap.Unlink(q);
}
}
else
list.Add(-1, Null, "", AttrText("Nothing to do").SetFont(StdFont().Italic()));
}
}

void SvnSync::DoDiff(int ii)
{
String f = list.Get(ii, 1);
if(!IsNull(f))
RunSvnDiff(f);
}

void SvnSync::Diff()
{
int cr = list.GetClickRow();
if(cr >= 0)
DoDiff(cr);
}

#ifdef PLATFORM_WIN32
void sDeleteFolderDeep(const char *dir)
{
{
FindFile ff(AppendFileName(dir, "*.*"));
while(ff) {
String name = ff.GetName();
String p = AppendFileName(dir, name);
if(ff.IsFile()) {
SetFileAttributes(p, GetFileAttributes(p) & ~FILE_ATTRIBUTE_READONLY);
FileDelete(p);
}
else
if(ff.IsFolder())
sDeleteFolderDeep(p);
ff.Next();
}
}
DirectoryDelete(dir);
}
#else
void sDeleteFolderDeep(const char *path)
{
DeleteFolderDeep(path);
}
#endif

void SvnDel(const char *path)
{
FindFile ff(AppendFileName(path, "*.*"));
while(ff) {
if(ff.IsFolder()) {
String dir = AppendFileName(path, ff.GetName());
if(ff.GetName() == ".svn")
sDeleteFolderDeep(dir);
else
SvnDel(dir);
}
ff.Next();
}
}

void SvnSync::Dir(const char *dir, bool readonly)
{
setup.Hide();
works.Add(dir, Null, Null, readonly);
}

void SvnSync::FixRevision(const char *dir, int revision){
for(int i=0;i<works.GetCount();i++)
if(works[i].working==dir){
works.SetRevision(i,revision);
return;
}
}

void SvnSync::Perform()
{
if(!CheckSvn())
return;
const Vector<String>& cl = CommandLine();
if(cl.GetCount())
for(int i = 0; i < cl.GetCount(); i++) {
if(cl[i] == "-") {
works.Load(LoadFile(ConfigFile("svnworks")));
DoSync();
SaveFile(ConfigFile("svnworks"), works.Save());
return;
}
String d = GetFullPath(cl[i]);
if(!DirectoryExists(cl[i])) {
Cerr() << cl[i] << " not a directory\n";
SetExitCode(1);
return;
}
works.Add(d, "", "");
}
else
works.Add(GetCurrentDirectory(), "", "");
setup.Hide();
DoSync();
}

void MoveSvn(const String& path, const String& tp)
{
FindFile ff(AppendFileName(path, "*.*"));
while(ff) {
String nm = ff.GetName();
String s = AppendFileName(path, nm);
String t = AppendFileName(tp, nm);
if(ff.IsFolder())
if(nm == ".svn")
FileMove(s, t);
else
MoveSvn(s, t);
ff.Next();
}
}

void SvnSync::DoSync()
{
SyncList();
msgmap.Sweep();
again:
if(Execute() != IDOK || list.GetCount() == 0) {
int repoi = 0;
for(int i = 0; i < list.GetCount(); i++)
if(list.Get(i, 0) == MESSAGE)
msgmap.GetAdd(works[repoi++].working) = list.Get(i, 3);
return;
}
bool changes = false;
for(int i = 0; i < list.GetCount(); i++) {
int action = list.Get(i, 0);
Value v = list.Get(i, 2);
if(action == MESSAGE) {
if(changes && IsNull(list.Get(i, 3))
&& !PromptYesNo("Commit message is empty.&Do you want to continue?"))
goto again;
changes = false;
}
else if(action != REPOSITORY && IsNumber(v) && v==1)
changes = true;
}
SysConsole sys;
int repoi = 0;
int l = 0;
bool commit = false;
while(l < list.GetCount()) {
SvnWork w = works[repoi++];
l++;
String message;
String filelist; // <-- list of files to update
while(l < list.GetCount()) {
int action = list.Get(l, 0);
String path = list.Get(l, 1);
if(action == MESSAGE && commit) {
String msg = list.Get(l, 3);
// now we commit only files in filelist
if(sys.CheckSystem(SvnCmd("commit", w).Cat() << filelist << " -m \"" << msg << "\""))
msgmap.GetAdd(w.working) = msg;
l++;
break;
}
if(action == REPOSITORY)
break;
Value v = list.Get(l, 2);
if(IsNumber(v) && (int)v == 0) {
if(action == REPLACE || action == ADD)
DeleteFolderDeep(path);
if(action != ADD)
sys.CheckSystem("svn revert \"" + path + "\"");
}
else
if(IsNumber(v) && (int)v==2 || action == SVN_IGNORE) {
l++;
continue;
}
else {
if(action != DELETEC)
filelist << " \"" << path << "\""; // <-- add the file to the list
commit = true;
switch(action) {
case ADD:
SvnDel(path);
sys.CheckSystem("svn add --force \"" + path + "\"");
break;
case REMOVE:
sys.CheckSystem("svn delete \"" + path + "\"");
break;
case CONFLICT:
sys.CheckSystem("svn resolved \"" + path + "\"");
break;
case REPLACE: {
SvnDel(path);
String tp = AppendFileName(GetFileFolder(path), Format(Uuid::Create()));
FileMove(path, tp);
sys.CheckSystem(SvnCmd("update", w).Cat() << " \"" << path << "\"");
MoveSvn(path, tp);
sDeleteFolderDeep(path);
FileMove(tp, path);
Vector<String> ln = Split(Sys("svn status \"" + path + "\""), CharFilterCrLf);
for(int l = 0; l < ln.GetCount(); l++) {
String h = ln[l];
if(h.GetCount() > 7) {
String file = h.Mid(7);
if(IsFullPath(file)) {
h.Trim(7);
if(h == "? ")
sys.CheckSystem("svn add --force \"" + file + "\"");
if(h == "! ")
sys.CheckSystem("svn delete \"" + file + "\"");
}
}
}
}
break;
case DELETEC:
FileDelete(path);
break;
}
}
l++;
}
sys.CheckSystem(SvnCmd("update", w).Cat() << w.working);
}
sys.Perform();
}

void SvnSync::SetMsgs(const String& s)
{
LoadFromString(msgmap, s);
}

String SvnSync::GetMsgs()
{
return StoreAsString(msgmap);
}

bool IsSvnDir(const String& p)
{
return DirectoryExists(AppendFileName(p, ".svn")) || DirectoryExists(AppendFileName(p, "_svn"));
}

#ifdef flagMAIN
GUI_APP_MAIN
{
if(!CheckSvn())
return;
SvnSync ss;
String mp = ConfigFile("usvn.msg");
ss.SetMsgs(LoadFile(mp));
ss.Perform();
SaveFile(mp, ss.GetMsgs());
}
#endif

Change log

r4480 by cxl on Jan 28, 2012   Diff
*ide: Fixed conflict and 'svn add' issues
in usvn
Go to: 
Project members, sign in to write a code review

Older revisions

r4479 by cxl on Jan 28, 2012   Diff
.developing usvn
r3409 by cxl on May 8, 2011   Diff
*theide: usvn support for filenames
with spaces
r3396 by cxl on May 2, 2011   Diff
*usvn: Fixed for filenames with spaces
All revisions of this file

File info

Size: 9829 bytes, 385 lines
Powered by Google Project Hosting