/// <exception cref="System.IO.IOException"></exception> private IgnoreNode GetIgnoreNode() { if (ignoreNode is WorkingTreeIterator.PerDirectoryIgnoreNode) { ignoreNode = ((WorkingTreeIterator.PerDirectoryIgnoreNode)ignoreNode).Load(); } return(ignoreNode); }
public void LoadIgnoreFile() { if (mIgnoreNodeRoot == null) { mIgnoreNodeRoot = new IgnoreNode(); } if (!mIgnoreNodeRoot.Load(string.Format("{0}/../config/check_xml_ignore.txt", Application.dataPath))) { mIgnoreNodeRoot = null; } }
public bool Load(string fileName) { Clear(); string text = string.Empty; try { text = File.ReadAllText(fileName, System.Text.Encoding.UTF8); }catch (Exception) { return(false); } if (string.IsNullOrEmpty(text)) { return(true); } string[] lines = text.Split(new char[] { '\r', '\n' }); if (lines == null || lines.Length <= 0) { return(true); } List <string> listLines = new List <string>(); for (int i = 0; i < lines.Length; ++i) { string line = lines[i].Trim(new char[] { '\r', '\n', '\t', ' ' }); if (string.IsNullOrEmpty(line) || line.StartsWith("//") || line.StartsWith("--")) { continue; } listLines.Add(line); } for (int i = 0; i < listLines.Count; ++i) { string[] nameArray = listLines[i].Split(new char[] { '\\', '/' }); if (nameArray == null || nameArray.Length <= 0) { continue; } IgnoreNode parent = this; for (int j = 0; j < nameArray.Length; ++j) { string curName = nameArray[j].Trim(new char[] { '\r', '\n', '\t', ' ' }); if (string.IsNullOrEmpty(curName)) { continue; } parent = parent.GetChild(curName, true); } } return(true); }
/// <summary>Initialize this iterator for the root level of a repository.</summary> /// <remarks> /// Initialize this iterator for the root level of a repository. /// <p> /// This method should only be invoked after calling /// <see cref="Init(Entry[])">Init(Entry[])</see> /// , /// and only for the root iterator. /// </remarks> /// <param name="repo">the repository.</param> protected internal virtual void InitRootIterator(Repository repo) { WorkingTreeIterator.Entry entry; if (ignoreNode is WorkingTreeIterator.PerDirectoryIgnoreNode) { entry = ((WorkingTreeIterator.PerDirectoryIgnoreNode)ignoreNode).entry; } else { entry = null; } ignoreNode = new WorkingTreeIterator.RootIgnoreNode(entry, repo); }
public bool IsIgnored(XmlType type, string childName = null) { if (type == null) { return(false); } if (dicChildren.Count <= 0) { return(false); } if (GetChild("*") != null) { return(true); } List <XmlType> listXmlType = new List <XmlType>(); XmlType cur = type; while (cur != null) { if (!cur.IsArrayElement()) { listXmlType.Insert(0, cur); } cur = cur.parent; } IgnoreNode parentNode = this; for (int i = 0; i < listXmlType.Count; ++i) { IgnoreNode child = parentNode.GetChild(listXmlType[i].name); if (child == null) { break; } parentNode = child; } if (parentNode.dicChildren.Count <= 0) { return(true); } if (!string.IsNullOrEmpty(childName)) { IgnoreNode child = parentNode.GetChild(childName); if (child != null && child.dicChildren.Count <= 0) { //Debug.Log(type.GetPathName()+"/"+childName); return(true); } } return(false); }
/// <exception cref="System.IO.FileNotFoundException"></exception> /// <exception cref="System.IO.IOException"></exception> private void LoadRulesFromFile(IgnoreNode r, FilePath exclude) { if (exclude.Exists()) { FileInputStream @in = new FileInputStream(exclude); try { r.Parse(@in); } finally { @in.Close(); } } }
/// <exception cref="System.IO.IOException"></exception> internal virtual IgnoreNode Load() { IgnoreNode r = new IgnoreNode(); InputStream @in = entry.OpenInputStream(); try { r.Parse(@in); } finally { @in.Close(); } return(r.GetRules().IsEmpty() ? null : r); }
/// <summary>Constructor helper.</summary> /// <remarks>Constructor helper.</remarks> /// <param name="list"> /// files in the subtree of the work tree this iterator operates /// on /// </param> protected internal virtual void Init(WorkingTreeIterator.Entry[] list) { // Filter out nulls, . and .. as these are not valid tree entries, // also cache the encoded forms of the path names for efficient use // later on during sorting and iteration. // entries = list; int i; int o; CharsetEncoder nameEncoder = state.nameEncoder; for (i = 0, o = 0; i < entries.Length; i++) { WorkingTreeIterator.Entry e = entries[i]; if (e == null) { continue; } string name = e.GetName(); if (".".Equals(name) || "..".Equals(name)) { continue; } if (Constants.DOT_GIT.Equals(name)) { continue; } if (Constants.DOT_GIT_IGNORE.Equals(name)) { ignoreNode = new WorkingTreeIterator.PerDirectoryIgnoreNode(e); } if (i != o) { entries[o] = e; } e.EncodeName(nameEncoder); o++; } entryCnt = o; Arrays.Sort(entries, 0, entryCnt, ENTRY_CMP); contentIdFromPtr = -1; ptr = 0; if (!Eof) { ParseEntry(); } }
public IgnoreNode GetChild(string name, bool createIfNotExist = false) { IgnoreNode node = null; if (dicChildren.TryGetValue(name, out node) && node != null) { return(node); } if (createIfNotExist) { node = new IgnoreNode(); node.name = name; node.parent = this; dicChildren[node.name] = node; } return(node); }
public string Check(XmlType xmlType, IgnoreNode ignoreNodeRoot, bool checkExtraField = false) { if (xmlType == null || ignoreNodeRoot == null) { return(string.Empty); } string error = string.Empty; if (xmlType.name != name) { if (checkExtraField && !ignoreNodeRoot.IsIgnored(xmlType)) { error += "<color=yellow> XML多填了: " + GetPathName() + GetPosition() + "</color>\n"; } } else { Dictionary <string, XmlType> dicChildren = new Dictionary <string, XmlType>(); xmlType.GetAllMembers(dicChildren); for (int i = 0; i < listChildren.Count; ++i) { Node child = listChildren[i]; XmlType childXmlType = xmlType.GetMember(child.name); if (childXmlType == null) { if (checkExtraField && !ignoreNodeRoot.IsIgnored(xmlType, child.name)) { error += "<color=yellow> XML多填了: " + child.GetPathName() + child.GetPosition() + "</color>\n"; } continue; } dicChildren.Remove(child.name); error += child.Check(childXmlType, ignoreNodeRoot, checkExtraField); } foreach (KeyValuePair <string, XmlType> temp in dicChildren) { if (!temp.Value.IsArray() && !ignoreNodeRoot.IsIgnored(temp.Value)) { error += "<color=red> XML少填了: " + GetPathName() + "/" + temp.Value.name + GetPosition() + "</color>\n"; } } } return(error); }
bool IsEntryIgnoredInternal(int pLen) { IgnoreNode rules = GetIgnoreNode(); if (rules != null) { // The ignore code wants path to start with a '/' if possible. // If we have the '/' in our path buffer because we are inside // a subdirectory include it in the range we convert to string. // int pOff = pathOffset; if (0 < pOff) { pOff--; } string p = TreeWalk.PathOf(path, pOff, pLen); switch (rules.IsIgnored(p, FileMode.TREE.Equals(mode))) { case IgnoreNode.MatchResult.IGNORED: { return(true); } case IgnoreNode.MatchResult.NOT_IGNORED: { return(false); } case IgnoreNode.MatchResult.CHECK_PARENT: { break; } } } if (parent is NGit.Treewalk.WorkingTreeIterator) { return(((NGit.Treewalk.WorkingTreeIterator)parent).IsEntryIgnored(pLen)); } return(false); }
/// <exception cref="System.IO.IOException"></exception> internal override IgnoreNode Load() { IgnoreNode r; if (entry != null) { r = base.Load(); if (r == null) { r = new IgnoreNode(); } } else { r = new IgnoreNode(); } FS fs = repository.FileSystem; string path = repository.GetConfig().Get(CoreConfig.KEY).GetExcludesFile(); if (path != null) { FilePath excludesfile; if (path.StartsWith("~/")) { excludesfile = fs.Resolve(fs.UserHome(), Sharpen.Runtime.Substring(path, 2)); } else { excludesfile = fs.Resolve(null, path); } LoadRulesFromFile(r, excludesfile); } FilePath exclude = fs.Resolve(repository.Directory, "info/exclude"); LoadRulesFromFile(r, exclude); return(r.GetRules().IsEmpty() ? null : r); }
public void Clear() { name = string.Empty; parent = null; dicChildren.Clear(); }