@matheusbsbs / matheus-bagliano / commits / 16652170bf
Fork 0

An illustration of rev-list --parents --pretty=raw

This script creates two separate histories, A and B, each of which does: (A0, B0): create fileA and subdir/fileB (A1, B1): modify fileA (A2, B2): modify subdir/fileB and then grafts them together to make B0 a child of A2. So the final history looks like (time flows from top to bottom): true parent touches subdir? A0 none yes (creates it) A1 A0 no A2 A1 yes B0 none yes (different from what's in A2) B1 B0 no B2 B1 yes "git rev-list --parents --pretty=raw B2" would give "fake" parents on the "commit " header lines while "parent " header lines show the parent as recorded in the commit object (i.e. B0 appears to have A2 as its parent on "commit " header but there is no "parent A2" header line in it). When you have path limiters, we simplify history to omit commits that do not affect the specified paths. So "git rev-list --parents --pretty=raw B2 subdir" would return "B2 B0 A2 A0" (because B1 and A1 do not touch the path). When it does so, the "commit " header lines have "fake" parents (i.e. B2 appears to have B0 as its parent on "commit " header), but you can still get the true parents by looking at "parent " header. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 27, 2006 at 12:34 UTC 16652170bf80542fd77de75fb88da2f7761f65c4
1 file changed +113
t/t6001-rev-list-graft.sh new
+113
@@ -0,0 +1,113 @@
1 +#!/bin/sh
2 +
3 +test_description='Revision traversal vs grafts and path limiter'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + mkdir subdir &&
9 + echo >fileA fileA &&
10 + echo >subdir/fileB fileB &&
11 + git add fileA subdir/fileB &&
12 + git commit -a -m "Initial in one history." &&
13 + A0=`git rev-parse --verify HEAD` &&
14 +
15 + echo >fileA fileA modified &&
16 + git commit -a -m "Second in one history." &&
17 + A1=`git rev-parse --verify HEAD` &&
18 +
19 + echo >subdir/fileB fileB modified &&
20 + git commit -a -m "Third in one history." &&
21 + A2=`git rev-parse --verify HEAD` &&
22 +
23 + rm -f .git/refs/heads/master .git/index &&
24 +
25 + echo >fileA fileA again &&
26 + echo >subdir/fileB fileB again &&
27 + git add fileA subdir/fileB &&
28 + git commit -a -m "Initial in alternate history." &&
29 + B0=`git rev-parse --verify HEAD` &&
30 +
31 + echo >fileA fileA modified in alternate history &&
32 + git commit -a -m "Second in alternate history." &&
33 + B1=`git rev-parse --verify HEAD` &&
34 +
35 + echo >subdir/fileB fileB modified in alternate history &&
36 + git commit -a -m "Third in alternate history." &&
37 + B2=`git rev-parse --verify HEAD` &&
38 + : done
39 +'
40 +
41 +check () {
42 + type=$1
43 + shift
44 +
45 + arg=
46 + which=arg
47 + rm -f test.expect
48 + for a
49 + do
50 + if test "z$a" = z--
51 + then
52 + which=expect
53 + child=
54 + continue
55 + fi
56 + if test "$which" = arg
57 + then
58 + arg="$arg$a "
59 + continue
60 + fi
61 + if test "$type" = basic
62 + then
63 + echo "$a"
64 + else
65 + if test "z$child" != z
66 + then
67 + echo "$child $a"
68 + fi
69 + child="$a"
70 + fi
71 + done >test.expect
72 + if test "$type" != basic && test "z$child" != z
73 + then
74 + echo >>test.expect $child
75 + fi
76 + if test $type = basic
77 + then
78 + git rev-list $arg >test.actual
79 + elif test $type = parents
80 + then
81 + git rev-list --parents $arg >test.actual
82 + elif test $type = parents-raw
83 + then
84 + git rev-list --parents --pretty=raw $arg |
85 + sed -n -e 's/^commit //p' >test.actual
86 + fi
87 + diff test.expect test.actual
88 +}
89 +
90 +for type in basic parents parents-raw
91 +do
92 + test_expect_success 'without grafts' "
93 + rm -f .git/info/grafts
94 + check $type $B2 -- $B2 $B1 $B0
95 + "
96 +
97 + test_expect_success 'with grafts' "
98 + echo '$B0 $A2' >.git/info/grafts
99 + check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0
100 + "
101 +
102 + test_expect_success 'without grafts, with pathlimit' "
103 + rm -f .git/info/grafts
104 + check $type $B2 subdir -- $B2 $B0
105 + "
106 +
107 + test_expect_success 'with grafts, with pathlimit' "
108 + echo '$B0 $A2' >.git/info/grafts
109 + check $type $B2 subdir -- $B2 $B0 $A2 $A0
110 + "
111 +
112 +done
113 +test_done