Skip to content

Commit 130b04a

Browse files
committed
Merge branch 'js/maint-graft-unhide-true-parents'
* js/maint-graft-unhide-true-parents: git repack: keep commits hidden by a graft Add a test showing that 'git repack' throws away grafted-away parents Conflicts: git-repack.sh
2 parents a7c1ef3 + 7f3140c commit 130b04a

File tree

7 files changed

+31
-3
lines changed

7 files changed

+31
-3
lines changed

Documentation/git-pack-objects.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SYNOPSIS
1111
[verse]
1212
'git pack-objects' [-q] [--no-reuse-delta] [--delta-base-offset] [--non-empty]
1313
[--local] [--incremental] [--window=N] [--depth=N] [--all-progress]
14-
[--revs [--unpacked | --all]*] [--stdout | base-name] < object-list
14+
[--revs [--unpacked | --all]*] [--stdout | base-name]
15+
[--keep-true-parents] < object-list
1516

1617

1718
DESCRIPTION
@@ -197,6 +198,10 @@ base-name::
197198
to force the version for the generated pack index, and to force
198199
64-bit index entries on objects located above the given offset.
199200

201+
--keep-true-parents::
202+
With this option, parents that are hidden by grafts are packed
203+
nevertheless.
204+
200205

201206
Author
202207
------

builtin-pack-objects.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
22552255
die("bad %s", arg);
22562256
continue;
22572257
}
2258+
if (!strcmp(arg, "--keep-true-parents")) {
2259+
grafts_replace_parents = 0;
2260+
continue;
2261+
}
22582262
usage(pack_usage);
22592263
}
22602264

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ enum object_creation_mode {
560560

561561
extern enum object_creation_mode object_creation_mode;
562562

563+
extern int grafts_replace_parents;
564+
563565
#define GIT_REPO_VERSION 0
564566
extern int repository_format_version;
565567
extern int check_repository_format(void);

commit.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
262262
bufptr[47] != '\n')
263263
return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
264264
bufptr += 48;
265-
if (graft)
265+
/*
266+
* The clone is shallow if nr_parent < 0, and we must
267+
* not traverse its real parents even when we unhide them.
268+
*/
269+
if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
266270
continue;
267271
new_parent = lookup_commit(parent);
268272
if (new_parent)

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
4747
#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
4848
#endif
4949
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
50+
int grafts_replace_parents = 1;
5051

5152
/* Parallel index stat data preload? */
5253
int core_preload_index = 0;

git-repack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ case ",$all_into_one," in
8181
esac
8282

8383
args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
84-
names=$(git pack-objects --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
84+
names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
8585
exit 1
8686
if [ -z "$names" ]; then
8787
say Nothing new to pack.

t/t7700-repack.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,17 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
149149
test_must_fail git show $csha1
150150
'
151151

152+
test_expect_success 'objects made unreachable by grafts only are kept' '
153+
test_tick &&
154+
git commit --allow-empty -m "commit 4" &&
155+
H0=$(git rev-parse HEAD) &&
156+
H1=$(git rev-parse HEAD^) &&
157+
H2=$(git rev-parse HEAD^^) &&
158+
echo "$H0 $H2" > .git/info/grafts &&
159+
git reflog expire --expire=now --expire-unreachable=now --all &&
160+
git repack -a -d &&
161+
git cat-file -t $H1
162+
'
163+
152164
test_done
153165

0 commit comments

Comments
 (0)