8000 Merge pull request #3880 from libgit2/ethomson/diff_file · libgit2/libgit2@baa87df · GitHub
[go: up one dir, main page]

Skip to content

Commit baa87df

Browse files
author
Edward Thomson
authored
Merge pull request #3880 from libgit2/ethomson/diff_file
git_diff_file: move `id_abbrev`
2 parents 152efee + 002c8e2 commit baa87df

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ v0.24 + 1
5151
* `git_blob_create_fromchunks()` has been removed in favour of
5252
`git_blob_create_fromstream()`.
5353

54-
5554
### Breaking API changes
5655

5756
* `git_packbuilder_object_count` and `git_packbuilder_written` now
@@ -61,6 +60,9 @@ v0.24 + 1
6160
* `git_packbuiler_progress` now provides explicitly sized `uint32_t`
6261
values instead of `unsigned int`.
6362

63+
* `git_diff_file` now includes an `id_abbrev` field that reflects the
64+
number of nibbles set in the `id` field.
65+
6466
v0.24
6567
-------
6668

include/git2/diff.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,6 @@ typedef enum {
268268
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
269269
* then the oid will be zeroes.
270270
*
271-
* The `id_abbrev` represents the known length of the `id` field, when
272-
* converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
273-
* delta was created from reading a patch file, in which case it may be
274-
* abbreviated to something reasonable, like 7 characters.
275-
*
276271
* `path` is the NUL-terminated path to the entry relative to the working
277272
* directory of the repository.
278273
*
@@ -282,14 +277,19 @@ typedef enum {
282277
*
283278
* `mode` is, roughly, the stat() `st_mode` value for the item. This will
284279
* be restricted to one of the `git_filemode_t` values.
280+
*
281+
* The `id_abbrev` represents the known length of the `id` field, when
282+
* converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
283+
* delta was created from reading a patch file, in which case it may be
284+
* abbreviated to something reasonable, like 7 characters.
285285
*/
286286
typedef struct {
287287
git_oid id;
288-
int id_abbrev;
289288
const char *path;
290289
git_off_t size;
291290
uint32_t flags;
292291
uint16_t mode;
292+
uint16_t id_abbrev;
293293
} git_diff_file;
294294

295295
/**

src/patch_parse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int parse_header_mode(uint16_t *mode, git_patch_parse_ctx *ctx)
192192

193193
static int parse_header_oid(
194194
git_oid *oid,
195-
int *oid_len,
195+
uint16_t *oid_len,
196196
git_patch_parse_ctx *ctx)
197197
{
198198
size_t len;
@@ -202,14 +202,14 @@ static int parse_header_oid(
202202
break;
203203
}
204204

205-
if (len < GIT_OID_MINPREFIXLEN ||
205+
if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ ||
206206
git_oid_fromstrn(oid, ctx->line, len) < 0)
207207
return parse_err("invalid hex formatted object id at line %d",
208208
ctx->line_num);
209209

210210
parse_advance_chars(ctx, len);
211211

212-
*oid_len = (int)len;
212+
*oid_len = (uint16_t)len;
213213

214214
return 0;
215215
}

0 commit comments

Comments
 (0)
0