Ejemplo n.º 1
0
        /// <summary>Parse a remote block from an existing configuration file.</summary>
        /// <remarks>
        /// Parse a remote block from an existing configuration file.
        /// <p>
        /// This constructor succeeds even if the requested remote is not defined
        /// within the supplied configuration file. If that occurs then there will be
        /// no URIs and no ref specifications known to the new instance.
        /// </remarks>
        /// <param name="rc">
        /// the existing configuration to get the remote settings from.
        /// The configuration must already be loaded into memory.
        /// </param>
        /// <param name="remoteName">subsection key indicating the name of this remote.</param>
        /// <exception cref="Sharpen.URISyntaxException">one of the URIs within the remote's configuration is invalid.
        ///     </exception>
        public RemoteConfig(Config rc, string remoteName)
        {
            name    = remoteName;
            oldName = remoteName;
            string[] vlst;
            string   val;

            vlst = rc.GetStringList(SECTION, name, KEY_URL);
            IDictionary <string, string> insteadOf = GetReplacements(rc, KEY_INSTEADOF);

            uris = new AList <URIish>(vlst.Length);
            foreach (string s in vlst)
            {
                uris.AddItem(new URIish(ReplaceUri(s, insteadOf)));
            }
            IDictionary <string, string> pushInsteadOf = GetReplacements(rc, KEY_PUSHINSTEADOF
                                                                         );

            vlst     = rc.GetStringList(SECTION, name, KEY_PUSHURL);
            pushURIs = new AList <URIish>(vlst.Length);
            foreach (string s_1 in vlst)
            {
                pushURIs.AddItem(new URIish(ReplaceUri(s_1, pushInsteadOf)));
            }
            vlst  = rc.GetStringList(SECTION, name, KEY_FETCH);
            fetch = new AList <RefSpec>(vlst.Length);
            foreach (string s_2 in vlst)
            {
                fetch.AddItem(new RefSpec(s_2));
            }
            vlst = rc.GetStringList(SECTION, name, KEY_PUSH);
            push = new AList <RefSpec>(vlst.Length);
            foreach (string s_3 in vlst)
            {
                push.AddItem(new RefSpec(s_3));
            }
            val = rc.GetString(SECTION, name, KEY_UPLOADPACK);
            if (val == null)
            {
                val = DEFAULT_UPLOAD_PACK;
            }
            uploadpack = val;
            val        = rc.GetString(SECTION, name, KEY_RECEIVEPACK);
            if (val == null)
            {
                val = DEFAULT_RECEIVE_PACK;
            }
            receivepack = val;
            val         = rc.GetString(SECTION, name, KEY_TAGOPT);
            tagopt      = NGit.Transport.TagOpt.FromOption(val);
            mirror      = rc.GetBoolean(SECTION, name, KEY_MIRROR, DEFAULT_MIRROR);
            timeout     = rc.GetInt(SECTION, name, KEY_TIMEOUT, 0);
        }
Ejemplo n.º 2
0
        /// <summary>Update this remote's definition within the configuration.</summary>
        /// <remarks>Update this remote's definition within the configuration.</remarks>
        /// <param name="rc">the configuration file to store ourselves into.</param>
        public virtual void Update(Config rc)
        {
            IList <string> vlst = new AList <string>();

            vlst.Clear();
            foreach (URIish u in URIs)
            {
                vlst.AddItem(u.ToPrivateString());
            }
            rc.SetStringList(SECTION, Name, KEY_URL, vlst);
            vlst.Clear();
            foreach (URIish u_1 in PushURIs)
            {
                vlst.AddItem(u_1.ToPrivateString());
            }
            rc.SetStringList(SECTION, Name, KEY_PUSHURL, vlst);
            vlst.Clear();
            foreach (RefSpec u_2 in FetchRefSpecs)
            {
                vlst.AddItem(u_2.ToString());
            }
            rc.SetStringList(SECTION, Name, KEY_FETCH, vlst);
            vlst.Clear();
            foreach (RefSpec u_3 in PushRefSpecs)
            {
                vlst.AddItem(u_3.ToString());
            }
            rc.SetStringList(SECTION, Name, KEY_PUSH, vlst);
            Set(rc, KEY_UPLOADPACK, UploadPack, DEFAULT_UPLOAD_PACK);
            Set(rc, KEY_RECEIVEPACK, ReceivePack, DEFAULT_RECEIVE_PACK);
            Set(rc, KEY_TAGOPT, TagOpt.Option(), NGit.Transport.TagOpt.AUTO_FOLLOW.Option());
            Set(rc, KEY_MIRROR, mirror, DEFAULT_MIRROR);
            Set(rc, KEY_TIMEOUT, timeout, 0);
            if (!oldName.Equals(name))
            {
                rc.UnsetSection(SECTION, oldName);
                oldName = name;
            }
        }
Ejemplo n.º 3
0
 /// <summary>Set the description of how annotated tags should be treated on fetch.</summary>
 /// <remarks>Set the description of how annotated tags should be treated on fetch.</remarks>
 /// <param name="option">method to use when handling annotated tags.</param>
 public virtual void SetTagOpt(TagOpt option)
 {
     tagopt = option != null ? option : TagOpt.AUTO_FOLLOW;
 }
Ejemplo n.º 4
0
        /// <exception cref="System.NotSupportedException"></exception>
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void ExecuteImp(ProgressMonitor monitor, FetchResult result)
        {
            conn = transport.OpenFetch();
            try
            {
                result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap());
                ICollection <Ref> matched = new HashSet <Ref>();
                foreach (RefSpec spec in toFetch)
                {
                    if (spec.GetSource() == null)
                    {
                        throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec
                                                                          , spec));
                    }
                    if (spec.IsWildcard())
                    {
                        ExpandWildcard(spec, matched);
                    }
                    else
                    {
                        ExpandSingle(spec, matched);
                    }
                }
                ICollection <Ref> additionalTags = Sharpen.Collections.EmptyList <Ref>();
                TagOpt            tagopt         = transport.GetTagOpt();
                if (tagopt == TagOpt.AUTO_FOLLOW)
                {
                    additionalTags = ExpandAutoFollowTags();
                }
                else
                {
                    if (tagopt == TagOpt.FETCH_TAGS)
                    {
                        ExpandFetchTags();
                    }
                }
                bool includedTags;
                if (!askFor.IsEmpty() && !AskForIsComplete())
                {
                    FetchObjects(monitor);
                    includedTags = conn.DidFetchIncludeTags();
                    // Connection was used for object transfer. If we
                    // do another fetch we must open a new connection.
                    //
                    CloseConnection(result);
                }
                else
                {
                    includedTags = false;
                }
                if (tagopt == TagOpt.AUTO_FOLLOW && !additionalTags.IsEmpty())
                {
                    // There are more tags that we want to follow, but
                    // not all were asked for on the initial request.
                    //
                    Sharpen.Collections.AddAll(have, askFor.Keys);
                    askFor.Clear();
                    foreach (Ref r in additionalTags)
                    {
                        ObjectId id = r.GetPeeledObjectId();
                        if (id == null || transport.local.HasObject(id))
                        {
                            WantTag(r);
                        }
                    }
                    if (!askFor.IsEmpty() && (!includedTags || !AskForIsComplete()))
                    {
                        ReopenConnection();
                        if (!askFor.IsEmpty())
                        {
                            FetchObjects(monitor);
                        }
                    }
                }
            }
            finally
            {
                CloseConnection(result);
            }
            RevWalk walk = new RevWalk(transport.local);

            try
            {
                if (transport.IsRemoveDeletedRefs())
                {
                    DeleteStaleTrackingRefs(result, walk);
                }
                foreach (TrackingRefUpdate u in localUpdates)
                {
                    try
                    {
                        u.Update(walk);
                        result.Add(u);
                    }
                    catch (IOException err)
                    {
                        throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef
                                                                          , u.GetLocalName(), err.Message), err);
                    }
                }
            }
            finally
            {
                walk.Release();
            }
            if (!fetchHeadUpdates.IsEmpty())
            {
                try
                {
                    UpdateFETCH_HEAD(result);
                }
                catch (IOException err)
                {
                    throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD
                                                                      , err.Message), err);
                }
            }
        }
Ejemplo n.º 5
0
		/// <summary>Parse a remote block from an existing configuration file.</summary>
		/// <remarks>
		/// Parse a remote block from an existing configuration file.
		/// <p>
		/// This constructor succeeds even if the requested remote is not defined
		/// within the supplied configuration file. If that occurs then there will be
		/// no URIs and no ref specifications known to the new instance.
		/// </remarks>
		/// <param name="rc">
		/// the existing configuration to get the remote settings from.
		/// The configuration must already be loaded into memory.
		/// </param>
		/// <param name="remoteName">subsection key indicating the name of this remote.</param>
		/// <exception cref="Sharpen.URISyntaxException">one of the URIs within the remote's configuration is invalid.
		/// 	</exception>
		public RemoteConfig(Config rc, string remoteName)
		{
			name = remoteName;
			oldName = remoteName;
			string[] vlst;
			string val;
			vlst = rc.GetStringList(SECTION, name, KEY_URL);
			IDictionary<string, string> insteadOf = GetReplacements(rc, KEY_INSTEADOF);
			uris = new AList<URIish>(vlst.Length);
			foreach (string s in vlst)
			{
				uris.AddItem(new URIish(ReplaceUri(s, insteadOf)));
			}
			IDictionary<string, string> pushInsteadOf = GetReplacements(rc, KEY_PUSHINSTEADOF
				);
			vlst = rc.GetStringList(SECTION, name, KEY_PUSHURL);
			pushURIs = new AList<URIish>(vlst.Length);
			foreach (string s_1 in vlst)
			{
				pushURIs.AddItem(new URIish(ReplaceUri(s_1, pushInsteadOf)));
			}
			vlst = rc.GetStringList(SECTION, name, KEY_FETCH);
			fetch = new AList<RefSpec>(vlst.Length);
			foreach (string s_2 in vlst)
			{
				fetch.AddItem(new RefSpec(s_2));
			}
			vlst = rc.GetStringList(SECTION, name, KEY_PUSH);
			push = new AList<RefSpec>(vlst.Length);
			foreach (string s_3 in vlst)
			{
				push.AddItem(new RefSpec(s_3));
			}
			val = rc.GetString(SECTION, name, KEY_UPLOADPACK);
			if (val == null)
			{
				val = DEFAULT_UPLOAD_PACK;
			}
			uploadpack = val;
			val = rc.GetString(SECTION, name, KEY_RECEIVEPACK);
			if (val == null)
			{
				val = DEFAULT_RECEIVE_PACK;
			}
			receivepack = val;
			val = rc.GetString(SECTION, name, KEY_TAGOPT);
			tagopt = NGit.Transport.TagOpt.FromOption(val);
			mirror = rc.GetBoolean(SECTION, name, KEY_MIRROR, DEFAULT_MIRROR);
			timeout = rc.GetInt(SECTION, name, KEY_TIMEOUT, 0);
		}
Ejemplo n.º 6
0
        /// <exception cref="System.NotSupportedException"></exception>
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void ExecuteImp(ProgressMonitor monitor, FetchResult result)
        {
            conn = transport.OpenFetch();
            try
            {
                result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap());
                ICollection <Ref> matched = new HashSet <Ref>();
                foreach (RefSpec spec in toFetch)
                {
                    if (spec.GetSource() == null)
                    {
                        throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec
                                                                          , spec));
                    }
                    if (spec.IsWildcard())
                    {
                        ExpandWildcard(spec, matched);
                    }
                    else
                    {
                        ExpandSingle(spec, matched);
                    }
                }
                ICollection <Ref> additionalTags = Sharpen.Collections.EmptyList <Ref>();
                TagOpt            tagopt         = transport.GetTagOpt();
                if (tagopt == TagOpt.AUTO_FOLLOW)
                {
                    additionalTags = ExpandAutoFollowTags();
                }
                else
                {
                    if (tagopt == TagOpt.FETCH_TAGS)
                    {
                        ExpandFetchTags();
                    }
                }
                bool includedTags;
                if (!askFor.IsEmpty() && !AskForIsComplete())
                {
                    FetchObjects(monitor);
                    includedTags = conn.DidFetchIncludeTags();
                    // Connection was used for object transfer. If we
                    // do another fetch we must open a new connection.
                    //
                    CloseConnection(result);
                }
                else
                {
                    includedTags = false;
                }
                if (tagopt == TagOpt.AUTO_FOLLOW && !additionalTags.IsEmpty())
                {
                    // There are more tags that we want to follow, but
                    // not all were asked for on the initial request.
                    //
                    Sharpen.Collections.AddAll(have, askFor.Keys);
                    askFor.Clear();
                    foreach (Ref r in additionalTags)
                    {
                        ObjectId id = r.GetPeeledObjectId();
                        if (id == null)
                        {
                            id = r.GetObjectId();
                        }
                        if (transport.local.HasObject(id))
                        {
                            WantTag(r);
                        }
                    }
                    if (!askFor.IsEmpty() && (!includedTags || !AskForIsComplete()))
                    {
                        ReopenConnection();
                        if (!askFor.IsEmpty())
                        {
                            FetchObjects(monitor);
                        }
                    }
                }
            }
            finally
            {
                CloseConnection(result);
            }
            BatchRefUpdate batch = transport.local.RefDatabase.NewBatchUpdate().SetAllowNonFastForwards
                                       (true).SetRefLogMessage("fetch", true);
            RevWalk walk = new RevWalk(transport.local);

            try
            {
                if (monitor is BatchingProgressMonitor)
                {
                    ((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS);
                }
                if (transport.IsRemoveDeletedRefs())
                {
                    DeleteStaleTrackingRefs(result, batch);
                }
                foreach (TrackingRefUpdate u in localUpdates)
                {
                    result.Add(u);
                    batch.AddCommand(u.AsReceiveCommand());
                }
                foreach (ReceiveCommand cmd in batch.GetCommands())
                {
                    cmd.UpdateType(walk);
                    if (cmd.GetType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD && cmd is TrackingRefUpdate.Command &&
                        !((TrackingRefUpdate.Command)cmd).CanForceUpdate())
                    {
                        cmd.SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD);
                    }
                }
                if (transport.IsDryRun())
                {
                    foreach (ReceiveCommand cmd_1 in batch.GetCommands())
                    {
                        if (cmd_1.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED)
                        {
                            cmd_1.SetResult(ReceiveCommand.Result.OK);
                        }
                    }
                }
                else
                {
                    batch.Execute(walk, monitor);
                }
            }
            catch (IOException err)
            {
                throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef
                                                                  , GetFirstFailedRefName(batch), err.Message), err);
            }
            finally
            {
                walk.Release();
            }
            if (!fetchHeadUpdates.IsEmpty())
            {
                try
                {
                    UpdateFETCH_HEAD(result);
                }
                catch (IOException err)
                {
                    throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD
                                                                      , err.Message), err);
                }
            }
        }