<commit_before>﻿using System;
using System.Runtime.InteropServices;
using libgit2net.Wrapper;

namespace libgit2net
{
    public class Repository : IDisposable
    {
        private IntPtr _repositoryPtr = IntPtr.Zero;
        private readonly RepositoryDetails _details;

        public RepositoryDetails Details
        {
            get { return _details; }
        }

        public Repository(string repositoryDirectory, string databaseDirectory, string index, string workingDirectory)
        {
            #region Parameters Validation

            if (string.IsNullOrEmpty(repositoryDirectory))
            {
                throw new ArgumentNullException("repositoryDirectory");
            }

            if (string.IsNullOrEmpty(databaseDirectory))
            {
                throw new ArgumentNullException("databaseDirectory");
            }

            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentNullException("index");
            }

            if (string.IsNullOrEmpty(workingDirectory))
            {
                throw new ArgumentNullException("workingDirectory");
            }

            #endregion Parameters Validation

            wrapped_git_repository_details repositoryDetails;
            OperationResult result = LibGit2Api.wrapped_git_repository_open(out repositoryDetails, out _repositoryPtr, repositoryDirectory);
            _repositoryPtr = repositoryDetails.repository;

            if (result != OperationResult.GIT_SUCCESS)
            {
                throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }

            _details = BuildFrom(repositoryDetails);
        }

        public Repository(string repositoryDirectory)
        {
            #region Parameters Validation 

            if (string.IsNullOrEmpty(repositoryDirectory))
            {
                throw new ArgumentNullException(repositoryDirectory);
            }

            #endregion Parameters Validation

            wrapped_git_repository_details repositoryDetails;
            OperationResult result = LibGit2Api.wrapped_git_repository_open(out repositoryDetails, out _repositoryPtr, repositoryDirectory);
            _repositoryPtr = repositoryDetails.repository;

            if (result != OperationResult.GIT_SUCCESS)
            {
                throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }

            _details = BuildFrom(repositoryDetails);
        }

        private static RepositoryDetails BuildFrom(wrapped_git_repository_details repositoryDetails)
        {
            string index = Marshal.PtrToStringAnsi(repositoryDetails.path_index);
            string databaseDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_odb);
            string repositoryDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_repository);
            string workingDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_workdir);

            return new RepositoryDetails(repositoryDirectory, index, databaseDirectory, workingDirectory, repositoryDetails.is_bare);
        }

        public GitObject Lookup(string objectId)
        {
            return new GitObject() { Id = objectId };
        }

        public Header ReadHeader(string objectId)
        {
            git_rawobj rawObj;

            OperationResult result = LibGit2Api.wrapped_git_odb_read_header(out rawObj, _repositoryPtr, objectId);

            switch (result)
            {
                case OperationResult.GIT_SUCCESS:
                    return new Header(objectId, (ObjectType)rawObj.type, rawObj.len.ToUInt64());

                case OperationResult.GIT_ENOTFOUND:
                    return null;

                default:
                    throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }
        }

        void IDisposable.Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (_repositoryPtr == (IntPtr)0)
                    return;

            LibGit2Api.wrapped_git_repository_free(_repositoryPtr);
            _repositoryPtr = (IntPtr)0;
        }

        ~Repository()
        {
            Dispose(false);
        }
    }
}<commit_msg>Fixed the opening of the repository when all paths are being passed in.<commit_after>﻿using System;
using System.Runtime.InteropServices;
using libgit2net.Wrapper;

namespace libgit2net
{
    public class Repository : IDisposable
    {
        private IntPtr _repositoryPtr = IntPtr.Zero;
        private readonly RepositoryDetails _details;

        public RepositoryDetails Details
        {
            get { return _details; }
        }

        public Repository(string repositoryDirectory, string databaseDirectory, string index, string workingDirectory)
        {
            #region Parameters Validation

            if (string.IsNullOrEmpty(repositoryDirectory))
            {
                throw new ArgumentNullException("repositoryDirectory");
            }

            if (string.IsNullOrEmpty(databaseDirectory))
            {
                throw new ArgumentNullException("databaseDirectory");
            }

            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentNullException("index");
            }

            if (string.IsNullOrEmpty(workingDirectory))
            {
                throw new ArgumentNullException("workingDirectory");
            }

            #endregion Parameters Validation

            wrapped_git_repository_details repositoryDetails;
            OperationResult result = LibGit2Api.wrapped_git_repository_open2(out repositoryDetails, out _repositoryPtr, repositoryDirectory, databaseDirectory, index, workingDirectory);
            _repositoryPtr = repositoryDetails.repository;

            if (result != OperationResult.GIT_SUCCESS)
            {
                throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }

            _details = BuildFrom(repositoryDetails);
        }

        public Repository(string repositoryDirectory)
        {
            #region Parameters Validation 

            if (string.IsNullOrEmpty(repositoryDirectory))
            {
                throw new ArgumentNullException(repositoryDirectory);
            }

            #endregion Parameters Validation

            wrapped_git_repository_details repositoryDetails;
            OperationResult result = LibGit2Api.wrapped_git_repository_open(out repositoryDetails, out _repositoryPtr, repositoryDirectory);
            _repositoryPtr = repositoryDetails.repository;

            if (result != OperationResult.GIT_SUCCESS)
            {
                throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }

            _details = BuildFrom(repositoryDetails);
        }

        private static RepositoryDetails BuildFrom(wrapped_git_repository_details repositoryDetails)
        {
            string index = Marshal.PtrToStringAnsi(repositoryDetails.path_index);
            string databaseDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_odb);
            string repositoryDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_repository);
            string workingDirectory = Marshal.PtrToStringAnsi(repositoryDetails.path_workdir);

            return new RepositoryDetails(repositoryDirectory, index, databaseDirectory, workingDirectory, repositoryDetails.is_bare);
        }

        public GitObject Lookup(string objectId)
        {
            return new GitObject() { Id = objectId };
        }

        public Header ReadHeader(string objectId)
        {
            git_rawobj rawObj;

            OperationResult result = LibGit2Api.wrapped_git_odb_read_header(out rawObj, _repositoryPtr, objectId);

            switch (result)
            {
                case OperationResult.GIT_SUCCESS:
                    return new Header(objectId, (ObjectType)rawObj.type, rawObj.len.ToUInt64());

                case OperationResult.GIT_ENOTFOUND:
                    return null;

                default:
                    throw new Exception(Enum.GetName(typeof(OperationResult), result));
            }
        }

        void IDisposable.Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (_repositoryPtr == (IntPtr)0)
                    return;

            LibGit2Api.wrapped_git_repository_free(_repositoryPtr);
            _repositoryPtr = (IntPtr)0;
        }

        ~Repository()
        {
            Dispose(false);
        }
    }
}
{'fraction_non_alphanumeric': 0.06395927852163329, 'fraction_numerical': 0.0023237800154918666, 'mean_word_length': 1.9033087054288467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4861901', 'n_tokens_mistral': 2122, 'n_tokens_neox': 1968, 'n_words': 407}