Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
799f9a04
Commit
799f9a04
authored
Mar 19, 2013
by
Philip Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce the number of unnecessary objects in pushed packs
parent
7dbf4039
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
34 deletions
+141
-34
src/push.c
+141
-34
No files found.
src/push.c
View file @
799f9a04
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include "remote.h"
#include "remote.h"
#include "vector.h"
#include "vector.h"
#include "push.h"
#include "push.h"
#include "tree.h"
static
int
push_spec_rref_cmp
(
const
void
*
a
,
const
void
*
b
)
static
int
push_spec_rref_cmp
(
const
void
*
a
,
const
void
*
b
)
{
{
...
@@ -346,60 +347,166 @@ on_error:
...
@@ -346,60 +347,166 @@ on_error:
return
error
==
GIT_ITEROVER
?
0
:
error
;
return
error
==
GIT_ITEROVER
?
0
:
error
;
}
}
static
int
queue_objects
(
git_push
*
push
)
static
int
queue_differences
(
git_tree
*
base
,
git_tree
*
delta
,
git_packbuilder
*
pb
)
{
{
git_vector
commits
;
git_tree
*
b_child
=
NULL
,
*
d_child
=
NULL
;
git_oid
*
o
;
size_t
b_length
=
git_tree_entrycount
(
base
);
unsigned
int
i
;
size_t
d_length
=
git_tree_entrycount
(
delta
);
size_t
i
=
0
,
j
=
0
;
int
error
;
int
error
;
if
(
git_vector_init
(
&
commits
,
0
,
NULL
)
<
0
)
#define _enqueue_object(ENTRY) do { \
return
-
1
;
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
);
int
cmp
=
0
;
if
(
!
git_oid_cmp
(
&
b_entry
->
oid
,
&
d_entry
->
oid
))
goto
loop
;
cmp
=
memcmp
(
b_entry
->
filename
,
d_entry
->
filename
,
b_entry
->
filename_len
);
/* If the entries are both trees and they have the same name but are
* different, then we'll recurse after adding the right-hand entry */
if
(
!
cmp
&&
git_tree_entry__is_tree
(
b_entry
)
&&
git_tree_entry__is_tree
(
d_entry
))
{
/* Add the right-hand entry */
if
((
error
=
git_packbuilder_insert
(
pb
,
&
d_entry
->
oid
,
d_entry
->
filename
))
<
0
)
goto
on_error
;
if
((
error
=
revwalk
(
&
commits
,
push
))
<
0
)
/* Acquire the subtrees and recurse */
if
((
error
=
git_tree_lookup
(
&
b_child
,
git_tree_owner
(
base
),
&
b_entry
->
oid
))
<
0
||
(
error
=
git_tree_lookup
(
&
d_child
,
git_tree_owner
(
delta
),
&
d_entry
->
oid
))
<
0
||
(
error
=
queue_differences
(
b_child
,
d_child
,
pb
))
<
0
)
goto
on_error
;
goto
on_error
;
if
(
!
commits
.
length
)
{
git_tree_free
(
b_child
);
b_child
=
NULL
;
git_vector_free
(
&
commits
);
git_tree_free
(
d_child
);
d_child
=
NULL
;
return
0
;
/* nothing to do */
}
}
/* If the object is new or different in the right-hand tree,
* then enumerate it */
else
if
(
cmp
>=
0
)
_enqueue_object
(
d_entry
);
git_vector_foreach
(
&
commits
,
i
,
o
)
{
loop:
if
(
(
error
=
git_packbuilder_insert
(
push
->
pb
,
o
,
NULL
))
<
0
)
if
(
cmp
<=
0
)
i
++
;
goto
on_error
;
if
(
cmp
>=
0
)
j
++
;
}
}
git_vector_foreach
(
&
commits
,
i
,
o
)
{
/* Drain the right-hand tree of entries */
git_object
*
obj
;
for
(;
j
<
d_length
;
j
++
)
_enqueue_object
(
git_tree_entry_byindex
(
delta
,
j
));
#undef _enqueue_object
error
=
0
;
on_error:
if
(
b_child
)
git_tree_free
(
b_child
);
if
((
error
=
git_object_lookup
(
&
obj
,
push
->
repo
,
o
,
GIT_OBJ_ANY
))
<
0
)
if
(
d_child
)
git_tree_free
(
d_child
);
return
error
;
}
static
int
queue_objects
(
git_push
*
push
)
{
git_vector
commits
=
GIT_VECTOR_INIT
;
git_oid
*
oid
;
size_t
i
;
unsigned
j
;
int
error
;
if
((
error
=
revwalk
(
&
commits
,
push
))
<
0
)
goto
on_error
;
goto
on_error
;
switch
(
git_object_type
(
obj
)
)
{
git_vector_foreach
(
&
commits
,
i
,
oid
)
{
case
GIT_OBJ_TAG
:
/* TODO: expect tags */
git_commit
*
parent
=
NULL
,
*
commit
;
case
GIT_OBJ_COMMIT
:
git_tree
*
tree
=
NULL
,
*
ptree
=
NULL
;
if
((
error
=
git_packbuilder_insert_tree
(
push
->
pb
,
size_t
parentcount
;
git_commit_tree_id
((
git_commit
*
)
obj
)))
<
0
)
{
git_object_free
(
obj
);
if
((
error
=
git_commit_lookup
(
&
commit
,
push
->
repo
,
oid
))
<
0
)
goto
on_error
;
goto
on_error
;
/* Insert the commit */
if
((
error
=
git_packbuilder_insert
(
push
->
pb
,
oid
,
NULL
))
<
0
)
goto
loop_error
;
parentcount
=
git_commit_parentcount
(
commit
);
if
(
!
parentcount
)
{
if
((
error
=
git_packbuilder_insert_tree
(
push
->
pb
,
git_commit_tree_id
(
commit
)))
<
0
)
goto
loop_error
;
}
else
{
if
((
error
=
git_tree_lookup
(
&
tree
,
push
->
repo
,
git_commit_tree_id
(
commit
)))
<
0
||
(
error
=
git_packbuilder_insert
(
push
->
pb
,
git_commit_tree_id
(
commit
),
NULL
))
<
0
)
goto
loop_error
;
/* For each parent, add the items which are different */
for
(
j
=
0
;
j
<
parentcount
;
j
++
)
{
if
((
error
=
git_commit_parent
(
&
parent
,
commit
,
j
))
<
0
||
(
error
=
git_commit_tree
(
&
ptree
,
parent
))
<
0
||
(
error
=
queue_differences
(
ptree
,
tree
,
push
->
pb
))
<
0
)
goto
loop_error
;
git_tree_free
(
ptree
);
ptree
=
NULL
;
git_commit_free
(
parent
);
parent
=
NULL
;
}
}
break
;
case
GIT_OBJ_TREE
:
case
GIT_OBJ_BLOB
:
default:
git_object_free
(
obj
);
giterr_set
(
GITERR_INVALID
,
"Given object type invalid"
);
error
=
-
1
;
goto
on_error
;
}
}
git_object_free
(
obj
);
error
=
0
;
loop_error:
if
(
tree
)
git_tree_free
(
tree
);
if
(
ptree
)
git_tree_free
(
ptree
);
if
(
parent
)
git_commit_free
(
parent
);
git_commit_free
(
commit
);
if
(
error
<
0
)
goto
on_error
;
}
}
error
=
0
;
error
=
0
;
on_error:
on_error:
git_vector_foreach
(
&
commits
,
i
,
o
)
{
git_vector_foreach
(
&
commits
,
i
,
o
id
)
git__free
(
o
);
git__free
(
o
id
);
}
git_vector_free
(
&
commits
);
git_vector_free
(
&
commits
);
return
error
;
return
error
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment