private Func<string, bool> BuildBranchMatch(HgPrincipal principal, string section, IEnumerable<HgAclEntry> hgAclEntries)
        {
            if(hgAclEntries == null) return null;

            var patterns = hgAclEntries.Where(e => Matches(principal, e)).Select(e => e.Path).ToList();
            
            if(patterns.Count == 0) 
                return s => false;
            
            return s => patterns.Contains(s);
        }
        private bool Matches(HgPrincipal principal, HgAclEntry entry)
        {
            foreach(var aclPrincipal in entry.Principals)
            {
                if(aclPrincipal.Name == "*") return true;

                if(aclPrincipal.Excludes)
                {
                    if(aclPrincipal.Type == HgAclPrincipalType.User && principal.Name != aclPrincipal.Name)
                        return true;
                    
                    if(aclPrincipal.Type == HgAclPrincipalType.Group && !principal.Groups.Contains(aclPrincipal.Name))
                        return true;
                } // if
                else
                {
                    if(aclPrincipal.Type == HgAclPrincipalType.User && principal.Name == aclPrincipal.Name)
                        return true;

                    if(aclPrincipal.Type == HgAclPrincipalType.Group && principal.Groups.Contains(aclPrincipal.Name))
                        return true;
                } // else
            } // foreach

            return false;
        }
 private HgPrincipal NormalizeHgPrincipal(HgPrincipal hgPrincipal)
 {
     return new HgPrincipal(hgPrincipal.Name.ToLowerInvariant(), hgPrincipal.Groups.Select(g => g.ToLowerInvariant()));
 }
        private Func<HgPath, bool> BuildPathMatch(HgPrincipal principal, string section, IEnumerable<HgAclEntry> hgAclEntries)
        {
            if(hgAclEntries == null) return null;

            var matchers = hgAclEntries.Where(e => Matches(principal, e)).Select(e => HgPathPatternMatcher.Parse(e.Path)).ToList();
            
            if(matchers.Count == 0) return s => false;
            
            return s => matchers.Any(m => m.Matches(s));
        }