Improve git-for-steve.sh script
authorSteve Youngs <steve@sxemacs.org>
Fri, 28 Feb 2020 05:58:24 +0000 (15:58 +1000)
committerSteve Youngs <steve@sxemacs.org>
Fri, 28 Feb 2020 05:58:24 +0000 (15:58 +1000)
* .gitattributes: New.

* contrib/git-for-steve.sh (set_diff): Try to get the function
name onto the diff hunk header. Set the git config to do the
magic.
(set_fsck): Set 'transfer.fsckObjects' in the config.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
.gitattributes [new file with mode: 0644]
contrib/git-for-steve.sh

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..03a37b3
--- /dev/null
@@ -0,0 +1,30 @@
+### Better diff hunk headers
+# Git's builtin diff hunk header styles.
+*.ad[abs] diff=ada
+*.[Cch] diff=cpp
+*.cc diff=cpp
+*.[ch]pp diff=cpp
+*.hh diff=cpp
+*.for diff=fortran
+*.html diff=html
+*.shtml diff=html
+*.xml diff=html
+*.java diff=java
+*.[HMm] diff=objc
+*.pas diff=pascal
+*.perl diff=perl
+*.pl diff=perl
+*.php diff=php
+*.py diff=python
+*.rb diff=ruby
+*.tex diff=tex
+
+# Snarfed this from FSF; see contrib/git-for-steve.sh
+*.el diff=elisp
+*.ac diff=m4
+*.m4 diff=m4
+*.mk diff=make
+*[Mm]akefile diff=make
+Makefile.in diff=make
+*[-.]sh diff=shell
+*.texi diff=texinfo
index 48b8884..ba66d91 100755 (executable)
@@ -518,6 +518,68 @@ EOF
     set_formats
 fi
 
+## Diff xfuncname
+set_diff()
+{
+    # Configure 'git diff' hunk header format. (lifted from FSF's
+    # autogen.sh)
+
+    # This xfuncname is based on Git's built-in 'cpp' pattern.
+    # The first line rejects jump targets and access declarations.
+    # The second line matches top-level functions and methods.
+    # The third line matches preprocessor and DEFUN macros.
+    [ -n "$(git config diff.cpp.xfuncname)" ] ||
+        git config diff.cpp.xfuncname \
+           '!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])
+^((::[[:space:]]*)?[A-Za-z_][A-Za-z_0-9]*[[:space:]]*\(.*)$
+^((#define[[:space:]]|DEFUN).*)$'
+    # Elisp
+    [ -n "$(git config diff.elisp.xfuncname)" ] ||
+        git config diff.elisp.xfuncname \
+           '^\([^[:space:]]*def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
+    # Texinfo
+    [ -n "$(git config diff.texinfo.xfuncname)" ] ||
+        git config diff.texinfo.xfuncname '^@node[[:space:]]+([^,[:space:]][^,]+)'
+
+    git config --bool sxemacs.diffunks true
+}
+
+BOOL=$(git config sxemacs.diffhunks)
+if [ "${BOOL}" != "true" ]; then
+    cat<<EOF
+
+**[Diff Hunk Headers]*************************************************
+git-diff can be configured to display a customised hunk header we, use
+that feature to try to always print the function name the hunk is 
+pointing to.  This will set the appropriate things in your config to 
+cover C, Elisp, and Texinfo.  But only if you have not already set
+these yourself.
+**********************************************************************
+EOF
+    echo -n "               Would you like more helpful diff hunk headers? [Y/n]: "
+    read HUNKS
+    if [ "${HUNKS}" = "Y" -o "${HUNKS}" = "y" -o "${HUNKS}" = "" ]; then
+       set_diff
+    fi
+fi
+
+## transfer.fsckObjects
+set_fsck()
+{
+    cat<<EOF
+
+**[Data Integrity]****************************************************
+The integrity of the data in our repo is of upmost importance to us.
+Having git check it automatically for us is a big help so we are going
+to set transfer.fsckObjects in your config.
+**********************************************************************
+EOF
+    echo -n "                            Hit [RETURN] to continue, or C-c to abort."
+    read junk
+    git config --bool transfer.fsckObjects true
+}
+git config transfer.fsckObjects || set_fsck
+
 ## Hooks
 set_hook()
 {