static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url) { Debug.Assert(repoHandle != null && !repoHandle.IsNull); Debug.Assert(url != null); RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repoHandle, url); Debug.Assert(remoteHandle != null && !(remoteHandle.IsNull)); return(remoteHandle); }
private static RemoteHandle RemoteFromNameOrUrl(RepositoryHandle repoHandle, string remote) { RemoteHandle handle = null; handle = Proxy.git_remote_lookup(repoHandle, remote, false); // If that wasn't the name of a remote, let's use it as a url if (handle == null) { handle = Proxy.git_remote_create_anonymous(repoHandle, remote); } return(handle); }
public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false) { Ensure.ArgumentNotNull(handle, "handle"); if (allowNullObjectId && id == null) { objectPtr = new ObjectHandle(null, false); } else { Ensure.ArgumentNotNull(id, "id"); objectPtr = Proxy.git_object_lookup(handle, id, GitObjectType.Any); } }
public bool TryBegin(out RepositoryHandle handle) { lock (lockHandle) { if (isLocked) { handle = null; return(false); } isLocked = true; handle = new RepositoryHandle(this, End); return(true); } }
public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false, bool throwIfMissing = false) { Ensure.ArgumentNotNull(handle, "handle"); if (allowNullObjectId && id == null) { objectPtr = new ObjectHandle(null, false); } else { Ensure.ArgumentNotNull(id, "id"); objectPtr = Proxy.git_object_lookup(handle, id, GitObjectType.Any); } if (objectPtr == null && throwIfMissing) { throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository."); } }
private async Task LoadProjectSource() { if (Project.Source is ProjectFileSystemSource fsSource) { Output.WriteLine($"Copying File-System directory '{fsSource.Path}' to work content directory.", ConsoleColor.DarkCyan); CopyDirectory(fsSource.Path, ContentDirectory); Output.WriteLine("Copy completed successfully.", ConsoleColor.DarkGreen); return; } if (Project.Source is ProjectGithubSource githubSource) { Output.WriteLine($"Cloning Git Repository '{githubSource.CloneUrl}' to work content directory.", ConsoleColor.DarkCyan); RepositoryHandle handle = null; try { handle = await GetRepositoryHandle(githubSource.CloneUrl, TimeSpan.FromMinutes(1), TokenSource.Token); handle.Username = githubSource.Username; handle.Password = githubSource.Password; handle.UseCommandLine = githubSource.UseCommandLine; handle.CommandLineExe = githubSource.CommandLineExe; handle.EnableTracing = githubSource.EnableTracing; handle.Output = Output; handle.Checkout(GitRefspec, TokenSource.Token); CommitHash = handle.Module?.CommitHash; CommitAuthor = handle.Module?.CommitAuthor; CommitMessage = handle.Module?.CommitMessage; Output.WriteLine("Copying repository to work content directory.", ConsoleColor.DarkCyan); CopyDirectory(handle.Source.RepositoryPath, ContentDirectory); Output.WriteLine("Copy completed successfully.", ConsoleColor.DarkGreen); } finally { handle?.Dispose(); } return; } throw new ApplicationException($"Unknown source type '{Project.Source?.GetType().Name}'!"); }
private void Init(Repository repository) { configHandle = Proxy.git_config_new(); RepositoryHandle repoHandle = (repository != null) ? repository.Handle : null; if (repoHandle != null) { //TODO: push back this logic into libgit2. // As stated by @carlosmn "having a helper function to load the defaults and then allowing you // to modify it before giving it to git_repository_open_ext() would be a good addition, I think." // -- Agreed :) string repoConfigLocation = Path.Combine(repository.Info.Path, "config"); Proxy.git_config_add_file_ondisk(configHandle, repoConfigLocation, ConfigurationLevel.Local, repoHandle); Proxy.git_repository_set_config(repoHandle, configHandle); } else if (repoConfigPath != null) { Proxy.git_config_add_file_ondisk(configHandle, repoConfigPath, ConfigurationLevel.Local, repoHandle); } if (globalConfigPath != null) { Proxy.git_config_add_file_ondisk(configHandle, globalConfigPath, ConfigurationLevel.Global, repoHandle); } if (xdgConfigPath != null) { Proxy.git_config_add_file_ondisk(configHandle, xdgConfigPath, ConfigurationLevel.Xdg, repoHandle); } if (systemConfigPath != null) { Proxy.git_config_add_file_ondisk(configHandle, systemConfigPath, ConfigurationLevel.System, repoHandle); } if (programDataConfigPath != null) { Proxy.git_config_add_file_ondisk(configHandle, programDataConfigPath, ConfigurationLevel.ProgramData, repoHandle); } }
internal unsafe BlameHunkCollection(Repository repo, RepositoryHandle repoHandle, string path, BlameOptions options) { this.repo = repo; var rawopts = new git_blame_options { version = 1, flags = options.Strategy.ToGitBlameOptionFlags(), min_line = new UIntPtr((uint)options.MinLine), max_line = new UIntPtr((uint)options.MaxLine), }; if (options.StartingAt != null) { fixed(byte *p = rawopts.newest_commit.Id) { Marshal.Copy(repo.Committish(options.StartingAt).Oid.Id, 0, new IntPtr(p), git_oid.Size); } } if (options.StoppingAt != null) { fixed(byte *p = rawopts.oldest_commit.Id) { Marshal.Copy(repo.Committish(options.StoppingAt).Oid.Id, 0, new IntPtr(p), git_oid.Size); } } using (var blameHandle = Proxy.git_blame_file(repoHandle, path, rawopts)) { var numHunks = NativeMethods.git_blame_get_hunk_count(blameHandle); for (uint i = 0; i < numHunks; ++i) { var rawHunk = Proxy.git_blame_get_hunk_byindex(blameHandle, i); hunks.Add(new BlameHunk(this.repo, rawHunk)); } } }
private void LoadProjectSource() { if (Project.Source is ProjectFileSystemSource fsSource) { Output.WriteLine($"Copying File-System directory '{fsSource.Path}' to work content directory.", ConsoleColor.DarkCyan); CopyDirectory(fsSource.Path, ContentDirectory); Output.WriteLine("Copy completed successfully.", ConsoleColor.DarkGreen); return; } if (Project.Source is ProjectGithubSource githubSource) { Output.WriteLine($"Cloning Git Repository '{githubSource.CloneUrl}' to work content directory.", ConsoleColor.DarkCyan); RepositoryHandle handle = null; try { handle = GetRepositoryHandle(githubSource.CloneUrl, TimeSpan.FromMinutes(1)) .GetAwaiter().GetResult(); handle.Username = githubSource.Username; handle.Password = githubSource.Password; handle.Checkout(Output, GitRefspec); Output.WriteLine("Copying repository to work content directory.", ConsoleColor.DarkCyan); CopyDirectory(handle.Source.RepositoryPath, ContentDirectory); Output.WriteLine("Copy completed successfully.", ConsoleColor.DarkGreen); } finally { handle?.Dispose(); } return; } throw new ApplicationException($"Unknown source type '{Project.SourceType}'!"); }