diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-03-12 19:09:24 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-03-12 19:09:24 +0400 |
commit | 493b2ae9e0f52972fe6c7b71d8060ba41699fb37 (patch) | |
tree | cf4795e35de01a602be1f6039c87453289e7f643 | |
parent | 79af4422664243836f400ff67513b0e2b27c9f1b (diff) | |
parent | 23ddc59cc5c7b4b631983ef8fd6d3913320286c9 (diff) |
Merge branch 'master' into newresolver
19 files changed, 375 insertions, 99 deletions
diff --git a/main/contrib/NGit/NGit.Api.Errors/CheckoutConflictException.cs b/main/contrib/NGit/NGit.Api.Errors/CheckoutConflictException.cs index ae91a50a0b..91bcc0fc26 100755 --- a/main/contrib/NGit/NGit.Api.Errors/CheckoutConflictException.cs +++ b/main/contrib/NGit/NGit.Api.Errors/CheckoutConflictException.cs @@ -65,7 +65,12 @@ namespace NGit.Api.Errors /// <summary>Translate internal exception to API exception</summary> /// <param name="conflictingPaths">list of conflicting paths</param> - /// <param name="e"></param> + /// <param name="e"> + /// a + /// <see cref="NGit.Errors.CheckoutConflictException">NGit.Errors.CheckoutConflictException + /// </see> + /// exception + /// </param> public CheckoutConflictException(IList<string> conflictingPaths, NGit.Errors.CheckoutConflictException e) : base(e.Message, e) { diff --git a/main/contrib/NGit/NGit.Api/AddCommand.cs b/main/contrib/NGit/NGit.Api/AddCommand.cs index 9994bcd284..bedc9cec39 100755 --- a/main/contrib/NGit/NGit.Api/AddCommand.cs +++ b/main/contrib/NGit/NGit.Api/AddCommand.cs @@ -214,7 +214,7 @@ namespace NGit.Api } else { - if (!update) + if (c != null && (!update || FileMode.GITLINK == c.EntryFileMode)) { builder.Add(c.GetDirCacheEntry()); } diff --git a/main/contrib/NGit/NGit.Api/CheckoutCommand.cs b/main/contrib/NGit/NGit.Api/CheckoutCommand.cs index f8a4d36bea..6494b46bfa 100755 --- a/main/contrib/NGit/NGit.Api/CheckoutCommand.cs +++ b/main/contrib/NGit/NGit.Api/CheckoutCommand.cs @@ -97,6 +97,7 @@ namespace NGit.Api /// </exception> /// <returns>the newly created branch</returns> /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception> + /// <exception cref="NGit.Api.Errors.CheckoutConflictException"></exception> public override Ref Call() { CheckCallable(); @@ -146,7 +147,7 @@ namespace NGit.Api catch (NGit.Errors.CheckoutConflictException e) { status = new CheckoutResult(CheckoutResult.Status.CONFLICTS, dco.GetConflicts()); - throw; + throw new NGit.Api.Errors.CheckoutConflictException(dco.GetConflicts(), e); } Ref @ref = repo.GetRef(name); if (@ref != null && !@ref.GetName().StartsWith(Constants.R_HEADS)) @@ -296,7 +297,7 @@ namespace NGit.Api { ObjectId blobId = startWalk.GetObjectId(0); FileMode mode = startWalk.GetFileMode(0); - editor.Add(new _PathEdit_285(this, blobId, mode, workTree, r, startWalk.PathString + editor.Add(new _PathEdit_286(this, blobId, mode, workTree, r, startWalk.PathString )); } editor.Commit(); @@ -315,9 +316,9 @@ namespace NGit.Api return this; } - private sealed class _PathEdit_285 : DirCacheEditor.PathEdit + private sealed class _PathEdit_286 : DirCacheEditor.PathEdit { - public _PathEdit_285(CheckoutCommand _enclosing, ObjectId blobId, FileMode mode, + public _PathEdit_286(CheckoutCommand _enclosing, ObjectId blobId, FileMode mode, FilePath workTree, ObjectReader r, string baseArg1) : base(baseArg1) { this._enclosing = _enclosing; diff --git a/main/contrib/NGit/NGit.Api/RebaseCommand.cs b/main/contrib/NGit/NGit.Api/RebaseCommand.cs index 977edfc346..19f8fb436e 100755 --- a/main/contrib/NGit/NGit.Api/RebaseCommand.cs +++ b/main/contrib/NGit/NGit.Api/RebaseCommand.cs @@ -193,6 +193,15 @@ namespace NGit.Api if (operation == RebaseCommand.Operation.CONTINUE) { newHead = ContinueRebase(); + if (newHead == null) + { + // continueRebase() returns null only if no commit was + // neccessary. This means that no changes where left over + // after resolving all conflicts. In this case, cgit stops + // and displays a nice message to the user, telling him to + // either do changes or skip the commit instead of continue. + return RebaseResult.NOTHING_TO_COMMIT_RESULT; + } } if (operation == RebaseCommand.Operation.SKIP) { @@ -765,6 +774,10 @@ namespace NGit.Api { throw new JGitInternalException(e.Message, e); } + catch (NGit.Api.Errors.CheckoutConflictException e) + { + throw new JGitInternalException(e.Message, e); + } } /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException"></exception> diff --git a/main/contrib/NGit/NGit.Api/RebaseResult.cs b/main/contrib/NGit/NGit.Api/RebaseResult.cs index cad8637f9e..3699500f94 100755 --- a/main/contrib/NGit/NGit.Api/RebaseResult.cs +++ b/main/contrib/NGit/NGit.Api/RebaseResult.cs @@ -74,6 +74,9 @@ namespace NGit.Api public static RebaseResult.Status FAST_FORWARD = new RebaseResult.Status.FAST_FORWARD_Class (); + public static RebaseResult.Status NOTHING_TO_COMMIT = new RebaseResult.Status.NOTHING_TO_COMMIT_Class + (); + internal class OK_Class : RebaseResult.Status { public override bool IsSuccessful() @@ -122,6 +125,14 @@ namespace NGit.Api } } + internal class NOTHING_TO_COMMIT_Class : RebaseResult.Status + { + public override bool IsSuccessful() + { + return false; + } + } + public abstract bool IsSuccessful(); } @@ -137,6 +148,9 @@ namespace NGit.Api internal static readonly RebaseResult FAST_FORWARD_RESULT = new RebaseResult(RebaseResult.Status .FAST_FORWARD); + internal static readonly RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult + (RebaseResult.Status.NOTHING_TO_COMMIT); + private readonly RebaseResult.Status status; private readonly RevCommit currentCommit; diff --git a/main/contrib/NGit/NGit.Transport/BasePackFetchConnection.cs b/main/contrib/NGit/NGit.Transport/BasePackFetchConnection.cs index acb1b4f27e..2f23b5f061 100755 --- a/main/contrib/NGit/NGit.Transport/BasePackFetchConnection.cs +++ b/main/contrib/NGit/NGit.Transport/BasePackFetchConnection.cs @@ -114,25 +114,45 @@ namespace NGit.Transport /// </remarks> protected internal const int MIN_CLIENT_BUFFER = 2 * 32 * 46 + 8; - internal static readonly string OPTION_INCLUDE_TAG = "include-tag"; + /// <summary>Include tags if we are also including the referenced objects.</summary> + /// <remarks>Include tags if we are also including the referenced objects.</remarks> + public static readonly string OPTION_INCLUDE_TAG = "include-tag"; - internal static readonly string OPTION_MULTI_ACK = "multi_ack"; + /// <summary>Mutli-ACK support for improved negotiation.</summary> + /// <remarks>Mutli-ACK support for improved negotiation.</remarks> + public static readonly string OPTION_MULTI_ACK = "multi_ack"; - internal static readonly string OPTION_MULTI_ACK_DETAILED = "multi_ack_detailed"; + /// <summary>Mutli-ACK detailed support for improved negotiation.</summary> + /// <remarks>Mutli-ACK detailed support for improved negotiation.</remarks> + public static readonly string OPTION_MULTI_ACK_DETAILED = "multi_ack_detailed"; - internal static readonly string OPTION_THIN_PACK = "thin-pack"; + /// <summary>The client supports packs with deltas but not their bases.</summary> + /// <remarks>The client supports packs with deltas but not their bases.</remarks> + public static readonly string OPTION_THIN_PACK = "thin-pack"; - internal static readonly string OPTION_SIDE_BAND = "side-band"; + /// <summary>The client supports using the side-band for progress messages.</summary> + /// <remarks>The client supports using the side-band for progress messages.</remarks> + public static readonly string OPTION_SIDE_BAND = "side-band"; - internal static readonly string OPTION_SIDE_BAND_64K = "side-band-64k"; + /// <summary>The client supports using the 64K side-band for progress messages.</summary> + /// <remarks>The client supports using the 64K side-band for progress messages.</remarks> + public static readonly string OPTION_SIDE_BAND_64K = "side-band-64k"; - internal static readonly string OPTION_OFS_DELTA = "ofs-delta"; + /// <summary>The client supports packs with OFS deltas.</summary> + /// <remarks>The client supports packs with OFS deltas.</remarks> + public static readonly string OPTION_OFS_DELTA = "ofs-delta"; - internal static readonly string OPTION_SHALLOW = "shallow"; + /// <summary>The client supports shallow fetches.</summary> + /// <remarks>The client supports shallow fetches.</remarks> + public static readonly string OPTION_SHALLOW = "shallow"; - internal static readonly string OPTION_NO_PROGRESS = "no-progress"; + /// <summary>The client does not want progress messages and will ignore them.</summary> + /// <remarks>The client does not want progress messages and will ignore them.</remarks> + public static readonly string OPTION_NO_PROGRESS = "no-progress"; - internal static readonly string OPTION_NO_DONE = "no-done"; + /// <summary>The client supports receiving a pack before it has sent "done".</summary> + /// <remarks>The client supports receiving a pack before it has sent "done".</remarks> + public static readonly string OPTION_NO_DONE = "no-done"; internal class MultiAck { @@ -219,10 +239,10 @@ namespace NGit.Transport private class FetchConfig { - private sealed class _SectionParser_216 : Config.SectionParser<BasePackFetchConnection.FetchConfig + private sealed class _SectionParser_226 : Config.SectionParser<BasePackFetchConnection.FetchConfig > { - public _SectionParser_216() + public _SectionParser_226() { } @@ -233,7 +253,7 @@ namespace NGit.Transport } internal static readonly Config.SectionParser<BasePackFetchConnection.FetchConfig - > KEY = new _SectionParser_216(); + > KEY = new _SectionParser_226(); internal readonly bool allowOfsDelta; @@ -725,12 +745,12 @@ READ_RESULT_break2: ; walk.ResetRetain(REACHABLE, ADVERTISED); walk.MarkStart(reachableCommits); walk.Sort(RevSort.COMMIT_TIME_DESC); - walk.SetRevFilter(new _RevFilter_609(this)); + walk.SetRevFilter(new _RevFilter_619(this)); } - private sealed class _RevFilter_609 : RevFilter + private sealed class _RevFilter_619 : RevFilter { - public _RevFilter_609(BasePackFetchConnection _enclosing) + public _RevFilter_619(BasePackFetchConnection _enclosing) { this._enclosing = _enclosing; } diff --git a/main/contrib/NGit/NGit.Transport/BasePackPushConnection.cs b/main/contrib/NGit/NGit.Transport/BasePackPushConnection.cs index a00cc04270..c41bdcdc0a 100755 --- a/main/contrib/NGit/NGit.Transport/BasePackPushConnection.cs +++ b/main/contrib/NGit/NGit.Transport/BasePackPushConnection.cs @@ -82,13 +82,21 @@ namespace NGit.Transport /// </remarks> public abstract class BasePackPushConnection : BasePackConnection, PushConnection { - internal static readonly string CAPABILITY_REPORT_STATUS = "report-status"; + /// <summary>The client expects a status report after the server processes the pack.</summary> + /// <remarks>The client expects a status report after the server processes the pack.</remarks> + public static readonly string CAPABILITY_REPORT_STATUS = "report-status"; - internal static readonly string CAPABILITY_DELETE_REFS = "delete-refs"; + /// <summary>The server supports deleting refs.</summary> + /// <remarks>The server supports deleting refs.</remarks> + public static readonly string CAPABILITY_DELETE_REFS = "delete-refs"; - internal static readonly string CAPABILITY_OFS_DELTA = "ofs-delta"; + /// <summary>The server supports packs with OFS deltas.</summary> + /// <remarks>The server supports packs with OFS deltas.</remarks> + public static readonly string CAPABILITY_OFS_DELTA = "ofs-delta"; - internal static readonly string CAPABILITY_SIDE_BAND_64K = "side-band-64k"; + /// <summary>The client supports using the 64K side-band for progress messages.</summary> + /// <remarks>The client supports using the 64K side-band for progress messages.</remarks> + public static readonly string CAPABILITY_SIDE_BAND_64K = "side-band-64k"; private readonly bool thinPack; diff --git a/main/contrib/NGit/NGit.Transport/ReceivePack.cs b/main/contrib/NGit/NGit.Transport/ReceivePack.cs index 42ff370b6e..688064171c 100755 --- a/main/contrib/NGit/NGit.Transport/ReceivePack.cs +++ b/main/contrib/NGit/NGit.Transport/ReceivePack.cs @@ -59,6 +59,45 @@ namespace NGit.Transport /// <remarks>Implements the server side of a push connection, receiving objects.</remarks> public class ReceivePack { + /// <summary>Data in the first line of a request, the line itself plus capabilities.</summary> + /// <remarks>Data in the first line of a request, the line itself plus capabilities.</remarks> + public class FirstLine + { + private readonly string line; + + private readonly ICollection<string> capabilities; + + /// <summary>Parse the first line of a receive-pack request.</summary> + /// <remarks>Parse the first line of a receive-pack request.</remarks> + /// <param name="line">line from the client.</param> + public FirstLine(string line) + { + HashSet<string> caps = new HashSet<string>(); + int nul = line.IndexOf('\0'); + if (nul >= 0) + { + foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" ")) + { + caps.AddItem(c); + } + } + this.line = Sharpen.Runtime.Substring(line, 0, nul); + this.capabilities = Sharpen.Collections.UnmodifiableSet(caps); + } + + /// <returns>non-capabilities part of the line.</returns> + public virtual string GetLine() + { + return line; + } + + /// <returns>capabilities parsed from the line.</returns> + public virtual ICollection<string> GetCapabilities() + { + return capabilities; + } + } + /// <summary>Database we write the stored objects into.</summary> /// <remarks>Database we write the stored objects into.</remarks> private readonly Repository db; @@ -160,7 +199,7 @@ namespace NGit.Transport /// <summary>Capabilities requested by the client.</summary> /// <remarks>Capabilities requested by the client.</remarks> - private ICollection<string> enabledCapablities; + private ICollection<string> enabledCapabilities; /// <summary>Commands to execute, as received by the client.</summary> /// <remarks>Commands to execute, as received by the client.</remarks> @@ -222,10 +261,10 @@ namespace NGit.Transport private class ReceiveConfig { - private sealed class _SectionParser_227 : Config.SectionParser<ReceivePack.ReceiveConfig + private sealed class _SectionParser_260 : Config.SectionParser<ReceivePack.ReceiveConfig > { - public _SectionParser_227() + public _SectionParser_260() { } @@ -236,7 +275,7 @@ namespace NGit.Transport } internal static readonly Config.SectionParser<ReceivePack.ReceiveConfig> KEY = new - _SectionParser_227(); + _SectionParser_260(); internal readonly bool checkReceivedObjects; @@ -711,6 +750,29 @@ namespace NGit.Transport maxObjectSizeLimit = limit; } + /// <summary>Check whether the client expects a side-band stream.</summary> + /// <remarks>Check whether the client expects a side-band stream.</remarks> + /// <returns> + /// true if the client has advertised a side-band capability, false + /// otherwise. + /// </returns> + /// <exception cref="RequestNotYetReadException"> + /// if the client's request has not yet been read from the wire, so + /// we do not know if they expect side-band. Note that the client + /// may have already written the request, it just has not been + /// read. + /// </exception> + /// <exception cref="NGit.Transport.RequestNotYetReadException"></exception> + public virtual bool IsSideBand() + { + if (enabledCapabilities == null) + { + throw new RequestNotYetReadException(); + } + return enabledCapabilities.Contains(BasePackPushConnection.CAPABILITY_SIDE_BAND_64K + ); + } + /// <returns>all of the command received by the current request.</returns> public virtual IList<ReceiveCommand> GetAllCommands() { @@ -824,7 +886,6 @@ namespace NGit.Transport pckIn = new PacketLineIn(rawIn); pckOut = new PacketLineOut(rawOut); pckOut.SetFlushOnEnd(false); - enabledCapablities = new HashSet<string>(); commands = new AList<ReceiveCommand>(); Service(); } @@ -870,7 +931,7 @@ namespace NGit.Transport pckIn = null; pckOut = null; refs = null; - enabledCapablities = null; + enabledCapabilities = null; commands = null; if (timer != null) { @@ -949,14 +1010,14 @@ namespace NGit.Transport UnlockPack(); if (reportStatus) { - SendStatusReport(true, new _Reporter_810(this)); + SendStatusReport(true, new _Reporter_859(this)); pckOut.End(); } else { if (msgOut != null) { - SendStatusReport(false, new _Reporter_817(this)); + SendStatusReport(false, new _Reporter_866(this)); } } postReceive.OnPostReceive(this, ReceiveCommand.Filter(commands, ReceiveCommand.Result @@ -968,9 +1029,9 @@ namespace NGit.Transport } } - private sealed class _Reporter_810 : ReceivePack.Reporter + private sealed class _Reporter_859 : ReceivePack.Reporter { - public _Reporter_810(ReceivePack _enclosing) + public _Reporter_859(ReceivePack _enclosing) { this._enclosing = _enclosing; } @@ -984,9 +1045,9 @@ namespace NGit.Transport private readonly ReceivePack _enclosing; } - private sealed class _Reporter_817 : ReceivePack.Reporter + private sealed class _Reporter_866 : ReceivePack.Reporter { - public _Reporter_817(ReceivePack _enclosing) + public _Reporter_866(ReceivePack _enclosing) { this._enclosing = _enclosing; } @@ -1081,15 +1142,9 @@ namespace NGit.Transport } if (commands.IsEmpty()) { - int nul = line.IndexOf('\0'); - if (nul >= 0) - { - foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" ")) - { - enabledCapablities.AddItem(c); - } - line = Sharpen.Runtime.Substring(line, 0, nul); - } + ReceivePack.FirstLine firstLine = new ReceivePack.FirstLine(line); + enabledCapabilities = firstLine.GetCapabilities(); + line = firstLine.GetLine(); } if (line.Length < 83) { @@ -1115,9 +1170,9 @@ namespace NGit.Transport private void EnableCapabilities() { - reportStatus = enabledCapablities.Contains(BasePackPushConnection.CAPABILITY_REPORT_STATUS + reportStatus = enabledCapabilities.Contains(BasePackPushConnection.CAPABILITY_REPORT_STATUS ); - sideBand = enabledCapablities.Contains(BasePackPushConnection.CAPABILITY_SIDE_BAND_64K + sideBand = enabledCapabilities.Contains(BasePackPushConnection.CAPABILITY_SIDE_BAND_64K ); if (sideBand) { diff --git a/main/contrib/NGit/NGit.Transport/RequestNotYetReadException.cs b/main/contrib/NGit/NGit.Transport/RequestNotYetReadException.cs new file mode 100644 index 0000000000..7e00191e37 --- /dev/null +++ b/main/contrib/NGit/NGit.Transport/RequestNotYetReadException.cs @@ -0,0 +1,71 @@ +/* +This code is derived from jgit (http://eclipse.org/jgit). +Copyright owners are documented in jgit's IP log. + +This program and the accompanying materials are made available +under the terms of the Eclipse Distribution License v1.0 which +accompanies this distribution, is reproduced below, and is +available at http://www.eclipse.org/org/documents/edl-v10.php + +All rights reserved. + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following +conditions are met: + +- Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +- Neither the name of the Eclipse Foundation, Inc. nor the + names of its contributors may be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using Sharpen; + +namespace NGit.Transport +{ + /// <summary>Indicates that a client request has not yet been read from the wire.</summary> + /// <remarks>Indicates that a client request has not yet been read from the wire.</remarks> + [System.Serializable] + public class RequestNotYetReadException : InvalidOperationException + { + private const long serialVersionUID = 1L; + + /// <summary>Initialize with no message.</summary> + /// <remarks>Initialize with no message.</remarks> + public RequestNotYetReadException() + { + } + + /// <param name="msg"> + /// a message explaining the state. This message should not + /// be shown to an end-user. + /// </param> + public RequestNotYetReadException(string msg) : base(msg) + { + } + // Do not set a message. + } +} diff --git a/main/contrib/NGit/NGit.Transport/SideBandOutputStream.cs b/main/contrib/NGit/NGit.Transport/SideBandOutputStream.cs index cce6161ffa..104abfba2e 100755 --- a/main/contrib/NGit/NGit.Transport/SideBandOutputStream.cs +++ b/main/contrib/NGit/NGit.Transport/SideBandOutputStream.cs @@ -55,17 +55,27 @@ namespace NGit.Transport /// This stream is buffered at packet sizes, so the caller doesn't need to wrap /// it in yet another buffered stream. /// </remarks> - internal class SideBandOutputStream : OutputStream + public class SideBandOutputStream : OutputStream { - internal const int CH_DATA = SideBandInputStream.CH_DATA; + /// <summary>Channel used for pack data.</summary> + /// <remarks>Channel used for pack data.</remarks> + public const int CH_DATA = SideBandInputStream.CH_DATA; - internal const int CH_PROGRESS = SideBandInputStream.CH_PROGRESS; + /// <summary>Channel used for progress messages.</summary> + /// <remarks>Channel used for progress messages.</remarks> + public const int CH_PROGRESS = SideBandInputStream.CH_PROGRESS; - internal const int CH_ERROR = SideBandInputStream.CH_ERROR; + /// <summary>Channel used for error messages.</summary> + /// <remarks>Channel used for error messages.</remarks> + public const int CH_ERROR = SideBandInputStream.CH_ERROR; - internal const int SMALL_BUF = 1000; + /// <summary>Default buffer size for a small amount of data.</summary> + /// <remarks>Default buffer size for a small amount of data.</remarks> + public const int SMALL_BUF = 1000; - internal const int MAX_BUF = 65520; + /// <summary>Maximum buffer size for a single packet of sideband data.</summary> + /// <remarks>Maximum buffer size for a single packet of sideband data.</remarks> + public const int MAX_BUF = 65520; internal const int HDR_SIZE = 5; @@ -101,7 +111,7 @@ namespace NGit.Transport /// stream that the packets are written onto. This stream should /// be attached to a SideBandInputStream on the remote side. /// </param> - internal SideBandOutputStream(int chan, int sz, OutputStream os) + public SideBandOutputStream(int chan, int sz, OutputStream os) { if (chan <= 0 || chan > 255) { diff --git a/main/contrib/NGit/NGit.Transport/UploadPack.cs b/main/contrib/NGit/NGit.Transport/UploadPack.cs index eeb54595af..d903ecb695 100755 --- a/main/contrib/NGit/NGit.Transport/UploadPack.cs +++ b/main/contrib/NGit/NGit.Transport/UploadPack.cs @@ -87,6 +87,54 @@ namespace NGit.Transport ANY } + /// <summary>Data in the first line of a request, the line itself plus options.</summary> + /// <remarks>Data in the first line of a request, the line itself plus options.</remarks> + public class FirstLine + { + private readonly string line; + + private readonly ICollection<string> options; + + /// <summary>Parse the first line of a receive-pack request.</summary> + /// <remarks>Parse the first line of a receive-pack request.</remarks> + /// <param name="line">line from the client.</param> + public FirstLine(string line) + { + if (line.Length > 45) + { + HashSet<string> opts = new HashSet<string>(); + string opt = Sharpen.Runtime.Substring(line, 45); + if (opt.StartsWith(" ")) + { + opt = Sharpen.Runtime.Substring(opt, 1); + } + foreach (string c in opt.Split(" ")) + { + opts.AddItem(c); + } + this.line = Sharpen.Runtime.Substring(line, 0, 45); + this.options = Sharpen.Collections.UnmodifiableSet(opts); + } + else + { + this.line = line; + this.options = Sharpen.Collections.EmptySet<string>(); + } + } + + /// <returns>non-capabilities part of the line.</returns> + public virtual string GetLine() + { + return line; + } + + /// <returns>options parsed from the line.</returns> + public virtual ICollection<string> GetOptions() + { + return options; + } + } + /// <summary>Database we read the objects from.</summary> /// <remarks>Database we read the objects from.</remarks> private readonly Repository db; @@ -158,7 +206,7 @@ namespace NGit.Transport /// <summary>Capabilities requested by the client.</summary> /// <remarks>Capabilities requested by the client.</remarks> - private readonly ICollection<string> options = new HashSet<string>(); + private ICollection<string> options; /// <summary>Raw ObjectIds the client has asked for, before validating them.</summary> /// <remarks>Raw ObjectIds the client has asked for, before validating them.</remarks> @@ -469,6 +517,29 @@ namespace NGit.Transport this.logger = logger; } + /// <summary>Check whether the client expects a side-band stream.</summary> + /// <remarks>Check whether the client expects a side-band stream.</remarks> + /// <returns> + /// true if the client has advertised a side-band capability, false + /// otherwise. + /// </returns> + /// <exception cref="RequestNotYetReadException"> + /// if the client's request has not yet been read from the wire, so + /// we do not know if they expect side-band. Note that the client + /// may have already written the request, it just has not been + /// read. + /// </exception> + /// <exception cref="NGit.Transport.RequestNotYetReadException"></exception> + public virtual bool IsSideBand() + { + if (options == null) + { + throw new RequestNotYetReadException(); + } + return (options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K + )); + } + /// <summary>Execute the upload task on the socket.</summary> /// <remarks>Execute the upload task on the socket.</remarks> /// <param name="input"> @@ -778,16 +849,9 @@ namespace NGit.Transport } if (isFirst && line.Length > 45) { - string opt = Sharpen.Runtime.Substring(line, 45); - if (opt.StartsWith(" ")) - { - opt = Sharpen.Runtime.Substring(opt, 1); - } - foreach (string c in opt.Split(" ")) - { - options.AddItem(c); - } - line = Sharpen.Runtime.Substring(line, 0, 45); + UploadPack.FirstLine firstLine = new UploadPack.FirstLine(line); + options = firstLine.GetOptions(); + line = firstLine.GetLine(); } wantIds.AddItem(ObjectId.FromString(Sharpen.Runtime.Substring(line, 5))); isFirst = false; diff --git a/main/contrib/NGit/NGit.Treewalk/WorkingTreeIterator.cs b/main/contrib/NGit/NGit.Treewalk/WorkingTreeIterator.cs index 2e8fa3291d..ac12949243 100755 --- a/main/contrib/NGit/NGit.Treewalk/WorkingTreeIterator.cs +++ b/main/contrib/NGit/NGit.Treewalk/WorkingTreeIterator.cs @@ -501,7 +501,7 @@ namespace NGit.Treewalk /// <exception cref="System.IO.IOException"></exception> private InputStream FilterClean(InputStream @in) { - return new EolCanonicalizingInputStream(@in); + return new EolCanonicalizingInputStream(@in, true); } /// <summary>Returns the working tree options used by this iterator.</summary> @@ -617,7 +617,7 @@ namespace NGit.Treewalk InputStream @is; if (GetOptions().GetAutoCRLF() != CoreConfig.AutoCRLF.FALSE) { - @is = new EolCanonicalizingInputStream(rawis); + @is = new EolCanonicalizingInputStream(rawis, true); } else { diff --git a/main/contrib/NGit/NGit.Util.IO/EolCanonicalizingInputStream.cs b/main/contrib/NGit/NGit.Util.IO/EolCanonicalizingInputStream.cs index e3b6c90dbd..2f8eb09542 100755 --- a/main/contrib/NGit/NGit.Util.IO/EolCanonicalizingInputStream.cs +++ b/main/contrib/NGit/NGit.Util.IO/EolCanonicalizingInputStream.cs @@ -46,14 +46,12 @@ using Sharpen; namespace NGit.Util.IO { - /// <summary> - /// An input stream which canonicalizes EOLs bytes on the fly to '\n', unless the - /// first 8000 bytes indicate the stream is binary. - /// </summary> + /// <summary>An input stream which canonicalizes EOLs bytes on the fly to '\n'.</summary> /// <remarks> - /// An input stream which canonicalizes EOLs bytes on the fly to '\n', unless the - /// first 8000 bytes indicate the stream is binary. - /// Note: Make sure to apply this InputStream only to text files! + /// An input stream which canonicalizes EOLs bytes on the fly to '\n'. + /// Optionally, a binary check on the first 8000 bytes is performed + /// and in case of binary files, canonicalization is turned off + /// (for the complete file). /// </remarks> public class EolCanonicalizingInputStream : InputStream { @@ -69,13 +67,14 @@ namespace NGit.Util.IO private bool isBinary; - private bool modeDetected; + private bool detectBinary; /// <summary>Creates a new InputStream, wrapping the specified stream</summary> /// <param name="in">raw input stream</param> - public EolCanonicalizingInputStream(InputStream @in) + public EolCanonicalizingInputStream(InputStream @in, bool detectBinary) { this.@in = @in; + this.detectBinary = detectBinary; } /// <exception cref="System.IO.IOException"></exception> @@ -143,10 +142,10 @@ namespace NGit.Util.IO { return false; } - if (!modeDetected) + if (detectBinary) { isBinary = RawText.IsBinary(buf, cnt); - modeDetected = true; + detectBinary = false; } ptr = 0; return true; diff --git a/main/contrib/NGit/NGit.Util/IOUtil.cs b/main/contrib/NGit/NGit.Util/IOUtil.cs index 7230a15a79..0b74f54059 100755 --- a/main/contrib/NGit/NGit.Util/IOUtil.cs +++ b/main/contrib/NGit/NGit.Util/IOUtil.cs @@ -138,13 +138,7 @@ namespace NGit.Util throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path)); } byte[] buf = new byte[(int)sz]; - int actSz = IOUtil.ReadFully(@in, buf, 0); - if (actSz == sz) - { - byte[] ret = new byte[actSz]; - System.Array.Copy(buf, 0, ret, 0, actSz); - return ret; - } + IOUtil.ReadFully(@in, buf, 0); return buf; } finally diff --git a/main/contrib/NGit/NGit.csproj b/main/contrib/NGit/NGit.csproj index 40953651a9..2e523d0f78 100644 --- a/main/contrib/NGit/NGit.csproj +++ b/main/contrib/NGit/NGit.csproj @@ -570,6 +570,7 @@ <Compile Include="NGit.Util\GitDateFormatter.cs" /> <Compile Include="NGit.Api.Errors\PatchApplyException.cs" /> <Compile Include="NGit.Api.Errors\PatchFormatException.cs" /> + <Compile Include="NGit.Transport\RequestNotYetReadException.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/main/contrib/NSch/NSch/Sharpen/Cipher.cs b/main/contrib/NSch/NSch/Sharpen/Cipher.cs index 9fed53b6d5..8a0648d479 100755 --- a/main/contrib/NSch/NSch/Sharpen/Cipher.cs +++ b/main/contrib/NSch/NSch/Sharpen/Cipher.cs @@ -90,14 +90,28 @@ namespace Sharpen class AesCipher: Cipher { + Aes encryptor; + ICryptoTransform transformer; + public AesCipher (CipherMode mode) { - throw new NotSupportedException (); + encryptor = Aes.Create (); + encryptor.Mode = mode; + encryptor.Padding = PaddingMode.None; } - + public override void Init (int mode, Key keyspec, IvParameterSpec spec) { - //SecretKeySpec ks = (SecretKeySpec) keyspec; + SecretKeySpec key = (SecretKeySpec)keyspec; + if (mode == Cipher.ENCRYPT_MODE) + transformer = encryptor.CreateEncryptor (key.Key, spec.Iv); + else + transformer = encryptor.CreateDecryptor (key.Key, spec.Iv); + } + + public override void Update (byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) + { + transformer.TransformBlock (input, inputOffset, inputLen, output, outputOffset); } } diff --git a/main/contrib/NSch/NSch/UserAuthPublicKey.cs b/main/contrib/NSch/NSch/UserAuthPublicKey.cs index ace5b761cd..5bd27eef49 100755 --- a/main/contrib/NSch/NSch/UserAuthPublicKey.cs +++ b/main/contrib/NSch/NSch/UserAuthPublicKey.cs @@ -154,6 +154,10 @@ loop1_break: ; { break; } + else + { + throw new System.Exception ("Invalid passphrase supplied for the ssh key"); + } } Util.Bzero(passphrase); passphrase = null; diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/AutoSave.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/AutoSave.cs index 5edb903966..4091de5b51 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/AutoSave.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/AutoSave.cs @@ -80,7 +80,13 @@ namespace MonoDevelop.SourceEditor return; try { // Directory may have removed/unmounted. Therefore this operation is not guaranteed to work. - File.WriteAllText (GetAutoSaveFileName (fileName), content); + string tmpFile = Path.GetTempFileName (); + File.WriteAllText (tmpFile, content); + + var autosaveFileName = GetAutoSaveFileName (fileName); + if (File.Exists (autosaveFileName)) + File.Delete (autosaveFileName); + File.Move (tmpFile, autosaveFileName); Counters.AutoSavedFiles++; } catch (Exception e) { LoggingService.LogError ("Error in auto save while creating: " + fileName +". Disableing auto save.", e); diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitCredentials.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitCredentials.cs index 525c0d2610..a3f1e5d0f4 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitCredentials.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitCredentials.cs @@ -35,7 +35,7 @@ namespace MonoDevelop.VersionControl.Git { public class GitCredentials: CredentialsProvider { - DateTime LastAsked { + bool HasReset { get; set; } @@ -60,8 +60,7 @@ namespace MonoDevelop.VersionControl.Git if (TryGetUsernamePassword (uri, items, out passwordItem) || TryGetPassphrase (uri, items, out passphraseItem)) { // If the password store has a password and we already tried using it, it could be incorrect. // If this happens, do not return true and ask the user for a new password. - if (!ProbablyIncorrect ()) { - LastAsked = DateTime.Now; + if (!HasReset) { return true; } } @@ -75,7 +74,7 @@ namespace MonoDevelop.VersionControl.Git } }); - LastAsked = DateTime.Now; + HasReset = false; if (result) { if (passwordItem != null) { PasswordService.AddWebPassword (new Uri (uri.ToString ()), new string (passwordItem.GetValue ())); @@ -86,11 +85,9 @@ namespace MonoDevelop.VersionControl.Git return result; } - bool ProbablyIncorrect () + public override void Reset (URIish uri) { - // If we are queried multiple times in rapid succession it is probably - // because the supplied password is incorrect and we should dump it. - return (DateTime.Now - LastAsked) < TimeSpan.FromSeconds (2); + HasReset = true; } bool TryGetPassphrase (URIish uri, CredentialItem[] items, out CredentialItem.StringType passphraseItem) |