-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
144 lines (109 loc) · 3.72 KB
/
Program.cs
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
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
namespace MergeSvnRepos
{
class Program
{
static void Main(string[] args)
{
long global_rev = 0;
string new_repo_path = args[0];
List<ContributingRepository> repo_list = new List<ContributingRepository>();
for( int i = 1; i < args.Length; i++ )
repo_list.Add(new ContributingRepository(args[i]));
ContributingRepository[] repos = repo_list.ToArray();
// create the parent dirs
foreach( ContributingRepository repo in repos )
{
// create the dir
CreateDirectory(new_repo_path, repo.Path);
// increment the global rev
global_rev++;
}
while( true )
{
// find the next repository
ContributingRepository next_repo = FindNextRevision(repos);
// check to see if we're done
if( next_repo.CurrentRevisionDate == DateTime.MaxValue )
{
Console.WriteLine("Done!");
return;
}
// display a pretty notice
Console.WriteLine("Taking next revision ({0}) from {1}", next_repo.CurrentRevision, next_repo.Path);
// increment the global revision
global_rev++;
// map the revision
next_repo.RevisionMap.AddRevisionMapping(next_repo.CurrentRevision, global_rev);
byte[] rev_to_load;
// dump and process the revision
using( MemoryStream input = new MemoryStream(next_repo.GetCurrentRevision()) )
{
using( MemoryStream output = new MemoryStream() )
{
DumpProcessor.ProcessDump(input, output, next_repo.RevisionMap, global_rev);
rev_to_load = output.ToArray();
}
}
// and, load the revision
LoadRevision(new_repo_path, rev_to_load, next_repo.Path);
}
}
static ContributingRepository FindNextRevision(ContributingRepository[] repos)
{
ContributingRepository cur_repo = repos[0];
for( int i = 1; i < repos.Length; i++ )
{
if( repos[i].CurrentRevisionDate < cur_repo.CurrentRevisionDate )
cur_repo = repos[i];
}
return cur_repo;
}
static void LoadRevision(string path, byte[] data, string reponame)
{
reponame = Path.GetFileName(reponame);
using( Process p = new Process() )
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = string.Format("load {0} --ignore-uuid --parent-dir /{1}", path, reponame);
psi.CreateNoWindow = false;
psi.FileName = "svnadmin";
psi.RedirectStandardOutput = false;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
p.StartInfo = psi;
p.Start();
p.StandardInput.BaseStream.Write(data, 0, data.Length);
p.StandardInput.BaseStream.Flush();
p.StandardInput.BaseStream.Close();
p.WaitForExit();
p.Close();
}
}
static void CreateDirectory(string repo, string path)
{
DirectoryInfo di = new DirectoryInfo(repo);
if( !di.Exists )
throw new ApplicationException("Repository does not exist: " + repo);
path = Path.GetFileName(path);
Console.WriteLine("Creating parent dir {0} in {1}...", path, repo);
string url = string.Format("file:///{0}/{1}", di.FullName.Replace('\\', '/'), path);
using( Process p = new Process() )
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "mkdir " + url + " --non-interactive -m \"Created directory to hold merged-in repository\" --username MergeSvnRepos";
psi.CreateNoWindow = true;
psi.FileName = "svn";
psi.RedirectStandardOutput = false;
psi.UseShellExecute = false;
p.StartInfo = psi;
p.Start();
p.WaitForExit();
p.Close();
}
}
}
}