PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/t/t9301-fast-import-notes.sh

https://gitlab.com/nmusco/git
Shell | 682 lines | 571 code | 95 blank | 16 comment | 56 complexity | 3a397ac6fae886cf172a570385c08927 MD5 | raw file
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2009 Johan Herland
  4. #
  5. test_description='test git fast-import of notes objects'
  6. . ./test-lib.sh
  7. test_tick
  8. cat >input <<INPUT_END
  9. commit refs/heads/master
  10. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  11. data <<COMMIT
  12. first commit
  13. COMMIT
  14. M 644 inline foo
  15. data <<EOF
  16. file foo in first commit
  17. EOF
  18. M 755 inline bar
  19. data <<EOF
  20. file bar in first commit
  21. EOF
  22. M 644 inline baz/xyzzy
  23. data <<EOF
  24. file baz/xyzzy in first commit
  25. EOF
  26. commit refs/heads/master
  27. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  28. data <<COMMIT
  29. second commit
  30. COMMIT
  31. M 644 inline foo
  32. data <<EOF
  33. file foo in second commit
  34. EOF
  35. M 755 inline baz/xyzzy
  36. data <<EOF
  37. file baz/xyzzy in second commit
  38. EOF
  39. commit refs/heads/master
  40. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  41. data <<COMMIT
  42. third commit
  43. COMMIT
  44. M 644 inline foo
  45. data <<EOF
  46. file foo in third commit
  47. EOF
  48. commit refs/heads/master
  49. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  50. data <<COMMIT
  51. fourth commit
  52. COMMIT
  53. M 755 inline bar
  54. data <<EOF
  55. file bar in fourth commit
  56. EOF
  57. INPUT_END
  58. test_expect_success 'set up master branch' '
  59. git fast-import <input &&
  60. git whatchanged master
  61. '
  62. commit4=$(git rev-parse refs/heads/master)
  63. commit3=$(git rev-parse "$commit4^")
  64. commit2=$(git rev-parse "$commit4~2")
  65. commit1=$(git rev-parse "$commit4~3")
  66. test_tick
  67. cat >input <<INPUT_END
  68. commit refs/notes/test
  69. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  70. data <<COMMIT
  71. first notes commit
  72. COMMIT
  73. M 644 inline $commit1
  74. data <<EOF
  75. first note for first commit
  76. EOF
  77. M 755 inline $commit2
  78. data <<EOF
  79. first note for second commit
  80. EOF
  81. INPUT_END
  82. cat >expect <<EXPECT_END
  83. fourth commit
  84. third commit
  85. second commit
  86. first note for second commit
  87. first commit
  88. first note for first commit
  89. EXPECT_END
  90. test_expect_success 'add notes with simple M command' '
  91. git fast-import <input &&
  92. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  93. test_cmp expect actual
  94. '
  95. test_tick
  96. cat >input <<INPUT_END
  97. feature notes
  98. commit refs/notes/test
  99. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  100. data <<COMMIT
  101. second notes commit
  102. COMMIT
  103. from refs/notes/test^0
  104. N inline $commit3
  105. data <<EOF
  106. first note for third commit
  107. EOF
  108. N inline $commit4
  109. data <<EOF
  110. first note for fourth commit
  111. EOF
  112. INPUT_END
  113. cat >expect <<EXPECT_END
  114. fourth commit
  115. first note for fourth commit
  116. third commit
  117. first note for third commit
  118. second commit
  119. first note for second commit
  120. first commit
  121. first note for first commit
  122. EXPECT_END
  123. test_expect_success 'add notes with simple N command' '
  124. git fast-import <input &&
  125. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  126. test_cmp expect actual
  127. '
  128. test_tick
  129. cat >input <<INPUT_END
  130. commit refs/notes/test
  131. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  132. data <<COMMIT
  133. third notes commit
  134. COMMIT
  135. from refs/notes/test^0
  136. N inline $commit1
  137. data <<EOF
  138. second note for first commit
  139. EOF
  140. N inline $commit2
  141. data <<EOF
  142. second note for second commit
  143. EOF
  144. N inline $commit3
  145. data <<EOF
  146. second note for third commit
  147. EOF
  148. N inline $commit4
  149. data <<EOF
  150. second note for fourth commit
  151. EOF
  152. INPUT_END
  153. cat >expect <<EXPECT_END
  154. fourth commit
  155. second note for fourth commit
  156. third commit
  157. second note for third commit
  158. second commit
  159. second note for second commit
  160. first commit
  161. second note for first commit
  162. EXPECT_END
  163. test_expect_success 'update existing notes with N command' '
  164. git fast-import <input &&
  165. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  166. test_cmp expect actual
  167. '
  168. test_tick
  169. cat >input <<INPUT_END
  170. commit refs/notes/test
  171. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  172. data <<COMMIT
  173. fourth notes commit
  174. COMMIT
  175. from refs/notes/test^0
  176. M 644 inline $(echo "$commit3" | sed "s|^..|&/|")
  177. data <<EOF
  178. prefix of note for third commit
  179. EOF
  180. M 644 inline $(echo "$commit4" | sed "s|^..|&/|")
  181. data <<EOF
  182. prefix of note for fourth commit
  183. EOF
  184. M 644 inline $(echo "$commit4" | sed "s|^\(..\)\(..\)|\1/\2/|")
  185. data <<EOF
  186. pre-prefix of note for fourth commit
  187. EOF
  188. N inline $commit1
  189. data <<EOF
  190. third note for first commit
  191. EOF
  192. N inline $commit2
  193. data <<EOF
  194. third note for second commit
  195. EOF
  196. N inline $commit3
  197. data <<EOF
  198. third note for third commit
  199. EOF
  200. N inline $commit4
  201. data <<EOF
  202. third note for fourth commit
  203. EOF
  204. INPUT_END
  205. whitespace=" "
  206. cat >expect <<EXPECT_END
  207. fourth commit
  208. pre-prefix of note for fourth commit
  209. $whitespace
  210. prefix of note for fourth commit
  211. $whitespace
  212. third note for fourth commit
  213. third commit
  214. prefix of note for third commit
  215. $whitespace
  216. third note for third commit
  217. second commit
  218. third note for second commit
  219. first commit
  220. third note for first commit
  221. EXPECT_END
  222. test_expect_success 'add concatentation notes with M command' '
  223. git fast-import <input &&
  224. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  225. test_cmp expect actual
  226. '
  227. test_tick
  228. cat >input <<INPUT_END
  229. commit refs/notes/test
  230. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  231. data <<COMMIT
  232. fifth notes commit
  233. COMMIT
  234. from refs/notes/test^0
  235. deleteall
  236. INPUT_END
  237. cat >expect <<EXPECT_END
  238. fourth commit
  239. third commit
  240. second commit
  241. first commit
  242. EXPECT_END
  243. test_expect_success 'verify that deleteall also removes notes' '
  244. git fast-import <input &&
  245. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  246. test_cmp expect actual
  247. '
  248. test_tick
  249. cat >input <<INPUT_END
  250. commit refs/notes/test
  251. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  252. data <<COMMIT
  253. sixth notes commit
  254. COMMIT
  255. from refs/notes/test^0
  256. M 644 inline $commit1
  257. data <<EOF
  258. third note for first commit
  259. EOF
  260. M 644 inline $commit3
  261. data <<EOF
  262. third note for third commit
  263. EOF
  264. N inline $commit1
  265. data <<EOF
  266. fourth note for first commit
  267. EOF
  268. N inline $commit3
  269. data <<EOF
  270. fourth note for third commit
  271. EOF
  272. INPUT_END
  273. cat >expect <<EXPECT_END
  274. fourth commit
  275. third commit
  276. fourth note for third commit
  277. second commit
  278. first commit
  279. fourth note for first commit
  280. EXPECT_END
  281. test_expect_success 'verify that later N commands override earlier M commands' '
  282. git fast-import <input &&
  283. GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
  284. test_cmp expect actual
  285. '
  286. # Write fast-import commands to create the given number of commits
  287. fast_import_commits () {
  288. my_ref=$1
  289. my_num_commits=$2
  290. my_append_to_file=$3
  291. my_i=0
  292. while test $my_i -lt $my_num_commits
  293. do
  294. my_i=$(($my_i + 1))
  295. test_tick
  296. cat >>"$my_append_to_file" <<INPUT_END
  297. commit $my_ref
  298. mark :$my_i
  299. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  300. data <<COMMIT
  301. commit #$my_i
  302. COMMIT
  303. M 644 inline file
  304. data <<EOF
  305. file contents in commit #$my_i
  306. EOF
  307. INPUT_END
  308. done
  309. }
  310. # Write fast-import commands to create the given number of notes annotating
  311. # the commits created by fast_import_commits()
  312. fast_import_notes () {
  313. my_notes_ref=$1
  314. my_num_commits=$2
  315. my_append_to_file=$3
  316. my_note_append=$4
  317. test_tick
  318. cat >>"$my_append_to_file" <<INPUT_END
  319. commit $my_notes_ref
  320. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  321. data <<COMMIT
  322. committing $my_num_commits notes
  323. COMMIT
  324. INPUT_END
  325. my_i=0
  326. while test $my_i -lt $my_num_commits
  327. do
  328. my_i=$(($my_i + 1))
  329. cat >>"$my_append_to_file" <<INPUT_END
  330. N inline :$my_i
  331. data <<EOF
  332. note for commit #$my_i$my_note_append
  333. EOF
  334. INPUT_END
  335. done
  336. }
  337. rm input expect
  338. num_commits=400
  339. # Create lots of commits
  340. fast_import_commits "refs/heads/many_commits" $num_commits input
  341. # Create one note per above commit
  342. fast_import_notes "refs/notes/many_notes" $num_commits input
  343. # Add a couple of non-notes as well
  344. test_tick
  345. cat >>input <<INPUT_END
  346. commit refs/notes/many_notes
  347. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  348. data <<COMMIT
  349. committing some non-notes to the notes tree
  350. COMMIT
  351. M 755 inline foobar/non-note.txt
  352. data <<EOF
  353. This is not a note, but rather a regular file residing in a notes tree
  354. EOF
  355. M 644 inline deadbeef
  356. data <<EOF
  357. Non-note file
  358. EOF
  359. M 644 inline de/adbeef
  360. data <<EOF
  361. Another non-note file
  362. EOF
  363. INPUT_END
  364. # Finally create the expected output from all these notes and commits
  365. i=$num_commits
  366. while test $i -gt 0
  367. do
  368. cat >>expect <<EXPECT_END
  369. commit #$i
  370. note for commit #$i
  371. EXPECT_END
  372. i=$(($i - 1))
  373. done
  374. test_expect_success 'add lots of commits and notes' '
  375. git fast-import <input &&
  376. GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
  377. grep "^ " > actual &&
  378. test_cmp expect actual
  379. '
  380. test_expect_success 'verify that lots of notes trigger a fanout scheme' '
  381. # None of the entries in the top-level notes tree should be a full SHA1
  382. git ls-tree --name-only refs/notes/many_notes |
  383. while read path
  384. do
  385. if test $(expr length "$path") -ge 40
  386. then
  387. return 1
  388. fi
  389. done
  390. '
  391. cat >>expect_non-note1 << EOF
  392. This is not a note, but rather a regular file residing in a notes tree
  393. EOF
  394. cat >>expect_non-note2 << EOF
  395. Non-note file
  396. EOF
  397. cat >>expect_non-note3 << EOF
  398. Another non-note file
  399. EOF
  400. test_expect_success 'verify that non-notes are untouched by a fanout change' '
  401. git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
  402. test_cmp expect_non-note1 actual &&
  403. git cat-file -p refs/notes/many_notes:deadbeef > actual &&
  404. test_cmp expect_non-note2 actual &&
  405. git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
  406. test_cmp expect_non-note3 actual
  407. '
  408. # Change the notes for the three top commits
  409. test_tick
  410. cat >input <<INPUT_END
  411. commit refs/notes/many_notes
  412. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  413. data <<COMMIT
  414. changing notes for the top three commits
  415. COMMIT
  416. from refs/notes/many_notes^0
  417. INPUT_END
  418. rm expect
  419. i=$num_commits
  420. j=0
  421. while test $j -lt 3
  422. do
  423. cat >>input <<INPUT_END
  424. N inline refs/heads/many_commits~$j
  425. data <<EOF
  426. changed note for commit #$i
  427. EOF
  428. INPUT_END
  429. cat >>expect <<EXPECT_END
  430. commit #$i
  431. changed note for commit #$i
  432. EXPECT_END
  433. i=$(($i - 1))
  434. j=$(($j + 1))
  435. done
  436. test_expect_success 'change a few existing notes' '
  437. git fast-import <input &&
  438. GIT_NOTES_REF=refs/notes/many_notes git log -n3 refs/heads/many_commits |
  439. grep "^ " > actual &&
  440. test_cmp expect actual
  441. '
  442. test_expect_success 'verify that changing notes respect existing fanout' '
  443. # None of the entries in the top-level notes tree should be a full SHA1
  444. git ls-tree --name-only refs/notes/many_notes |
  445. while read path
  446. do
  447. if test $(expr length "$path") -ge 40
  448. then
  449. return 1
  450. fi
  451. done
  452. '
  453. remaining_notes=10
  454. test_tick
  455. cat >input <<INPUT_END
  456. commit refs/notes/many_notes
  457. committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  458. data <<COMMIT
  459. removing all notes but $remaining_notes
  460. COMMIT
  461. from refs/notes/many_notes^0
  462. INPUT_END
  463. i=$(($num_commits - $remaining_notes))
  464. for sha1 in $(git rev-list -n $i refs/heads/many_commits)
  465. do
  466. cat >>input <<INPUT_END
  467. N 0000000000000000000000000000000000000000 $sha1
  468. INPUT_END
  469. done
  470. i=$num_commits
  471. rm expect
  472. while test $i -gt 0
  473. do
  474. cat >>expect <<EXPECT_END
  475. commit #$i
  476. EXPECT_END
  477. if test $i -le $remaining_notes
  478. then
  479. cat >>expect <<EXPECT_END
  480. note for commit #$i
  481. EXPECT_END
  482. fi
  483. i=$(($i - 1))
  484. done
  485. test_expect_success 'remove lots of notes' '
  486. git fast-import <input &&
  487. GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
  488. grep "^ " > actual &&
  489. test_cmp expect actual
  490. '
  491. test_expect_success 'verify that removing notes trigger fanout consolidation' '
  492. # All entries in the top-level notes tree should be a full SHA1
  493. git ls-tree --name-only -r refs/notes/many_notes |
  494. while read path
  495. do
  496. # Explicitly ignore the non-note paths
  497. test "$path" = "foobar/non-note.txt" && continue
  498. test "$path" = "deadbeef" && continue
  499. test "$path" = "de/adbeef" && continue
  500. if test $(expr length "$path") -ne 40
  501. then
  502. return 1
  503. fi
  504. done
  505. '
  506. test_expect_success 'verify that non-notes are untouched by a fanout change' '
  507. git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
  508. test_cmp expect_non-note1 actual &&
  509. git cat-file -p refs/notes/many_notes:deadbeef > actual &&
  510. test_cmp expect_non-note2 actual &&
  511. git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
  512. test_cmp expect_non-note3 actual
  513. '
  514. rm input expect
  515. num_notes_refs=10
  516. num_commits=16
  517. some_commits=8
  518. # Create commits
  519. fast_import_commits "refs/heads/more_commits" $num_commits input
  520. # Create one note per above commit per notes ref
  521. i=0
  522. while test $i -lt $num_notes_refs
  523. do
  524. i=$(($i + 1))
  525. fast_import_notes "refs/notes/more_notes_$i" $num_commits input
  526. done
  527. # Trigger branch reloading in git-fast-import by repeating the note creation
  528. i=0
  529. while test $i -lt $num_notes_refs
  530. do
  531. i=$(($i + 1))
  532. fast_import_notes "refs/notes/more_notes_$i" $some_commits input " (2)"
  533. done
  534. # Finally create the expected output from the notes in refs/notes/more_notes_1
  535. i=$num_commits
  536. while test $i -gt 0
  537. do
  538. note_data="note for commit #$i"
  539. if test $i -le $some_commits
  540. then
  541. note_data="$note_data (2)"
  542. fi
  543. cat >>expect <<EXPECT_END
  544. commit #$i
  545. $note_data
  546. EXPECT_END
  547. i=$(($i - 1))
  548. done
  549. test_expect_success "add notes to $num_commits commits in each of $num_notes_refs refs" '
  550. git fast-import --active-branches=5 <input &&
  551. GIT_NOTES_REF=refs/notes/more_notes_1 git log refs/heads/more_commits |
  552. grep "^ " > actual &&
  553. test_cmp expect actual
  554. '
  555. test_done