示例#1
0
 private void CloseConnection(FetchResult result)
 {
     if (conn != null)
     {
         conn.Close();
         result.AddMessages(conn.GetMessages());
         conn = null;
     }
 }
示例#2
0
        /// <summary>
        /// Executes the
        /// <code>LsRemote</code>
        /// command with all the options and parameters
        /// collected by the setter methods (e.g.
        /// <see cref="SetHeads(bool)">SetHeads(bool)</see>
        /// ) of this
        /// class. Each instance of this class should only be used for one invocation
        /// of the command. Don't call this method twice on an instance.
        /// </summary>
        /// <returns>a collection of references in the remote repository</returns>
        /// <exception cref="NGit.Api.Errors.InvalidRemoteException">when called with an invalid remote uri
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.TransportException">for errors that occurs during transport
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
        public override ICollection <Ref> Call()
        {
            CheckCallable();
            NGit.Transport.Transport transport = null;
            FetchConnection          fc        = null;

            try
            {
                transport = NGit.Transport.Transport.Open(repo, remote);
                transport.SetOptionUploadPack(uploadPack);
                Configure(transport);
                ICollection <RefSpec> refSpecs = new AList <RefSpec>(1);
                if (tags)
                {
                    refSpecs.AddItem(new RefSpec("refs/tags/*:refs/remotes/origin/tags/*"));
                }
                if (heads)
                {
                    refSpecs.AddItem(new RefSpec("refs/heads/*:refs/remotes/origin/*"));
                }
                ICollection <Ref>         refs;
                IDictionary <string, Ref> refmap = new Dictionary <string, Ref>();
                fc   = transport.OpenFetch();
                refs = fc.GetRefs();
                if (refSpecs.IsEmpty())
                {
                    foreach (Ref r in refs)
                    {
                        refmap.Put(r.GetName(), r);
                    }
                }
                else
                {
                    foreach (Ref r_1 in refs)
                    {
                        foreach (RefSpec rs in refSpecs)
                        {
                            if (rs.MatchSource(r_1))
                            {
                                refmap.Put(r_1.GetName(), r_1);
                                break;
                            }
                        }
                    }
                }
                return(refmap.Values);
            }
            catch (URISyntaxException)
            {
                throw new InvalidRemoteException(MessageFormat.Format(JGitText.Get().invalidRemote
                                                                      , remote));
            }
            catch (NGit.Errors.NotSupportedException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfLsRemoteCommand
                                                , e);
            }
            catch (NGit.Errors.TransportException e)
            {
                throw new NGit.Errors.TransportException(e.Message, e);
            }
            finally
            {
                if (fc != null)
                {
                    fc.Close();
                }
                if (transport != null)
                {
                    transport.Close();
                }
            }
        }