Skip to content

Commit 793c438

Browse files
arrbeeben
authored andcommitted
Update diff callback param order
This makes the diff functions that take callbacks both take the payload parameter after the callback function pointers and pass the payload as the last argument to the callback function instead of the first. This should make them consistent with other callbacks across the API.
1 parent 54b2a37 commit 793c438

File tree

15 files changed

+225
-221
lines changed

15 files changed

+225
-221
lines changed

examples/diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ char *colors[] = {
6363
};
6464

6565
static int printer(
66-
void *data,
6766
const git_diff_delta *delta,
6867
const git_diff_range *range,
6968
char usage,
7069
const char *line,
71-
size_t line_len)
70+
size_t line_len,
71+
void *data)
7272
{
7373
int *last_color = data, color = 0;
7474

@@ -225,9 +225,9 @@ int main(int argc, char *argv[])
225225
fputs(colors[0], stdout);
226226

227227
if (compact)
228-
check(git_diff_print_compact(diff, &color, printer), "Displaying diff");
228+
check(git_diff_print_compact(diff, printer, &color), "Displaying diff");
229229
else
230-
check(git_diff_print_patch(diff, &color, printer), "Displaying diff");
230+
check(git_diff_print_patch(diff, printer, &color), "Displaying diff");
231231

232232
if (color >= 0)
233233
fputs(colors[0], stdout);

examples/general.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int main (int argc, char** argv)
298298
// Note that this buffer may not be contain ASCII data for certain blobs (e.g. binary files):
299299
// do not consider the buffer a NULL-terminated string, and use the `git_blob_rawsize` attribute to
300300
// find out its exact size in bytes
301-
printf("Blob Size: %ld\n", git_blob_rawsize(blob)); // 8
301+
printf("Blob Size: %ld\n", (long)git_blob_rawsize(blob)); // 8
302302
git_blob_rawcontent(blob); // "content"
303303

304304
// ### Revwalking

include/git2/diff.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ typedef struct {
188188
* When iterating over a diff, callback that will be made per file.
189189
*/
190190
typedef int (*git_diff_file_cb)(
191-
void *cb_data,
192191
const git_diff_delta *delta,
193-
float progress);
192+
float progress,
193+
void *payload);
194194

195195
/**
196196
* Structure describing a hunk of a diff.
@@ -206,11 +206,11 @@ typedef struct {
206206
* When iterating over a diff, callback that will be made per hunk.
207207
*/
208208
typedef int (*git_diff_hunk_cb)(
209-
void *cb_data,
210209
const git_diff_delta *delta,
211210
const git_diff_range *range,
212211
const char *header,
213-
size_t header_len);
212+
size_t header_len,
213+
void *payload);
214214

215215
/**
216216
* Line origin constants.
@@ -247,12 +247,12 @@ typedef enum {
247247
* of lines of file and hunk headers.
248248
*/
249249
typedef int (*git_diff_data_cb)(
250-
void *cb_data,
251250
const git_diff_delta *delta,
252251
const git_diff_range *range,
253252
char line_origin, /**< GIT_DIFF_LINE_... value from above */
254253
const char *content,
255-
size_t content_len);
254+
size_t content_len,
255+
void *payload);
256256

257257
/**
258258
* The diff patch is used to store all the text diffs for a delta.
@@ -284,6 +284,8 @@ typedef enum {
284284
* Control behavior of rename and copy detection
285285
*/
286286
typedef struct {
287+
unsigned int version;
288+
287289
/** Combination of git_diff_find_t values (default FIND_RENAMES) */
288290
unsigned int flags;
289291

@@ -462,22 +464,22 @@ GIT_EXTERN(int) git_diff_find_similar(
462464
* the iteration and cause this return `GIT_EUSER`.
463465
*
464466
* @param diff A git_diff_list generated by one of the above functions.
465-
* @param cb_data Reference pointer that will be passed to your callbacks.
466467
* @param file_cb Callback function to make per file in the diff.
467468
* @param hunk_cb Optional callback to make per hunk of text diff. This
468469
* callback is called to describe a range of lines in the
469470
* diff. It will not be issued for binary files.
470471
* @param line_cb Optional callback to make per line of diff text. This
471472
* same callback will be made for context lines, added, and
472473
* removed lines, and even for a deleted trailing newline.
474+
* @param payload Reference pointer that will be passed to your callbacks.
473475
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
474476
*/
475477
GIT_EXTERN(int) git_diff_foreach(
476478
git_diff_list *diff,
477-
void *cb_data,
478479
git_diff_file_cb file_cb,
479480
git_diff_hunk_cb hunk_cb,
480-
git_diff_data_cb line_cb);
481+
git_diff_data_cb line_cb,
482+
void *payload);
481483

482484
/**
483485
* Iterate over a diff generating text output like "git diff --name-status".
@@ -486,14 +488,14 @@ GIT_EXTERN(int) git_diff_foreach(
486488
* iteration and cause this return `GIT_EUSER`.
487489
*
488490
* @param diff A git_diff_list generated by one of the above functions.
489-
* @param cb_data Reference pointer that will be passed to your callback.
490491
* @param print_cb Callback to make per line of diff text.
492+
* @param payload Reference pointer that will be passed to your callback.
491493
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
492494
*/
493495
GIT_EXTERN(int) git_diff_print_compact(
494496
git_diff_list *diff,
495-
void *cb_data,
496-
git_diff_data_cb print_cb);
497+
git_diff_data_cb print_cb,
498+
void *payload);
497499

498500
/**
499501
* Look up the single character abbreviation for a delta status code.
@@ -518,7 +520,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
518520
* iteration and cause this return `GIT_EUSER`.
519521
*
520522
* @param diff A git_diff_list generated by one of the above functions.
521-
* @param cb_data Reference pointer that will be passed to your callbacks.
523+
* @param payload Reference pointer that will be passed to your callbacks.
522524
* @param print_cb Callback function to output lines of the diff. This
523525
* same function will be called for file headers, hunk
524526
* headers, and diff lines. Fortunately, you can probably
@@ -528,8 +530,8 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
528530
*/
529531
GIT_EXTERN(int) git_diff_print_patch(
530532
git_diff_list *diff,
531-
void *cb_data,
532-
git_diff_data_cb print_cb);
533+
git_diff_data_cb print_cb,
534+
void *payload);
533535

534536
/**
535537
* Query how many diff records are there in a diff list.
@@ -573,15 +575,15 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
573575
* It is okay to pass NULL for either of the output parameters; if you pass
574576
* NULL for the `git_diff_patch`, then the text diff will not be calculated.
575577
*
576-
* @param patch Output parameter for the delta patch object
577-
* @param delta Output parameter for the delta object
578+
* @param patch_out Output parameter for the delta patch object
579+
* @param delta_out Output parameter for the delta object
578580
* @param diff Diff list object
579581
* @param idx Index into diff list
580582
* @return 0 on success, other value < 0 on error
581583
*/
582584
GIT_EXTERN(int) git_diff_get_patch(
583-
git_diff_patch **patch,
584-
const git_diff_delta **delta,
585+
git_diff_patch **patch_out,
586+
const git_diff_delta **delta_out,
585587
git_diff_list *diff,
586588
size_t idx);
587589

@@ -673,15 +675,15 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
673675
* and cause this return `GIT_EUSER`.
674676
*
675677
* @param patch A git_diff_patch representing changes to one file
676-
* @param cb_data Reference pointer that will be passed to your callbacks.
677678
* @param print_cb Callback function to output lines of the patch. Will be
678679
* called for file headers, hunk headers, and diff lines.
680+
* @param payload Reference pointer that will be passed to your callbacks.
679681
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
680682
*/
681683
GIT_EXTERN(int) git_diff_patch_print(
682684
git_diff_patch *patch,
683-
void *cb_data,
684-
git_diff_data_cb print_cb);
685+
git_diff_data_cb print_cb,
686+
void *payload);
685687

686688
/**
687689
* Get the content of a patch as a single diff text.
@@ -719,10 +721,10 @@ GIT_EXTERN(int) git_diff_blobs(
719721
git_blob *old_blob,
720722
git_blob *new_blob,
721723
const git_diff_options *options,
722-
void *cb_data,
723724
git_diff_file_cb file_cb,
724725
git_diff_hunk_cb hunk_cb,
725-
git_diff_data_cb line_cb);
726+
git_diff_data_cb line_cb,
727+
void *payload);
726728

727729
GIT_END_DECL
728730

0 commit comments

Comments
 (0)