예제 #1
0
void onSetSvnPath(CmdLine& cmdLine)
{
	std::wstring path = cmdLine.next();
	if(path.empty())
		JStd::CmdLine::throwUsage(L"<new svn path> [remote name]");

	string remote = GitSvn::wtoa(cmdLine.next());
	if(remote.empty())
		remote = "svn";

	remote = GitSvn::toRef(remote, GitSvn::eRT_meta);

	//Git::CRepo gitRepo(L".\");
	Git::CRepo gitRepo;
	GitSvn::openCur(gitRepo);

	Git::VectorCommit parents;
	parents.push_back(std::tr1::shared_ptr<Git::CCommit>(new Git::CCommit(gitRepo, gitRepo.GetRef(remote.c_str()).Oid())));
	Git::CTree tree(gitRepo, parents.front()->Tree());


	std::string commitMsg = GitSvn::wtoa(L"SvnPath: " + path);

	Git::CSignature sig(gitRepo);
	gitRepo.Commit(remote.c_str(), sig, sig, commitMsg.c_str(), tree, parents);
	cout << "SVN path set to " << GitSvn::wtoa(path) << endl;
}
예제 #2
0
void onClone(CmdLine& cmdLine)
{
	std::wstring gitPath = cmdLine.next();
	std::wstring svnPath = cmdLine.next();
	if(gitPath.empty() || svnPath.empty())
		JStd::CmdLine::throwUsage(L"<git repo path> <svn repo path> [remote name]");

	std::string remoteName = JStd::String::ToMult(cmdLine.next(), CP_UTF8);
	if(remoteName.empty())
		remoteName = "svn";
	SvnToGitSync(gitPath.c_str(), JStd::String::ToMult(svnPath.c_str(), CP_UTF8).c_str(), remoteName.c_str());
}
예제 #3
0
void onFetch(CmdLine& cmdLine)
{
	Git::CRepo gitRepo;
	GitSvn::openCur(gitRepo);

	svn::Repo svnRepo;

	string remote = GitSvn::wtoa(cmdLine.next());
	if(remote.empty())
		remote = "svn";


	RevSyncCtxt ctxt(gitRepo, svnRepo, "");

	ctxt.m_csBaseRefName = remote;

	//Initialize
	std::string			svnPath;
	bool				bFirst = true;
	svn_revnum_t		LastRev = 0;
	Git::CCommitWalker	walker;
	walker.Init(gitRepo);
	walker.AddRev(gitRepo.GetRef(GitSvn::toRef(remote, GitSvn::eRT_meta).c_str()).Oid());

	for(;!walker.End(); ++walker)
	{
		if(ctxt.m_lastCommit.isNull())
			ctxt.m_lastCommit = walker.Curr();

		Git::CCommit commit(gitRepo, walker.Curr());
		istringstream msg(commit.Message());
		string line;
		string svnMsg;
		bool bSvnMsg = false;
		int rev = -1;
		while(getline(msg, line))
		{
			if(bSvnMsg)
				svnMsg += line;
			else if(strncmp(line.c_str(), "SvnPath: ", 9) == 0)
			{
				if(svnPath.empty())
					svnPath = line.c_str() + 9;				
			}
			else if(strncmp(line.c_str(), "Rev: ", 5) == 0)
			{
				rev = atoi(line.c_str() + 4);
				if(LastRev <= 0 && rev > 0)
				{
					LastRev = rev;
					cout << "Head is at r" << LastRev << ", " << ctxt.m_lastCommit << endl;
				}
				cout << "Initializing... " << rev << "  \r" << flush;
			}
			else if(strncmp(line.c_str(), "Msg:", 4) == 0)
				bSvnMsg = true;
		}
		if(rev >= 0)
		{
			GitOids& rootOids			= ctxt.SetOids("", rev);
			Git::CTree tree(gitRepo, commit.Tree());
			
			rootOids.m_oidContentTree	= tree.Entry("content").Oid();
			rootOids.m_oidMetaTree		= tree.Entry("meta").Oid();
			if(bFirst)
			{
				bFirst = false;
				ctxt.SetOids("", SVN_INVALID_REVNUM) = rootOids;
			}
		}
	}

	if(svnPath.empty())
		throw std::runtime_error("SVN path not set. Please specify with 'gitsvn setsvnpath <path>' command.");

	svnRepo.Open(G_svnCtxt, svnPath.c_str());

	gitRepo.BuildTreeNode(ctxt.m_rootTree, Git::CTree(gitRepo, Git::CCommit(gitRepo, ctxt.m_lastCommit).Tree()));
	ctxt.m_svnRepoUrl = svnPath;

	cout << "Initializing... " << "Done. Continuing from rev " << LastRev << "..." << endl;

	RevSyncCtxt::EditorMaker editorMaker(&ctxt);
	editorMaker.replay(&svnRepo, LastRev+1, svnRepo.head(), 1, true);

	cout << "Done." << endl;
}