mirror of
https://review.coreboot.org/flashrom.git
synced 2025-08-23 06:50:49 +02:00
Convert flashrom to git
- Drop support for Subversion in the getrevision script and Makefile. - Refinement of getrevision to have a single function determining the new flashrom version string (based on git describe). - Add .gitignore and .gitattributes file (the latter to limit exports). - Restore modification dates of the exported files from the VCS. - Stop exporting VCS log dumps to CHANGELOG. This makes no sense. - Export VCS metadata needed by the Makefile to versioninfo.inc - Do not export the pre-"compiled" manpage. It can be generated like anything else from the code dump with versioninfo.inc - Add some initial client-side git hooks that get installed automatically on make runs: * pre-commit: - test for whitespace errors via git diff-index --check * commit-msg: - Use the up to date hook from gerrit to add Change-Id tags. Unlike the upstream hook, add them to fixup/squash changes too to allow for our staging process. - Test for duplicate sign-offs/acks. * When pushing to one of the upstream repositories check mandatory rules: - existing signoffs and acks in all new commits - no deletions of branches - no new branches other than versioned branches (e.g., 0.0.x) - no history rewriting of branches - Various other small refinements, bikesheddings and cosmetic changes to slow down progress of flashrom and humanity as a whole. Original-Change-Id: I64eef21982cac0a0a7419bcd2c8a936672ae9cb2 Original-Reviewed-on: https://review.coreboot.org/19206 Original-Reviewed-by: Nico Huber <nico.h@gmx.de> Original-Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Change-Id: I325edb7d9890c412a44ecacb5161268d3dbccc57 Signed-off-by: Stefan Tauner <stefan.tauner@gmx.at> Signed-off-by: David Hendricks <dhendricks@fb.com> Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/21923 Acked-by: Stefan Tauner <stefan.tauner@gmx.at>
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#!/bin/sh
|
||||
# NB: Supposed to be POSIX compatible but at least the usage of 'local' is not.
|
||||
#
|
||||
# This file is part of the flashrom project.
|
||||
#
|
||||
# Copyright (C) 2005 coresystems GmbH <stepan@coresystems.de>
|
||||
# Copyright (C) 2009,2010 Carl-Daniel Hailfinger
|
||||
# Copyright (C) 2010 Chromium OS Authors
|
||||
# Copyright (C) 2013 Stefan Tauner
|
||||
# Copyright (C) 2013-2016 Stefan Tauner
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -31,30 +32,24 @@ export LC_ALL=C
|
||||
export TZ=UTC0
|
||||
|
||||
# Helper functions
|
||||
# First argument is the path to inspect (usually optional; w/o it the whole repository will be considered)
|
||||
svn_has_local_changes() {
|
||||
svn status "$1" | egrep '^ *[ADMR] *' >/dev/null
|
||||
}
|
||||
|
||||
# First argument is the path to inspect (usually optional; without
|
||||
# it the whole repository will be considered)
|
||||
git_has_local_changes() {
|
||||
git update-index -q --refresh >/dev/null
|
||||
! git diff-index --quiet HEAD -- "$1"
|
||||
}
|
||||
|
||||
git_last_commit() {
|
||||
# git rev-parse --short HEAD would suffice if repository as a whole is of interest (no $1)
|
||||
git log --pretty=format:"%h" -1 -- "$1"
|
||||
}
|
||||
|
||||
svn_is_file_tracked() {
|
||||
svn info "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
git_is_file_tracked() {
|
||||
git ls-files --error-unmatch -- "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
is_file_tracked() {
|
||||
svn_is_file_tracked "$1" || git_is_file_tracked "$1"
|
||||
git_is_file_tracked "$1"
|
||||
}
|
||||
|
||||
# Tries to find a remote source for the changes committed locally.
|
||||
@@ -62,7 +57,7 @@ is_file_tracked() {
|
||||
# Takes one optional argument: the path to inspect
|
||||
git_url() {
|
||||
last_commit=$(git_last_commit "$1")
|
||||
# get all remote branches containing the last commit (excluding origin/HEAD and git-svn branches/tags)
|
||||
# get all remote branches containing the last commit (excluding origin/HEAD)
|
||||
branches=$(git branch -r --contains $last_commit | sed '/\//!d;/.*->.*/d;s/[\t ]*//')
|
||||
if [ -z "$branches" ] ; then
|
||||
echo "No remote branch contains a suitable commit">&2
|
||||
@@ -84,18 +79,12 @@ git_url() {
|
||||
echo "$(git ls-remote --exit-code --get-url ${target%/*}) ${target#*/}"
|
||||
}
|
||||
|
||||
# Returns a string indicating where others can get the current source code (excluding uncommitted changes)
|
||||
# Returns a string indicating where others can get the current source code (excluding uncommitted changes).
|
||||
# Takes one optional argument: the path to inspect
|
||||
scm_url() {
|
||||
local url=
|
||||
|
||||
# for a primitive VCS like subversion finding the URL is easy: there is only one upstream host
|
||||
if svn_is_file_tracked "$1" ; then
|
||||
url="$(svn info "$1" 2>/dev/null |
|
||||
grep URL: |
|
||||
sed 's/.*URL:[[:blank:]]*//;s/:\/\/.*@/:\/\//' |
|
||||
grep ^.)"
|
||||
elif git_is_file_tracked "$1" ; then
|
||||
if git_is_file_tracked "$1" ; then
|
||||
url="$(git_url "$1")"
|
||||
else
|
||||
return ${EXIT_FAILURE}
|
||||
@@ -116,29 +105,7 @@ timestamp() {
|
||||
# freebsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
|
||||
# dragonflybsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...]
|
||||
# openbsd date [-aju] [-d dst] [-r seconds] [+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]] [...]
|
||||
if svn_is_file_tracked "$2" ; then
|
||||
if svn_has_local_changes "$2"; then
|
||||
t=$(date -u "$1")
|
||||
else
|
||||
# No local changes, get date of the last log record. Subversion provides that in
|
||||
# ISO 8601 format when using the --xml switch. The sed call extracts that ignoring any
|
||||
# fractional parts started by a comma or a dot.
|
||||
local last_commit_date="$(svn info --xml "$2"| \
|
||||
sed -n -e 's/<date>\([^,\.]*\)\([\.,].*\)*Z<\/date>/\1Z/p')"
|
||||
|
||||
case $(uname) in
|
||||
# Most BSD dates do not support parsing date values from user input with -d but all of
|
||||
# them support parsing the syntax with [[[[[[cc]yy]mm]dd]HH]MM[.ss]]. We have to
|
||||
# transform the ISO8601 date first though.
|
||||
NetBSD|OpenBSD|DragonFly|FreeBSD)
|
||||
last_commit_date="$(echo ${last_commit_date} | \
|
||||
sed -n -e 's/\(....\)-\(..\)-\(..\)T\(..\):\(..\):\(..\)Z/\1\2\3\4\5\.\6/p')"
|
||||
t=$(date -u -j "${last_commit_date}" "$1" 2>/dev/null);;
|
||||
*)
|
||||
t=$(date -u -d "${last_commit_date}" "$1" 2>/dev/null);;
|
||||
esac
|
||||
fi
|
||||
elif git_is_file_tracked "$2" ; then
|
||||
if git_is_file_tracked "$2" ; then
|
||||
# are there local changes?
|
||||
if git_has_local_changes "$2" ; then
|
||||
t=$(date -u "${1}")
|
||||
@@ -163,58 +130,20 @@ timestamp() {
|
||||
echo "${t}"
|
||||
}
|
||||
|
||||
# Retrieve local SCM revision info. This is useful if we're working in a different SCM than upstream and/or
|
||||
# have local changes.
|
||||
local_revision() {
|
||||
local r=
|
||||
|
||||
if svn_is_file_tracked "$1" ; then
|
||||
r=$(svn_has_local_changes "$1" && echo "dirty")
|
||||
elif git_is_file_tracked "$1" ; then
|
||||
r=$(git_last_commit "$1")
|
||||
|
||||
local svn_base=$(git log --grep=git-svn-id -1 --format='%h')
|
||||
if [ "$svn_base" != "" ] ; then
|
||||
local diff_to_svn=$(git rev-list --count ${svn_base}..${r})
|
||||
if [ "$diff_to_svn" -gt 0 ] ; then
|
||||
r="$r-$diff_to_svn"
|
||||
fi
|
||||
fi
|
||||
|
||||
revision() {
|
||||
local r
|
||||
if git_is_file_tracked "$1" ; then
|
||||
r=$(git describe $(git_last_commit "$1"))
|
||||
if git_has_local_changes "$1" ; then
|
||||
r="$r-dirty"
|
||||
fi
|
||||
else
|
||||
return ${EXIT_FAILURE}
|
||||
r="unknown"
|
||||
fi
|
||||
|
||||
echo "${r}"
|
||||
}
|
||||
|
||||
# Get the upstream flashrom revision stored in SVN metadata.
|
||||
upstream_revision() {
|
||||
local r=
|
||||
|
||||
if svn_is_file_tracked "$1" ; then
|
||||
r=$(svn info "$1" 2>/dev/null | \
|
||||
grep "Last Changed Rev:" | \
|
||||
sed -e "s/^Last Changed Rev: *//" -e "s/\([0-9]*\).*/r\1/" | \
|
||||
grep "r[0-9]")
|
||||
elif git_is_file_tracked "$1" ; then
|
||||
# If this is a "native" git-svn clone we could use git svn log:
|
||||
# git svn log --oneline -1 | sed 's/^r//;s/[[:blank:]].*//' or even git svn find-rev
|
||||
# but it is easier to just grep for the git-svn-id unconditionally
|
||||
r=$(git log --grep=git-svn-id -1 -- "$1" | \
|
||||
grep git-svn-id | \
|
||||
sed 's/.*@/r/;s/[[:blank:]].*//')
|
||||
fi
|
||||
|
||||
if [ -z "$r" ]; then
|
||||
r="unknown" # default to unknown
|
||||
fi
|
||||
echo "${r}"
|
||||
}
|
||||
|
||||
is_tracked() {
|
||||
is_file_tracked "$1"
|
||||
}
|
||||
@@ -228,10 +157,9 @@ Commands
|
||||
this message
|
||||
-c or --check
|
||||
test if path is under version control at all
|
||||
-l or --local
|
||||
local revision information including an indicator for uncommitted changes
|
||||
-u or --upstream
|
||||
upstream revision
|
||||
-r or --revision
|
||||
return unique revision information including an indicator for
|
||||
uncommitted changes
|
||||
-U or --url
|
||||
URL associated with the latest commit
|
||||
-d or --date
|
||||
@@ -260,14 +188,6 @@ main() {
|
||||
-h|--help)
|
||||
action=show_help;
|
||||
shift;;
|
||||
-l|--local)
|
||||
check_action $1
|
||||
action=local_revision
|
||||
shift;;
|
||||
-u|--upstream)
|
||||
check_action $1
|
||||
action=upstream_revision
|
||||
shift;;
|
||||
-U|--url)
|
||||
check_action $1
|
||||
action=scm_url
|
||||
@@ -276,13 +196,17 @@ main() {
|
||||
check_action $1
|
||||
action="timestamp +%Y-%m-%d" # refrain from suffixing 'Z' to indicate it's UTC
|
||||
shift;;
|
||||
-r|--revision)
|
||||
check_action $1
|
||||
action=revision
|
||||
shift;;
|
||||
-t|--timestamp)
|
||||
check_action $1
|
||||
action="timestamp +%Y-%m-%dT%H:%M:%SZ" # There is only one valid time format! ISO 8601
|
||||
shift;;
|
||||
-c|--check)
|
||||
check_action=$1
|
||||
action="is_tracked"
|
||||
check_action $1
|
||||
action=is_tracked
|
||||
shift;;
|
||||
-*)
|
||||
show_help;
|
||||
@@ -306,9 +230,6 @@ main() {
|
||||
if [ -z "$query_path" ] ; then
|
||||
query_path=.
|
||||
fi
|
||||
if ! is_file_tracked "$query_path" ; then
|
||||
echo "Warning: Path \"${query_path}\" is not under version control.">&2
|
||||
fi
|
||||
if [ -z "$action" ] ; then
|
||||
show_help
|
||||
echo "Error: No actions specified"
|
||||
|
Reference in New Issue
Block a user