Skip to content

Commit 2dcfe51

Browse files
committed
Use git_packbuilder_insert_walk in queue_objects.
1 parent 709768a commit 2dcfe51

File tree

1 file changed

+2
-169
lines changed

1 file changed

+2
-169
lines changed

src/push.c

Lines changed: 2 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,11 @@ static int enqueue_tag(git_object **out, git_push *push, git_oid *id)
260260
return error;
261261
}
262262

263-
static int revwalk(git_vector *commits, git_push *push)
263+
static int queue_objects(git_push *push)
264264
{
265265
git_remote_head *head;
266266
push_spec *spec;
267267
git_revwalk *rw;
268-
git_oid oid;
269268
unsigned int i;
270269
int error = -1;
271270

@@ -350,176 +349,10 @@ static int revwalk(git_vector *commits, git_push *push)
350349
git_revwalk_hide(rw, &head->oid);
351350
}
352351

353-
while ((error = git_revwalk_next(&oid, rw)) == 0) {
354-
git_oid *o = git__malloc(GIT_OID_RAWSZ);
355-
if (!o) {
356-
error = -1;
357-
goto on_error;
358-
}
359-
git_oid_cpy(o, &oid);
360-
if ((error = git_vector_insert(commits, o)) < 0)
361-
goto on_error;
362-
}
352+
error = git_packbuilder_insert_walk(push->pb, rw);
363353

364354
on_error:
365355
git_revwalk_free(rw);
366-
return error == GIT_ITEROVER ? 0 : error;
367-
}
368-
369-
static int enqueue_object(
370-
const git_tree_entry *entry,
371-
git_packbuilder *pb)
372-
{
373-
switch (git_tree_entry_type(entry)) {
374-
case GIT_OBJ_COMMIT:
375-
return 0;
376-
case GIT_OBJ_TREE:
377-
return git_packbuilder_insert_tree(pb, entry->oid);
378-
default:
379-
return git_packbuilder_insert(pb, entry->oid, entry->filename);
380-
}
381-
}
382-
383-
static int queue_differences(
384-
git_tree *base,
385-
git_tree *delta,
386-
git_packbuilder *pb)
387-
{
388-
git_tree *b_child = NULL, *d_child = NULL;
389-
size_t b_length = git_tree_entrycount(base);
390-
size_t d_length = git_tree_entrycount(delta);
391-
size_t i = 0, j = 0;
392-
int error;
393-
394-
while (i < b_length && j < d_length) {
395-
const git_tree_entry *b_entry = git_tree_entry_byindex(base, i);
396-
const git_tree_entry *d_entry = git_tree_entry_byindex(delta, j);
397-
int cmp = 0;
398-
399-
if (!git_oid__cmp(b_entry->oid, d_entry->oid))
400-
goto loop;
401-
402-
cmp = strcmp(b_entry->filename, d_entry->filename);
403-
404-
/* If the entries are both trees and they have the same name but are
405-
* different, then we'll recurse after adding the right-hand entry */
406-
if (!cmp &&
407-
git_tree_entry__is_tree(b_entry) &&
408-
git_tree_entry__is_tree(d_entry)) {
409-
/* Add the right-hand entry */
410-
if ((error = git_packbuilder_insert(pb, d_entry->oid,
411-
d_entry->filename)) < 0)
412-
goto on_error;
413-
414-
/* Acquire the subtrees and recurse */
415-
if ((error = git_tree_lookup(&b_child,
416-
git_tree_owner(base), b_entry->oid)) < 0 ||
417-
(error = git_tree_lookup(&d_child,
418-
git_tree_owner(delta), d_entry->oid)) < 0 ||
419-
(error = queue_differences(b_child, d_child, pb)) < 0)
420-
goto on_error;
421-
422-
git_tree_free(b_child); b_child = NULL;
423-
git_tree_free(d_child); d_child = NULL;
424-
}
425-
/* If the object is new or different in the right-hand tree,
426-
* then enumerate it */
427-
else if (cmp >= 0 &&
428-
(error = enqueue_object(d_entry, pb)) < 0)
429-
goto on_error;
430-
431-
loop:
432-
if (cmp <= 0) i++;
433-
if (cmp >= 0) j++;
434-
}
435-
436-
/* Drain the right-hand tree of entries */
437-
for (; j < d_length; j++)
438-
if ((error = enqueue_object(git_tree_entry_byindex(delta, j), pb)) < 0)
439-
goto on_error;
440-
441-
error = 0;
442-
443-
on_error:
444-
if (b_child)
445-
git_tree_free(b_child);
446-
447-
if (d_child)
448-
git_tree_free(d_child);
449-
450-
return error;
451-
}
452-
453-
static int queue_objects(git_push *push)
454-
{
455-
git_vector commits = GIT_VECTOR_INIT;
456-
git_oid *oid;
457-
size_t i;
458-
unsigned j;
459-
int error;
460-
461-
if ((error = revwalk(&commits, push)) < 0)
462-
goto on_error;
463-
464-
git_vector_foreach(&commits, i, oid) {
465-
git_commit *parent = NULL, *commit;
466-
git_tree *tree = NULL, *ptree = NULL;
467-
size_t parentcount;
468-
469-
if ((error = git_commit_lookup(&commit, push->repo, oid)) < 0)
470-
goto on_error;
471-
472-
/* Insert the commit */
473-
if ((error = git_packbuilder_insert(push->pb, oid, NULL)) < 0)
474-
goto loop_error;
475-
476-
parentcount = git_commit_parentcount(commit);
477-
478-
if (!parentcount) {
479-
if ((error = git_packbuilder_insert_tree(push->pb,
480-
git_commit_tree_id(commit))) < 0)
481-
goto loop_error;
482-
} else {
483-
if ((error = git_tree_lookup(&tree, push->repo,
484-
git_commit_tree_id(commit))) < 0 ||
485-
(error = git_packbuilder_insert(push->pb,
486-
git_commit_tree_id(commit), NULL)) < 0)
487-
goto loop_error;
488-
489-
/* For each parent, add the items which are different */
490-
for (j = 0; j < parentcount; j++) {
491-
if ((error = git_commit_parent(&parent, commit, j)) < 0 ||
492-
(error = git_commit_tree(&ptree, parent)) < 0 ||
493-
(error = queue_differences(ptree, tree, push->pb)) < 0)
494-
goto loop_error;
495-
496-
git_tree_free(ptree); ptree = NULL;
497-
git_commit_free(parent); parent = NULL;
498-
}
499-
}
500-
501-
error = 0;
502-
503-
loop_error:
504-
if (tree)
505-
git_tree_free(tree);
506-
507-
if (ptree)
508-
git_tree_free(ptree);
509-
510-
if (parent)
511-
git_commit_free(parent);
512-
513-
git_commit_free(commit);
514-
515-
if (error < 0)
516-
goto on_error;
517-
}
518-
519-
error = 0;
520-
521-
on_error:
522-
git_vector_free_deep(&commits);
523356
return error;
524357
}
525358

0 commit comments

Comments
 (0)