Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e65752bb
Commit
e65752bb
authored
May 08, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #677 from arrbee/status-without-head
Add support for diffing index with no HEAD
parents
fd5faae3
7e000ab2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
3 deletions
+98
-3
src/diff.c
+1
-1
src/iterator.c
+48
-1
src/iterator.h
+3
-0
src/status.c
+1
-1
tests-clar/status/worktree.c
+45
-0
No files found.
src/diff.c
View file @
e65752bb
...
...
@@ -631,7 +631,7 @@ int git_diff_index_to_tree(
{
git_iterator
*
a
=
NULL
,
*
b
=
NULL
;
assert
(
repo
&&
old_tree
&&
diff
);
assert
(
repo
&&
diff
);
if
(
git_iterator_for_tree
(
repo
,
old_tree
,
&
a
)
<
0
||
git_iterator_for_index
(
repo
,
&
b
)
<
0
)
...
...
src/iterator.c
View file @
e65752bb
...
...
@@ -11,6 +11,48 @@
#include "buffer.h"
#include "git2/submodule.h"
static
int
empty_iterator__no_item
(
git_iterator
*
iter
,
const
git_index_entry
**
entry
)
{
GIT_UNUSED
(
iter
);
*
entry
=
NULL
;
return
0
;
}
static
int
empty_iterator__at_end
(
git_iterator
*
iter
)
{
GIT_UNUSED
(
iter
);
return
1
;
}
static
int
empty_iterator__noop
(
git_iterator
*
iter
)
{
GIT_UNUSED
(
iter
);
return
0
;
}
static
void
empty_iterator__free
(
git_iterator
*
iter
)
{
GIT_UNUSED
(
iter
);
}
int
git_iterator_for_nothing
(
git_iterator
**
iter
)
{
git_iterator
*
i
=
git__calloc
(
1
,
sizeof
(
git_iterator
));
GITERR_CHECK_ALLOC
(
i
);
i
->
type
=
GIT_ITERATOR_EMPTY
;
i
->
current
=
empty_iterator__no_item
;
i
->
at_end
=
empty_iterator__at_end
;
i
->
advance
=
empty_iterator__no_item
;
i
->
reset
=
empty_iterator__noop
;
i
->
free
=
empty_iterator__free
;
*
iter
=
i
;
return
0
;
}
typedef
struct
tree_iterator_frame
tree_iterator_frame
;
struct
tree_iterator_frame
{
tree_iterator_frame
*
next
;
...
...
@@ -155,7 +197,12 @@ int git_iterator_for_tree(
git_repository
*
repo
,
git_tree
*
tree
,
git_iterator
**
iter
)
{
int
error
;
tree_iterator
*
ti
=
git__calloc
(
1
,
sizeof
(
tree_iterator
));
tree_iterator
*
ti
;
if
(
tree
==
NULL
)
return
git_iterator_for_nothing
(
iter
);
ti
=
git__calloc
(
1
,
sizeof
(
tree_iterator
));
GITERR_CHECK_ALLOC
(
ti
);
ti
->
base
.
type
=
GIT_ITERATOR_TREE
;
...
...
src/iterator.h
View file @
e65752bb
...
...
@@ -13,6 +13,7 @@
typedef
struct
git_iterator
git_iterator
;
typedef
enum
{
GIT_ITERATOR_EMPTY
=
0
,
GIT_ITERATOR_TREE
=
1
,
GIT_ITERATOR_INDEX
=
2
,
GIT_ITERATOR_WORKDIR
=
3
...
...
@@ -27,6 +28,8 @@ struct git_iterator {
void
(
*
free
)(
git_iterator
*
);
};
int
git_iterator_for_nothing
(
git_iterator
**
iter
);
int
git_iterator_for_tree
(
git_repository
*
repo
,
git_tree
*
tree
,
git_iterator
**
iter
);
...
...
src/status.c
View file @
e65752bb
...
...
@@ -101,7 +101,7 @@ int git_status_foreach_ext(
diffopt
.
flags
=
diffopt
.
flags
|
GIT_DIFF_RECURSE_UNTRACKED_DIRS
;
/* TODO: support EXCLUDE_SUBMODULES flag */
if
(
show
!=
GIT_STATUS_SHOW_WORKDIR_ONLY
&&
head
!=
NULL
&&
if
(
show
!=
GIT_STATUS_SHOW_WORKDIR_ONLY
&&
(
err
=
git_diff_index_to_tree
(
repo
,
&
diffopt
,
head
,
&
idx2head
))
<
0
)
goto
cleanup
;
...
...
tests-clar/status/worktree.c
View file @
e65752bb
...
...
@@ -401,3 +401,48 @@ void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
git_repository_free
(
repo
);
}
typedef
struct
{
int
count
;
unsigned
int
status
;
}
status_entry_single
;
static
int
cb_status__single
(
const
char
*
p
,
unsigned
int
s
,
void
*
payload
)
{
status_entry_single
*
data
=
(
status_entry_single
*
)
payload
;
GIT_UNUSED
(
p
);
data
->
count
++
;
data
->
status
=
s
;
return
0
;
}
void
test_status_worktree__first_commit_in_progress
(
void
)
{
git_repository
*
repo
;
git_index
*
index
;
status_entry_single
result
;
cl_git_pass
(
git_repository_init
(
&
repo
,
"getting_started"
,
0
));
cl_git_mkfile
(
"getting_started/testfile.txt"
,
"content
\n
"
);
memset
(
&
result
,
0
,
sizeof
(
result
));
cl_git_pass
(
git_status_foreach
(
repo
,
cb_status__single
,
&
result
));
cl_assert
(
result
.
count
==
1
);
cl_assert
(
result
.
status
==
GIT_STATUS_WT_NEW
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add
(
index
,
"testfile.txt"
,
0
));
cl_git_pass
(
git_index_write
(
index
));
memset
(
&
result
,
0
,
sizeof
(
result
));
cl_git_pass
(
git_status_foreach
(
repo
,
cb_status__single
,
&
result
));
cl_assert
(
result
.
count
==
1
);
cl_assert
(
result
.
status
==
GIT_STATUS_INDEX_NEW
);
git_index_free
(
index
);
git_repository_free
(
repo
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment