1
- #include <git2.h>
2
- #include <stdio.h>
3
- #include <string.h>
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "common.h"
4
9
5
10
int main (int argc , char * * argv )
6
11
{
7
- git_repository * repo = NULL ;
8
12
git_index * index ;
9
13
unsigned int i , ecount ;
10
14
char * dir = "." ;
@@ -14,28 +18,19 @@ int main (int argc, char** argv)
14
18
15
19
git_threads_init ();
16
20
21
+ if (argc > 2 )
22
+ fatal ("usage: showindex [<repo-dir>]" , NULL );
17
23
if (argc > 1 )
18
24
dir = argv [1 ];
19
- if (!dir || argc > 2 ) {
20
- fprintf (stderr , "usage: showindex [<repo-dir>]\n" );
21
- return 1 ;
22
- }
23
25
24
26
dirlen = strlen (dir );
25
27
if (dirlen > 5 && strcmp (dir + dirlen - 5 , "index" ) == 0 ) {
26
- if (git_index_open (& index , dir ) < 0 ) {
27
- fprintf (stderr , "could not open index: %s\n" , dir );
28
- return 1 ;
29
- }
28
+ check_lg2 (git_index_open (& index , dir ), "could not open index" , dir );
30
29
} else {
31
- if (git_repository_open_ext (& repo , dir , 0 , NULL ) < 0 ) {
32
- fprintf (stderr , "could not open repository: %s\n" , dir );
33
- return 1 ;
34
- }
35
- if (git_repository_index (& index , repo ) < 0 ) {
36
- fprintf (stderr , "could not open repository index\n" );
37
- return 1 ;
38
- }
30
+ git_repository * repo ;
31
+ check_lg2 (git_repository_open_ext (& repo , dir , 0 , NULL ), "could not open repository" , dir );
32
+ check_lg2 (git_repository_index (& index , repo ), "could not open repository index" , NULL );
33
+ git_repository_free (repo );
39
34
}
40
35
41
36
git_index_read (index );
@@ -62,10 +57,7 @@ int main (int argc, char** argv)
62
57
}
63
58
64
59
git_index_free (index );
65
- git_repository_free (repo );
66
-
67
60
git_threads_shutdown ();
68
61
69
62
return 0 ;
70
63
}
71
-
0 commit comments