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
f83ef562
Commit
f83ef562
authored
Feb 21, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2129 from arrbee/rb/c89-or-c99
Improve C89 compatibility and clarify use of C99 features
parents
2dc49ea9
72556cc6
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
71 additions
and
53 deletions
+71
-53
CONTRIBUTING.md
+26
-17
CONVENTIONS.md
+14
-7
README.md
+5
-5
include/git2/common.h
+0
-7
include/git2/index.h
+6
-6
include/git2/oid.h
+1
-4
src/array.h
+1
-1
src/bitvec.h
+1
-1
src/common.h
+7
-0
src/index.c
+2
-2
src/merge.c
+1
-1
src/oid.c
+5
-0
src/vector.h
+1
-1
tests/repo/iterator.c
+1
-1
No files found.
CONTRIBUTING.md
View file @
f83ef562
...
@@ -5,9 +5,13 @@ your help.
...
@@ -5,9 +5,13 @@ your help.
## Licensing
## Licensing
By contributing to libgit2, you agree to release your contribution under the terms of the license.
By contributing to libgit2, you agree to release your contribution under
For code under
`examples`
, this is governed by the
[
CC0 Public Domain Dedication
](
examples/COPYING
)
.
the terms of the license. Except for the
`examples`
directory, all code
All other code is released under the
[
GPL v2 with linking exception
](
COPYING
)
.
is released under the
[
GPL v2 with linking exception
](
COPYING
)
.
The
`examples`
code is governed by the
[
CC0 Public Domain Dedication
](
examples/COPYING
)
, so that you may copy
from them into your own application.
## Discussion & Chat
## Discussion & Chat
...
@@ -76,15 +80,19 @@ you're porting code *from* to see what you need to do. As a general rule,
...
@@ -76,15 +80,19 @@ you're porting code *from* to see what you need to do. As a general rule,
MIT and BSD (3-clause) licenses are typically no problem. Apache 2.0
MIT and BSD (3-clause) licenses are typically no problem. Apache 2.0
license typically doesn't work due to GPL incompatibility.
license typically doesn't work due to GPL incompatibility.
If you are pulling in code from core Git, another project or code you've pulled from
If you are pulling in code from core Git, another project or code you've
a forum / Stack Overflow then please flag this in your PR and also make sure you've
pulled from a forum / Stack Overflow then please flag this in your PR and
given proper credit to the original author in the code snippet.
also make sure you've given proper credit to the original author in the
code snippet.
## Style Guide
## Style Guide
`libgit2`
is written in
[
ANSI C
](
http://en.wikipedia.org/wiki/ANSI_C
)
The public API of
`libgit2`
is
[
ANSI C
](
http://en.wikipedia.org/wiki/ANSI_C
)
(a.k.a. C89) with some specific conventions for function and type naming,
(a.k.a. C89) compatible. Internally,
`libgit2`
is written using a portable
code formatting, and testing.
subset of C99 - in order to compile with GCC, Clang, MSVC, etc., we keep
local variable declarations at the tops of blocks only and avoid
`//`
style
comments. Additionally,
`libgit2`
follows some extra conventions for
function and type naming, code formatting, and testing.
We like to keep the source code consistent and easy to read. Maintaining
We like to keep the source code consistent and easy to read. Maintaining
this takes some discipline, but it's been more than worth it. Take a look
this takes some discipline, but it's been more than worth it. Take a look
...
@@ -101,14 +109,15 @@ are any unresolved issues to jump in on. Also, here is a list of some
...
@@ -101,14 +109,15 @@ are any unresolved issues to jump in on. Also, here is a list of some
smaller project ideas that could help you become familiar with the code
smaller project ideas that could help you become familiar with the code
base and make a nice first step:
base and make a nice first step:
*
Convert a
`git_*modulename*_foreach()`
callback-based iteration API
*
Look at the
`examples/`
programs, find an existing one that mirrors a
into a
`git_*modulename*_iterator`
object with a create/advance style
core Git command and add a missing command-line option. There are many
of API. This helps folks writing language bindings and usually isn't
gaps right now and this helps demonstrate how to use the library.
too complicated.
*
Pick a Git command that is not emulates in
`examples/`
and write a new
*
Write a new
`examples/`
program that mirrors a particular core git
example that mirrors the behavior. Examples don't have to be perfect
command. (See
`examples/diff.c`
for example.) This lets you (and us)
emulations, but should demonstrate how to use the libgit2 APIs to get
easily exercise a particular facet of the API and measure compatability
results that are similar to Git commands. This lets you (and us) easily
and feature parity with core git.
exercise a particular facet of the API and measure compatability and
feature parity with core git.
*
Submit a PR to clarify documentation! While we do try to document all of
*
Submit a PR to clarify documentation! While we do try to document all of
the APIs, your fresh eyes on the documentation will find areas that are
the APIs, your fresh eyes on the documentation will find areas that are
confusing much more easily.
confusing much more easily.
CONVENTIONS.md
View file @
f83ef562
...
@@ -6,14 +6,18 @@ guidelines that should help with that.
...
@@ -6,14 +6,18 @@ guidelines that should help with that.
## Compatibility
## Compatibility
`libgit2`
runs on many different platforms with many different compilers.
`libgit2`
runs on many different platforms with many different compilers.
It is written in
[
ANSI C
](
http://en.wikipedia.org/wiki/ANSI_C
)
(
a.k.a.
C89)
with some specific standards for function and type naming, code formatting,
and testing.
We try to avoid more recent extensions to maximize portability. We also, to
The public API of
`libgit2`
is
[
ANSI C
](
http://en.wikipedia.org/wiki/ANSI_C
)
the greatest extent possible, try to avoid lots of
`#ifdef`
s inside the core
(a.k.a. C89) compatible.
code base. This is somewhat unavoidable, but since it can really hamper
maintainability, we keep it to a minimum.
Internally,
`libgit2`
is written using a portable subset of C99 - in order
to maximize compatibility (e.g. with MSVC) we avoid certain C99
extensions. Specifically, we keep local variable declarations at the tops
of blocks only and we avoid
`//`
style comments.
Also, to the greatest extent possible, we try to avoid lots of
`#ifdef`
s
inside the core code base. This is somewhat unavoidable, but since it can
really hamper maintainability, we keep it to a minimum.
## Match Surrounding Code
## Match Surrounding Code
...
@@ -209,6 +213,9 @@ All inlined functions must be declared as:
...
@@ -209,6 +213,9 @@ All inlined functions must be declared as:
GIT_INLINE(result_type) git_modulename_functionname(arg_list);
GIT_INLINE(result_type) git_modulename_functionname(arg_list);
```
```
`GIT_INLINE`
(or
`inline`
) should not be used in public headers in order
to preserve ANSI C compatibility.
## Tests
## Tests
`libgit2`
uses the
[
clar
](
https://github.com/vmg/clar
)
testing framework.
`libgit2`
uses the
[
clar
](
https://github.com/vmg/clar
)
testing framework.
...
...
README.md
View file @
f83ef562
...
@@ -20,17 +20,17 @@ Additionally, the example code has been released to the public domain (see the
...
@@ -20,17 +20,17 @@ Additionally, the example code has been released to the public domain (see the
*
API documentation:
<http://libgit2.github.com/libgit2>
*
API documentation:
<http://libgit2.github.com/libgit2>
*
IRC:
[
#libgit2
](
irc://irc.freenode.net/libgit2
)
on irc.freenode.net.
*
IRC:
[
#libgit2
](
irc://irc.freenode.net/libgit2
)
on irc.freenode.net.
*
Mailing list: The libgit2 mailing list was
*
Mailing list: The libgit2 mailing list was
traditionally hosted in Librelist but has been deprecated. We encourage you to
traditionally hosted in Librelist but has been deprecated. We encourage you to
[
use StackOverflow
](
http://stackoverflow.com/questions/tagged/libgit2
)
instead for any questions regarding
[
use StackOverflow
](
http://stackoverflow.com/questions/tagged/libgit2
)
instead for any questions regarding
the library, or
[
open an issue
](
https://github.com/libgit2/libgit2/issues
)
the library, or
[
open an issue
](
https://github.com/libgit2/libgit2/issues
)
on GitHub for bug reports. The mailing list archives are still available at
on GitHub for bug reports. The mailing list archives are still available at
<http://librelist.com/browser/libgit2/>
.
<http://librelist.com/browser/libgit2/>
.
What It Can Do
What It Can Do
==============
==============
`libgit2`
is already very usable and is being used in production for many applications including the GitHub.com site, in Plastic SCM
`libgit2`
is already very usable and is being used in production for many applications including the GitHub.com site, in Plastic SCM
and also powering Microsoft's Visual Studio tools for Git. The library provides:
and also powering Microsoft's Visual Studio tools for Git. The library provides:
*
SHA conversions, formatting and shortening
*
SHA conversions, formatting and shortening
...
@@ -65,7 +65,7 @@ Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthrea
...
@@ -65,7 +65,7 @@ Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthrea
they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
for threading.
for threading.
The
`libgit2`
library is built using
`CMake 2.6+`
(
<http://www.cmake.org>
) on all platforms.
The
`libgit2`
library is built using
[
CMake
](
<
http://www.cmake.org
>
)
(
version
2.6 or newer
) on all platforms.
On most systems you can build the library using the following commands
On most systems you can build the library using the following commands
...
...
include/git2/common.h
View file @
f83ef562
...
@@ -37,13 +37,6 @@
...
@@ -37,13 +37,6 @@
# define GIT_EXTERN(type) extern type
# define GIT_EXTERN(type) extern type
#endif
#endif
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define GIT_INLINE(type) static __inline type
#else
# define GIT_INLINE(type) static inline type
#endif
/** Declare a function's takes printf style arguments. */
/** Declare a function's takes printf style arguments. */
#ifdef __GNUC__
#ifdef __GNUC__
# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
...
...
include/git2/index.h
View file @
f83ef562
...
@@ -120,10 +120,10 @@ typedef struct git_index_entry {
...
@@ -120,10 +120,10 @@ typedef struct git_index_entry {
/** Capabilities of system that affect index actions. */
/** Capabilities of system that affect index actions. */
typedef
enum
{
typedef
enum
{
GIT_INDEXCAP_IGNORE_CASE
=
1
u
,
GIT_INDEXCAP_IGNORE_CASE
=
1
,
GIT_INDEXCAP_NO_FILEMODE
=
2
u
,
GIT_INDEXCAP_NO_FILEMODE
=
2
,
GIT_INDEXCAP_NO_SYMLINKS
=
4
u
,
GIT_INDEXCAP_NO_SYMLINKS
=
4
,
GIT_INDEXCAP_FROM_OWNER
=
~
0u
GIT_INDEXCAP_FROM_OWNER
=
-
1
,
}
git_indexcap_t
;
}
git_indexcap_t
;
/** Callback for APIs that add/remove/update files matching pathspec */
/** Callback for APIs that add/remove/update files matching pathspec */
...
@@ -206,7 +206,7 @@ GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
...
@@ -206,7 +206,7 @@ GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
* @param index An existing index object
* @param index An existing index object
* @return A combination of GIT_INDEXCAP values
* @return A combination of GIT_INDEXCAP values
*/
*/
GIT_EXTERN
(
unsigned
int
)
git_index_caps
(
const
git_index
*
index
);
GIT_EXTERN
(
int
)
git_index_caps
(
const
git_index
*
index
);
/**
/**
* Set index capabilities flags.
* Set index capabilities flags.
...
@@ -219,7 +219,7 @@ GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
...
@@ -219,7 +219,7 @@ GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
* @param caps A combination of GIT_INDEXCAP values
* @param caps A combination of GIT_INDEXCAP values
* @return 0 on success, -1 on failure
* @return 0 on success, -1 on failure
*/
*/
GIT_EXTERN
(
int
)
git_index_set_caps
(
git_index
*
index
,
unsigned
int
caps
);
GIT_EXTERN
(
int
)
git_index_set_caps
(
git_index
*
index
,
int
caps
);
/**
/**
* Update the contents of an existing index object in memory by reading
* Update the contents of an existing index object in memory by reading
...
...
include/git2/oid.h
View file @
f83ef562
...
@@ -167,10 +167,7 @@ GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
...
@@ -167,10 +167,7 @@ GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
* @param b second oid structure.
* @param b second oid structure.
* @return true if equal, false otherwise
* @return true if equal, false otherwise
*/
*/
GIT_INLINE
(
int
)
git_oid_equal
(
const
git_oid
*
a
,
const
git_oid
*
b
)
GIT_EXTERN
(
int
)
git_oid_equal
(
const
git_oid
*
a
,
const
git_oid
*
b
);
{
return
!
git_oid_cmp
(
a
,
b
);
}
/**
/**
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
...
...
src/array.h
View file @
f83ef562
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#ifndef INCLUDE_array_h__
#ifndef INCLUDE_array_h__
#define INCLUDE_array_h__
#define INCLUDE_array_h__
#include "
util
.h"
#include "
common
.h"
/*
/*
* Use this to declare a typesafe resizable array of items, a la:
* Use this to declare a typesafe resizable array of items, a la:
...
...
src/bitvec.h
View file @
f83ef562
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#ifndef INCLUDE_bitvec_h__
#ifndef INCLUDE_bitvec_h__
#define INCLUDE_bitvec_h__
#define INCLUDE_bitvec_h__
#include "
util
.h"
#include "
common
.h"
/*
/*
* This is a silly little fixed length bit vector type that will store
* This is a silly little fixed length bit vector type that will store
...
...
src/common.h
View file @
f83ef562
...
@@ -10,6 +10,13 @@
...
@@ -10,6 +10,13 @@
#include "git2/common.h"
#include "git2/common.h"
#include "cc-compat.h"
#include "cc-compat.h"
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define GIT_INLINE(type) static __inline type
#else
# define GIT_INLINE(type) static inline type
#endif
#include <assert.h>
#include <assert.h>
#include <errno.h>
#include <errno.h>
#include <limits.h>
#include <limits.h>
...
...
src/index.c
View file @
f83ef562
...
@@ -438,7 +438,7 @@ static int create_index_error(int error, const char *msg)
...
@@ -438,7 +438,7 @@ static int create_index_error(int error, const char *msg)
return
error
;
return
error
;
}
}
int
git_index_set_caps
(
git_index
*
index
,
unsigned
int
caps
)
int
git_index_set_caps
(
git_index
*
index
,
int
caps
)
{
{
unsigned
int
old_ignore_case
;
unsigned
int
old_ignore_case
;
...
@@ -474,7 +474,7 @@ int git_index_set_caps(git_index *index, unsigned int caps)
...
@@ -474,7 +474,7 @@ int git_index_set_caps(git_index *index, unsigned int caps)
return
0
;
return
0
;
}
}
unsigned
int
git_index_caps
(
const
git_index
*
index
)
int
git_index_caps
(
const
git_index
*
index
)
{
{
return
((
index
->
ignore_case
?
GIT_INDEXCAP_IGNORE_CASE
:
0
)
|
return
((
index
->
ignore_case
?
GIT_INDEXCAP_IGNORE_CASE
:
0
)
|
(
index
->
distrust_filemode
?
GIT_INDEXCAP_NO_FILEMODE
:
0
)
|
(
index
->
distrust_filemode
?
GIT_INDEXCAP_NO_FILEMODE
:
0
)
|
...
...
src/merge.c
View file @
f83ef562
...
@@ -2364,7 +2364,7 @@ done:
...
@@ -2364,7 +2364,7 @@ done:
int
git_merge__indexes
(
git_repository
*
repo
,
git_index
*
index_new
)
int
git_merge__indexes
(
git_repository
*
repo
,
git_index
*
index_new
)
{
{
git_index
*
index_repo
=
NULL
;
git_index
*
index_repo
=
NULL
;
unsigned
int
index_repo_caps
=
0
;
int
index_repo_caps
=
0
;
git_vector
paths
=
GIT_VECTOR_INIT
;
git_vector
paths
=
GIT_VECTOR_INIT
;
size_t
index_conflicts
=
0
,
wd_conflicts
=
0
,
conflicts
,
i
;
size_t
index_conflicts
=
0
,
wd_conflicts
=
0
,
conflicts
,
i
;
char
*
path
;
char
*
path
;
...
...
src/oid.c
View file @
f83ef562
...
@@ -179,6 +179,11 @@ int git_oid_cmp(const git_oid *a, const git_oid *b)
...
@@ -179,6 +179,11 @@ int git_oid_cmp(const git_oid *a, const git_oid *b)
return
git_oid__cmp
(
a
,
b
);
return
git_oid__cmp
(
a
,
b
);
}
}
int
git_oid_equal
(
const
git_oid
*
a
,
const
git_oid
*
b
)
{
return
(
git_oid__cmp
(
a
,
b
)
==
0
);
}
int
git_oid_ncmp
(
const
git_oid
*
oid_a
,
const
git_oid
*
oid_b
,
size_t
len
)
int
git_oid_ncmp
(
const
git_oid
*
oid_a
,
const
git_oid
*
oid_b
,
size_t
len
)
{
{
const
unsigned
char
*
a
=
oid_a
->
id
;
const
unsigned
char
*
a
=
oid_a
->
id
;
...
...
src/vector.h
View file @
f83ef562
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#ifndef INCLUDE_vector_h__
#ifndef INCLUDE_vector_h__
#define INCLUDE_vector_h__
#define INCLUDE_vector_h__
#include "
git2/
common.h"
#include "common.h"
typedef
int
(
*
git_vector_cmp
)(
const
void
*
,
const
void
*
);
typedef
int
(
*
git_vector_cmp
)(
const
void
*
,
const
void
*
);
...
...
tests/repo/iterator.c
View file @
f83ef562
...
@@ -156,7 +156,7 @@ void test_repo_iterator__index_icase(void)
...
@@ -156,7 +156,7 @@ void test_repo_iterator__index_icase(void)
{
{
git_iterator
*
i
;
git_iterator
*
i
;
git_index
*
index
;
git_index
*
index
;
unsigned
int
caps
;
int
caps
;
g_repo
=
cl_git_sandbox_init
(
"icase"
);
g_repo
=
cl_git_sandbox_init
(
"icase"
);
...
...
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