Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5915a2a

Browse files
committed
Merge pull request libgit2#3349 from libgit2/cmn/for-v23
A second round of 0.23 maint updates
2 parents 6a0d569 + 16cee5d commit 5915a2a

24 files changed

+137
-31
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# > cmake --build . --target install
1313

1414
PROJECT(libgit2 C)
15-
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
15+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
1616
CMAKE_POLICY(SET CMP0015 NEW)
1717

1818
# Add find modules to the path
@@ -412,6 +412,7 @@ ELSE ()
412412
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
413413
ENDIF ()
414414

415+
ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation)
415416
ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers)
416417
ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2)
417418
ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthrea
8888
they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
8989
for threading.
9090

91-
The `libgit2` library is built using [CMake](<http://www.cmake.org>) (version 2.6 or newer) on all platforms.
91+
The `libgit2` library is built using [CMake](<http://www.cmake.org>) (version 2.8 or newer) on all platforms.
9292

9393
On most systems you can build the library using the following commands
9494

include/git2/repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, cons
745745
*
746746
* @param repo the repository to configure
747747
* @param name the name to use for the reflog entries
748-
* @param name the email to use for the reflog entries
748+
* @param email the email to use for the reflog entries
749749
*/
750750
GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email);
751751

include/git2/sys/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct git_config_backend {
7676
* Initializes a `git_config_backend` with default values. Equivalent to
7777
* creating an instance with GIT_CONFIG_BACKEND_INIT.
7878
*
79-
* @param opts the `git_config_backend` struct to initialize.
79+
* @param backend the `git_config_backend` struct to initialize.
8080
* @param version Version of struct; pass `GIT_CONFIG_BACKEND_VERSION`
8181
* @return Zero on success; -1 on failure.
8282
*/

include/git2/sys/diff.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ GIT_EXTERN(int) git_diff_print_callback__to_buf(
3838
const git_diff_delta *delta,
3939
const git_diff_hunk *hunk,
4040
const git_diff_line *line,
41-
void *payload); /*< payload must be a `git_buf *` */
41+
void *payload); /**< payload must be a `git_buf *` */
4242

4343
/**
4444
* Diff print callback that writes to stdio FILE handle.
@@ -58,16 +58,16 @@ GIT_EXTERN(int) git_diff_print_callback__to_file_handle(
5858
const git_diff_delta *delta,
5959
const git_diff_hunk *hunk,
6060
const git_diff_line *line,
61-
void *payload); /*< payload must be a `FILE *` */
61+
void *payload); /**< payload must be a `FILE *` */
6262

6363

6464
/**
6565
* Performance data from diffing
6666
*/
6767
typedef struct {
6868
unsigned int version;
69-
size_t stat_calls; /*< Number of stat() calls performed */
70-
size_t oid_calculations; /*< Number of ID calculations */
69+
size_t stat_calls; /**< Number of stat() calls performed */
70+
size_t oid_calculations; /**< Number of ID calculations */
7171
} git_diff_perfdata;
7272

7373
#define GIT_DIFF_PERFDATA_VERSION 1

include/git2/sys/odb_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct git_odb_backend {
9393
* Initializes a `git_odb_backend` with default values. Equivalent to
9494
* creating an instance with GIT_ODB_BACKEND_INIT.
9595
*
96-
* @param opts the `git_odb_backend` struct to initialize.
96+
* @param backend the `git_odb_backend` struct to initialize.
9797
* @param version Version the struct; pass `GIT_ODB_BACKEND_VERSION`
9898
* @return Zero on success; -1 on failure.
9999
*/

include/git2/sys/refdb_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct git_refdb_backend {
175175
* Initializes a `git_refdb_backend` with default values. Equivalent to
176176
* creating an instance with GIT_REFDB_BACKEND_INIT.
177177
*
178-
* @param opts the `git_refdb_backend` struct to initialize
178+
* @param backend the `git_refdb_backend` struct to initialize
179179
* @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION`
180180
* @return Zero on success; -1 on failure.
181181
*/

src/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "vector.h"
2020
#include "repository.h"
2121

22-
GIT__USE_OIDMAP;
22+
GIT__USE_OIDMAP
2323

2424
/* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */
2525

src/filebuf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void git_filebuf_cleanup(git_filebuf *file)
101101
if (file->fd_is_open && file->fd >= 0)
102102
p_close(file->fd);
103103

104-
if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock))
104+
if (file->created_lock && !file->did_rename && file->path_lock && git_path_exists(file->path_lock))
105105
p_unlink(file->path_lock);
106106

107107
if (file->compute_digest) {
@@ -258,6 +258,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode
258258
goto cleanup;
259259
}
260260
file->fd_is_open = true;
261+
file->created_lock = true;
261262

262263
/* No original path */
263264
file->path_original = NULL;
@@ -281,6 +282,8 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode
281282
/* open the file for locking */
282283
if ((error = lock_file(file, flags, mode)) < 0)
283284
goto cleanup;
285+
286+
file->created_lock = true;
284287
}
285288

286289
return 0;
@@ -340,6 +343,8 @@ int git_filebuf_commit(git_filebuf *file)
340343
goto on_error;
341344
}
342345

346+
file->did_rename = true;
347+
343348
git_filebuf_cleanup(file);
344349
return 0;
345350

src/filebuf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct git_filebuf {
4444
size_t buf_size, buf_pos;
4545
git_file fd;
4646
bool fd_is_open;
47+
bool created_lock;
48+
bool did_rename;
4749
bool do_not_buffer;
4850
int last_error;
4951
};

src/index.c

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,45 @@ int git_index_add_frombuffer(
12281228
return 0;
12291229
}
12301230

1231+
static int add_repo_as_submodule(git_index_entry **out, git_index *index, const char *path)
1232+
{
1233+
git_repository *sub;
1234+
git_buf abspath = GIT_BUF_INIT;
1235+
git_repository *repo = INDEX_OWNER(index);
1236+
git_reference *head;
1237+
git_index_entry *entry;
1238+
struct stat st;
1239+
int error;
1240+
1241+
if (index_entry_create(&entry, INDEX_OWNER(index), path) < 0)
1242+
return -1;
1243+
1244+
if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
1245+
return error;
1246+
1247+
if ((error = p_stat(abspath.ptr, &st)) < 0) {
1248+
giterr_set(GITERR_OS, "failed to stat repository dir");
1249+
return -1;
1250+
}
1251+
1252+
git_index_entry__init_from_stat(entry, &st, !index->distrust_filemode);
1253+
1254+
if ((error = git_repository_open(&sub, abspath.ptr)) < 0)
1255+
return error;
1256+
1257+
if ((error = git_repository_head(&head, sub)) < 0)
1258+
return error;
1259+
1260+
git_oid_cpy(&entry->id, git_reference_target(head));
1261+
entry->mode = GIT_FILEMODE_COMMIT;
1262+
1263+
git_reference_free(head);
1264+
git_repository_free(sub);
1265+
git_buf_free(&abspath);
1266+
1267+
*out = entry;
1268+
return 0;
1269+
}
12311270

12321271
int git_index_add_bypath(git_index *index, const char *path)
12331272
{
@@ -1252,12 +1291,26 @@ int git_index_add_bypath(git_index *index, const char *path)
12521291
ret = git_submodule_lookup(&sm, INDEX_OWNER(index), path);
12531292
if (ret == GIT_ENOTFOUND)
12541293
return giterr_restore(&err);
1255-
else
1256-
git__free(err.error_msg.message);
12571294

1258-
ret = git_submodule_add_to_index(sm, false);
1259-
git_submodule_free(sm);
1260-
return ret;
1295+
git__free(err.error_msg.message);
1296+
1297+
/*
1298+
* EEXISTS means that there is a repository at that path, but it's not known
1299+
* as a submodule. We add its HEAD as an entry and don't register it.
1300+
*/
1301+
if (ret == GIT_EEXISTS) {
1302+
if ((ret = add_repo_as_submodule(&entry, index, path)) < 0)
1303+
return ret;
1304+
1305+
if ((ret = index_insert(index, &entry, 1, false)) < 0)
1306+
return ret;
1307+
} else if (ret < 0) {
1308+
return ret;
1309+
} else {
1310+
ret = git_submodule_add_to_index(sm, false);
1311+
git_submodule_free(sm);
1312+
return ret;
1313+
}
12611314
}
12621315

12631316
/* Adding implies conflict was resolved, move conflict entries to REUC */

src/indexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "oidmap.h"
1919
#include "zstream.h"
2020

21-
GIT__USE_OIDMAP;
21+
GIT__USE_OIDMAP
2222

2323
extern git_mutex git__mwindow_mutex;
2424

src/iterator.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,11 @@ static int dirload_with_stat(
10271027
strncomp = (flags & GIT_PATH_DIR_IGNORE_CASE) != 0 ?
10281028
git__strncasecmp : git__strncmp;
10291029

1030-
if ((error = git_path_diriter_init(&diriter, dirpath, flags)) < 0)
1030+
/* Any error here is equivalent to the dir not existing, skip over it */
1031+
if ((error = git_path_diriter_init(&diriter, dirpath, flags)) < 0) {
1032+
error = GIT_ENOTFOUND;
10311033
goto done;
1034+
}
10321035

10331036
while ((error = git_path_diriter_next(&diriter)) == 0) {
10341037
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)

src/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct pack_write_context {
4141
git_transfer_progress *stats;
4242
};
4343

44-
GIT__USE_OIDMAP;
44+
GIT__USE_OIDMAP
4545

4646
#ifdef GIT_THREADS
4747

src/pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include <zlib.h>
1818

19-
GIT__USE_OFFMAP;
20-
GIT__USE_OIDMAP;
19+
GIT__USE_OFFMAP
20+
GIT__USE_OIDMAP
2121

2222
static int packfile_open(struct git_pack_file *p);
2323
static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);

src/path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ extern int git_path_cmp(
319319
* @param callback Function to invoke on each path. Passed the `payload`
320320
* and the buffer containing the current path. The path should not
321321
* be modified in any way. Return non-zero to stop iteration.
322-
* @param state Passed to fn as the first ath.
322+
* @param payload Passed to fn as the first ath.
323323
*/
324324
extern int git_path_walk_up(
325325
git_buf *pathbuf,

src/push.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int git_push_add_refspec(git_push *push, const char *refspec);
8383
* Update remote tips after a push
8484
*
8585
* @param push The push object
86-
* @param signature The identity to use when updating reflogs
86+
* @param callbacks the callbacks to use for this connection
8787
*
8888
* @return 0 or an error code
8989
*/
@@ -100,6 +100,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks);
100100
* order to find out which updates were accepted or rejected.
101101
*
102102
* @param push The push object
103+
* @param callbacks the callbacks to use for this connection
103104
*
104105
* @return 0 or an error code
105106
*/
@@ -117,6 +118,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks);
117118
*
118119
* @param push The push object
119120
* @param cb The callback to call on each object
121+
* @param data The payload passed to the callback
120122
*
121123
* @return 0 on success, non-zero callback return value, or error code
122124
*/

src/revwalk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "git2/revparse.h"
1515
#include "merge.h"
1616

17-
GIT__USE_OIDMAP;
17+
GIT__USE_OIDMAP
1818

1919
git_commit_list_node *git_revwalk__commit_lookup(
2020
git_revwalk *walk, const git_oid *oid)

src/transports/git.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
5050
}
5151

5252
repo = delim;
53+
if (repo[1] == '~')
54+
++repo;
5355

5456
delim = strchr(url, ':');
5557
if (delim == NULL)

src/transports/http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int on_header_ready(http_subtransport *t)
255255
GITERR_CHECK_ALLOC(t->content_type);
256256
}
257257
}
258-
else if (!strcmp("WWW-Authenticate", git_buf_cstr(name))) {
258+
else if (!strcasecmp("WWW-Authenticate", git_buf_cstr(name))) {
259259
char *dup = git__strdup(git_buf_cstr(value));
260260
GITERR_CHECK_ALLOC(dup);
261261

src/transports/ssh.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
6666
if (!git__prefixcmp(url, prefix_ssh)) {
6767
url = url + strlen(prefix_ssh);
6868
repo = strchr(url, '/');
69+
if (repo && repo[1] == '~')
70+
++repo;
6971
} else {
7072
repo = strchr(url, ':');
7173
if (repo) repo++;

tests/core/filebuf.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,30 @@ void test_core_filebuf__umask(void)
124124
cl_must_pass(p_unlink(test));
125125
}
126126

127+
void test_core_filebuf__rename_error(void)
128+
{
129+
git_filebuf file = GIT_FILEBUF_INIT;
130+
char *dir = "subdir", *test = "subdir/test", *test_lock = "subdir/test.lock";
131+
int fd;
132+
133+
#ifndef GIT_WIN32
134+
cl_skip();
135+
#endif
136+
137+
cl_git_pass(p_mkdir(dir, 0666));
138+
cl_git_mkfile(test, "dummy content");
139+
fd = p_open(test, O_RDONLY);
140+
cl_assert(fd > 0);
141+
cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
142+
143+
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
144+
145+
cl_assert_equal_i(true, git_path_exists(test_lock));
146+
147+
cl_git_fail(git_filebuf_commit(&file));
148+
p_close(fd);
149+
150+
git_filebuf_cleanup(&file);
151+
152+
cl_assert_equal_i(false, git_path_exists(test_lock));
153+
}

tests/index/bypath.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ void test_index_bypath__add_submodule(void)
3333
cl_git_pass(git_submodule_status(&status, g_repo, sm_name, 0));
3434
cl_assert_equal_i(0, status & GIT_SUBMODULE_STATUS_WD_MODIFIED);
3535
}
36+
37+
void test_index_bypath__add_submodule_unregistered(void)
38+
{
39+
const char *sm_name = "not-submodule";
40+
const char *sm_head = "68e92c611b80ee1ed8f38314ff9577f0d15b2444";
41+
const git_index_entry *entry;
42+
43+
cl_git_pass(git_index_add_bypath(g_idx, sm_name));
44+
45+
cl_assert(entry = git_index_get_bypath(g_idx, sm_name, 0));
46+
cl_assert_equal_s(sm_head, git_oid_tostr_s(&entry->id));
47+
cl_assert_equal_s(sm_name, entry->path);
48+
}

0 commit comments

Comments
 (0)