Commit f5dd7ce1 authored by Stefan Tauner's avatar Stefan Tauner

Convert flashrom to git

 - Drop support for Subversion in the getrevision script and Makefile.
 - Add .gitignore and .gitattributes file (the latter to limit exports).
 - Restore modification dates of the exported files from the SCM.
 - Stop exporting SCM log dumps to CHANGELOG. This makes no sense.
 - Remove djgpp-dos target (it is not different to other x-compilations).
 - Do not export the pre-"compiled" manpage. It can be generated like
   anything else from the code dump when we export the respective variable.
   The latter is added with this change.
 - Add some initial client-side git hooks
   * When committing check for obvious stuff you never want anyway:
     - white space errors
     - duplicate sign-offs
   * When pushing to the upstream repository check mandatory rules:
      - existing signoffs and acks in all new commits
      - no deletions or creation of branches
      - do not rewrite history of the precious branches, even if forced
 - Change version string of flashrom as follows.
   Previously, we included the last stable version according to a hard-
   coded string in the Makefile and appended the subversion revision number.

   With this patch the version string includes the last reachable git tag,
   number of commits since said tag in the upstream branches (if any),
   the name of said upstream branch, number of commits since that branch
   (if any), and the shortened git hash.
   In case there are uncommitted changes a "-dirty" indicator is also added.
   The case of unknown versions is explicitly handled in getrevision instead
   of simply appending "-unknown" to a hardcoded release number.

   The version information is either taken from an existing git remote
   pointing to an upstream repository (or a known mirror), or if that
   is not available - with the user's consent - a shadow copy is fetched
   from the upstream repo that is updated on every build (usually takes
   less than a second).

In the following some examples of the version string changes are shown.
Basically we print the distance to the last known upstream tag, which
comprises any upstream commits since that tag as well as local commits on
top of that. Additionally we handle upstream's stable and staging branches
specially.

Old output:
flashrom v0.9.7-r1716 on Linux 3.8.0-6-generic (x86_64)

New output variants:

Build of the 0.9.99 release without any changes:
flashrom v0.9.99-e4f6643 on Linux 3.13.0-76-generic (x86_64)

5 commits since last tag in upstream's stable branch:
flashrom v0.9.99-5-stable-e4f6643-dirty on Linux 3.13.0-76-generic (x86_64)

3 commits since last tag in upstream's staging branch and
4 local commits on top of that:
flashrom v0.9.99-3-staging-4-e4f6643 on Linux 3.13.0-76-generic (x86_64)

3 commits since last tag in upstream's staging branch and
4 local commits on top of that, and some local uncommitted changes too:
flashrom v0.9.99-3-staging-4-e4f6643-dirty on Linux 3.13.0-76-generic (x86_64)

3 commits since the last tag in an unrelated upstream branch
(e.g., a stable release *branch* such as 0.9.99.x) or local branch:
flashrom v0.9.99-3-e4f6643 on Linux 3.13.0-76-generic (x86_64)

No tags reachable from current commit (generic git fallback):
flashrom d95935a version on Linux 3.13.0-76-generic (x86_64)

Not in a repository:
flashrom unknown version on Linux 3.13.0-76-generic (x86_64)
Signed-off-by: default avatarStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: default avatarStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
parent 40ba6fd0
.gitattributes export-ignore
.gitignore export-ignore
/util/getrevision.sh export-ignore
/util/git-hooks export-ignore
/util/git-hooks/** export-ignore
*.d
*.o
/.features
/.dependencies
/.libdeps
/build_details.txt
/flashrom
/flashrom-*
/flashrom.exe
/flashrom.8
/util/ich_descriptors_tool/ich_descriptors_tool
/util/ich_descriptors_tool/ich_descriptors_tool.exe
/util/ich_descriptors_tool/.dep
/util/ich_descriptors_tool/.obj
......@@ -526,23 +526,27 @@ LIB_OBJS = layout.o flashrom.o udelay.o programmer.o helpers.o
CLI_OBJS = cli_classic.o cli_output.o cli_common.o print.o
# Set the flashrom version string from the highest revision number of the checked out flashrom files.
# Set the flashrom version string from the repository metadata (cf. util/getrevision.sh).
# Note to packagers: Any tree exported with "make export" or "make tarball"
# will not require subversion. The downloadable snapshots are already exported.
SVNVERSION := $(shell ./util/getrevision.sh -u 2>/dev/null )
RELEASE := 0.9.9
VERSION := $(RELEASE)-$(SVNVERSION)
RELEASENAME ?= $(VERSION)
# will not require git. The downloadable snapshots are already exported.
VERSION := $(shell ./util/getrevision.sh --revision)
# VERSION equals "offline" if online access is required but the respective git config variable is not set yet.
ifeq ($(VERSION),offline)
$(error Aborting)
endif
SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"'
SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
# No spaces in release names unless set explicitly
RELEASENAME ?= $(shell echo "$(VERSION)" | sed -e 's/ /_/')
# Inform user if there is no meaningful version string. If there is version information from a VCS print
# Inform user about the version string used. If there is no version information from a VCS then print
# something anyway because $(info...) will print a line break in any case which would look suspicious.
# The && between the echos is a workaround for old versions of GNU make that issue the error "unterminated
# variable reference" if a semicolon is used instead.
$(info $(shell ./util/getrevision.sh -c 2>/dev/null || echo "Files don't seem to be under version control." && \
echo "Replacing all version templates with $(VERSION)." ))
# Also, if a VCS is found then try to install hooks.
$(info $(shell ./util/getrevision.sh -c 2>/dev/null && ./util/git-hooks/install.sh || \
echo "Files don't seem to be under version control." && \
echo "Replacing all version templates with $(VERSION)."))
###############################################################################
# Default settings of CONFIG_* variables.
......@@ -1024,7 +1028,7 @@ libflashrom.a: $(LIBFLASHROM_OBJS)
TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
%.o: %.c .features
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@ -c $<
$(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o $@ -c $<
# Make sure to add all names of generated binaries here.
# This includes all frontends and libflashrom.
......@@ -1347,9 +1351,10 @@ endif
$(PROGRAM).8.html: $(PROGRAM).8
@groff -mandoc -Thtml $< >$@
MAN_DATE := $(shell ./util/getrevision.sh -d $(PROGRAM).8.tmpl 2>/dev/null)
$(PROGRAM).8: $(PROGRAM).8.tmpl
@# Add the man page change date and version to the man page
@sed -e 's#.TH FLASHROM 8 ".*".*#.TH FLASHROM 8 "$(shell ./util/getrevision.sh -d $(PROGRAM).8.tmpl 2>/dev/null)" "$(VERSION)"#' <$< >$@
@sed -e 's#.TH FLASHROM 8 .*#.TH FLASHROM 8 "$(MAN_DATE)" "$(VERSION)" "$(MAN_DATE)"#' <$< >$@
install: $(PROGRAM)$(EXEC_SUFFIX) $(PROGRAM).8
mkdir -p $(DESTDIR)$(PREFIX)/sbin
......@@ -1357,25 +1362,38 @@ install: $(PROGRAM)$(EXEC_SUFFIX) $(PROGRAM).8
$(INSTALL) -m 0755 $(PROGRAM)$(EXEC_SUFFIX) $(DESTDIR)$(PREFIX)/sbin
$(INSTALL) -m 0644 $(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
export: $(PROGRAM).8
@rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
@sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@cp $(PROGRAM).8 "$(EXPORTDIR)/flashrom-$(RELEASENAME)/$(PROGRAM).8"
@svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
tarball: export
@tar cjf $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2 -C $(EXPORTDIR)/ $(TAROPTIONS) flashrom-$(RELEASENAME)/
_export: $(PROGRAM).8
@rm -rf "$(EXPORTDIR)/flashrom-$(RELEASENAME)"
@mkdir -p "$(EXPORTDIR)/flashrom-$(RELEASENAME)"
@git archive HEAD | tar -x -C "$(EXPORTDIR)/flashrom-$(RELEASENAME)"
@sed -e 's/^VERSION :=.*/VERSION := $(VERSION)/' \
-e 's/^MAN_DATE :=.*/MAN_DATE := $(MAN_DATE)/' \
-e 's#./util/getrevision.sh -c#false#' \
Makefile >"$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile"
# Restore modification date of all tracked files not marked 'export-ignore' in .gitattributes.
# sed is required to filter out file names having the attribute set.
@git ls-tree -r -z -t --full-name --name-only HEAD | \
git check-attr -z --stdin export-ignore | \
sed -zne 'x;n;n;s/^set$$//;t;x;p' | \
xargs -0 sh -c 'for f; do \
touch -d $$(git log --pretty=format:%cI -1 HEAD -- "$$f") \
"$(EXPORTDIR)/flashrom-$(RELEASENAME)/$$f"; \
done'
export: _export
@echo "Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/"
tarball: _export
@tar -cz --format=ustar -f $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.gz -C $(EXPORTDIR)/ \
$(TAROPTIONS) flashrom-$(RELEASENAME)/
# Delete the exported directory again because it is most likely what's expected by the user.
@rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
@echo Created $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2
@echo Created $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.gz
djgpp-dos: clean
make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip
libpayload: clean
make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
.PHONY: all install clean distclean compiler hwlibs features export tarball djgpp-dos featuresavailable libpayload
.PHONY: all install clean distclean compiler hwlibs features _export export tarball featuresavailable libpayload
# Disable implicit suffixes and built-in rules (for performance and profit)
.SUFFIXES:
......
......@@ -1801,7 +1801,7 @@ void print_buildinfo(void)
void print_version(void)
{
msg_ginfo("flashrom v%s", flashrom_version);
msg_ginfo("flashrom %s", flashrom_version);
print_sysinfo();
msg_ginfo("\n");
}
......
This diff is collapsed.
#!/bin/sh
#
# A hook script to check the commit log message taken by
# applypatch from an e-mail message (via git-am).
# We simply do the same as for other commit messages
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit. The hook is
# allowed to edit the commit message file.
#
. git-sh-setup
test -x "$GIT_DIR/hooks/commit-msg" &&
exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
:
#!/bin/sh
#
# A hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# Catches duplicate Signed-off-by lines.
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo "Duplicate Signed-off-by lines." >&2
exit 1
}
#!/bin/sh -e
root=$(git rev-parse --show-cdup 2>/dev/null) || \
{ echo "Not under git control. Cannot install git hooks." >&2 ; exit 0 ; }
dst="${root}"$(git rev-parse --git-path hooks/)
src=util/git-hooks/ # relative to root
hooks=$(cd "${root}${src}" && git ls-files -c | grep -Ev 'install.sh|wrapper.sh')
for h in $hooks; do
# Test if hook is not already installed, i.e. doesn't point at the wrapper
if [ ! "${dst}$h" -ef "${root}${src}wrapper.sh" ]; then
# preserve custom hooks if any
if [ -e "${dst}$h" ]; then
mv "${dst}$h" "${dst}$h.local"
fi
ln -s "../../${src}wrapper.sh" "${dst}$h"
fi
done
#!/bin/sh
#
# An example hook script to verify what is about to be committed
# by applypatch from an e-mail message.
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit.
. git-sh-setup
test -x "$GIT_DIR/hooks/pre-commit" &&
exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
:
#!/bin/sh
#
# A hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# Check for whitespace errors
git diff-index --check --cached HEAD -- || exit 1
#!/bin/sh
# A hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
# pushed. If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local sha1> <remote ref> <remote sha1>
remote="$1"
url="$2"
zero=0000000000000000000000000000000000000000
upstream_pattern="github\.com.flashrom/flashrom(\.git)?|flashrom\.org.git/flashrom(\.git)?"
precious_branches=( stable staging )
# Only care about the upstream repository
if echo "$url" | grep -q -v -E "$upstream_pattern" ; then
exit 0
fi
while read local_ref local_sha remote_ref remote_sha ; do
if [ "$remote_ref" != "refs/heads/staging" -a "$remote_ref" != "refs/heads/stable" ]; then
echo "Feature branches not allowed ($remote_ref)." >&2
exit 1
fi
if [ "$local_sha" = $zero ]; then
echo "Deletion of branches is prohibited." >&2
exit 1
else
if [ "$remote_sha" = "$zero" ]; then
echo "No new branches allowed." >&2
exit 1
else
range="$remote_sha..$local_sha"
fi
# Check for Signed-off-by and Acked-by
commit=$(git rev-list -n 1 --all-match --invert-grep -E \
--grep '^Signed-off-by: .+ <.+@.+\..+>$' --grep '^Acked-by: .+ <.+@.+\..+>$' "$range")
if [ -n "$commit" ]; then
echo "No Signoff or Ack found in commit $local_sha in $local_ref, not pushing." >&2
exit 1
fi
# Make _really_ sure we do not rewrite precious history
for lbranch in "${precious_branches[@]}"; do
if [ "$remote_ref" = "refs/heads/$lbranch" ]; then
nonreachable=$(git rev-list $remote_sha ^$local_sha)
if [ -n "$nonreachable" ]; then
echo "Only fast-forward pushes are allowed on $lbranch." >&2
echo "$nonreachable is not included in $remote_sha while pusing to $remote_ref" >&2
exit 1
fi
fi
done
# FIXME: check commit log format (subject without full stop at the end etc).
# FIXME: do buildbot checks if authorized?
fi
done
exit 0
#!/bin/sh
if [ -x $0.local ]; then
$0.local "$@" || exit $?
fi
hook=$(git rev-parse --show-toplevel)"/util/git-hooks/"$(basename $0)
if [ -x $hook ]; then
$hook "$@" || exit $?
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment