Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kicad-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
kicad-utils
Commits
e69c049f
Commit
e69c049f
authored
5 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Some cleanups
parent
cbc3e88f
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
kicad-git-setup
+32
-12
32 additions, 12 deletions
kicad-git-setup
kicad-sch-filter
+51
-20
51 additions, 20 deletions
kicad-sch-filter
post-checkout
+16
-0
16 additions, 0 deletions
post-checkout
post-commit
+17
-0
17 additions, 0 deletions
post-commit
with
116 additions
and
32 deletions
kicad-git-setup
+
32
−
12
View file @
e69c049f
...
...
@@ -2,26 +2,27 @@
shopt
-s
nullglob
# Symlink git filters
mkdir
-p
~/.config/git
for
s
in
kicad-pro-filter kicad-sch-filter
;
do
FILTER
=
$(
realpath
$(
dirname
$0
)
/kicad-sch-filter
)
if
[
-L
~/.config/git/
${
s
}
]
;
then
if
[
$(
readlink
~/.config/git/
${
s
}
)
!=
${
FILTER
}
]
;
then
FILTER
=
$(
realpath
$(
dirname
$0
)
/
${
s
}
)
CONFIG_PATH
=
~/.config/git/
${
s
}
if
[
-L
${
CONFIG_PATH
}
]
;
then
if
[
$(
readlink
${
CONFIG_PATH
}
)
!=
${
FILTER
}
]
;
then
echo
REPLACE
link
rm
~/.config/git/
${
s
}
rm
${
CONFIG_PATH
}
fi
elif
[
-f
~/.config/git/
${
s
}
]
;
then
if
diff
-q
<
(
$s
)
<
(
cat
~/.config/git/
${
s
}
)
;
then
elif
[
-f
${
CONFIG_PATH
}
]
;
then
echo
REPLACE file
rm
~/.config/git/
${
s
}
rm
${
CONFIG_PATH
}
fi
fi
if
[
!
-L
~/.config/git/
${
s
}
]
;
then
ln
-s
$FILTER
~/.config/git/
${
s
}
if
[
!
-L
${
CONFIG_PATH
}
]
;
then
ln
-s
${
FILTER
}
${
CONFIG_PATH
}
fi
done
# Sanity check kicad project
SCHEMATICS
=(
*
.sch
)
if
[
${#
SCHEMATICS
[*]
}
-eq
0
]
;
then
echo
"No schematic file(s) in directory"
>
&2
...
...
@@ -35,6 +36,7 @@ if [ ${#PROJECT[*]} -ne 1 ] ; then
exit
1
fi
# Setup git
if
[
!
-d
.git
]
;
then
# Initialize git
git init
...
...
@@ -42,7 +44,7 @@ fi
# Fill in .gitignore
GITIGNORE
=(
"*~"
"*.net"
"*.kicad_pcb-bak"
"*.bak"
"_autosave*"
)
GITIGNORE+
=(
"*.csv"
"*.tsv"
"*.xml"
)
GITIGNORE+
=(
"*.sch-bak"
"*.csv"
"*.tsv"
"*.xml"
)
for
s
in
${
PROJECT
[@]
}
;
do
if
[[
"
$s
"
=
~
(
.
*
)
\.
pro
]]
;
then
BASE
=
${
BASH_REMATCH
[1]
}
...
...
@@ -102,4 +104,22 @@ EOF
fi
done
# Install hooks
for
s
in
post-commit post-checkout
;
do
HOOK
=
$(
realpath
$(
dirname
$0
)
/
${
s
}
)
HOOK_PATH
=
.git/hooks/
${
s
}
if
[
-L
${
HOOK_PATH
}
]
;
then
if
[
$(
readlink
${
HOOK_PATH
}
)
!=
${
HOOK
}
]
;
then
echo
REPLACE
link
rm
${
HOOK_PATH
}
fi
elif
[
-f
${
HOOK_PATH
}
]
;
then
echo
REPLACE file
rm
${
HOOK_PATH
}
fi
if
[
!
-L
${
HOOK_PATH
}
]
;
then
ln
-s
${
HOOK
}
${
HOOK_PATH
}
fi
done
git status
This diff is collapsed.
Click to expand it.
kicad-sch-filter
+
51
−
20
View file @
e69c049f
#!/bin/bash
set
-e
clean
()
{
IFS
=
read
-r
LINE
if
[[
"
${
LINE
}
"
=
~ ^
(
EESchema.
*
[
^
\
])[
\
]
*
\#
(
\$
Id.
*
\$
)
$
]]
;
then
echo
"
${
BASH_REMATCH
[1]
}
#
${
BASH_REMATCH
[2]
}
"
elif
[[
"
${
LINE
}
"
=
~ ^
(
EESchema[^
\#\$
]
*
[
^
\
])[
\
]
*
$
]]
;
then
echo
"
${
BASH_REMATCH
[1]
}
#
\$
Id
\$
"
if
[[
"
${
LINE
}
"
=
~ ^EESchema.
*
$
]]
;
then
echo
"
${
LINE
}
"
else
echo
"Unknown schema type '
${
LINE
}
'"
1>&2
exit
1
fi
(
while
IFS
=
read
-r
LINE
;
do
if
[[
"
${
LINE
}
"
=
~ ^
((
Rev|Date
)
\ \"
)
.
*
(
\"
)
]]
;
then
if
[[
"
${
LINE
}
"
=
~ ^
((
Rev|Date
|Comment4
)
\ \"
)
.
*
(
\"
)
]]
;
then
# Clean out revision and date
echo
"
${
BASH_REMATCH
[1]
}${
BASH_REMATCH
[3]
}
"
elif
[[
"
${
LINE
}
"
=
~ ^
((
Comment[4]
)
\ \"
)
.
*
(
\"
)
]]
;
then
# Clean out auto comment
echo
"
${
BASH_REMATCH
[1]
}${
BASH_REMATCH
[3]
}
"
else
echo
"
${
LINE
}
"
fi
...
...
@@ -23,22 +26,39 @@ clean() {
}
smudge
()
{
local
REV
=
"Unknown"
local
DATE
=
"Unknown"
local
HASH
=
IFS
=
read
-r
LINE
if
[[
"
${
LINE
}
"
=
~ ^EESchema.
*
\#\$
Id:
(
.
*
)
\$
]]
;
then
local
HASH
=
${
BASH_REMATCH
[1]
}
REV
=
$(
git describe
${
HASH
}
2>/dev/null |
sed
-e
's/:.*//'
)
if
[
-z
"
${
REV
}
"
]
;
then
local
REV
local
DATE
local
AUTHOR
local
HASH
if
[[
"
$(
git
--no-pager
status
--short
--
"
$1
"
)
"
=
~ ^
(
.
)(
.
)
\
$1
]]
;
then
STATUS
=
${
BASH_REMATCH
[2]
}
case
"
${
STATUS
}
"
in
"?"
)
REV
=
"UNTRACKED"
DATE
=
$(
date
-r
"
$1
"
+
"%Y-%m-%d %H:%M:%S %z"
)
AUTHOR
=
$(
grep
$(
id
-u
)
/etc/passwd |
cut
-d
':'
-f
5
)
;;
"D"
)
REV
=
"DELETED"
DATE
=
""
AUTHOR
=
$(
grep
$(
id
-u
)
/etc/passwd |
cut
-d
':'
-f
5
)
;;
"M"
|
"A"
|
"R"
|
"C"
|
"U"
)
REV
=
"MODIFIED:
${
STATUS
}
"
DATE
=
$(
date
-r
"
$1
"
+
"%Y-%m-%d %H:%M:%S %z"
)
AUTHOR
=
$(
grep
$(
id
-u
)
/etc/passwd |
cut
-d
':'
-f
5
)
;;
esac
else
# File is unchanged
HASH
=
$(
git
--no-pager
hash-object
"
$1
"
)
REV
=
"g
$(
git describe
--always
${
HASH
}
|
sed
-e
's/:.*//'
)
"
DATE
=
$(
git
--no-pager
log
-n
1
--format
=
"%ai"
--
"
$1
"
)
AUTHOR
=
$(
git
--no-pager
log
-n
1
--format
=
"%aN"
--
"
$1
"
)
fi
DATE
=
$(
git log
--format
=
"%ai"
--
"
$1
"
|
head
-1
)
if
[
-z
"
${
DATE
}
"
]
;
then
DATE
=
"Unknown2"
fi
echo
"
${
LINE
}
"
elif
[[
"
${
LINE
}
"
=
~ ^EESchema.
*
]]
;
then
IFS
=
read
-r
LINE
if
[[
"
${
LINE
}
"
=
~ ^EESchema.
*
]]
;
then
echo
"
${
LINE
}
"
else
echo
"Unknown schema type '
${
LINE
}
'"
1>&2
...
...
@@ -50,12 +70,15 @@ smudge() {
echo
"
${
BASH_REMATCH
[1]
}${
REV
}${
BASH_REMATCH
[2]
}
"
elif
[[
"
${
LINE
}
"
=
~ ^
(
Date
\ \"
)
.
*
(
\"
)
]]
;
then
echo
"
${
BASH_REMATCH
[1]
}${
DATE
}${
BASH_REMATCH
[2]
}
"
elif
[[
"
${
LINE
}
"
=
~ ^
(
Comment4
\ \"
)
.
*
(
\"
)
]]
;
then
echo
"
${
BASH_REMATCH
[1]
}
Last edit by
${
AUTHOR
}${
BASH_REMATCH
[2]
}
"
else
echo
"
${
LINE
}
"
fi
done
}
#echo $1 $(stat $2) 1>&2
case
"
$1
"
in
clean
)
clean
$2
...
...
@@ -63,7 +86,15 @@ case "$1" in
smudge
)
smudge
$2
;;
post-checkout
)
smudge
$2
;;
post-commit
)
smudge
$2
;;
*
)
echo
"unknown command '
$1
'"
1>&2
exit
1
;;
esac
#stat $2 1>&2
This diff is collapsed.
Click to expand it.
post-checkout
0 → 100755
+
16
−
0
View file @
e69c049f
#!/bin/bash
set
-e
shopt
-s
nullglob
for
f
in
*
.sch
;
do
TMP
=
$(
mktemp
-p
.
)
cat
"
$f
"
|
$(
dirname
$(
realpath
$0
))
/kicad-sch-filter post-checkout
"
$f
"
>
${
TMP
}
if
!
diff
-q
"
$f
"
"
${
TMP
}
"
>
/dev/null
;
then
touch
-r
"
$f
"
${
TMP
}
mv
${
TMP
}
"
$f
"
else
rm
"
${
TMP
}
"
fi
done
This diff is collapsed.
Click to expand it.
post-commit
0 → 100755
+
17
−
0
View file @
e69c049f
#!/bin/bash
set
-e
shopt
-s
nullglob
for
f
in
*
.sch
;
do
TMP
=
$(
mktemp
-p
.
)
cat
"
$f
"
|
$(
dirname
$(
realpath
$0
))
/kicad-sch-filter post-commit
"
$f
"
>
${
TMP
}
if
!
diff
-q
"
$f
"
"
${
TMP
}
"
>
/dev/null
;
then
touch
-r
"
$f
"
${
TMP
}
mv
${
TMP
}
"
$f
"
else
rm
"
${
TMP
}
"
fi
done
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment