Пример #1
0
        internal bool CreateTag(SvnListEventArgs selectedTrunk, string tagName)
        {
            try
            {
                if (selectedTrunk != null)
                {
                    using (SvnClient client = new SvnClient())
                    {
                        // Bind the SharpSvn UI to our client for SSL certificate and credentials
                        SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                        SvnUI.Bind(client, bindArgs);

                        string relativeComponentPath = selectedTrunk.BaseUri.AbsoluteUri;

                        Uri tagUri = new Uri(relativeComponentPath + "tags/" + tagName);

                        SvnTarget source = SvnTarget.FromUri(selectedTrunk.Uri);

                        SvnCopyArgs arg = new SvnCopyArgs();
                        arg.CreateParents = false;
                        arg.LogMessage    = string.Format("ADMIN-0: Tag Created from Trunk");

                        return(client.RemoteCopy(source, tagUri, arg));
                    }
                }
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        internal bool CreateBranch(SvnListEventArgs selectedTag, string branchName)
        {
            try
            {
                if (selectedTag != null)
                {
                    using (SvnClient client = new SvnClient())
                    {
                        // Bind the SharpSvn UI to our client for SSL certificate and credentials
                        SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                        SvnUI.Bind(client, bindArgs);

                        string relativeComponentPath = string.Join(string.Empty, selectedTag.BaseUri.Segments.Take(selectedTag.BaseUri.Segments.Count() - 1).ToArray());
                        string server = selectedTag.BaseUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);

                        Uri barnchUri = new Uri(server + relativeComponentPath + "branches/project/" + branchName);

                        SvnTarget source = SvnTarget.FromUri(selectedTag.Uri);

                        SvnCopyArgs arg = new SvnCopyArgs();
                        arg.CreateParents = false;
                        arg.LogMessage    = string.Format("ADMIN-0: Branch Created from Tag {0}", selectedTag.Name);

                        return(client.RemoteCopy(source, barnchUri, arg));
                    }
                }
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        private static void GetAndAddRevision(VssRevProps properties, Dictionary <string, VssFileVersion> files,
                                              SvnClient svnClient)
        {
            string dir      = Path.Combine(repoDIR, vssPROJ.Substring(2).Replace("/", "\\"));
            string filePath = string.Empty;
            var    delkeys  = new List <string>();

            foreach (string key in files.Keys)
            {
                try
                {
                    //take care of the rare case of an item both file and label
                    if (!String.IsNullOrEmpty(files[key].Version.Label))
                    {
                        if (files[key].Version.VSSItem.Type != 0)
                        {
                            GetFileVersion(files[key].Version.VSSItem, files[key].Version, svnClient);
                            var commitArgs = new SvnCommitArgs {
                                LogMessage = properties.Comment
                            };
                            svnClient.Commit(dir, commitArgs);

                            filePath =
                                Path.Combine(
                                    Path.GetDirectoryName(
                                        string.Format("{0}{1}", repoDIR, files[key].Spec.Substring(1)).Replace("/", "\\")),
                                    files[key].Version.VSSItem.Name);

                            var uri = new Uri(string.Format("{0}{1}", svnURL, svnPROJ));
                            //svnClient.GetInfo(SvnTarget.FromString(filePath), out infoEventArgs);
                            CounterfeitRevProps(svnClient, SvnTarget.FromUri(uri), files[key].Version);
                        }

                        TagSourceUrl = String.Empty;
                        var tag = new Tag
                        {
                            fromUrlString = GenerateSourceUrl(files[key].Version.VSSItem),
                            tagString     = String.Format("{0}/{1}/{2}_{3}",
                                                          svnURL,
                                                          svnTAG,
                                                          files[key].Version.VSSItem.Name,
                                                          sanitizeLabel(files[key].Version.Label)),
                            label = files[key].Version.Label
                        };
                        ApplyTag(files[key].Version.VSSItem, svnClient, files[key].Version, tag);

                        return;
                    } //rare case end

                    GetFileVersion(files[key].Version.VSSItem, files[key].Version, svnClient);
                    //Only need one file to get the revision information from
                    if (string.IsNullOrEmpty(filePath))
                    {
                        filePath =
                            Path.Combine(
                                Path.GetDirectoryName(
                                    string.Format("{0}{1}", repoDIR, files[key].Spec.Substring(1)).Replace("/", "\\")),
                                files[key].Version.VSSItem.Name);
                    }

                    if (files[key].Deleted)
                    {
                        delkeys.Add(filePath);
                    }
                }
                catch (COMException ex)
                {
                    switch ((uint)ex.ErrorCode)
                    {
                    case 0x8004D838:     //version is corrupted and unavailable
                        migrateLog.WarnFormat("Skipping version due to corruption in file {1}:{0}",
                                              files[key].VersionNumber, files[key].Spec);
                        continue;

                    default:
                        if (IgnoreExceptions)
                        {
                            migrateLog.ErrorFormat("Error processing file {1}:{0}",
                                                   files[key].VersionNumber, files[key].Spec);
                            migrateLog.ErrorFormat(ex.ToString());
                            continue;
                        }
                        throw;
                    }
                }
            }
            //Only commit if we actually have a file that has been updated as a result of the get
            if (!string.IsNullOrEmpty(filePath))
            {
                var commitArgs = new SvnCommitArgs {
                    LogMessage = properties.Comment
                };
                migrateLog.DebugFormat("Committing revision ...");
                //SLOW!!!, change to ICollection of FilePaths (only verify updated files!)
                svnClient.Commit(dir, commitArgs);

                //delete files which are marked as deleted in vss
                foreach (string delFilePath in delkeys)
                {
                    svnClient.Delete(delFilePath);
                    migrateLog.Info(String.Format("Deleted: {0}", delFilePath));
                }
                delkeys.Clear();

                SvnInfoEventArgs infoEventArgs;
                //Use one of the committed files to determine the revision we just committed
                var uri = new Uri(string.Format("{0}{1}", svnURL, svnPROJ));
                //svnClient.GetInfo(SvnTarget.FromString(filePath), out infoEventArgs);
                svnClient.GetInfo(SvnTarget.FromUri(uri), out infoEventArgs);

                svnClient.SetRevisionProperty(new Uri(svnURL), infoEventArgs.Revision,
                                              SvnPropertyNames.SvnAuthor,
                                              properties.Author);

                string   strCfgTime;
                string[] strSplit, strSplit2;

                strSplit  = properties.Time.ToString().Split(' ');
                strSplit2 = strSplit[0].Split('/');

                strCfgTime = strSplit2[2] + '-' + strSplit2[1] + '-' + strSplit2[0] + 'T' + strSplit[1] + ".000000Z";

                svnClient.SetRevisionProperty(new Uri(svnURL), infoEventArgs.Revision,
                                              SvnPropertyNames.SvnDate,
                                              strCfgTime);
            }
        }
Пример #4
0
        private static bool ImportDirectories()
        {
            var    uri = new Uri(string.Format("{0}{1}", svnURL, svnPROJ));
            string dir = Path.Combine(repoDIR, vssPROJ.Substring(2).Replace("/", "\\"));

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            using (SvnClient svnClient = GetSvnClient())
            {
                var importArgs = new SvnImportArgs
                {
                    LogMessage = string.Format("Initial import from VSS on {0}", DateTime.Now)
                };

                SvnInfoEventArgs infoEventArgs;
                try
                {
                    trunkexists = svnClient.GetInfo(SvnTarget.FromUri(uri), out infoEventArgs);
                    migrateLog.DebugFormat(svnClient.GetInfo(SvnTarget.FromUri(uri), out infoEventArgs) ?
                                           "Getting trunk revision was successful." :
                                           "Getting trunk revision was NOT successful!");

                    migrateLog.DebugFormat("Base Revision: " + infoEventArgs.Revision);

                    if (infoEventArgs.Revision == 0)
                    {
                        if (!svnClient.Import(dir, uri, importArgs))
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception)
                {
                    if (!svnClient.Import(dir, uri, importArgs))
                    {
                        return(false);
                    }
                }

                var tagurl    = new Uri(String.Format("{1}/{0}", svnTAG, svnURL));
                var branchurl = new Uri(String.Format("{1}/{0}", svnBRANCH, svnURL));

                try
                {
                    svnClient.GetInfo(tagurl, out infoEventArgs);
                    svnClient.GetInfo(branchurl, out infoEventArgs);
                    migrateLog.DebugFormat(svnClient.GetInfo(tagurl, out infoEventArgs)?
                                           "Getting tag dir revision was successful." :
                                           "Getting tag dir revision was NOT successful!");

                    migrateLog.DebugFormat(svnClient.GetInfo(branchurl, out infoEventArgs)?
                                           "Getting branch dir revision was successful." :
                                           "Getting branch dir revision was NOT successful!");
                }
                catch (SvnRepositoryIOException)
                {
                    var tagdircreated = svnClient.RemoteCreateDirectory((tagurl), new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial creation of tag directory", CreateParents = true
                    });
                    var branchdircreated = svnClient.RemoteCreateDirectory((branchurl),
                                                                           new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial creation of branch directory", CreateParents = true
                    });
                }

                try
                {
                    svnClient.GetInfo(uri, out infoEventArgs);
                }
                catch (SvnRepositoryIOException)
                {
                    svnClient.RemoteCreateDirectory((uri),
                                                    new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial import", CreateParents = true
                    });
                }


                migrateLog.DebugFormat(dir);
                //Update the author and time of the first import revision to correspond to the first file revision
                //minus a minute in time for proper ordering of the revisions in time);
                if (!string.IsNullOrEmpty(svnREVPROPSPATH))
                {
                    svnClient.GetInfo(trunkexists
                                          ? SvnTarget.FromUri(uri)
                                          : SvnTarget.FromString(dir),
                                      out infoEventArgs);

                    var props = new SvnRevProps(svnREVPROPSPATH, infoEventArgs.Revision);

                    //This helps to make sure the revisions are imported in chronological order
                    props.SetDate(revisions.Keys[0].Time.AddMinutes(-1));
                }

                Cleanup();

                var checkOutArgs = new SvnCheckOutArgs {
                    Depth = SvnDepth.Infinity
                };
                return(svnClient.CheckOut(uri, dir, checkOutArgs));
            }
        }
Пример #5
0
        private static void ApplyTag(IVSSItem vssFile, SvnClient svnClient, IVSSVersion vssVersion, Tag tag)
        {
            var copyArgs = new SvnCopyArgs
            {
                LogMessage =
                    string.Format("Released {0}\n{1}", vssVersion.Label, vssVersion.LabelComment)
            };

            migrateLog.DebugFormat("------------------------------------");
            migrateLog.DebugFormat(string.Format("Setting Tag:"));
            migrateLog.DebugFormat(string.Format("Label: {0}", vssVersion.Label));
            migrateLog.DebugFormat(string.Format("Comment: {0}", vssVersion.LabelComment));
            migrateLog.DebugFormat(string.Format("from Url: {0}", tag.fromUrlString));
            migrateLog.DebugFormat(string.Format("to Url: {0}", tag.tagString));


            try
            {
                svnClient.RemoteCopy(SvnTarget.FromString(tag.fromUrlString),
                                     new Uri(tag.tagString),
                                     copyArgs);

                CounterfeitRevProps(svnClient, SvnTarget.FromUri(new Uri(tag.tagString)), vssVersion);
            }


            catch (SvnFileSystemException e)
            {
                //tags with same names get handled here

                if (e.ToString().Contains("already exists"))
                {
                    int index = tag.tagString.IndexOf(svnTAG) + svnTAG.Length + 1;
                    //FIXME: correct calculation of // and /
                    string newstring = tag.tagString.Insert(index, vssFile.Parent.Name + "_");
                    tag.tagString = newstring;
                    migrateLog.DebugFormat("Tag already existing, adding parent name ...");

                    ApplyTag(vssFile, svnClient, vssVersion, tag);

                    return;
                }

                migrateLog.ErrorFormat("Error: Line was: " + tag.fromUrlString);
                migrateLog.ErrorFormat(e.ToString());
                migrateLog.InfoFormat(String.Format("Fallback, tagging repository successful: "
                                                    + (svnClient.RemoteCopy(
                                                           SvnTarget.FromString(String.Format("{0}/{1}", svnURL,
                                                                                              svnPROJ)),
                                                           new Uri(tag.tagString)
                                                           , copyArgs))));


                CounterfeitRevProps(svnClient, SvnTarget.FromUri(new Uri(tag.tagString)), vssVersion);
            }

            catch (Exception e)
            {
                migrateLog.ErrorFormat(e.ToString());
                //Console.Out.WriteLine("Press a key to continue");
                //Console.ReadKey();
            }

            migrateLog.DebugFormat("------------------------------------");
        }