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
24f61bc5
Commit
24f61bc5
authored
Apr 15, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1469 from libgit2/vmg/unified-revision
Unified rev-parse, with a revision object
parents
54e05482
32ef1d1c
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
228 additions
and
128 deletions
+228
-128
CMakeLists.txt
+3
-0
examples/Makefile
+1
-1
examples/diff.c
+2
-2
examples/rev-list.c
+19
-15
include/git2/revparse.h
+43
-13
src/push.c
+4
-6
src/revparse.c
+34
-16
src/revwalk.c
+10
-9
tests-clar/checkout/tree.c
+2
-5
tests-clar/clone/nonetwork.c
+5
-5
tests-clar/refs/revparse.c
+97
-41
tests-clar/stash/drop.c
+2
-8
tests-clar/stash/save.c
+6
-7
No files found.
CMakeLists.txt
View file @
24f61bc5
...
@@ -388,4 +388,7 @@ IF (BUILD_EXAMPLES)
...
@@ -388,4 +388,7 @@ IF (BUILD_EXAMPLES)
ADD_EXECUTABLE(git-showindex examples/showindex.c)
ADD_EXECUTABLE(git-showindex examples/showindex.c)
TARGET_LINK_LIBRARIES(git-showindex git2)
TARGET_LINK_LIBRARIES(git-showindex git2)
ADD_EXECUTABLE(git-rev-list examples/rev-list.c)
TARGET_LINK_LIBRARIES(git-rev-list git2)
ENDIF ()
ENDIF ()
examples/Makefile
View file @
24f61bc5
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
CC
=
gcc
CC
=
gcc
CFLAGS
=
-g
-I
../include
-I
../src
-Wall
-Wextra
-Wmissing-prototypes
-Wno-missing-field-initializers
CFLAGS
=
-g
-I
../include
-I
../src
-Wall
-Wextra
-Wmissing-prototypes
-Wno-missing-field-initializers
LFLAGS
=
-L
../build
-lgit2
-lz
LFLAGS
=
-L
../build
-lgit2
-lz
APPS
=
general showindex diff
APPS
=
general showindex diff
rev-list
all
:
$(APPS)
all
:
$(APPS)
...
...
examples/diff.c
View file @
24f61bc5
...
@@ -17,8 +17,8 @@ static int resolve_to_tree(
...
@@ -17,8 +17,8 @@ static int resolve_to_tree(
int
err
=
0
;
int
err
=
0
;
git_object
*
obj
=
NULL
;
git_object
*
obj
=
NULL
;
if
(
git_revparse_single
(
&
obj
,
repo
,
identifier
)
<
0
)
if
(
(
err
=
git_revparse_single
(
&
obj
,
repo
,
identifier
)
)
<
0
)
return
GIT_ENOTFOUND
;
return
err
;
switch
(
git_object_type
(
obj
))
{
switch
(
git_object_type
(
obj
))
{
case
GIT_OBJ_TREE
:
case
GIT_OBJ_TREE
:
...
...
examples/rev-list.c
View file @
24f61bc5
...
@@ -14,12 +14,12 @@ static void check_error(int error_code, const char *action)
...
@@ -14,12 +14,12 @@ static void check_error(int error_code, const char *action)
exit
(
1
);
exit
(
1
);
}
}
static
int
push_commit
(
git_revwalk
*
walk
,
git_object
*
obj
,
int
hide
)
static
int
push_commit
(
git_revwalk
*
walk
,
const
git_oid
*
oid
,
int
hide
)
{
{
if
(
hide
)
if
(
hide
)
return
git_revwalk_hide
(
walk
,
git_object_id
(
obj
)
);
return
git_revwalk_hide
(
walk
,
oid
);
else
else
return
git_revwalk_push
(
walk
,
git_object_id
(
obj
)
);
return
git_revwalk_push
(
walk
,
oid
);
}
}
static
int
push_spec
(
git_repository
*
repo
,
git_revwalk
*
walk
,
const
char
*
spec
,
int
hide
)
static
int
push_spec
(
git_repository
*
repo
,
git_revwalk
*
walk
,
const
char
*
spec
,
int
hide
)
...
@@ -27,35 +27,39 @@ static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec,
...
@@ -27,35 +27,39 @@ static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec,
int
error
;
int
error
;
git_object
*
obj
;
git_object
*
obj
;
if
((
error
=
git_revparse_single
(
&
obj
,
repo
,
spec
)))
if
((
error
=
git_revparse_single
(
&
obj
,
repo
,
spec
))
<
0
)
return
error
;
error
=
push_commit
(
walk
,
git_object_id
(
obj
),
hide
);
git_object_free
(
obj
);
return
error
;
return
error
;
return
push_commit
(
walk
,
obj
,
hide
);
}
}
static
int
push_range
(
git_repository
*
repo
,
git_revwalk
*
walk
,
const
char
*
range
,
int
hide
)
static
int
push_range
(
git_repository
*
repo
,
git_revwalk
*
walk
,
const
char
*
range
,
int
hide
)
{
{
git_object
*
left
,
*
right
;
git_revspec
revspec
;
int
threedots
;
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_revparse
_rangelike
(
&
left
,
&
right
,
&
threedots
,
repo
,
range
)))
if
((
error
=
git_revparse
(
&
revspec
,
repo
,
range
)))
return
error
;
return
error
;
if
(
threedots
)
{
if
(
revspec
.
flags
&
GIT_REVPARSE_MERGE_BASE
)
{
/* TODO: support "<commit>...<commit>" */
/* TODO: support "<commit>...<commit>" */
return
GIT_EINVALIDSPEC
;
return
GIT_EINVALIDSPEC
;
}
}
if
((
error
=
push_commit
(
walk
,
left
,
!
hide
)))
if
((
error
=
push_commit
(
walk
,
git_object_id
(
revspec
.
from
)
,
!
hide
)))
goto
out
;
goto
out
;
error
=
push_commit
(
walk
,
right
,
hide
);
out:
error
=
push_commit
(
walk
,
git_object_id
(
revspec
.
to
),
hide
);
git_object_free
(
left
);
git_object_free
(
right
);
out:
git_object_free
(
revspec
.
from
);
git_object_free
(
revspec
.
to
);
return
error
;
return
error
;
}
}
static
int
revwalk_parseopts
(
git_repository
*
repo
,
git_revwalk
*
walk
,
int
nopts
,
c
onst
char
*
const
*
opts
)
static
int
revwalk_parseopts
(
git_repository
*
repo
,
git_revwalk
*
walk
,
int
nopts
,
c
har
*
*
opts
)
{
{
int
hide
,
i
,
error
;
int
hide
,
i
,
error
;
unsigned
int
sorting
=
GIT_SORT_NONE
;
unsigned
int
sorting
=
GIT_SORT_NONE
;
...
...
include/git2/revparse.h
View file @
24f61bc5
...
@@ -21,29 +21,59 @@
...
@@ -21,29 +21,59 @@
GIT_BEGIN_DECL
GIT_BEGIN_DECL
/**
/**
* Find an object, as specified by a revision string. See `man gitrevisions`, or the documentation
* Find a single object, as specified by a revision string. See `man gitrevisions`,
* for `git rev-parse` for information on the syntax accepted.
* or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
* information on the syntax accepted.
*
*
* @param out pointer to output object
* @param out pointer to output object
* @param repo the repository to search in
* @param repo the repository to search in
* @param spec the textual specification for an object
* @param spec the textual specification for an object
* @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS,
* @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, GIT_EINVALIDSPEC or an error code
* GIT_EINVALIDSPEC or an error code
*/
*/
GIT_EXTERN
(
int
)
git_revparse_single
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
);
GIT_EXTERN
(
int
)
git_revparse_single
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
);
/**
/**
* Parse a string with the form of a revision range, as accepted by
* Revparse flags. These indicate the intended behavior of the spec passed to
* `git rev-list`, `git diff`, and others.
* git_revparse.
*/
typedef
enum
{
/** The spec targeted a single object. */
GIT_REVPARSE_SINGLE
=
1
<<
0
,
/** The spec targeted a range of commits. */
GIT_REVPARSE_RANGE
=
1
<<
1
,
/** The spec used the '...' operator, which invokes special semantics. */
GIT_REVPARSE_MERGE_BASE
=
1
<<
2
,
}
git_revparse_mode_t
;
/**
* Git Revision Spec: output of a `git_revparse` operation
*/
typedef
struct
{
/** The left element of the revspec; must be freed by the user */
git_object
*
from
;
/** The right element of the revspec; must be freed by the user */
git_object
*
to
;
/** The intent of the revspec */
unsigned
int
flags
;
}
git_revspec
;
/**
* Parse a revision string for `from`, `to`, and intent. See `man gitrevisions` or
* http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for information
* on the syntax accepted.
*
*
* @param left (output) the left-hand commit
* @param revspec Pointer to an user-allocated git_revspec struct where the result
* @param right (output) the right-hand commit
* of the rev-parse will be stored
* @param threedots (output) 0 if the endpoints are separated by two dots, 1 if by three
* @param repo the repository to search in
* @param repo the repository to find the commits in
* @param spec the rev-parse spec to parse
* @param rangelike the rangelike string to be parsed
* @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code
* @return 0 on success, or any error `git_revparse_single` can return
*/
*/
GIT_EXTERN
(
int
)
git_revparse_rangelike
(
git_object
**
left
,
git_object
**
right
,
int
*
threedots
,
git_repository
*
repo
,
const
char
*
rangelike
);
GIT_EXTERN
(
int
)
git_revparse
(
git_revspec
*
revspec
,
git_repository
*
repo
,
const
char
*
spec
);
/** @} */
/** @} */
GIT_END_DECL
GIT_END_DECL
...
...
src/push.c
View file @
24f61bc5
...
@@ -99,19 +99,17 @@ static int check_lref(git_push *push, char *ref)
...
@@ -99,19 +99,17 @@ static int check_lref(git_push *push, char *ref)
/* lref must be resolvable to an existing object */
/* lref must be resolvable to an existing object */
git_object
*
obj
;
git_object
*
obj
;
int
error
=
git_revparse_single
(
&
obj
,
push
->
repo
,
ref
);
int
error
=
git_revparse_single
(
&
obj
,
push
->
repo
,
ref
);
git_object_free
(
obj
);
if
(
!
error
)
return
0
;
if
(
error
)
{
if
(
error
==
GIT_ENOTFOUND
)
if
(
error
==
GIT_ENOTFOUND
)
giterr_set
(
GITERR_REFERENCE
,
giterr_set
(
GITERR_REFERENCE
,
"src refspec '%s' does not match any existing object"
,
ref
);
"src refspec '%s' does not match any existing object"
,
ref
);
else
else
giterr_set
(
GITERR_INVALID
,
"Not a valid reference '%s'"
,
ref
);
giterr_set
(
GITERR_INVALID
,
"Not a valid reference '%s'"
,
ref
);
return
-
1
;
return
-
1
;
}
else
git_object_free
(
obj
);
return
0
;
}
}
static
int
parse_refspec
(
git_push
*
push
,
push_spec
**
spec
,
const
char
*
str
)
static
int
parse_refspec
(
git_push
*
push
,
push_spec
**
spec
,
const
char
*
str
)
...
...
src/revparse.c
View file @
24f61bc5
...
@@ -868,27 +868,45 @@ cleanup:
...
@@ -868,27 +868,45 @@ cleanup:
return
error
;
return
error
;
}
}
int
git_revparse_rangelike
(
git_object
**
left
,
git_object
**
right
,
int
*
threedots
,
git_repository
*
repo
,
const
char
*
rangelike
)
int
git_revparse
(
git_revspec
*
revspec
,
git_repository
*
repo
,
const
char
*
spec
)
{
{
const
char
*
dotdot
;
int
error
=
0
;
int
error
=
0
;
const
char
*
p
,
*
q
;
char
*
revspec
;
p
=
strstr
(
rangelike
,
".."
);
assert
(
revspec
&&
repo
&&
spec
);
if
(
!
p
)
{
giterr_set
(
GITERR_INVALID
,
"Malformed range (or rangelike syntax): %s"
,
rangelike
);
memset
(
revspec
,
0x0
,
sizeof
(
*
revspec
));
return
GIT_EINVALIDSPEC
;
}
else
if
(
p
[
2
]
==
'.'
)
{
if
((
dotdot
=
strstr
(
spec
,
".."
))
!=
NULL
)
{
*
threedots
=
1
;
char
*
lstr
;
q
=
p
+
3
;
const
char
*
rstr
;
revspec
->
flags
=
GIT_REVPARSE_RANGE
;
lstr
=
git__substrdup
(
spec
,
dotdot
-
spec
);
rstr
=
dotdot
+
2
;
if
(
dotdot
[
2
]
==
'.'
)
{
revspec
->
flags
|=
GIT_REVPARSE_MERGE_BASE
;
rstr
++
;
}
if
((
error
=
git_revparse_single
(
&
revspec
->
from
,
repo
,
lstr
))
<
0
)
{
return
error
;
}
if
((
error
=
git_revparse_single
(
&
revspec
->
to
,
repo
,
rstr
))
<
0
)
{
return
error
;
}
git__free
((
void
*
)
lstr
);
}
else
{
}
else
{
*
threedots
=
0
;
revspec
->
flags
=
GIT_REVPARSE_SINGLE
;
q
=
p
+
2
;
error
=
git_revparse_single
(
&
revspec
->
from
,
repo
,
spec
)
;
}
}
revspec
=
git__substrdup
(
rangelike
,
p
-
rangelike
);
error
=
(
git_revparse_single
(
left
,
repo
,
revspec
)
||
git_revparse_single
(
right
,
repo
,
q
));
git__free
(
revspec
);
return
error
;
return
error
;
}
}
src/revwalk.c
View file @
24f61bc5
...
@@ -231,25 +231,26 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
...
@@ -231,25 +231,26 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
int
git_revwalk_push_range
(
git_revwalk
*
walk
,
const
char
*
range
)
int
git_revwalk_push_range
(
git_revwalk
*
walk
,
const
char
*
range
)
{
{
git_object
*
left
,
*
right
;
git_revspec
revspec
;
int
threedots
;
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_revparse
_rangelike
(
&
left
,
&
right
,
&
threedots
,
walk
->
repo
,
range
)))
if
((
error
=
git_revparse
(
&
revspec
,
walk
->
repo
,
range
)))
return
error
;
return
error
;
if
(
threedots
)
{
if
(
revspec
.
flags
&
GIT_REVPARSE_MERGE_BASE
)
{
/* TODO: support "<commit>...<commit>" */
/* TODO: support "<commit>...<commit>" */
giterr_set
(
GITERR_INVALID
,
"Symmetric differences not implemented in revwalk"
);
giterr_set
(
GITERR_INVALID
,
"Symmetric differences not implemented in revwalk"
);
return
GIT_EINVALIDSPEC
;
return
GIT_EINVALIDSPEC
;
}
}
if
((
error
=
push_commit
(
walk
,
git_object_id
(
left
),
1
)))
if
((
error
=
push_commit
(
walk
,
git_object_id
(
revspec
.
from
),
1
)))
goto
out
;
goto
out
;
error
=
push_commit
(
walk
,
git_object_id
(
right
),
0
);
out:
error
=
push_commit
(
walk
,
git_object_id
(
revspec
.
to
),
0
);
git_object_free
(
left
);
git_object_free
(
right
);
out:
git_object_free
(
revspec
.
from
);
git_object_free
(
revspec
.
to
);
return
error
;
return
error
;
}
}
...
...
tests-clar/checkout/tree.c
View file @
24f61bc5
...
@@ -30,7 +30,6 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void)
...
@@ -30,7 +30,6 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void)
{
{
/* blob */
/* blob */
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
"a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"
));
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
"a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"
));
cl_git_fail
(
git_checkout_tree
(
g_repo
,
g_object
,
NULL
));
cl_git_fail
(
git_checkout_tree
(
g_repo
,
g_object
,
NULL
));
}
}
...
@@ -283,8 +282,7 @@ void test_checkout_tree__can_checkout_with_pattern(void)
...
@@ -283,8 +282,7 @@ void test_checkout_tree__can_checkout_with_pattern(void)
g_opts
.
checkout_strategy
=
g_opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
|
GIT_CHECKOUT_REMOVE_UNTRACKED
;
GIT_CHECKOUT_FORCE
|
GIT_CHECKOUT_REMOVE_UNTRACKED
;
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
"8496071c1b46c854b31185ea97743be6a8774479"
));
"8496071c1b46c854b31185ea97743be6a8774479"
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
cl_git_pass
(
cl_git_pass
(
...
@@ -323,8 +321,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
...
@@ -323,8 +321,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
g_opts
.
checkout_strategy
=
g_opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
|
GIT_CHECKOUT_REMOVE_UNTRACKED
;
GIT_CHECKOUT_FORCE
|
GIT_CHECKOUT_REMOVE_UNTRACKED
;
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
"8496071c1b46c854b31185ea97743be6a8774479"
));
"8496071c1b46c854b31185ea97743be6a8774479"
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
cl_git_pass
(
cl_git_pass
(
...
...
tests-clar/clone/nonetwork.c
View file @
24f61bc5
...
@@ -214,23 +214,23 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
...
@@ -214,23 +214,23 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
void
test_clone_nonetwork__can_detached_head
(
void
)
void
test_clone_nonetwork__can_detached_head
(
void
)
{
{
git_object
*
commit
;
git_object
*
obj
;
git_repository
*
cloned
;
git_repository
*
cloned
;
git_reference
*
cloned_head
;
git_reference
*
cloned_head
;
cl_git_pass
(
git_clone
(
&
g_repo
,
cl_git_fixture_url
(
"testrepo.git"
),
"./foo"
,
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_repo
,
cl_git_fixture_url
(
"testrepo.git"
),
"./foo"
,
&
g_options
));
cl_git_pass
(
git_revparse_single
(
&
commit
,
g_repo
,
"master~1"
));
cl_git_pass
(
git_revparse_single
(
&
obj
,
g_repo
,
"master~1"
));
cl_git_pass
(
git_repository_set_head_detached
(
g_repo
,
git_object_id
(
commit
)));
cl_git_pass
(
git_repository_set_head_detached
(
g_repo
,
git_object_id
(
obj
)));
cl_git_pass
(
git_clone
(
&
cloned
,
"./foo"
,
"./foo1"
,
&
g_options
));
cl_git_pass
(
git_clone
(
&
cloned
,
"./foo"
,
"./foo1"
,
&
g_options
));
cl_assert
(
git_repository_head_detached
(
cloned
));
cl_assert
(
git_repository_head_detached
(
cloned
));
cl_git_pass
(
git_repository_head
(
&
cloned_head
,
cloned
));
cl_git_pass
(
git_repository_head
(
&
cloned_head
,
cloned
));
cl_assert
(
!
git_oid_cmp
(
git_object_id
(
commit
),
git_reference_target
(
cloned_head
)));
cl_assert
(
!
git_oid_cmp
(
git_object_id
(
obj
),
git_reference_target
(
cloned_head
)));
git_
commit_free
((
git_commit
*
)
commit
);
git_
object_free
(
obj
);
git_reference_free
(
cloned_head
);
git_reference_free
(
cloned_head
);
git_repository_free
(
cloned
);
git_repository_free
(
cloned
);
...
...
tests-clar/refs/revparse.c
View file @
24f61bc5
...
@@ -27,6 +27,37 @@ static void test_object_inrepo(const char *spec, const char *expected_oid, git_r
...
@@ -27,6 +27,37 @@ static void test_object_inrepo(const char *spec, const char *expected_oid, git_r
git_object_free
(
obj
);
git_object_free
(
obj
);
}
}
static
void
test_id_inrepo
(
const
char
*
spec
,
const
char
*
expected_left
,
const
char
*
expected_right
,
git_revparse_mode_t
expected_flags
,
git_repository
*
repo
)
{
git_revspec
revspec
;
int
error
=
git_revparse
(
&
revspec
,
repo
,
spec
);
if
(
expected_left
)
{
char
str
[
64
]
=
{
0
};
cl_assert_equal_i
(
0
,
error
);
git_oid_fmt
(
str
,
git_object_id
(
revspec
.
from
));
cl_assert_equal_s
(
str
,
expected_left
);
git_object_free
(
revspec
.
from
);
}
else
{
cl_assert_equal_i
(
GIT_ENOTFOUND
,
error
);
}
if
(
expected_right
)
{
char
str
[
64
]
=
{
0
};
git_oid_fmt
(
str
,
git_object_id
(
revspec
.
to
));
cl_assert_equal_s
(
str
,
expected_right
);
git_object_free
(
revspec
.
to
);
}
if
(
expected_flags
)
cl_assert_equal_i
(
expected_flags
,
revspec
.
flags
);
}
static
void
test_object
(
const
char
*
spec
,
const
char
*
expected_oid
)
static
void
test_object
(
const
char
*
spec
,
const
char
*
expected_oid
)
{
{
test_object_inrepo
(
spec
,
expected_oid
,
g_repo
);
test_object_inrepo
(
spec
,
expected_oid
,
g_repo
);
...
@@ -35,30 +66,38 @@ static void test_object(const char *spec, const char *expected_oid)
...
@@ -35,30 +66,38 @@ static void test_object(const char *spec, const char *expected_oid)
static
void
test_rangelike
(
const
char
*
rangelike
,
static
void
test_rangelike
(
const
char
*
rangelike
,
const
char
*
expected_left
,
const
char
*
expected_left
,
const
char
*
expected_right
,
const
char
*
expected_right
,
int
expected_threedot
s
)
git_revparse_mode_t
expected_revparseflag
s
)
{
{
char
objstr
[
64
]
=
{
0
};
char
objstr
[
64
]
=
{
0
};
git_object
*
left
=
NULL
,
*
right
=
NULL
;
git_revspec
revspec
;
int
threedots
;
int
error
;
int
error
;
error
=
git_revparse
_rangelike
(
&
left
,
&
right
,
&
threedots
,
g_repo
,
rangelike
);
error
=
git_revparse
(
&
revspec
,
g_repo
,
rangelike
);
if
(
expected_left
!=
NULL
)
{
if
(
expected_left
!=
NULL
)
{
cl_assert_equal_i
(
0
,
error
);
cl_assert_equal_i
(
0
,
error
);
cl_assert_equal_i
(
threedots
,
expected_threedot
s
);
cl_assert_equal_i
(
revspec
.
flags
,
expected_revparseflag
s
);
git_oid_fmt
(
objstr
,
git_object_id
(
left
));
git_oid_fmt
(
objstr
,
git_object_id
(
revspec
.
from
));
cl_assert_equal_s
(
objstr
,
expected_left
);
cl_assert_equal_s
(
objstr
,
expected_left
);
git_oid_fmt
(
objstr
,
git_object_id
(
r
ight
));
git_oid_fmt
(
objstr
,
git_object_id
(
r
evspec
.
to
));
cl_assert_equal_s
(
objstr
,
expected_right
);
cl_assert_equal_s
(
objstr
,
expected_right
);
}
else
}
else
cl_assert
(
error
!=
0
);
cl_assert
(
error
!=
0
);
git_object_free
(
left
);
git_object_free
(
revspec
.
from
);
git_object_free
(
r
ight
);
git_object_free
(
r
evspec
.
to
);
}
}
static
void
test_id
(
const
char
*
spec
,
const
char
*
expected_left
,
const
char
*
expected_right
,
git_revparse_mode_t
expected_flags
)
{
test_id_inrepo
(
spec
,
expected_left
,
expected_right
,
expected_flags
,
g_repo
);
}
void
test_refs_revparse__initialize
(
void
)
void
test_refs_revparse__initialize
(
void
)
{
{
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"testrepo.git"
)));
...
@@ -76,7 +115,7 @@ void test_refs_revparse__nonexistant_object(void)
...
@@ -76,7 +115,7 @@ void test_refs_revparse__nonexistant_object(void)
test_object
(
"this-does-not-exist~2"
,
NULL
);
test_object
(
"this-does-not-exist~2"
,
NULL
);
}
}
static
void
assert_invalid_spec
(
const
char
*
invalid_spec
)
static
void
assert_invalid_s
ingle_s
pec
(
const
char
*
invalid_spec
)
{
{
cl_assert_equal_i
(
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_revparse_single
(
&
g_obj
,
g_repo
,
invalid_spec
));
GIT_EINVALIDSPEC
,
git_revparse_single
(
&
g_obj
,
g_repo
,
invalid_spec
));
...
@@ -84,9 +123,9 @@ static void assert_invalid_spec(const char *invalid_spec)
...
@@ -84,9 +123,9 @@ static void assert_invalid_spec(const char *invalid_spec)
void
test_refs_revparse__invalid_reference_name
(
void
)
void
test_refs_revparse__invalid_reference_name
(
void
)
{
{
assert_invalid_spec
(
"this doesn't make sense"
);
assert_invalid_s
ingle_s
pec
(
"this doesn't make sense"
);
assert_invalid_spec
(
"Inv@{id"
);
assert_invalid_s
ingle_s
pec
(
"Inv@{id"
);
assert_invalid_spec
(
""
);
assert_invalid_s
ingle_s
pec
(
""
);
}
}
void
test_refs_revparse__shas
(
void
)
void
test_refs_revparse__shas
(
void
)
...
@@ -125,11 +164,11 @@ void test_refs_revparse__describe_output(void)
...
@@ -125,11 +164,11 @@ void test_refs_revparse__describe_output(void)
void
test_refs_revparse__nth_parent
(
void
)
void
test_refs_revparse__nth_parent
(
void
)
{
{
assert_invalid_spec
(
"be3563a^-1"
);
assert_invalid_s
ingle_s
pec
(
"be3563a^-1"
);
assert_invalid_spec
(
"^"
);
assert_invalid_s
ingle_s
pec
(
"^"
);
assert_invalid_spec
(
"be3563a^{tree}^"
);
assert_invalid_s
ingle_s
pec
(
"be3563a^{tree}^"
);
assert_invalid_spec
(
"point_to_blob^{blob}^"
);
assert_invalid_s
ingle_s
pec
(
"point_to_blob^{blob}^"
);
assert_invalid_spec
(
"this doesn't make sense^1"
);
assert_invalid_s
ingle_s
pec
(
"this doesn't make sense^1"
);
test_object
(
"be3563a^1"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
test_object
(
"be3563a^1"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
test_object
(
"be3563a^"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
test_object
(
"be3563a^"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
...
@@ -156,7 +195,7 @@ void test_refs_revparse__not_tag(void)
...
@@ -156,7 +195,7 @@ void test_refs_revparse__not_tag(void)
void
test_refs_revparse__to_type
(
void
)
void
test_refs_revparse__to_type
(
void
)
{
{
assert_invalid_spec
(
"wrapped_tag^{trip}"
);
assert_invalid_s
ingle_s
pec
(
"wrapped_tag^{trip}"
);
test_object
(
"point_to_blob^{commit}"
,
NULL
);
test_object
(
"point_to_blob^{commit}"
,
NULL
);
cl_assert_equal_i
(
cl_assert_equal_i
(
GIT_EAMBIGUOUS
,
git_revparse_single
(
&
g_obj
,
g_repo
,
"wrapped_tag^{blob}"
));
GIT_EAMBIGUOUS
,
git_revparse_single
(
&
g_obj
,
g_repo
,
"wrapped_tag^{blob}"
));
...
@@ -169,15 +208,15 @@ void test_refs_revparse__to_type(void)
...
@@ -169,15 +208,15 @@ void test_refs_revparse__to_type(void)
void
test_refs_revparse__linear_history
(
void
)
void
test_refs_revparse__linear_history
(
void
)
{
{
assert_invalid_spec
(
"~"
);
assert_invalid_s
ingle_s
pec
(
"~"
);
test_object
(
"foo~bar"
,
NULL
);
test_object
(
"foo~bar"
,
NULL
);
assert_invalid_spec
(
"master~bar"
);
assert_invalid_s
ingle_s
pec
(
"master~bar"
);
assert_invalid_spec
(
"master~-1"
);
assert_invalid_s
ingle_s
pec
(
"master~-1"
);
assert_invalid_spec
(
"master~0bar"
);
assert_invalid_s
ingle_s
pec
(
"master~0bar"
);
assert_invalid_spec
(
"this doesn't make sense~2"
);
assert_invalid_s
ingle_s
pec
(
"this doesn't make sense~2"
);
assert_invalid_spec
(
"be3563a^{tree}~"
);
assert_invalid_s
ingle_s
pec
(
"be3563a^{tree}~"
);
assert_invalid_spec
(
"point_to_blob^{blob}~"
);
assert_invalid_s
ingle_s
pec
(
"point_to_blob^{blob}~"
);
test_object
(
"master~0"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
);
test_object
(
"master~0"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
);
test_object
(
"master~1"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
test_object
(
"master~1"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
...
@@ -188,10 +227,10 @@ void test_refs_revparse__linear_history(void)
...
@@ -188,10 +227,10 @@ void test_refs_revparse__linear_history(void)
void
test_refs_revparse__chaining
(
void
)
void
test_refs_revparse__chaining
(
void
)
{
{
assert_invalid_spec
(
"master@{0}@{0}"
);
assert_invalid_s
ingle_s
pec
(
"master@{0}@{0}"
);
assert_invalid_spec
(
"@{u}@{-1}"
);
assert_invalid_s
ingle_s
pec
(
"@{u}@{-1}"
);
assert_invalid_spec
(
"@{-1}@{-1}"
);
assert_invalid_s
ingle_s
pec
(
"@{-1}@{-1}"
);
assert_invalid_spec
(
"@{-3}@{0}"
);
assert_invalid_s
ingle_s
pec
(
"@{-3}@{0}"
);
test_object
(
"master@{0}~1^1"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
test_object
(
"master@{0}~1^1"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
);
test_object
(
"@{u}@{0}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
test_object
(
"@{u}@{0}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
...
@@ -207,8 +246,8 @@ void test_refs_revparse__chaining(void)
...
@@ -207,8 +246,8 @@ void test_refs_revparse__chaining(void)
void
test_refs_revparse__upstream
(
void
)
void
test_refs_revparse__upstream
(
void
)
{
{
assert_invalid_spec
(
"e90810b@{u}"
);
assert_invalid_s
ingle_s
pec
(
"e90810b@{u}"
);
assert_invalid_spec
(
"refs/tags/e90810b@{u}"
);
assert_invalid_s
ingle_s
pec
(
"refs/tags/e90810b@{u}"
);
test_object
(
"refs/heads/e90810b@{u}"
,
NULL
);
test_object
(
"refs/heads/e90810b@{u}"
,
NULL
);
test_object
(
"master@{upstream}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
test_object
(
"master@{upstream}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
...
@@ -220,7 +259,7 @@ void test_refs_revparse__upstream(void)
...
@@ -220,7 +259,7 @@ void test_refs_revparse__upstream(void)
void
test_refs_revparse__ordinal
(
void
)
void
test_refs_revparse__ordinal
(
void
)
{
{
assert_invalid_spec
(
"master@{-2}"
);
assert_invalid_s
ingle_s
pec
(
"master@{-2}"
);
/* TODO: make the test below actually fail
/* TODO: make the test below actually fail
* cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
* cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
...
@@ -242,9 +281,9 @@ void test_refs_revparse__ordinal(void)
...
@@ -242,9 +281,9 @@ void test_refs_revparse__ordinal(void)
void
test_refs_revparse__previous_head
(
void
)
void
test_refs_revparse__previous_head
(
void
)
{
{
assert_invalid_spec
(
"@{-xyz}"
);
assert_invalid_s
ingle_s
pec
(
"@{-xyz}"
);
assert_invalid_spec
(
"@{-0}"
);
assert_invalid_s
ingle_s
pec
(
"@{-0}"
);
assert_invalid_spec
(
"@{-1b}"
);
assert_invalid_s
ingle_s
pec
(
"@{-1b}"
);
test_object
(
"@{-42}"
,
NULL
);
test_object
(
"@{-42}"
,
NULL
);
...
@@ -304,7 +343,7 @@ void test_refs_revparse__revwalk(void)
...
@@ -304,7 +343,7 @@ void test_refs_revparse__revwalk(void)
{
{
test_object
(
"master^{/not found in any commit}"
,
NULL
);
test_object
(
"master^{/not found in any commit}"
,
NULL
);
test_object
(
"master^{/merge}"
,
NULL
);
test_object
(
"master^{/merge}"
,
NULL
);
assert_invalid_spec
(
"master^{/((}"
);
assert_invalid_s
ingle_s
pec
(
"master^{/((}"
);
test_object
(
"master^{/anoth}"
,
"5b5b025afb0b4c913b4c338a42934a3863bf3644"
);
test_object
(
"master^{/anoth}"
,
"5b5b025afb0b4c913b4c338a42934a3863bf3644"
);
test_object
(
"master^{/Merge}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
test_object
(
"master^{/Merge}"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
...
@@ -385,8 +424,8 @@ void test_refs_revparse__date(void)
...
@@ -385,8 +424,8 @@ void test_refs_revparse__date(void)
void
test_refs_revparse__colon
(
void
)
void
test_refs_revparse__colon
(
void
)
{
{
assert_invalid_spec
(
":/"
);
assert_invalid_s
ingle_s
pec
(
":/"
);
assert_invalid_spec
(
"point_to_blob:readme.txt"
);
assert_invalid_s
ingle_s
pec
(
"point_to_blob:readme.txt"
);
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
":2:README"
));
/* Not implemented */
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
":2:README"
));
/* Not implemented */
test_object
(
":/not found in any commit"
,
NULL
);
test_object
(
":/not found in any commit"
,
NULL
);
...
@@ -627,15 +666,32 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
...
@@ -627,15 +666,32 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
void
test_refs_revparse__range
(
void
)
void
test_refs_revparse__range
(
void
)
{
{
assert_invalid_single_spec
(
"be3563a^1..be3563a"
);
test_rangelike
(
"be3563a^1..be3563a"
,
test_rangelike
(
"be3563a^1..be3563a"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
,
0
);
GIT_REVPARSE_RANGE
);
test_rangelike
(
"be3563a^1...be3563a"
,
test_rangelike
(
"be3563a^1...be3563a"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
,
"9fd738e8f7967c078dceed8190330fc8648ee56a"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
,
1
);
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
test_rangelike
(
"be3563a^1.be3563a"
,
NULL
,
NULL
,
0
);
test_rangelike
(
"be3563a^1.be3563a"
,
NULL
,
NULL
,
0
);
}
}
void
test_refs_revparse__parses_range_operator
(
void
)
{
test_id
(
"HEAD"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
NULL
,
GIT_REVPARSE_SINGLE
);
test_id
(
"HEAD~3..HEAD"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
);
test_id
(
"HEAD~3...HEAD"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
}
tests-clar/stash/drop.c
View file @
24f61bc5
...
@@ -146,8 +146,6 @@ void retrieve_top_stash_id(git_oid *out)
...
@@ -146,8 +146,6 @@ void retrieve_top_stash_id(git_oid *out)
cl_git_pass
(
git_reference_name_to_id
(
out
,
repo
,
GIT_REFS_STASH_FILE
));
cl_git_pass
(
git_reference_name_to_id
(
out
,
repo
,
GIT_REFS_STASH_FILE
));
cl_assert_equal_i
(
true
,
git_oid_cmp
(
out
,
git_object_id
(
top_stash
))
==
0
);
cl_assert_equal_i
(
true
,
git_oid_cmp
(
out
,
git_object_id
(
top_stash
))
==
0
);
git_object_free
(
top_stash
);
}
}
void
test_stash_drop__dropping_the_top_stash_updates_the_stash_reference
(
void
)
void
test_stash_drop__dropping_the_top_stash_updates_the_stash_reference
(
void
)
...
@@ -160,15 +158,11 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
...
@@ -160,15 +158,11 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
retrieve_top_stash_id
(
&
oid
);
retrieve_top_stash_id
(
&
oid
);
cl_git_pass
(
git_revparse_single
(
&
next_top_stash
,
repo
,
"stash@{1}"
));
cl_git_pass
(
git_revparse_single
(
&
next_top_stash
,
repo
,
"stash@{1}"
));
cl_assert_equal_i
(
cl_assert_equal_i
(
false
,
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
))
==
0
);
false
,
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
))
==
0
);
cl_git_pass
(
git_stash_drop
(
repo
,
0
));
cl_git_pass
(
git_stash_drop
(
repo
,
0
));
retrieve_top_stash_id
(
&
oid
);
retrieve_top_stash_id
(
&
oid
);
cl_assert_equal_i
(
cl_git_pass
(
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
)));
true
,
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
))
==
0
);
git_object_free
(
next_top_stash
);
}
}
tests-clar/stash/save.c
View file @
24f61bc5
...
@@ -37,10 +37,10 @@ void test_stash_save__cleanup(void)
...
@@ -37,10 +37,10 @@ void test_stash_save__cleanup(void)
static
void
assert_object_oid
(
const
char
*
revision
,
const
char
*
expected_oid
,
git_otype
type
)
static
void
assert_object_oid
(
const
char
*
revision
,
const
char
*
expected_oid
,
git_otype
type
)
{
{
git_object
*
object
;
int
result
;
int
result
;
git_object
*
obj
;
result
=
git_revparse_single
(
&
obj
ect
,
repo
,
revision
);
result
=
git_revparse_single
(
&
obj
,
repo
,
revision
);
if
(
!
expected_oid
)
{
if
(
!
expected_oid
)
{
cl_assert_equal_i
(
GIT_ENOTFOUND
,
result
);
cl_assert_equal_i
(
GIT_ENOTFOUND
,
result
);
...
@@ -48,10 +48,9 @@ static void assert_object_oid(const char* revision, const char* expected_oid, gi
...
@@ -48,10 +48,9 @@ static void assert_object_oid(const char* revision, const char* expected_oid, gi
}
else
}
else
cl_assert_equal_i
(
0
,
result
);
cl_assert_equal_i
(
0
,
result
);
cl_assert_equal_i
(
type
,
git_object_type
(
object
));
cl_git_pass
(
git_oid_streq
(
git_object_id
(
obj
),
expected_oid
));
cl_git_pass
(
git_oid_streq
(
git_object_id
(
object
),
expected_oid
));
cl_assert_equal_i
(
type
,
git_object_type
(
obj
));
git_object_free
(
obj
);
git_object_free
(
object
);
}
}
static
void
assert_blob_oid
(
const
char
*
revision
,
const
char
*
expected_oid
)
static
void
assert_blob_oid
(
const
char
*
revision
,
const
char
*
expected_oid
)
...
@@ -147,7 +146,7 @@ static void assert_commit_message_contains(const char *revision, const char *fra
...
@@ -147,7 +146,7 @@ static void assert_commit_message_contains(const char *revision, const char *fra
{
{
git_commit
*
commit
;
git_commit
*
commit
;
cl_git_pass
(
git_revparse_single
((
(
git_object
**
)
&
commit
)
,
repo
,
revision
));
cl_git_pass
(
git_revparse_single
((
git_object
**
)
&
commit
,
repo
,
revision
));
cl_assert
(
strstr
(
git_commit_message
(
commit
),
fragment
)
!=
NULL
);
cl_assert
(
strstr
(
git_commit_message
(
commit
),
fragment
)
!=
NULL
);
...
...
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