Debian Codegraph @

getrevid

raw symbols SCIP
1 #!/bin/sh
2 ###############################################################################
3 # BRLTTY - A background process providing access to the console screen (when in
4 # text mode) for a blind person using a refreshable braille display.
5 #
6 # Copyright (C) 1995-2026 by The BRLTTY Developers.
7 #
8 # BRLTTY comes with ABSOLUTELY NO WARRANTY.
9 #
10 # This is free software, placed under the terms of the
11 # GNU Lesser General Public License, as published by the Free Software
12 # Foundation; either version 2.1 of the License, or (at your option) any
13 # later version. Please see the file LICENSE-LGPL for details.
14 #
15 # Web Page: http://brltty.app/
16 #
17 # This software is maintained by Dave Mielke <[email protected]>.
18 ###############################################################################
19
20 defaultModifiedIndicator="+"
21
22 . "`dirname "${0}"`/brltty-prologue.sh"
23 addProgramOption a string.anything appendText "text to append to the revision identifier"
24 addProgramOption d string.anything defaultIdentifier "the default revision identifier"
25 addProgramOption f string.file outputFile "the file in which to write the revision identifier" "standard output"
26 addProgramOption i flag asInteger "render the revision identifier as a 32-bit integer"
27 addProgramOption m string.anything modifiedIndicator "the modified indicator" "${defaultModifiedIndicator}"
28 addProgramOption p string.anything prependText "text to prepend to the revision identifier"
29 addProgramOption r string.anything revisionIdentifier "the revision identifier"
30 addProgramOption s flag asString "render the revision identifier as a quoted string"
31 optionalProgramParameters
32 addProgramParameter source sourceRoot "the top-level directory of the source tree"
33 parseProgramArguments "${@}"
34
35 [ -n "${sourceRoot}" ] || sourceRoot="${programDirectory}"
36 [ -e "${sourceRoot}" ] || semanticError "directory not found: ${sourceRoot}"
37 [ -d "${sourceRoot}" ] || semanticError "not a directory: ${sourceRoot}"
38
39 [ -n "${modifiedIndicator}" ] || modifiedIndicator="${defaultModifiedIndicator}"
40
41 [ -n "${revisionIdentifier}" ] || {
42 if [ -e "${sourceRoot}/.git" ]
43 then
44 revisionIdentifier="`git -C "${sourceRoot}" describe --tags --abbrev=8 --dirty="${modifiedIndicator}" --match="BRLTTY-*" 2>/dev/null`"
45 elif [ -d "${sourceRoot}/.svn" ]
46 then
47 revisionIdentifier="`svnversion -n "${sourceRoot}" 2>/dev/null`"
48 [ "${revisionIdentifier}" != "exported" ] || revisionIdentifier=""
49 else
50 revisionFile="${sourceRoot}/REVISION"
51 [ -f "${revisionFile}" ] && read <"${revisionFile}" revisionIdentifier
52 fi
53
54 [ -n "${revisionIdentifier}" ] || logWarning "unrecognized source repository type: ${sourceRoot}"
55 }
56
57 [ -n "${revisionIdentifier}" ] || {
58 [ -n "${defaultIdentifier}" ] || semanticError "revision identifier not known"
59 revisionIdentifier="${defaultIdentifier}"
60 }
61
62 "${asInteger}" && {
63 makeInteger() {
64 set -- `echo "${revisionIdentifier}" | sed -e 's/-/ /g'`
65 local commitCount="${3:-0}"
66
67 revisionIdentifier=0
68 local width=6
69 local shift=30
70 local number
71
72 for number in `echo "${2}" | sed -e 's/\./ /g'`
73 do
74 shift=$((shift - width))
75 revisionIdentifier=$((revisionIdentifier | (number << shift)))
76 done
77
78 revisionIdentifier=$((revisionIdentifier | commitCount))
79 }
80
81 makeInteger
82 }
83
84 [ -n "${prependText}" ] && revisionIdentifier="${prependText}${revisionIdentifier}"
85 [ -n "${appendText}" ] && revisionIdentifier="${revisionIdentifier}${appendText}"
86 "${asString}" && revisionIdentifier='"'"${revisionIdentifier}"'"'
87
88 if [ -z "${outputFile}" ]
89 then
90 echo "${revisionIdentifier}"
91 else
92 if [ -e "${outputFile}" ]
93 then
94 [ -f "${outputFile}" ] || semanticError "not a file: ${outputFile}"
95 [ -r "${outputFile}" ] || semanticError "file not readable: ${outputFile}"
96
97 exec 3<"${outputFile}"
98 read <&3 -r firstLine && {
99 [ "${firstLine}" != "${revisionIdentifier}" ] || read <&3 -r secondLine || exit 0
100 }
101 exec 3<&-
102
103 [ -w "${outputFile}" ] || semanticError "file not writable: ${outputFile}"
104 else
105 outputDirectory="$(dirname "${outputFile}")"
106 [ -d "${outputDirectory}" ] || semanticError "not a directory: ${outputDirectory}"
107 [ -w "${outputDirectory}" ] || semanticError "directory not writable: ${outputDirectory}"
108 fi
109
110 echo "${revisionIdentifier}" >"${outputFile}"
111 fi
112
113 exit 0