Skip to content

Commit 6a0d569

Browse files
committed
Merge pull request libgit2#3333 from libgit2/cmn/for-v23
Maintenance updates for v0.23
2 parents 159061a + ac1a5e2 commit 6a0d569

38 files changed

+363
-121
lines changed

examples/network/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ int fetch(git_repository *repo, int argc, char **argv)
143143
* network.
144144
*/
145145
if (stats->local_objects > 0) {
146-
printf("\rReceived %d/%d objects in %zu bytes (used %d local objects)\n",
146+
printf("\rReceived %d/%d objects in %" PRIuZ " bytes (used %d local objects)\n",
147147
stats->indexed_objects, stats->total_objects, stats->received_bytes, stats->local_objects);
148148
} else{
149-
printf("\rReceived %d/%d objects in %zu bytes\n",
149+
printf("\rReceived %d/%d objects in %" PRIuZ "bytes\n",
150150
stats->indexed_objects, stats->total_objects, stats->received_bytes);
151151
}
152152

include/git2/errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef enum {
4848
GIT_EEOF = -20, /**< Unexpected EOF */
4949
GIT_EINVALID = -21, /**< Invalid operation or input */
5050
GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */
51+
GIT_EDIRECTORY = -23, /**< The operation is not valid for a directory */
5152

5253
GIT_PASSTHROUGH = -30, /**< Internal only */
5354
GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */

include/git2/remote.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ typedef enum {
511511
GIT_REMOTE_DOWNLOAD_TAGS_ALL,
512512
} git_remote_autotag_option_t;
513513

514+
/**
515+
* Fetch options structure.
516+
*
517+
* Zero out for defaults. Initialize with `GIT_FETCH_OPTIONS_INIT` macro to
518+
* correctly set the `version` field. E.g.
519+
*
520+
* git_fetch_options opts = GIT_FETCH_OPTIONS_INIT;
521+
*/
514522
typedef struct {
515523
int version;
516524

@@ -739,7 +747,7 @@ GIT_EXTERN(int) git_remote_prune_refs(const git_remote *remote);
739747
* stored here for further processing by the caller. Always free this
740748
* strarray on successful return.
741749
* @param repo the repository in which to rename
742-
* @param name the current name of the reamote
750+
* @param name the current name of the remote
743751
* @param new_name the new name the remote should bear
744752
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
745753
*/

src/blame_git.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,16 @@ static void blame_chunk(
304304
}
305305

306306
static int my_emit(
307-
xdfenv_t *xe,
308-
xdchange_t *xscr,
309-
xdemitcb_t *ecb,
310-
xdemitconf_t const *xecfg)
307+
long start_a, long count_a,
308+
long start_b, long count_b,
309+
void *cb_data)
311310
{
312-
xdchange_t *xch = xscr;
313-
GIT_UNUSED(xe);
314-
GIT_UNUSED(xecfg);
315-
while (xch) {
316-
blame_chunk_cb_data *d = ecb->priv;
317-
blame_chunk(d->blame, d->tlno, d->plno, xch->i2, d->target, d->parent);
318-
d->plno = xch->i1 + xch->chg1;
319-
d->tlno = xch->i2 + xch->chg2;
320-
xch = xch->next;
321-
}
311+
blame_chunk_cb_data *d = (blame_chunk_cb_data *)cb_data;
312+
313+
blame_chunk(d->blame, d->tlno, d->plno, start_b, d->target, d->parent);
314+
d->plno = start_a + count_a;
315+
d->tlno = start_b + count_b;
316+
322317
return 0;
323318
}
324319

@@ -352,7 +347,7 @@ static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data)
352347
xdemitconf_t xecfg = {0};
353348
xdemitcb_t ecb = {0};
354349

355-
xecfg.emit_func = (void(*)(void))my_emit;
350+
xecfg.hunk_func = my_emit;
356351
ecb.priv = cb_data;
357352

358353
trim_common_tail(&file_a, &file_b, 0);

src/blob.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ int git_blob__create_from_paths(
185185
(error = git_repository_odb(&odb, repo)) < 0)
186186
goto done;
187187

188+
if (S_ISDIR(st.st_mode)) {
189+
giterr_set(GITERR_ODB, "cannot create blob from '%s'; it is a directory", content_path);
190+
error = GIT_EDIRECTORY;
191+
goto done;
192+
}
193+
188194
if (out_st)
189195
memcpy(out_st, &st, sizeof(st));
190196

src/cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ void git_cache_dump_stats(git_cache *cache)
5050
if (kh_size(cache->map) == 0)
5151
return;
5252

53-
printf("Cache %p: %d items cached, %d bytes\n",
54-
cache, kh_size(cache->map), (int)cache->used_memory);
53+
printf("Cache %p: %d items cached, %"PRIdZ" bytes\n",
54+
cache, kh_size(cache->map), cache->used_memory);
5555

5656
kh_foreach_value(cache->map, object, {
5757
char oid_str[9];
58-
printf(" %s%c %s (%d)\n",
58+
printf(" %s%c %s (%"PRIuZ")\n",
5959
git_object_type2string(object->type),
6060
object->flags == GIT_CACHE_STORE_PARSED ? '*' : ' ',
6161
git_oid_tostr(oid_str, sizeof(oid_str), &object->oid),
62-
(int)object->size
62+
object->size
6363
);
6464
});
6565
}

src/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,8 @@ static int checkout_get_actions(
12991299
if (counts[CHECKOUT_ACTION__CONFLICT] > 0 &&
13001300
(data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 0)
13011301
{
1302-
giterr_set(GITERR_CHECKOUT, "%d %s checkout",
1303-
(int)counts[CHECKOUT_ACTION__CONFLICT],
1302+
giterr_set(GITERR_CHECKOUT, "%"PRIuZ" %s checkout",
1303+
counts[CHECKOUT_ACTION__CONFLICT],
13041304
counts[CHECKOUT_ACTION__CONFLICT] == 1 ?
13051305
"conflict prevents" : "conflicts prevent");
13061306
error = GIT_ECONFLICT;

src/filter.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,18 +947,20 @@ int git_filter_list_stream_data(
947947
{
948948
git_vector filter_streams = GIT_VECTOR_INIT;
949949
git_writestream *stream_start;
950-
int error = 0;
950+
int error = 0, close_error;
951951

952952
git_buf_sanitize(data);
953953

954-
if ((error = stream_list_init(
955-
&stream_start, &filter_streams, filters, target)) == 0 &&
956-
(error =
957-
stream_start->write(stream_start, data->ptr, data->size)) == 0)
958-
error = stream_start->close(stream_start);
954+
if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
955+
goto out;
959956

957+
error = stream_start->write(stream_start, data->ptr, data->size);
958+
959+
out:
960+
close_error = stream_start->close(stream_start);
960961
stream_list_free(&filter_streams);
961-
return error;
962+
/* propagate the stream init or write error */
963+
return error < 0 ? error : close_error;
962964
}
963965

964966
int git_filter_list_stream_blob(

src/index.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,29 @@ int git_index_add_bypath(git_index *index, const char *path)
12361236

12371237
assert(index && path);
12381238

1239-
if ((ret = index_entry_init(&entry, index, path)) < 0 ||
1240-
(ret = index_insert(index, &entry, 1, false)) < 0)
1239+
if ((ret = index_entry_init(&entry, index, path)) == 0)
1240+
ret = index_insert(index, &entry, 1, false);
1241+
1242+
/* If we were given a directory, let's see if it's a submodule */
1243+
if (ret < 0 && ret != GIT_EDIRECTORY)
1244+
return ret;
1245+
1246+
if (ret == GIT_EDIRECTORY) {
1247+
git_submodule *sm;
1248+
git_error_state err;
1249+
1250+
giterr_capture(&err, ret);
1251+
1252+
ret = git_submodule_lookup(&sm, INDEX_OWNER(index), path);
1253+
if (ret == GIT_ENOTFOUND)
1254+
return giterr_restore(&err);
1255+
else
1256+
git__free(err.error_msg.message);
1257+
1258+
ret = git_submodule_add_to_index(sm, false);
1259+
git_submodule_free(sm);
12411260
return ret;
1261+
}
12421262

12431263
/* Adding implies conflict was resolved, move conflict entries to REUC */
12441264
if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)

src/khash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,4 @@ typedef const char *kh_cstr_t;
619619
#define KHASH_MAP_INIT_STR(name, khval_t) \
620620
KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
621621

622-
#endif /* __AC_KHASH_H */
622+
#endif /* __AC_KHASH_H */

0 commit comments

Comments
 (0)