private void LogChange(IVSSVersion version) { const int FILE_OR_PROJECT_DOES_NOT_EXIST = -2147166577; XmlElement node; XmlAttribute attrib; try { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); attrib.Value = version.VSSItem.Name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); attrib.Value = version.VSSItem.Spec; node.Attributes.Append(attrib); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode != FILE_OR_PROJECT_DOES_NOT_EXIST) { throw; } return; } attrib = _outputDoc.CreateAttribute("Action"); attrib.Value = version.Action; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Date"); attrib.Value = XmlConvert.ToString(version.Date, XmlDateTimeSerializationMode.Utc); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Version"); attrib.Value = XmlConvert.ToString(version.VersionNumber); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("User"); attrib.Value = version.Username; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Comment"); attrib.Value = version.Comment; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Label"); attrib.Value = version.Label; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("LabelComment"); attrib.Value = version.LabelComment; node.Attributes.Append(attrib); _outputDoc.ChildNodes.Item(0).AppendChild(node); }
private void AddFileVersionToChangeset(IVSSItem vssFile, Int32 f_count, IVSSVersion vssVersion, bool isAdd) { string filePath; VSSItem versionItem; string comment; Changeset thisChangeset; // define the working copy filename if (!this.IsPreview) { filePath = Path.Combine(this.SvnFullRepositoryPath, this.VssRelativeFilePaths[f_count]); } else { filePath = string.Empty; } //get version item to get the version of the file versionItem = vssFile.get_Version(vssVersion.VersionNumber); comment = versionItem.VSSVersion.Comment; if (Changesets.ContainsKey(vssVersion.Date)) { // using an existing change set thisChangeset = Changesets[vssVersion.Date]; // different comment, so create a new change set anyway if (thisChangeset.Comment != comment) { bool done = false; //there are two different changes at the same time //I'm not sure how this happened, but it did. //make the date/time of this changeset after any existing changeset thisChangeset = new Changeset() { Comment = comment, DateTime = vssVersion.Date, Username = vssVersion.Username }; //make sure not to try and add this entry if an entry with the time already exists while (!done) { if (Changesets.ContainsKey(thisChangeset.DateTime)) { thisChangeset.DateTime = thisChangeset.DateTime.AddSeconds(1); } else { done = true; } } this.Changesets.Add(thisChangeset.DateTime, thisChangeset); } } else { // create a new change set thisChangeset = new Changeset() { Comment = comment, DateTime = vssVersion.Date, Username = vssVersion.Username }; this.Changesets.Add(thisChangeset.DateTime, thisChangeset); } // add the file to the change set thisChangeset.Files.Add(new ChangesetFileInfo() { FilePath = filePath, IsAdd = isAdd, VssFile = vssFile, VssVersion = vssVersion }); }
private void LogChange(IVSSVersion version) { const int FILE_OR_PROJECT_DOES_NOT_EXIST = -2147166577; XmlElement node; XmlAttribute attrib; try { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); attrib.Value = version.VSSItem.Name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); attrib.Value = version.VSSItem.Spec; node.Attributes.Append(attrib); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode != FILE_OR_PROJECT_DOES_NOT_EXIST) { throw; } return; } attrib = _outputDoc.CreateAttribute("Action"); attrib.Value = version.Action; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Date"); attrib.Value = XmlConvert.ToString(version.Date, XmlDateTimeSerializationMode.Utc); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Version"); attrib.Value = XmlConvert.ToString(version.VersionNumber); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("User"); attrib.Value = version.Username; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Comment"); attrib.Value = version.Comment; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Label"); attrib.Value = version.Label; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("LabelComment"); attrib.Value = version.LabelComment; node.Attributes.Append(attrib); _outputDoc.ChildNodes.Item(0).AppendChild(node); }
private void LogChange(IVSSVersion version) { const int FILE_OR_PROJECT_DOES_NOT_EXIST = -2147166577; const int ERROR_LOADING_RESOURCE_STRING = -2147221504; XmlElement node; XmlAttribute attrib; string name = "not set"; string spec = "not set"; try { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); name = version.VSSItem.Name; attrib.Value = name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); spec = version.VSSItem.Spec; attrib.Value = spec; node.Attributes.Append(attrib); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == FILE_OR_PROJECT_DOES_NOT_EXIST) { return; } else if (ex.ErrorCode == ERROR_LOADING_RESOURCE_STRING) { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); name = "vss error geting file"; attrib.Value = name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); spec = "vss error geting spec"; attrib.Value = spec; node.Attributes.Append(attrib); } else { throw new BuildException(string.Format("retrival of name({0}) or spec({1}) failed: code({2}) {3}", name, spec, ex.ErrorCode, ex.ToString()), Location, ex); } } attrib = _outputDoc.CreateAttribute("Action"); attrib.Value = version.Action; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Date"); attrib.Value = XmlConvert.ToString(version.Date); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Version"); attrib.Value = XmlConvert.ToString(version.VersionNumber); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("User"); attrib.Value = version.Username; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Comment"); attrib.Value = version.Comment; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Label"); attrib.Value = version.Label; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("LabelComment"); attrib.Value = version.LabelComment; node.Attributes.Append(attrib); _outputDoc.ChildNodes.Item(0).AppendChild(node); }
private void LogChange(IVSSVersion version) { const int FILE_OR_PROJECT_DOES_NOT_EXIST = -2147166577; const int ERROR_LOADING_RESOURCE_STRING = -2147221504; XmlElement node; XmlAttribute attrib; string name = "not set"; string spec = "not set"; try { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); name = version.VSSItem.Name; attrib.Value = name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); spec = version.VSSItem.Spec; attrib.Value = spec; node.Attributes.Append(attrib); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == FILE_OR_PROJECT_DOES_NOT_EXIST) { return; } else if(ex.ErrorCode == ERROR_LOADING_RESOURCE_STRING) { node = _outputDoc.CreateElement("Entry"); attrib = _outputDoc.CreateAttribute("Name"); name = "vss error geting file"; attrib.Value = name; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Path"); spec = "vss error geting spec"; attrib.Value = spec; node.Attributes.Append(attrib); } else { throw new BuildException(string.Format("retrival of name({0}) or spec({1}) failed: code({2}) {3}", name, spec, ex.ErrorCode, ex.ToString()), Location, ex); } } attrib = _outputDoc.CreateAttribute("Action"); attrib.Value = version.Action; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Date"); attrib.Value = XmlConvert.ToString(version.Date); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Version"); attrib.Value = XmlConvert.ToString(version.VersionNumber); node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("User"); attrib.Value = version.Username; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Comment"); attrib.Value = version.Comment; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("Label"); attrib.Value = version.Label; node.Attributes.Append(attrib); attrib = _outputDoc.CreateAttribute("LabelComment"); attrib.Value = version.LabelComment; node.Attributes.Append(attrib); _outputDoc.ChildNodes.Item(0).AppendChild(node); }
private static void GetFileVersion(IVSSItem vssFile, IVSSVersion vssVersion, SvnClient svnClient) { numFilesHandled++; string dir = string.Format("{0}{1}", repoDIR, vssFile.Spec.Substring(1)).Replace("/", "\\"); dir = Path.GetDirectoryName(dir); string filePath = Path.Combine(dir, vssFile.Name); VSSItem versionItem = vssVersion.VSSItem; try { migrateLog.DebugFormat("Fetching VSSItem: {0}, Version: {1}", versionItem.Spec, versionItem.VersionNumber); if (versionItem.Type != (int)VSSItemType.VSSITEM_PROJECT) { versionItem.Get(ref filePath, (int) (VSSFlags.VSSFLAG_USERRONO | VSSFlags.VSSFLAG_CMPFAIL | VSSFlags.VSSFLAG_GETYES | VSSFlags.VSSFLAG_REPREPLACE | VSSFlags.VSSFLAG_TIMEMOD)); //kill them *.scc files worth for nothing string[] files = Directory.GetFiles(dir, "*.scc", SearchOption.TopDirectoryOnly); foreach (string file in files) { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } } else { Directory.CreateDirectory(filePath); } //This seems to fail rather often on binary files and directories, so dont let us use it on them if (versionItem.Type != (int)VSSItemType.VSSITEM_PROJECT) { if (!versionItem.Binary) { migrateLog.DebugFormat("Diffing ..."); if (versionItem.get_IsDifferent(filePath)) { migrateLog.WarnFormat( "Files should not be different for version {0}; possible corruption in file {1}:{0}", versionItem.VersionNumber, versionItem.Spec); } } } } catch (COMException e) { if (e.ErrorCode == -2147166575) { // VSS file's checkbox "keep only latest version" is checked therefore no file could be fetched // so that calling versionItem.Get(...) results in an exception migrateLog.WarnFormat( "Version {0} of file {1} not stored in VSS. File has option 'Keep only latest version' (see file's properties) enabled in VSS", versionItem.VersionNumber, versionItem.Spec); } else { throw; } } VssBindingRemover.RemoveBindings(filePath); Collection <SvnStatusEventArgs> svnStatus; svnClient.GetStatus(filePath, out svnStatus); if (svnStatus.Count == 1) { SvnStatus fileStatus = svnStatus[0].LocalContentStatus; if (fileStatus == SvnStatus.Normal) { migrateLog.WarnFormat("No modification detected for {0}:{1}", vssVersion.VSSItem.Spec, vssVersion.VersionNumber); return; } if (fileStatus == SvnStatus.NotVersioned || fileStatus == SvnStatus.Incomplete || fileStatus == SvnStatus.Missing) { try { svnClient.Add(filePath); } catch (SvnException e) { if (!e.ToString().Contains("already under version")) { throw; } } } } else { //Should never get here because we're always looking for the results of an individual file; only display a message migrateLog.WarnFormat("Invalid svn status detected for {0}:{1}", vssVersion.VSSItem.Spec, vssVersion.VersionNumber); migrateLog.WarnFormat("Status count was: {0}", svnStatus.Count); return; } //simply continue as expected }
private static void AddRevision(IVSSVersion version, bool deleted) { var key = new VssRevProps { Author = version.Username, Comment = version.Comment.Replace("\n", "").Replace("\t", "").Trim(), Time = version.Date }; var file = new VssFileVersion { Spec = version.VSSItem.Spec, VersionNumber = version.VersionNumber, Version = version, Action = version.Action, Deleted = deleted }; //Ignore branches and the root directory if (version.Action.Contains("Branched at version") || version.Action.ToLower().Contains("verzweigt bei version") || string.Compare("$/", file.Spec, true) == 0) { return; } //if pinned add to a special (and always last) revision if (version.VSSItem.IsPinned) { if (!revisions.ContainsKey(pinProps)) //if there is no pinprop revision, add one ... { revisions.Add(pinProps, new Dictionary <string, VssFileVersion>(StringComparer.CurrentCultureIgnoreCase) { { file.Spec, file } }); } else //else add file to pinprop revision { revisions[pinProps].Add(file.Spec, file); } } //filter duplicate labels if (!string.IsNullOrEmpty(version.Label)) { if (labellist.Contains(version.VSSItem.Spec)) { if (tagslist.Contains(version.Label)) { return; } tagslist.Add(version.Label); } else { labellist.Add(version.VSSItem.Spec); tagslist.Add(version.Label); } } //if revision is the same but file was not added yet, then ... if (revisions.Keys.Contains(key) && (!revisions[key].ContainsKey(file.Spec)))// || version.VSSItem.Type == (int) VSSItemType.VSSITEM_PROJECT)) { //Add the file to the existing revision if it exists searchLog.DebugFormat("Adding {0}:{1} to {2}", file.Spec, file.VersionNumber, key); revisions[key].Add(file.Spec, file); return; } if (revisions.Keys.Contains(key) && (revisions[key].ContainsKey(file.Spec))) { return; } //else revision has not been added yet, so ... var files = new Dictionary <string, VssFileVersion>(StringComparer.CurrentCultureIgnoreCase) { { file.Spec, file } }; searchLog.DebugFormat("New revision {0} {1}:{2}", key, file.Spec, file.VersionNumber); revisions.Add(key, files); return; }
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("------------------------------------"); }
private static void CounterfeitRevProps(SvnClient svnClient, SvnTarget target, IVSSVersion vssVersion) { SvnInfoEventArgs infoEventArgs; svnClient.GetInfo(target, out infoEventArgs); var props = new SvnRevProps(svnREVPROPSPATH, infoEventArgs.Revision); if (vssVersion != null) { props.SetAuthor(vssVersion.Username); props.SetDate(vssVersion.Date); } }