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
515a4c7c
Commit
515a4c7c
authored
Jun 19, 2012
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree: Proper path comparison logic
parent
ac8eac2f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
7 deletions
+75
-7
src/path.c
+12
-7
tests-clar/object/tree/write.c
+63
-0
No files found.
src/path.c
View file @
515a4c7c
...
...
@@ -468,19 +468,24 @@ int git_path_cmp(
const
char
*
name1
,
size_t
len1
,
int
isdir1
,
const
char
*
name2
,
size_t
len2
,
int
isdir2
)
{
unsigned
char
c1
,
c2
;
size_t
len
=
len1
<
len2
?
len1
:
len2
;
int
cmp
;
cmp
=
memcmp
(
name1
,
name2
,
len
);
if
(
cmp
)
return
cmp
;
if
(
len1
<
len2
)
return
(
!
isdir1
&&
!
isdir2
)
?
-
1
:
(
isdir1
?
'/'
-
name2
[
len1
]
:
name2
[
len1
]
-
'/'
);
if
(
len1
>
len2
)
return
(
!
isdir1
&&
!
isdir2
)
?
1
:
(
isdir2
?
name1
[
len2
]
-
'/'
:
'/'
-
name1
[
len2
]);
return
0
;
c1
=
name1
[
len
];
c2
=
name2
[
len
];
if
(
c1
==
'\0'
&&
isdir1
)
c1
=
'/'
;
if
(
c2
==
'\0'
&&
isdir2
)
c2
=
'/'
;
return
(
c1
<
c2
)
?
-
1
:
(
c1
>
c2
)
?
1
:
0
;
}
/* Taken from git.git */
...
...
tests-clar/object/tree/write.c
View file @
515a4c7c
...
...
@@ -82,3 +82,66 @@ void test_object_tree_write__subtree(void)
cl_assert
(
2
==
git_tree_entrycount
(
tree
));
git_tree_free
(
tree
);
}
/*
* And the Lord said: Is this tree properly sorted?
*/
void
test_object_tree_write__sorted_subtrees
(
void
)
{
git_treebuilder
*
builder
;
unsigned
int
i
,
position_c
,
position_cake
,
position_config
;
struct
{
unsigned
int
attr
;
const
char
*
filename
;
}
entries
[]
=
{
{
0100644
,
".gitattributes"
},
{
0100644
,
".gitignore"
},
{
0100644
,
".htaccess"
},
{
0100644
,
"Capfile"
},
{
0100644
,
"Makefile"
},
{
0100644
,
"README"
},
{
0040000
,
"app"
},
{
0040000
,
"cake"
},
{
0040000
,
"config"
},
{
0100644
,
"c"
},
{
0100644
,
"git_test.txt"
},
{
0100644
,
"htaccess.htaccess"
},
{
0100644
,
"index.php"
},
{
0040000
,
"plugins"
},
{
0040000
,
"schemas"
},
{
0040000
,
"ssl-certs"
},
{
0040000
,
"vendors"
}
};
git_oid
blank_oid
,
tree_oid
;
memset
(
&
blank_oid
,
0x0
,
sizeof
(
blank_oid
));
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
entries
);
++
i
)
{
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
entries
[
i
].
filename
,
&
blank_oid
,
entries
[
i
].
attr
));
}
cl_git_pass
(
git_treebuilder_write
(
&
tree_oid
,
g_repo
,
builder
));
for
(
i
=
0
;
i
<
builder
->
entries
.
length
;
++
i
)
{
git_tree_entry
*
entry
=
git_vector_get
(
&
builder
->
entries
,
i
);
if
(
strcmp
(
entry
->
filename
,
"c"
)
==
0
)
position_c
=
i
;
if
(
strcmp
(
entry
->
filename
,
"cake"
)
==
0
)
position_cake
=
i
;
if
(
strcmp
(
entry
->
filename
,
"config"
)
==
0
)
position_config
=
i
;
}
cl_assert
(
position_c
<
position_cake
);
cl_assert
(
position_cake
<
position_config
);
git_treebuilder_free
(
builder
);
}
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