Convert enqueue_object to a function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/push.c b/src/push.c
index ee21bd9..00745fb 100644
--- a/src/push.c
+++ b/src/push.c
@@ -347,6 +347,20 @@ on_error:
return error == GIT_ITEROVER ? 0 : error;
}
+static int enqueue_object(
+ const git_tree_entry *entry,
+ git_packbuilder *pb)
+{
+ switch (git_tree_entry_type(entry)) {
+ case GIT_OBJ_COMMIT:
+ return 0;
+ case GIT_OBJ_TREE:
+ return git_packbuilder_insert_tree(pb, &entry->oid);
+ default:
+ return git_packbuilder_insert(pb, &entry->oid, entry->filename);
+ }
+}
+
static int queue_differences(
git_tree *base,
git_tree *delta,
@@ -358,22 +372,6 @@ static int queue_differences(
size_t i = 0, j = 0;
int error;
-#define _enqueue_object(ENTRY) do { \
- switch (git_tree_entry_type((ENTRY))) { \
- case GIT_OBJ_COMMIT: \
- break; \
- case GIT_OBJ_TREE: \
- if ((error = git_packbuilder_insert_tree(pb, &(ENTRY)->oid)) < 0) \
- goto on_error; \
- break; \
- default: \
- if ((error = git_packbuilder_insert(pb, &(ENTRY)->oid, \
- (ENTRY)->filename)) < 0) \
- goto on_error; \
- break; \
- } \
-} while (0)
-
while (i < b_length && j < d_length) {
const git_tree_entry *b_entry = git_tree_entry_byindex(base, i);
const git_tree_entry *d_entry = git_tree_entry_byindex(delta, j);
@@ -409,8 +407,9 @@ static int queue_differences(
}
/* If the object is new or different in the right-hand tree,
* then enumerate it */
- else if (cmp >= 0)
- _enqueue_object(d_entry);
+ else if (cmp >= 0 &&
+ (error = enqueue_object(d_entry, pb)) < 0)
+ goto on_error;
loop:
if (cmp <= 0) i++;
@@ -419,9 +418,8 @@ static int queue_differences(
/* Drain the right-hand tree of entries */
for (; j < d_length; j++)
- _enqueue_object(git_tree_entry_byindex(delta, j));
-
-#undef _enqueue_object
+ if ((error = enqueue_object(git_tree_entry_byindex(delta, j), pb)) < 0)
+ goto on_error;
error = 0;