Esempio n. 1
0
        /// <summary>
        ///   The delegate with a signature that matches the native checkout progress_cb function's signature.
        /// </summary>
        /// <param name="str">The path that was updated.</param>
        /// <param name="completedSteps">The number of completed steps.</param>
        /// <param name="totalSteps">The total number of steps.</param>
        /// <param name="payload">Payload object.</param>
        private void OnGitCheckoutProgress(IntPtr str, UIntPtr completedSteps, UIntPtr totalSteps, IntPtr payload)
        {
            // Convert null strings into empty strings.
            string path = (str != IntPtr.Zero) ? Utf8Marshaler.FromNative(str) : string.Empty;

            onCheckoutProgress(path, (int)completedSteps, (int)totalSteps);
        }
Esempio n. 2
0
        private int HunkCallback(GitDiffDelta delta, GitDiffRange range, IntPtr header, UIntPtr headerlen, IntPtr payload)
        {
            string decodedContent = Utf8Marshaler.FromNative(header, (int)headerlen);

            AppendToPatch(decodedContent);
            return(0);
        }
Esempio n. 3
0
        private int LineCallback(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
        {
            string decodedContent = Utf8Marshaler.FromNative(content, (int)contentlen);

            string prefix;

            switch (lineorigin)
            {
            case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
                LinesAdded++;
                prefix = Encoding.ASCII.GetString(new[] { (byte)lineorigin });
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
                LinesDeleted++;
                prefix = Encoding.ASCII.GetString(new[] { (byte)lineorigin });
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT:
                prefix = Encoding.ASCII.GetString(new[] { (byte)lineorigin });
                break;

            default:
                prefix = string.Empty;
                break;
            }

            AppendToPatch(prefix);
            AppendToPatch(decodedContent);
            return(0);
        }
Esempio n. 4
0
        /// <summary>
        ///   List references in a <see cref = "Remote" /> repository.
        /// </summary>
        /// <param name="remote">The <see cref = "Remote" /> to list from.</param>
        /// <returns>The references in the <see cref = "Remote" /> repository.</returns>
        public virtual IEnumerable <DirectReference> ListReferences(Remote remote)
        {
            Ensure.ArgumentNotNull(remote, "remote");

            List <DirectReference> directReferences = new List <DirectReference>();

            using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
            {
                Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch);

                NativeMethods.git_headlist_cb cb = (ref GitRemoteHead remoteHead, IntPtr payload) =>
                {
                    // The name pointer should never be null - if it is,
                    // this indicates a bug somewhere (libgit2, server, etc).
                    if (remoteHead.NamePtr == IntPtr.Zero)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Invalid, "Not expecting null value for reference name.");
                        return(-1);
                    }

                    ObjectId oid  = remoteHead.Oid;
                    string   name = Utf8Marshaler.FromNative(remoteHead.NamePtr);
                    directReferences.Add(new DirectReference(name, this.repository, oid));

                    return(0);
                };

                Proxy.git_remote_ls(remoteHandle, cb);
            }

            return(directReferences);
        }
Esempio n. 5
0
            public int Callback(IntPtr referenceNamePtr, IntPtr msgPtr, IntPtr payload)
            {
                // Exit early if there is no callback.
                if (onError == null)
                {
                    return(0);
                }

                // The reference name pointer should never be null - if it is,
                // this indicates a bug somewhere (libgit2, server, etc).
                if (referenceNamePtr == IntPtr.Zero)
                {
                    Proxy.giterr_set_str(GitErrorCategory.Invalid, "Not expecting null for reference name in push status.");
                    return(-1);
                }

                // Only report updates where there is a message - indicating
                // that there was an error.
                if (msgPtr != IntPtr.Zero)
                {
                    string referenceName = Utf8Marshaler.FromNative(referenceNamePtr);
                    string msg           = Utf8Marshaler.FromNative(msgPtr);
                    onError(new PushStatusError(referenceName, msg));
                }

                return(0);
            }
 public static ICustomMarshaler GetInstance(string cookie)
 {
     if (_staticInstance == null)
     {
         return(_staticInstance = new Utf8Marshaler());
     }
     return(_staticInstance);
 }
Esempio n. 7
0
        internal Signature(IntPtr signaturePtr)
        {
            var handle = new GitSignature();

            Marshal.PtrToStructure(signaturePtr, handle);

            name  = Utf8Marshaler.FromNative(handle.Name);
            email = Utf8Marshaler.FromNative(handle.Email);
            when  = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset);
        }
Esempio n. 8
0
        /// <summary>
        ///   Handler for libgit2 Progress callback. Converts values
        ///   received from libgit2 callback to more suitable types
        ///   and calls delegate provided by LibGit2Sharp consumer.
        /// </summary>
        /// <param name="str">IntPtr to string from libgit2</param>
        /// <param name="len">length of string</param>
        /// <param name="data"></param>
        private void GitProgressHandler(IntPtr str, int len, IntPtr data)
        {
            ProgressHandler onProgress = Progress;

            if (onProgress != null)
            {
                string message = Utf8Marshaler.FromNative(str, len);
                onProgress(message);
            }
        }
Esempio n. 9
0
        private int PrintCallBack(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
        {
            string formattedoutput = Utf8Marshaler.FromNative(content, (int)contentlen);
            var    filePath        = FilePathMarshaler.FromNative(delta.NewFile.Path);

            fullPatchBuilder.Append(formattedoutput);
            this[filePath].AppendToPatch(formattedoutput);

            return(0);
        }
Esempio n. 10
0
        private IEnumerable <ConfigurationEntry <string> > BuildConfigEntries()
        {
            return(Proxy.git_config_foreach(configHandle, entryPtr =>
            {
                var entry = (GitConfigEntry)Marshal.PtrToStructure(entryPtr, typeof(GitConfigEntry));

                return new ConfigurationEntry <string>(Utf8Marshaler.FromNative(entry.namePtr),
                                                       Utf8Marshaler.FromNative(entry.valuePtr),
                                                       (ConfigurationLevel)entry.level);
            }));
        }
Esempio n. 11
0
        /// <summary>
        ///   Handler for libgit2 update_tips callback. Converts values
        ///   received from libgit2 callback to more suitable types
        ///   and calls delegate provided by LibGit2Sharp consumer.
        /// </summary>
        /// <param name="str">IntPtr to string</param>
        /// <param name="oldId">Old reference ID</param>
        /// <param name="newId">New referene ID</param>
        /// <param name="data"></param>
        /// <returns></returns>
        private int GitUpdateTipsHandler(IntPtr str, ref GitOid oldId, ref GitOid newId, IntPtr data)
        {
            UpdateTipsHandler onUpdateTips = UpdateTips;
            int result = 0;

            if (onUpdateTips != null)
            {
                string refName = Utf8Marshaler.FromNative(str);
                result = onUpdateTips(refName, oldId, newId);
            }

            return(result);
        }
Esempio n. 12
0
        private int PrintCallBack(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
        {
            string formattedoutput = Utf8Marshaler.FromNative(content, (int)contentlen);

            TreeEntryChanges currentChange = AddFileChange(delta, lineorigin);

            AddLineChange(currentChange, lineorigin);

            currentChange.AppendToPatch(formattedoutput);
            fullPatchBuilder.Append(formattedoutput);

            return(0);
        }
Esempio n. 13
0
        private static string ConvertPath(Func <byte[], int> pathRetriever)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = pathRetriever(buffer);

            //TODO: Make libgit2 return different codes to clearly identify a not found file (GIT_ENOTFOUND ) from any other error (!= GIT_SUCCESS)
            if (result != (int)GitErrorCode.GIT_SUCCESS)
            {
                return(null);
            }

            return(Utf8Marshaler.Utf8FromBuffer(buffer));
        }
Esempio n. 14
0
        /// <summary>
        ///   Probe for a git repository.
        ///   <para>The lookup start from <paramref name = "startingPath" /> and walk upward parent directories if nothing has been found.</para>
        /// </summary>
        /// <param name = "startingPath">The base path where the lookup starts.</param>
        /// <returns>The path to the git repository.</returns>
        public static string Discover(string startingPath)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = NativeMethods.git_repository_discover(buffer, buffer.Length, PosixPathHelper.ToPosix(startingPath), false, null);

            if ((GitErrorCode)result == GitErrorCode.GIT_ENOTAREPO)
            {
                return(null);
            }

            Ensure.Success(result);

            return(PosixPathHelper.ToNative(Utf8Marshaler.Utf8FromBuffer(buffer)));
        }
Esempio n. 15
0
        private static string ConvertPath(Func <byte[], uint, int> pathRetriever)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = pathRetriever(buffer, NativeMethods.GIT_PATH_MAX);

            if (result == (int)GitErrorCode.GIT_ENOTFOUND)
            {
                return(null);
            }

            Ensure.Success(result);

            return(Utf8Marshaler.Utf8FromBuffer(buffer));
        }
Esempio n. 16
0
        private static string branchToCanoncialName(IntPtr namePtr, GitBranchType branchType)
        {
            string shortName = Utf8Marshaler.FromNative(namePtr);

            switch (branchType)
            {
            case GitBranchType.GIT_BRANCH_LOCAL:
                return(ShortToLocalName(shortName));

            case GitBranchType.GIT_BRANCH_REMOTE:
                return(ShortToRemoteName(shortName));

            default:
                return(shortName);
            }
        }
Esempio n. 17
0
        /// <summary>
        ///   Probe for a git repository.
        ///   <para>The lookup start from <paramref name = "startingPath" /> and walk upward parent directories if nothing has been found.</para>
        /// </summary>
        /// <param name = "startingPath">The base path where the lookup starts.</param>
        /// <returns>The path to the git repository.</returns>
        public static string Discover(string startingPath)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = NativeMethods.git_repository_discover(buffer, buffer.Length, startingPath, false, null);

            if ((GitErrorCode)result == GitErrorCode.GIT_ENOTFOUND)
            {
                return(null);
            }

            Ensure.Success(result);

            FilePath discoveredPath = Utf8Marshaler.Utf8FromBuffer(buffer);

            return(discoveredPath.Native);
        }
Esempio n. 18
0
        public static void RequestFirmwareFile(MissingFirmwareMessage msg)
        {
            string filename = Utf8Marshaler.GetStringFromIntPtr(msg.Filename);

            if (MesenMsgBox.Show("FirmwareNotFound", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, msg.FirmwareType.ToString(), filename, msg.Size.ToString()) == DialogResult.OK)
            {
                using (OpenFileDialog ofd = new OpenFileDialog()) {
                    ofd.SetFilter(ResourceHelper.GetMessage("FilterAll"));
                    if (ofd.ShowDialog(Application.OpenForms[0]) == DialogResult.OK)
                    {
                        if (GetFileHash(ofd.FileName) != GetExpectedHash(msg.FirmwareType))
                        {
                            if (MesenMsgBox.Show("FirmwareMismatch", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, msg.FirmwareType.ToString(), GetFileHash(ofd.FileName), GetExpectedHash(msg.FirmwareType)) != DialogResult.OK)
                            {
                                //Files don't match and user cancelled the action
                                return;
                            }
                        }
                        File.Copy(ofd.FileName, Path.Combine(ConfigManager.FirmwareFolder, filename));
                    }
                }
            }
        }
Esempio n. 19
0
 /// <summary>
 ///   Returns an enumerator that iterates through the collection.
 /// </summary>
 /// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
 public IEnumerator <Submodule> GetEnumerator()
 {
     return(Proxy.git_submodule_foreach(repo.Handle, (h, n) => Utf8Marshaler.FromNative(n))
            .Select(n => this[n])
            .GetEnumerator());
 }