From e76a20316c26852aaa5cc6bff3989bffbda08171 Mon Sep 17 00:00:00 2001
From: Carlos O'Donell <carlos@systemhalted.org>
Date: Thu, 19 Apr 2018 14:01:54 -0500
Subject: [PATCH] Enable %autosetup -S git.

The following commit enables %autosetup -S git and simplifies working
with the glibc dist-git. We enable -S git which means that the
generated source tree is now a clean git repository with the spec
patches applied in order. This allows you to rebase or edit the
patches as if they were git commits, and therefore this is a complete
replacement for quilt.  This commit also removes the quilt support and
instead provides a README.git which explains how you can do all the
same things with git commands. As part of the conversion we
conditionalize the use of -S git for !bootstrap, since with git we
need BuildRequires: git, and we should avoid that for bootstrap.
Likewise git reveals we had extra whitespace in
glibc-c-utf8-locale.patch, which is now fixed.

Verified sources before and after are identical and that a scratch
build completes successfully (didn't when I tried the first time
becuase I needed BuildRequires: git for the use of -S git).
---
 README.git                | 44 ++++++++++++++++++++++++++++++++++++++++++++
 README.quilt              | 34 ----------------------------------
 gen-quilt-series.sh       | 34 ----------------------------------
 glibc-c-utf8-locale.patch | 13 ++++++-------
 glibc.spec                | 15 +++++++++++++--
 quilt-patch.sh            | 22 ----------------------
 6 files changed, 63 insertions(+), 99 deletions(-)
 create mode 100644 README.git
 delete mode 100644 README.quilt
 delete mode 100755 gen-quilt-series.sh
 delete mode 100755 quilt-patch.sh

diff --git a/README.git b/README.git
new file mode 100644
index 0000000..212df20
--- /dev/null
+++ b/README.git
@@ -0,0 +1,44 @@
+This package supports working with patch files using git (via %autosetup
+-S git).
+
+To start working with a local git patch repo run:
+fedpkg prep
+
+You can then enter the normal source tree and manipulate it as-if it
+were a git repository that contained only the patches applied as logical
+commits in the tree.
+
+To reorder patches use interactive rebasing:
+git rebase -i HEAD~N
+
+Where N is the number of commits back you want to rebase.
+
+With the interactive rebase you can move around the order the patches
+are applied in, apply them, and cleanup the fallout. Likewise you can
+edit patches this way, and then use `git format-patch` to output a new
+version of the patch.
+
+Create a new patch:
+cd glibc-2.27.9000-309-g583a27d525/
+<Manipulate file as you would with git to make a commit>
+git commit
+<Make the commit message as meaningful as you can>
+git format-patch HEAD~1
+<This outputs a patch file, if you edited another patch in the series
+ you can use `git format-patch REV^..REV` to output just that patch.>
+cd ..
+mv [git patch name] glibc-rhXXXXXX.patch
+#######################################################################
+# Please edit the patch file to follow template.patch format. It is
+# important we track the status of patches in Fedora and try to move
+# them upstream as soon as possible.
+#######################################################################
+<Then edit the glibc.spec file to build with the new patch>
+e.g.
+...
+PatchYYYY: glibc-rhXXXXXX.patch
+...
+git add glibc.spec
+git commit
+
+You're done!
diff --git a/README.quilt b/README.quilt
deleted file mode 100644
index 7b67937..0000000
--- a/README.quilt
+++ /dev/null
@@ -1,34 +0,0 @@
-This package supports working with patch files using quilt.
-
-To regenerate the quilt series file run:
-./gen-quilt-series.sh
-
-Setup environment:
-export QUILT_PATCHES=$PWD
-
-Setup the source:
-./quilt-patch.sh [-f]
-
-Use `-f` if you want to have quilt-patch always remove the existing
-source directory before starting. Otherwise you'll be patching on top of
-an already patched tree generated perhaps by `*pkg prep`.
-
-Create a new patch:
-cd glibc-2.17-c758a686/
-quilt new glibc-rh1234622.patch
-quilt add ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist
-vi ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist
-quilt refresh
-cd ..
-git add glibc-rh1234622.patch
-<Then edit the glibc.spec file to build with the new patch>
-e.g.
-...
-PatchXXXX: glibc-rh1234622.patch
-...
-%patchXXXX -p1
-...
-git add glibc.spec
-git commit
-
-You're done!
diff --git a/gen-quilt-series.sh b/gen-quilt-series.sh
deleted file mode 100755
index 3262fba..0000000
--- a/gen-quilt-series.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-# Autogeneries the quilt `series` from the patch order in the spec file.
-# We don't use `quilt setup` because it makes a huge mess and doesn't work.
-component="glibc"
-rm -f series.new
-extra_args="--fuzz=0"
-count=0
-# Filter out the patches, and use `_` as our pseudo-IFS to prevent expansion.
-for i in `grep '^%patch' glibc.spec | sed -e 's,%patch,,g' -e 's, ,_,g'`; do
-    # Split the patch into number and arguments.
-    # 1 - Patch number.
-    # 2-N - Patch arguments.
-    # Get back our elements by undoing pseudo-IFS change.
-    elements=(`echo $i | sed -e 's,_, ,g'`)
-    num=${elements[0]}
-    args=${elements[@]:1}
-    # Find the next patch that applies in order and write it out.
-    # This way we transform the patch # list into a patch file list in order.
-    grep "Patch${num}: " glibc.spec \
-	| sed -e 's,Patch.*: ,,g' -e "s,\$, ${args[@]} ${extra_args},g" \
-	| sed -e "s,%{name},${component},g" \
-	>> series.new
-    ((count++))
-done
-# Double check we processed the correct number of patches.
-fcount=`wc -l series.new | sed -e 's, .*$,,g'`
-if [ $fcount -ne $count ]; then
-    echo "Error! Processed patch count doesn't match spec file count ($fcount != $count)."
-    exit 1
-fi
-echo "Processed $count patches."
-mv series.new series
-echo "Generated quilt ./series file. Please do not commit."
-exit 0
diff --git a/glibc-c-utf8-locale.patch b/glibc-c-utf8-locale.patch
index 7215e15..db56b17 100644
--- a/glibc-c-utf8-locale.patch
+++ b/glibc-c-utf8-locale.patch
@@ -21,12 +21,12 @@ Subject: [PATCH] Add a C.UTF-8 locale
 
 ---
  localedata/SUPPORTED |   1 +
- localedata/locales/C | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++
- 2 files changed, 239 insertions(+)
+ localedata/locales/C | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 238 insertions(+)
  create mode 100644 localedata/locales/C
 
 diff --git a/localedata/SUPPORTED b/localedata/SUPPORTED
-index 8ca023e..2a78391 100644
+index 7d26c46..a8e5a0c 100644
 --- a/localedata/SUPPORTED
 +++ b/localedata/SUPPORTED
 @@ -1,6 +1,7 @@
@@ -39,10 +39,10 @@ index 8ca023e..2a78391 100644
  aa_ER/UTF-8 \
 diff --git a/localedata/locales/C b/localedata/locales/C
 new file mode 100644
-index 0000000..fdf460e
+index 0000000..3ae76a1
 --- /dev/null
 +++ b/localedata/locales/C
-@@ -0,0 +1,238 @@
+@@ -0,0 +1,237 @@
 +escape_char /
 +comment_char %
 +% Locale for C locale in UTF-8
@@ -280,7 +280,6 @@ index 0000000..fdf460e
 +%metric
 +measurement    1
 +END LC_MEASUREMENT
-+
 -- 
-2.4.3
+2.14.3
 
diff --git a/glibc.spec b/glibc.spec
index 052608c..46cbf1d 100644
--- a/glibc.spec
+++ b/glibc.spec
@@ -174,6 +174,11 @@ Requires: glibc-common = %{version}-%{release}
 
 Requires(pre): basesystem
 
+# We use autosetup with -S git.
+%if %{without bootstrap}
+BuildRequires: git
+%endif
+
 # This is for building auxiliary programs like memusage, nscd
 # For initial glibc bootstraps it can be commented out
 %if %{without bootstrap}
@@ -657,13 +662,15 @@ microbenchmark tests on the system.
 # Prepare for the build.
 ##############################################################################
 %prep
+%if %{without bootstrap}
+%autosetup -S git -n %{glibcsrcdir} -p1
+%else
 %autosetup -n %{glibcsrcdir} -p1
+%endif
 
 ##############################################################################
 # %%prep - Additional prep required...
 ##############################################################################
-# Make benchmark scripts executable
-chmod +x benchtests/scripts/*.py scripts/pylint
 
 # Remove all files generated from patching.
 find . -type f -size 0 -o -name "*.orig" -exec rm -f {} \;
@@ -1842,6 +1849,10 @@ fi
 
 %if %{with benchtests}
 %files benchtests -f benchtests.filelist
+%attr(0755,root,root) /usr/libexec/glibc-benchtests/compare_bench.py
+%attr(0755,root,root) /usr/libexec/glibc-benchtests/import_bench.py
+%attr(0755,root,root) /usr/libexec/glibc-benchtests/validate_benchout.py
+%attr(0755,root,root) /usr/libexec/glibc-benchtests/glibc-bench-compare
 %endif
 
 %changelog
diff --git a/quilt-patch.sh b/quilt-patch.sh
deleted file mode 100755
index eaf24d5..0000000
--- a/quilt-patch.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-# Patches are in the current directory.
-export QUILT_PATCHES=$PWD
-# Extract source file name from sources file,
-# and assume it's the same name as the directory.
-source=`awk -F '[() ]+'  '/^[A-Z0-9]+ /{print $2}; /^[0-9a-f]+ /{print $2}' sources`
-srcdir=${source%.tar.gz}
-if [ "$1" == "-f" ] && [ -d "$srcdir" ]; then
-    echo Cleaning up $srcdir
-    rm -rf $srcdir
-fi
-if [ -d "$srcdir" ]; then
-    # Don't overwrite existing source directory.
-    echo "ERROR: Source directory $srcdir already exists. Use -f to force cleanup step."
-    exit 1
-fi
-tar zxvf $source
-echo "Entering $srcdir"
-pushd $srcdir
-# Apply all patches.
-quilt push -a
-popd
-- 
2.14.3

