Ejemplo n.º 1
0
        public BranchData ParseBranch(QueryBranchRestriction restriction)
        {
            BranchData res;
            bool       current = CheckValue('*');

            Skip(2);
            int eol   = FindNewLineOrEndOfString();
            int space = FindSpace();

            if (current && (space == Position + 3) && CheckValue(GitConstants.NoBranch))
            {
                Skip(GitConstants.NoBranch.Length);
                Skip(' ');
                var sha1 = new Hash(String, Position);
                res = new BranchData(GitConstants.NoBranch, sha1, true, false, true);
            }
            else
            {
                var name = ReadStringUpTo(space, 1);
                Skip(' ');
                if (!(restriction == QueryBranchRestriction.Local) && CheckValue('-'))                // it's a remote head indicator, skip it
                {
                    res = null;
                }
                else
                {
                    var  sha1 = new Hash(String, Position);
                    bool remote;
                    switch (restriction)
                    {
                    case QueryBranchRestriction.All:
                        remote = !current && name.StartsWith(GitConstants.RemoteBranchShortPrefix);
                        if (remote)
                        {
                            name = name.Substring(8);
                        }
                        break;

                    case QueryBranchRestriction.Local:
                        remote = false;
                        break;

                    case QueryBranchRestriction.Remote:
                        remote = true;
                        break;

                    default:
                        throw new ArgumentException("restriction");
                    }
                    res = new BranchData(name, sha1, remote, current);
                }
            }
            Position = eol + 1;
            return(res);
        }
Ejemplo n.º 2
0
        public BranchesData ParseBranches(QueryBranchRestriction restriction, bool allowFakeBranch)
        {
            var heads   = new List <BranchData>();
            var remotes = new List <BranchData>();

            while (!IsAtEndOfString)
            {
                var branch = ParseBranch(restriction);
                if (branch != null && (allowFakeBranch || !branch.IsFake))
                {
                    if (branch.IsRemote)
                    {
                        remotes.Add(branch);
                    }
                    else
                    {
                        heads.Add(branch);
                    }
                }
            }
            return(new BranchesData(heads, remotes));
        }
Ejemplo n.º 3
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 /// <param name="mode">Relation between returned branches and specified <see cref="M:Revision"/> (HEAD if not specified).</param>
 /// <summary>Revision to check according to <see cref="M:Mode"/>.</summary>
 public QueryBranchesParameters(QueryBranchRestriction restriction, BranchQueryMode mode, string revision)
 {
     Restriction = restriction;
     Mode = mode;
     Revision = revision;
 }
Ejemplo n.º 4
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 /// <param name="mode">Relation between returned branches and specified <see cref="M:Revision"/> (HEAD if not specified).</param>
 public QueryBranchesParameters(QueryBranchRestriction restriction, BranchQueryMode mode)
 {
     Restriction = restriction;
     Mode = mode;
 }
Ejemplo n.º 5
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 public QueryBranchesParameters(QueryBranchRestriction restriction)
 {
     Restriction = restriction;
     Mode = BranchQueryMode.Default;
 }
Ejemplo n.º 6
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 /// <param name="mode">Relation between returned branches and specified <see cref="M:Revision"/> (HEAD if not specified).</param>
 /// <summary>Revision to check according to <see cref="M:Mode"/>.</summary>
 public QueryBranchesParameters(QueryBranchRestriction restriction, BranchQueryMode mode, string revision)
 {
     Restriction = restriction;
     Mode        = mode;
     Revision    = revision;
 }
Ejemplo n.º 7
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 /// <param name="mode">Relation between returned branches and specified <see cref="M:Revision"/> (HEAD if not specified).</param>
 public QueryBranchesParameters(QueryBranchRestriction restriction, BranchQueryMode mode)
 {
     Restriction = restriction;
     Mode        = mode;
 }
Ejemplo n.º 8
0
 /// <summary>Create <see cref="QueryBranchesParameters"/>.</summary>
 /// <param name="restriction">Restriction on types of branches to return.</param>
 public QueryBranchesParameters(QueryBranchRestriction restriction)
 {
     Restriction = restriction;
     Mode        = BranchQueryMode.Default;
 }
Ejemplo n.º 9
0
 public BranchesData ParseBranches(QueryBranchRestriction restriction, bool allowFakeBranch)
 {
     var heads = new List<BranchData>();
     var remotes = new List<BranchData>();
     while(!IsAtEndOfString)
     {
         var branch = ParseBranch(restriction);
         if(branch != null && (allowFakeBranch || !branch.IsFake))
         {
             if(branch.IsRemote)
             {
                 remotes.Add(branch);
             }
             else
             {
                 heads.Add(branch);
             }
         }
     }
     return new BranchesData(heads, remotes);
 }
Ejemplo n.º 10
0
 public BranchData ParseBranch(QueryBranchRestriction restriction)
 {
     BranchData res;
     bool current = CheckValue('*');
     Skip(2);
     int eol = FindNewLineOrEndOfString();
     int space = FindSpace();
     if(current && (space == Position + 3) && CheckValue(GitConstants.NoBranch))
     {
         Skip(GitConstants.NoBranch.Length);
         Skip(' ');
         var sha1 = new Hash(String, Position);
         res = new BranchData(GitConstants.NoBranch, sha1, true, false, true);
     }
     else
     {
         var name = ReadStringUpTo(space, 1);
         Skip(' ');
         if(!(restriction == QueryBranchRestriction.Local) && CheckValue('-')) // it's a remote head indicator, skip it
         {
             res = null;
         }
         else
         {
             var sha1 = new Hash(String, Position);
             bool remote;
             switch(restriction)
             {
                 case QueryBranchRestriction.All:
                     remote = !current && name.StartsWith(GitConstants.RemoteBranchShortPrefix);
                     if(remote) name = name.Substring(8);
                     break;
                 case QueryBranchRestriction.Local:
                     remote = false;
                     break;
                 case QueryBranchRestriction.Remote:
                     remote = true;
                     break;
                 default:
                     throw new ArgumentException("restriction");
             }
             res = new BranchData(name, sha1, remote, current);
         }
     }
     Position = eol + 1;
     return res;
 }