Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status API, reusing libgit2 test and a fix #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/libgit2/jagged/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public enum Mode
FILE(0100644),

/** A file with the executable bit set */
EXECUTABLE_FILE(0100755);
EXECUTABLE_FILE(0100755),

/** A symlink */
LINK(0120000);

private final int value;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/libgit2/jagged/ObjectId.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public final class ObjectId
public final static int SIZE = 20;
public final static int HEX_SIZE = 40;

public static final ObjectId NULL = new ObjectId("0000000000000000000000000000000000000000");

private final byte[] oid;
private final String hex;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/libgit2/jagged/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.libgit2.jagged.core.GitException;
import org.libgit2.jagged.core.NativeHandle;
import org.libgit2.jagged.core.NativeMethods;
import org.libgit2.jagged.status.Status;
import org.libgit2.jagged.status.StatusOptions;

/**
* A Repository is the primary interface to a git repository.
Expand Down Expand Up @@ -180,6 +182,11 @@ public Branch getHead()
return new DetachedHead(this, reference);
}

public Status[] statusListNew(StatusOptions options, boolean populateOids)
{
return NativeMethods.statusListNew(this, options, populateOids);
}

/**
* Disposes the underlying Repository object.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/libgit2/jagged/core/NativeMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import org.libgit2.jagged.Reference;
import org.libgit2.jagged.Reference.DirectReference;
import org.libgit2.jagged.Repository;
import org.libgit2.jagged.status.Status;
import org.libgit2.jagged.Tree;
import org.libgit2.jagged.TreeEntry;
import org.libgit2.jagged.Version;
import org.libgit2.jagged.status.StatusOptions;

public class NativeMethods
{
Expand Down Expand Up @@ -128,4 +130,12 @@ public void finalize()
public static native void repositoryOpen(Repository repository, String path);

public static native boolean repositoryIsBare(Repository repository);

/*
* Status operations
*/

public static native StatusOptions statusOptionsInit();

public static native Status[] statusListNew(Repository repository, StatusOptions options, boolean populateOids);
}
209 changes: 209 additions & 0 deletions src/main/java/org/libgit2/jagged/status/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
package org.libgit2.jagged.status;

import org.libgit2.jagged.ObjectId;

public class Status
{

public static final int GIT_STATUS_INDEX_NEW = (1 << 0);
public static final int GIT_STATUS_INDEX_MODIFIED = (1 << 1);
public static final int GIT_STATUS_INDEX_DELETED = (1 << 2);
public static final int GIT_STATUS_INDEX_RENAMED = (1 << 3);
public static final int GIT_STATUS_INDEX_TYPECHANGE = (1 << 4);
public static final int GIT_STATUS_WT_NEW = (1 << 7);
public static final int GIT_STATUS_WT_MODIFIED = (1 << 8);
public static final int GIT_STATUS_WT_DELETED = (1 << 9);
public static final int GIT_STATUS_WT_TYPECHANGE = (1 << 10);
public static final int GIT_STATUS_WT_RENAMED = (1 << 11);
public static final int GIT_STATUS_WT_UNREADABLE = (1 << 12);
public static final int GIT_STATUS_IGNORED = (1 << 14);
public static final int GIT_STATUS_CONFLICTED = (1 << 15);

public static final int GIT_DELTA_UNMODIFIED = 0;
public static final int GIT_DELTA_ADDED = 1;
public static final int GIT_DELTA_DELETED = 2;
public static final int GIT_DELTA_MODIFIED = 3;
public static final int GIT_DELTA_RENAMED = 4;
public static final int GIT_DELTA_COPIED = 5;
public static final int GIT_DELTA_IGNORED = 6;
public static final int GIT_DELTA_UNTRACKED = 7;
public static final int GIT_DELTA_TYPECHANGE = 8;
public static final int GIT_DELTA_UNREADABLE = 9;
public static final int GIT_DELTA_CONFLICTED = 10;

public static final int GIT_DIFF_FLAG_BINARY = (1 << 0);
public static final int GIT_DIFF_FLAG_NOT_BINARY = (1 << 1);
public static final int GIT_DIFF_FLAG_VALID_ID = (1 << 2);
public static final int GIT_DIFF_FLAG_EXISTS = (1 << 3);

public static final int GIT_FILEMODE_UNREADABLE = 0000000;
public static final int GIT_FILEMODE_TREE = 0040000;
public static final int GIT_FILEMODE_BLOB = 0100644;
public static final int GIT_FILEMODE_BLOB_EXECUTABLE = 0100755;
public static final int GIT_FILEMODE_LINK = 0120000;
public static final int GIT_FILEMODE_COMMIT = 0160000;

private final int status;
private final String headPath;
private final long headSize;
private final int headFlags;
private final int headMode;
private final ObjectId headId;
private final String indexPath;
private final long indexSize;
private final int indexFlags;
private final int indexMode;
private final ObjectId indexId;
private final String wtPath;
private final long wtSize;
private final int wtFlags;
private final int wtMode;
private final ObjectId wtId;
private final int headIndexFlags;
private final int headIndexSimilarity;
private final int headIndexNFiles;
private final int indexWtFlags;
private final int indexWtSimilarity;
private final int indexWtNFiles;

private Status(int status,
String headPath, long headSize, int headFlags, int headMode, ObjectId headId,
String indexPath, long indexSize, int indexFlags, int indexMode, ObjectId indexId,
String wtPath, long wtSize, int wtFlags, int wtMode, ObjectId wtId,
int headIndexFlags, int headIndexSimilarity, int headIndexNFiles,
int indexWtFlags, int indexWtSimilarity, int indexWtNFiles)
{
this.status = status;
this.headPath = headPath;
this.headSize = headSize;
this.headFlags = headFlags;
this.headMode = headMode;
this.headId = headId;
this.indexPath = indexPath;
this.indexSize = indexSize;
this.indexFlags = indexFlags;
this.indexMode = indexMode;
this.indexId = indexId;
this.wtPath = wtPath;
this.wtSize = wtSize;
this.wtFlags = wtFlags;
this.wtMode = wtMode;
this.wtId = wtId;
this.headIndexFlags = headIndexFlags;
this.headIndexSimilarity = headIndexSimilarity;
this.headIndexNFiles = headIndexNFiles;
this.indexWtFlags = indexWtFlags;
this.indexWtSimilarity = indexWtSimilarity;
this.indexWtNFiles = indexWtNFiles;
}

public int getStatus()
{
return status;
}

public String getHeadPath()
{
return headPath;
}

public long getHeadSize()
{
return headSize;
}

public int getHeadFlags()
{
return headFlags;
}

public int getHeadMode()
{
return headMode;
}

public ObjectId getHeadId()
{
return headId;
}

public String getIndexPath()
{
return indexPath;
}

public long getIndexSize()
{
return indexSize;
}

public int getIndexFlags()
{
return indexFlags;
}

public int getIndexMode()
{
return indexMode;
}

public ObjectId getIndexId()
{
return indexId;
}

public String getWtPath()
{
return wtPath;
}

public long getWtSize()
{
return wtSize;
}

public int getWtFlags()
{
return wtFlags;
}

public int getWtMode()
{
return wtMode;
}

public ObjectId getWtId()
{
return wtId;
}

public int getHeadIndexFlags()
{
return headIndexFlags;
}

public int getHeadIndexSimilarity()
{
return headIndexSimilarity;
}

public int getHeadIndexNFiles()
{
return headIndexNFiles;
}

public int getIndexWtFlags()
{
return indexWtFlags;
}

public int getIndexWtSimilarity()
{
return indexWtSimilarity;
}

public int getIndexWtNFiles()
{
return indexWtNFiles;
}
}
78 changes: 78 additions & 0 deletions src/main/java/org/libgit2/jagged/status/StatusOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.libgit2.jagged.status;

import java.util.Arrays;

import org.libgit2.jagged.core.NativeMethods;

public class StatusOptions
{

public static final int GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1 << 0);
public static final int GIT_STATUS_OPT_INCLUDE_IGNORED = (1 << 1);
public static final int GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1 << 2);
public static final int GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1 << 3);
public static final int GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4);
public static final int GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1 << 5);
public static final int GIT_STATUS_OPT_RECURSE_IGNORED_DIRS = (1 << 6);
public static final int GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX = (1 << 7);
public static final int GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR = (1 << 8);
public static final int GIT_STATUS_OPT_SORT_CASE_SENSITIVELY = (1 << 9);
public static final int GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY = (1 << 10);
public static final int GIT_STATUS_OPT_RENAMES_FROM_REWRITES = (1 << 11);
public static final int GIT_STATUS_OPT_NO_REFRESH = (1 << 12);
public static final int GIT_STATUS_OPT_UPDATE_INDEX = (1 << 13);
public static final int GIT_STATUS_OPT_INCLUDE_UNREADABLE = (1 << 14);
public static final int GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1 << 15);

private StatusShowOptions show;
private int flags;
private String[] pathSpecs;

private StatusOptions(StatusShowOptions show, int flags, String[] pathSpecs)
{
this.show = show;
this.flags = flags;
this.pathSpecs = pathSpecs;
}

public static StatusOptions createInitializedInstance()
{
return NativeMethods.statusOptionsInit();
}

public StatusShowOptions getShow()
{
return show;
}

public void setShow(StatusShowOptions show)
{
this.show = show;
}

public int getFlags()
{
return flags;
}

public void setFlags(int flags)
{
this.flags = flags;
}

public String[] getPathSpecs()
{
return pathSpecs;
}

public void setPathSpecs(String[] pathSpecs)
{
this.pathSpecs = pathSpecs;
}

@Override
public String toString()
{
return "show=" + show + ";flags=" + flags + ";pathSpecs=" + (pathSpecs != null ? Arrays.asList(pathSpecs) : null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.libgit2.jagged.status;

public enum StatusShowOptions
{
INDEX_AND_WORKDIR, INDEX_ONLY, WORKDIR_ONLY;
}
Loading