private int HunkCallback(GitDiffDelta delta, GitDiffRange range, IntPtr header, UIntPtr headerlen, IntPtr payload) { string decodedContent = Utf8Marshaler.FromNative(header, (int)headerlen); AppendToPatch(decodedContent); return(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); }
/// <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); }
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); }
/// <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); }
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); }
/// <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); } }
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); }
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); })); }
/// <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); }
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); }
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); } }
/// <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()); }