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
fe477951
Commit
fe477951
authored
Mar 03, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2885 from JIghtuse/master
describe example: function to add commits to opts
parents
99b68a2a
23d1dbe9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
examples/describe.c
+24
-6
No files found.
examples/describe.c
View file @
fe477951
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
*/
*/
#include "common.h"
#include "common.h"
#include <assert.h>
/**
/**
* The following example partially reimplements the `git describe` command
* The following example partially reimplements the `git describe` command
...
@@ -46,6 +47,27 @@ typedef struct {
...
@@ -46,6 +47,27 @@ typedef struct {
typedef
struct
args_info
args_info
;
typedef
struct
args_info
args_info
;
static
void
*
xrealloc
(
void
*
oldp
,
size_t
newsz
)
{
void
*
p
=
realloc
(
oldp
,
newsz
);
if
(
p
==
NULL
)
{
fprintf
(
stderr
,
"Cannot allocate memory, exiting.
\n
"
);
exit
(
1
);
}
return
p
;
}
static
void
opts_add_commit
(
describe_options
*
opts
,
const
char
*
commit
)
{
size_t
sz
;
assert
(
opts
!=
NULL
);
sz
=
++
opts
->
commit_count
*
sizeof
(
opts
->
commits
[
0
]);
opts
->
commits
=
xrealloc
(
opts
->
commits
,
sz
);
opts
->
commits
[
opts
->
commit_count
-
1
]
=
commit
;
}
static
void
do_describe_single
(
git_repository
*
repo
,
describe_options
*
opts
,
const
char
*
rev
)
static
void
do_describe_single
(
git_repository
*
repo
,
describe_options
*
opts
,
const
char
*
rev
)
{
{
git_object
*
commit
;
git_object
*
commit
;
...
@@ -96,9 +118,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
...
@@ -96,9 +118,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
const
char
*
curr
=
argv
[
args
.
pos
];
const
char
*
curr
=
argv
[
args
.
pos
];
if
(
curr
[
0
]
!=
'-'
)
{
if
(
curr
[
0
]
!=
'-'
)
{
size_t
newsz
=
++
opts
->
commit_count
*
sizeof
(
opts
->
commits
[
0
]);
opts_add_commit
(
opts
,
curr
);
opts
->
commits
=
(
const
char
**
)
realloc
((
void
*
)
opts
->
commits
,
newsz
);
opts
->
commits
[
opts
->
commit_count
-
1
]
=
curr
;
}
else
if
(
!
strcmp
(
curr
,
"--all"
))
{
}
else
if
(
!
strcmp
(
curr
,
"--all"
))
{
opts
->
describe_options
.
describe_strategy
=
GIT_DESCRIBE_ALL
;
opts
->
describe_options
.
describe_strategy
=
GIT_DESCRIBE_ALL
;
}
else
if
(
!
strcmp
(
curr
,
"--tags"
))
{
}
else
if
(
!
strcmp
(
curr
,
"--tags"
))
{
...
@@ -124,9 +144,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
...
@@ -124,9 +144,7 @@ static void parse_options(describe_options *opts, int argc, char **argv)
}
}
else
{
else
{
if
(
!
opts
->
format_options
.
dirty_suffix
||
!
opts
->
format_options
.
dirty_suffix
[
0
])
{
if
(
!
opts
->
format_options
.
dirty_suffix
||
!
opts
->
format_options
.
dirty_suffix
[
0
])
{
size_t
sz
=
++
opts
->
commit_count
*
sizeof
(
opts
->
commits
[
0
]);
opts_add_commit
(
opts
,
"HEAD"
);
opts
->
commits
=
(
const
char
**
)
malloc
(
sz
);
opts
->
commits
[
0
]
=
"HEAD"
;
}
}
}
}
}
}
...
...
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