Exemple #1
0
        public void Write(
            FilePath filePath,
            Stream data,
            DateTimeOffset modificationTime,
            int mode,
            string userId,
            string groupId,
            char typeflag,
            string userName,
            string groupName,
            string deviceMajorNumber,
            string deviceMinorNumber,
            string entrySha,
            bool isLink)
        {
            FileNameExtendedHeader fileNameExtendedHeader = FileNameExtendedHeader.Parse(filePath.Posix, entrySha);
            LinkExtendedHeader linkExtendedHeader = ParseLink(isLink, data, entrySha);

            WriteExtendedHeader(fileNameExtendedHeader, linkExtendedHeader, entrySha, modificationTime);

            // Note: in case of links, we won't add a content, but the size in the header will still be != 0. It seems strange, but it seem to be what git.git is doing?
            WriteHeader(fileNameExtendedHeader.Name, fileNameExtendedHeader.Prefix, modificationTime, (data != null) ? data.Length : 0, mode,
                userId, groupId, typeflag, linkExtendedHeader.Link, userName, groupName, deviceMajorNumber, deviceMinorNumber);

            // folders have no data, and so do links
            if (data != null && !isLink)
            {
                WriteContent(data.Length, data, OutStream);
            }
            AlignTo512((data != null) ? data.Length : 0, false);
        }
Exemple #2
0
 internal unsafe FilterSource(FilePath path, FilterMode mode, git_filter_source* source)
 {
     SourceMode = mode;
     ObjectId = ObjectId.BuildFromPtr(&source->oid);
     Path = path.Native;
     Root = Proxy.git_repository_workdir(new IntPtr(source->repository)).Native;
 }
        public static IntPtr FromManaged(FilePath filePath)
        {
            if (null == filePath)
            {
                return IntPtr.Zero;
            }

            return Utf8Marshaler.FromManaged(filePath.Posix);
        }
        public static IntPtr FromManaged(FilePath filePath)
        {
            if (filePath == null)
            {
                return IntPtr.Zero;
            }

            return StrictUtf8Marshaler.FromManaged(filePath.Posix);
        }
 internal TreeEntryChanges(FilePath path, Mode mode, ObjectId oid, ChangeKind status, FilePath oldPath, Mode oldMode, ObjectId oldOid)
 {
     Path = path.Native;
     Mode = mode;
     Oid = oid;
     Status = status;
     OldPath = oldPath.Native;
     OldMode = oldMode;
     OldOid = oldOid;
 }
 internal TreeEntryChanges(FilePath path, Mode mode, ObjectId oid, ChangeKind status, FilePath oldPath, Mode oldMode, ObjectId oldOid, bool isBinaryComparison)
 {
     Path = path.Native;
     Mode = mode;
     Oid = oid;
     Status = status;
     OldPath = oldPath.Native;
     OldMode = oldMode;
     OldOid = oldOid;
     IsBinaryComparison = isBinaryComparison;
 }
Exemple #7
0
        public static GitStrArrayIn BuildFrom(FilePath[] paths)
        {
            var nbOfPaths = paths.Length;
            var pathPtrs = new IntPtr[nbOfPaths];

            for (int i = 0; i < nbOfPaths; i++)
            {
                var s = paths[i].Posix;
                pathPtrs[i] = FilePathMarshaler.FromManaged(s);
            }

            int dim = IntPtr.Size * nbOfPaths;

            IntPtr arrayPtr = Marshal.AllocHGlobal(dim);
            Marshal.Copy(pathPtrs, 0, arrayPtr, nbOfPaths);

            return new GitStrArrayIn { strings = arrayPtr, size = (uint)nbOfPaths };
        }
        /// <summary>
        /// Create wrapper around <see cref="GitCheckoutOpts"/> from <see cref="CheckoutOptions"/>.
        /// </summary>
        /// <param name="options">Options to create native GitCheckoutOpts structure from.</param>
        /// <param name="paths">Paths to checkout.</param>
        public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[] paths = null)
        {
            Callbacks = options.GenerateCallbacks();

            if (paths != null)
            {
                PathArray = GitStrArrayManaged.BuildFrom(paths);
            }

            Options = new GitCheckoutOpts
            {
                version = 1,
                checkout_strategy = options.CheckoutStrategy,
                progress_cb = Callbacks.CheckoutProgressCallback,
                notify_cb = Callbacks.CheckoutNotifyCallback,
                notify_flags = options.CheckoutNotifyFlags,
                paths = PathArray.Array,
            };
        }
        public static GitRepositoryInitOptions BuildFrom(FilePath workdirPath, bool isBare)
        {
            var opts = new GitRepositoryInitOptions
                           {
                               Flags = GitRepositoryInitFlags.GIT_REPOSITORY_INIT_MKPATH,
                               Mode = 0  /* GIT_REPOSITORY_INIT_SHARED_UMASK  */
                           };

            if (workdirPath != null)
            {
                Debug.Assert(!isBare);

                opts.WorkDirPath = StrictFilePathMarshaler.FromManaged(workdirPath);
            }

            if (isBare)
            {
                opts.Flags |= GitRepositoryInitFlags.GIT_REPOSITORY_INIT_BARE;
            }

            return opts;
        }
        private static Tuple<string, string> ExtractPosixLeadingSegment(FilePath targetPath)
        {
            string[] segments = targetPath.Posix.Split(new[] { '/' }, 2);

            if (segments[0] == string.Empty || (segments.Length == 2 && (segments[1] == string.Empty || segments[1].StartsWith("/", StringComparison.Ordinal))))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid path.", targetPath));
            }

            return new Tuple<string, string>(segments[0], segments.Length == 2 ? segments[1] : null);
        }
Exemple #11
0
        private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[] filePaths = null, MatchedPathsAggregator matchedPathsAggregator = null, CompareOptions compareOptions = null)
        {
            var options = new GitDiffOptions();

            options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE;

            compareOptions = compareOptions ?? new CompareOptions();
            options.ContextLines = (ushort)compareOptions.ContextLines;
            options.InterhunkLines = (ushort)compareOptions.InterhunkLines;

            if (diffOptions.HasFlag(DiffModifiers.IncludeUntracked))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED |
                GitDiffOptionFlags.GIT_DIFF_RECURSE_UNTRACKED_DIRS |
                GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeIgnored))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_IGNORED;
            }

            if (diffOptions.HasFlag(DiffModifiers.IncludeUnmodified))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNMODIFIED;
            }

            if (diffOptions.HasFlag(DiffModifiers.DisablePathspecMatch))
            {
                options.Flags |= GitDiffOptionFlags.GIT_DIFF_DISABLE_PATHSPEC_MATCH;
            }

            if (matchedPathsAggregator != null)
            {
                options.NotifyCallback = matchedPathsAggregator.OnGitDiffNotify;
            }

            if (filePaths == null)
            {
                return options;
            }

            options.PathSpec = GitStrArrayIn.BuildFrom(filePaths);
            return options;
        }
Exemple #12
0
 internal GitObject LookupTreeEntryTarget(ObjectId id, FilePath path)
 {
     return LookupInternal(id, GitObjectType.Any, path);
 }
Exemple #13
0
        internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath knownPath)
        {
            Ensure.ArgumentNotNull(id, "id");

            GitOid oid = id.Oid;
            GitObjectSafeHandle obj = null;

            try
            {
                int res;
                if (id is AbbreviatedObjectId)
                {
                    res = NativeMethods.git_object_lookup_prefix(out obj, handle, ref oid, (uint)((AbbreviatedObjectId)id).Length, type);
                }
                else
                {
                    res = NativeMethods.git_object_lookup(out obj, handle, ref oid, type);
                }

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

                Ensure.Success(res);

                if (id is AbbreviatedObjectId)
                {
                    id = GitObject.ObjectIdOf(obj);
                }

                return GitObject.CreateFromPtr(obj, id, this, knownPath);
            }
            finally
            {
                obj.SafeDispose();
            }
        }