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
9e3fb594
Unverified
Commit
9e3fb594
authored
Oct 29, 2017
by
Carlos Martín Nieto
Committed by
GitHub
Oct 29, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4373 from cjhoward92/examples/log-show-log-size
example-log: add support for --log-size
parents
79e09e1a
12a888d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
7 deletions
+10
-7
PROJECTS.md
+0
-4
examples/log.c
+10
-3
No files found.
PROJECTS.md
View file @
9e3fb594
...
...
@@ -36,10 +36,6 @@ These are good small projects to get started with libgit2.
trick to this one will be doing it in a manner that is clean and
simple, but still handles the various cases correctly (e.g.
`-B/70%`
is apparently a legal setting).
*
Implement the
`--log-size`
option for
`examples/log.c`
. I think all
the data is available, you would just need to add the code into the
`print_commit()`
routine (along with a way of passing the option
into that function).
*
As an extension to the matching idea for
`examples/log.c`
, add the
`-i`
option to use
`strcasestr()`
for matches.
*
For
`examples/log.c`
, implement the
`--first-parent`
option now that
...
...
examples/log.c
View file @
9e3fb594
...
...
@@ -50,6 +50,7 @@ static int add_revision(struct log_state *s, const char *revstr);
/** log_options holds other command line options that affect log output */
struct
log_options
{
int
show_diff
;
int
show_log_size
;
int
skip
,
limit
;
int
min_parents
,
max_parents
;
git_time_t
before
;
...
...
@@ -63,7 +64,7 @@ struct log_options {
static
int
parse_options
(
struct
log_state
*
s
,
struct
log_options
*
opt
,
int
argc
,
char
**
argv
);
static
void
print_time
(
const
git_time
*
intime
,
const
char
*
prefix
);
static
void
print_commit
(
git_commit
*
commit
);
static
void
print_commit
(
git_commit
*
commit
,
struct
log_options
*
opts
);
static
int
match_with_parent
(
git_commit
*
commit
,
int
i
,
git_diff_options
*
);
/** utility functions for filtering */
...
...
@@ -148,7 +149,7 @@ int main(int argc, char *argv[])
break
;
}
print_commit
(
commit
);
print_commit
(
commit
,
&
opt
);
if
(
opt
.
show_diff
)
{
git_tree
*
a
=
NULL
,
*
b
=
NULL
;
...
...
@@ -337,7 +338,7 @@ static void print_time(const git_time *intime, const char *prefix)
}
/** Helper to print a commit object. */
static
void
print_commit
(
git_commit
*
commit
)
static
void
print_commit
(
git_commit
*
commit
,
struct
log_options
*
opts
)
{
char
buf
[
GIT_OID_HEXSZ
+
1
];
int
i
,
count
;
...
...
@@ -347,6 +348,10 @@ static void print_commit(git_commit *commit)
git_oid_tostr
(
buf
,
sizeof
(
buf
),
git_commit_id
(
commit
));
printf
(
"commit %s
\n
"
,
buf
);
if
(
opts
->
show_log_size
)
{
printf
(
"log size %d
\n
"
,
(
int
)
strlen
(
git_commit_message
(
commit
)));
}
if
((
count
=
(
int
)
git_commit_parentcount
(
commit
))
>
1
)
{
printf
(
"Merge:"
);
for
(
i
=
0
;
i
<
count
;
++
i
)
{
...
...
@@ -470,6 +475,8 @@ static int parse_options(
/** Found valid --min_parents. */
;
else
if
(
!
strcmp
(
a
,
"-p"
)
||
!
strcmp
(
a
,
"-u"
)
||
!
strcmp
(
a
,
"--patch"
))
opt
->
show_diff
=
1
;
else
if
(
!
strcmp
(
a
,
"--log-size"
))
opt
->
show_log_size
=
1
;
else
usage
(
"Unsupported argument"
,
a
);
}
...
...
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