Skip to content

Commit

Permalink
Finish up implementation of new/2.
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed May 30, 2019
1 parent a3c0d31 commit 0ae7bc0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/xgit/dircache/dir_cache_entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ defmodule Xgit.DirCache.DirCacheEntry do

use Bitwise

alias Xgit.Errors.InvalidPathError
alias Xgit.Lib.ObjectChecker
alias Xgit.Util.NB

# private static final byte[] nullpad = new byte[8];

# /** The standard (fully merged) stage for an entry. */
Expand Down Expand Up @@ -219,8 +223,8 @@ defmodule Xgit.DirCache.DirCacheEntry do
info =
stage
|> shift_left12()
|> add_path_length(length(path))
|> NB.encode_16()
|> add_path_length(path)
|> NB.encode_int16()
|> Enum.concat(List.duplicate(0, @p_flags))
|> :binary.list_to_bin()

Expand Down Expand Up @@ -682,18 +686,13 @@ defmodule Xgit.DirCache.DirCacheEntry do
# }

defp check_path(path) do
try do
ObjectChecker.check_path!(%ObjectChecker{}, path)
rescue
_ -> raise InvalidPathError, path: path
end
end

# private static void checkPath(byte[] path) {
# try {
# SystemReader.getInstance().checkPath(path);
# } catch (CorruptObjectException e) {
# InvalidPathException p = new InvalidPathException(toString(path));
# p.initCause(e);
# throw p;
# }
# }

# static String toString(byte[] path) {
# return UTF_8.decode(ByteBuffer.wrap(path)).toString();
# }
Expand Down
55 changes: 55 additions & 0 deletions lib/xgit/errors/invalid_path_error.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (C) 2011, Robin Rosenberg
# and other copyright owners as documented in the project's IP log.
#
# Elixir adaptation from jgit file:
# org.eclipse.jgit/src/org/eclipse/jgit/dircache/InvalidPathException.java
#
# Copyright (C) 2019, Eric Scouten <eric+xgit@scouten.com>
#
# This program and the accompanying materials are made available
# under the terms of the Eclipse Distribution License v1.0 which
# accompanies this distribution, is reproduced below, and is
# available at http://www.eclipse.org/org/documents/edl-v10.php
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# - Neither the name of the Eclipse Foundation, Inc. nor the
# names of its contributors may be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

defmodule Xgit.Errors.InvalidPathError do
@moduledoc ~S"""
Raised when Xgit detects and refuses to use an invalid path.
"""
defexception [:message, :path]

def exception(path: path) when is_binary(path),
do: %__MODULE__{message: "Invalid path: #{path}", path: path}
end

0 comments on commit 0ae7bc0

Please sign in to comment.