THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.6KB

  1. #!/bin/sh
  2. OPTIONS_KEEPDASHDASH=
  3. OPTIONS_STUCKLONG=
  4. OPTIONS_SPEC="\
  5. git quiltimport [options]
  6. --
  7. n,dry-run dry run
  8. author= author name and email address for patches without any
  9. patches= path to the quilt patches
  10. series= path to the quilt series file
  11. keep-non-patch Pass -b to git mailinfo
  12. "
  13. SUBDIRECTORY_ON=Yes
  14. . git-sh-setup
  15. dry_run=""
  16. quilt_author=""
  17. while test $# != 0
  18. do
  19. case "$1" in
  20. --author)
  21. shift
  22. quilt_author="$1"
  23. ;;
  24. -n|--dry-run)
  25. dry_run=1
  26. ;;
  27. --patches)
  28. shift
  29. QUILT_PATCHES="$1"
  30. ;;
  31. --series)
  32. shift
  33. QUILT_SERIES="$1"
  34. ;;
  35. --keep-non-patch)
  36. MAILINFO_OPT="-b"
  37. ;;
  38. --)
  39. shift
  40. break;;
  41. *)
  42. usage
  43. ;;
  44. esac
  45. shift
  46. done
  47. # Quilt Author
  48. if [ -n "$quilt_author" ] ; then
  49. quilt_author_name=$(expr "z$quilt_author" : 'z\(.*[^ ]\) *<.*') &&
  50. quilt_author_email=$(expr "z$quilt_author" : '.*<\([^>]*\)') &&
  51. test '' != "$quilt_author_name" &&
  52. test '' != "$quilt_author_email" ||
  53. die "malformed --author parameter"
  54. fi
  55. # Quilt patch directory
  56. : ${QUILT_PATCHES:=patches}
  57. if ! [ -d "$QUILT_PATCHES" ] ; then
  58. echo "The \"$QUILT_PATCHES\" directory does not exist."
  59. exit 1
  60. fi
  61. # Quilt series file
  62. : ${QUILT_SERIES:=$QUILT_PATCHES/series}
  63. if ! [ -e "$QUILT_SERIES" ] ; then
  64. echo "The \"$QUILT_SERIES\" file does not exist."
  65. exit 1
  66. fi
  67. # Temporary directories
  68. tmp_dir="$GIT_DIR"/rebase-apply
  69. tmp_msg="$tmp_dir/msg"
  70. tmp_patch="$tmp_dir/patch"
  71. tmp_info="$tmp_dir/info"
  72. # Find the initial commit
  73. commit=$(git rev-parse HEAD)
  74. mkdir $tmp_dir || exit 2
  75. while read patch_name level garbage <&3
  76. do
  77. case "$patch_name" in ''|'#'*) continue;; esac
  78. case "$level" in
  79. -p*) ;;
  80. ''|'#'*)
  81. level=;;
  82. *)
  83. echo "unable to parse patch level, ignoring it."
  84. level=;;
  85. esac
  86. case "$garbage" in
  87. ''|'#'*);;
  88. *)
  89. echo "trailing garbage found in series file: $garbage"
  90. exit 1;;
  91. esac
  92. if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
  93. echo "$patch_name doesn't exist. Skipping."
  94. continue
  95. fi
  96. echo $patch_name
  97. git mailinfo $MAILINFO_OPT "$tmp_msg" "$tmp_patch" \
  98. <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
  99. test -s "$tmp_patch" || {
  100. echo "Patch is empty. Was it split wrong?"
  101. exit 1
  102. }
  103. # Parse the author information
  104. GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
  105. GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
  106. export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
  107. while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
  108. if [ -n "$quilt_author" ] ; then
  109. GIT_AUTHOR_NAME="$quilt_author_name";
  110. GIT_AUTHOR_EMAIL="$quilt_author_email";
  111. elif [ -n "$dry_run" ]; then
  112. echo "No author found in $patch_name" >&2;
  113. GIT_AUTHOR_NAME="dry-run-not-found";
  114. GIT_AUTHOR_EMAIL="dry-run-not-found";
  115. else
  116. echo "No author found in $patch_name" >&2;
  117. echo "---"
  118. cat $tmp_msg
  119. printf "Author: ";
  120. read patch_author
  121. echo "$patch_author"
  122. patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') &&
  123. patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') &&
  124. test '' != "$patch_author_name" &&
  125. test '' != "$patch_author_email" &&
  126. GIT_AUTHOR_NAME="$patch_author_name" &&
  127. GIT_AUTHOR_EMAIL="$patch_author_email"
  128. fi
  129. done
  130. GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info")
  131. SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info")
  132. export GIT_AUTHOR_DATE SUBJECT
  133. if [ -z "$SUBJECT" ] ; then
  134. SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
  135. fi
  136. if [ -z "$dry_run" ] ; then
  137. git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
  138. tree=$(git write-tree) &&
  139. commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
  140. git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
  141. fi
  142. done 3<"$QUILT_SERIES"
  143. rm -rf $tmp_dir || exit 5