Пример #1
0
		public void Build(Options opts, bool noPrompt)
		{
			if (opts.ImportDriver == "git")
			{
				if (!opts.IsGitRepoDirExternal)
				{
					if (noPrompt || MessageBox.Show("Repository and work tree will be recreated", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
					{
						File.WriteAllText(Importer.DataFileName, "0\n");
						GitDriver.Create(opts.GitExe, opts.GitRepoDir);
					}
				}
			}
			else if(opts.ImportDriver == "tfs")
			{
				if (noPrompt || MessageBox.Show("Work tree will be cleanup", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
				{
					var driver = new TfsDriver(opts, Console.Out, false);
					driver.CleanupWorkingTree();
				}
			}
			else if (opts.ImportDriver == "svn")
			{
				if (opts.IsSvnRepoDirExternal)
				{
					if (noPrompt || MessageBox.Show("Working copy will be recreated (but not repository)", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
					{
						SvnDriver.Checkout(opts.SvnRepoUrl, opts.SvnWorkTreeDir);
					}
				}
				else
				{
					if (noPrompt || MessageBox.Show("Repository and Working copy will be recreated", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
					{
						File.WriteAllText(Importer.DataFileName, "0\n");
						SvnDriver.CreateRepo(opts.SvnRepoUrl);
						SvnDriver.Checkout(opts.SvnRepoUrl, opts.SvnWorkTreeDir);
					}
				}
			}
			else
			{
				throw new Exception("Unknown import driver: " + opts.ImportDriver);
			}
		}
Пример #2
0
		public void Import(Options opts, List<Commit> commits, bool startNewSession, Action<float> progress = null)
		{
			StopImport = false;
			DogWatch = DateTimeOffset.Now;

			if(startNewSession && File.Exists(DataFileName))
				File.Delete(DataFileName);

			_opts = opts;

			_unimportants = opts
				.Config["unimportant-diff"]
				.Select(v => {
					var sep = v.IndexOf('?');
					if (sep == -1)
						throw new ApplicationException("Incorrect unimportant-diff: " + v + "\nAbsent separator '?' between filename and unimportant regex");

					var fileNameRx = new Regex(v.Substring(0, sep), RegexOptions.IgnoreCase);
					var regex = new Regex(v.Substring(sep + 1), RegexOptions.IgnoreCase);

					return Tuple.Create(fileNameRx, regex);
				})
				.ToList()
			;

			// load censores
			_censors = LoadCensors(opts);

			var fromCommit = 0;

			if (!startNewSession)
			{
				if (File.Exists(DataFileName))
				{
					fromCommit = File.ReadAllLines(DataFileName)
						.Select(x => Int32.Parse(x) + 1)
						.DefaultIfEmpty(0)
						.Last()
					;
				}

				if (MessageBox.Show(string.Format("Cleanu work tree and start import from commit #{0} by {1}", fromCommit, commits[fromCommit].User), "Confirmation", MessageBoxButtons.OKCancel) != DialogResult.OK)
					return;

				if (opts.ImportDriver == "tfs")
				{
					new TfsDriver(opts, Console.Out, false).CleanupWorkingTree();
				}
			}

			using (_cache = new VssFileCache(opts.CacheDir, _opts.SourceSafeIni))
			using(var log = File.CreateText(LogFileName))
			{
				log.AutoFlush = true;

				try
				{
					IDestinationDriver driver;
					if (opts.ImportDriver == "git")
					{
						driver = new GitDriver(opts.GitExe, opts.GitRepoDir, opts.GitDefaultAuthorDomain, log);
					}
					else if (opts.ImportDriver == "tfs")
					{
						driver = new TfsDriver(opts, log, true);
					}
					else
					{
						driver = new SvnDriver(opts.SvnWorkTreeDir, log);
					}

					for (var i = fromCommit; i < commits.Count; i++)
					{
						var c = commits[i];

						Console.WriteLine("[{2,6}/{3}] Import: {0:yyyy-MMM-dd HH:ss:mm}, by {1}", c.At, c.User, i, commits.Count);
						if (progress != null)
							progress((float)i / commits.Count);

						DogWatch = DateTimeOffset.Now;

						driver.StartRevision();

						DogWatch = DateTimeOffset.Now;

						LoadRevision(driver, c, log);

						DogWatch = DateTimeOffset.Now;

						driver.CommitRevision(commits[i].User, c.Comment, commits[i].At);

						DogWatch = DateTimeOffset.Now;

						// OK
						File.AppendAllText(DataFileName, i + "\n");

						if (StopImport)
							break;
					}
				}
				catch (Exception ex)
				{
					log.WriteLine(ex.ToString());
					throw;
				}
			}

			DogWatch = null;

			if (StopImport)
			{
				Console.WriteLine("Import interrupted.");
			}
			else
			{
				Console.WriteLine("Import complete.");

				if (opts.ImportDriver == "git" && !string.IsNullOrWhiteSpace(opts.GitStartAfterImport))
				{
					Process.Start(opts.GitStartAfterImport, opts.GitStartAfterImportArgs.Replace("%REPODIR%", opts.GitRepoDir));
				}
			}
		}