git usage refactoring

There were heaps of "if type -t git" there already;
it wasn't an unintentional mishap but rather a moderate
copy-paste to get the use cases, and now these seem to
have essentially settled.

So time to scrap some dups.

NB: the scripts in the generated profile can't rely on
the contents of the metaprofile (these need to be able
to work in standalone case either), so a bit of crap
still lurks there.
This commit is contained in:
Michael Shigorin 2012-08-09 23:32:00 +03:00
parent a3779231cb
commit c4311108ea
8 changed files with 47 additions and 65 deletions

21
bin/mp-commit Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
# commit the directory ($1) with a message ($2) to git
. shell-error
[ -d "$1" ] || fatal "$1 is not an existing directory"
if type -t git >&/dev/null && pushd "$1" >/dev/null; then
if [ -z "$(git config --global user.name)" ]; then
exit 0
fi
if [ ! -d .git ]; then
git init -q || fatal "git init failed"
fi
if [ -n "$(git status -s)" ]; then
git add . \
&& git commit -qam "$2" \
|| fatal "git add/commit failed"
fi
popd >/dev/null
fi

11
bin/mp-showref Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# report on git repo in the current directory
if type -t git >&/dev/null; then
if pushd "$1" >/dev/null && [ -d .git ]; then
git show-ref --head -ds -- HEAD
git status -s
echo
popd >/dev/null
fi
fi

View File

@ -108,29 +108,16 @@ $(FEATURES):
done; \ done; \
popd >&/dev/null; \ popd >&/dev/null; \
done; \ done; \
if type -t git >&/dev/null && \
pushd "$(BUILDDIR)/$$dst/" >/dev/null; then \
test -n "`git status -s`" && \
git add . && \
if [ -n "$$dst" ]; then \ if [ -n "$$dst" ]; then \
the="$$sub subprofile"; \ the="$$sub subprofile"; \
else \ else \
the="toplevel"; \ the="toplevel"; \
fi && \
git commit -qam "$$feat feature: $$the part added"; \
popd >/dev/null; \
fi; \ fi; \
mp-commit "$(BUILDDIR)/$$dst/" "$$feat feature: $$the part added"; \
done; \ done; \
if [ -x "generate.sh" ]; then sh generate.sh; fi; \ if [ -x "generate.sh" ]; then sh generate.sh; fi; \
if [ -s "generate.mk" ]; then $(MAKE) -f generate.mk; fi; \ if [ -s "generate.mk" ]; then $(MAKE) -f generate.mk; fi; \
if type -t git >&/dev/null && \ mp-commit "$(BUILDDIR)" "$$feat feature generation complete"; \
pushd "$(BUILDDIR)/" >/dev/null; then \
if [ -n "`git status -s`" ]; then \
git add . && \
git commit -qam "$$feat feature generation complete"; \
fi; \
popd >/dev/null; \
fi; \
popd >/dev/null popd >/dev/null
finalize: finalize:

View File

@ -24,6 +24,7 @@ all: $(GLOBAL_DEBUG) prep copy-subdirs copy-tree run-scripts pack-image \
prep: $(GLOBAL_DEBUG) dot-disk $(WHATEVER) prep: $(GLOBAL_DEBUG) dot-disk $(WHATEVER)
# can't use mp-showref which belongs to the metaprofile
dot-disk: dot-disk:
@mkdir -p files/.disk @mkdir -p files/.disk
@echo "ALT Linux based" >files/.disk/info @echo "ALT Linux based" >files/.disk/info

View File

@ -44,13 +44,7 @@ profile/init: distclean
@$(call put,ifndef DISTCFG_MK) @$(call put,ifndef DISTCFG_MK)
@$(call put,DISTCFG_MK = 1) @$(call put,DISTCFG_MK = 1)
@{ \ @{ \
if type -t git >&/dev/null; then \ mp-showref $(LOG); \
if [ -d .git ]; then \
git show-ref --head -d -s -- HEAD && \
git status -s && \
echo; \
fi $(LOG); \
fi; \
{ \ { \
APTCONF="$(wildcard $(APTCONF))"; \ APTCONF="$(wildcard $(APTCONF))"; \
echo "** using $${APTCONF:-system apt configuration}:"; \ echo "** using $${APTCONF:-system apt configuration}:"; \
@ -71,14 +65,7 @@ profile/init: distclean
fi >&2; \ fi >&2; \
exit 1; \ exit 1; \
fi; \ fi; \
if type -t git >&/dev/null; then \ mp-commit "$(BUILDDIR)" "derivative profile initialized"; \
if cd $(BUILDDIR); then \
git init -q && \
git add . && \
git commit -qam 'derivative profile initialized'; \
cd ->&/dev/null; \
fi; \
fi; \
if [ -w . ]; then \ if [ -w . ]; then \
rm -f "$(SYMLINK)" && \ rm -f "$(SYMLINK)" && \
ln -s "$(BUILDDIR)" "$(SYMLINK)" && \ ln -s "$(BUILDDIR)" "$(SYMLINK)" && \
@ -99,20 +86,12 @@ profile/bare: profile/init
@$(call try,LOGDIR,$(LOGDIR)) @$(call try,LOGDIR,$(LOGDIR))
@$(call try,BRANDING,altlinux-sisyphus) @$(call try,BRANDING,altlinux-sisyphus)
@$(call set,IMAGE_INIT_LIST,+branding-$$(BRANDING)-release) @$(call set,IMAGE_INIT_LIST,+branding-$$(BRANDING)-release)
@if type -t git >&/dev/null && cd $(BUILDDIR); then \ @mp-commit "$(BUILDDIR)" "image configuration defaults set"
git init -q && \
git add . && \
git commit -qam 'image configuration defaults set'; \
fi
profile/finalize: profile/finalize:
@if [ -s $(RC) ]; then $(call put,-include $(RC)); fi @if [ -s $(RC) ]; then $(call put,-include $(RC)); fi
@$(call put,endif) @$(call put,endif)
@if type -t git >&/dev/null && cd $(BUILDDIR); then \ @mp-commit "$(BUILDDIR)" "image configuration finalized"
git init -q && \
git add . && \
git commit -qam 'image configuration finalized'; \
fi
# requires already formed distcfg.mk for useful output # requires already formed distcfg.mk for useful output
profile/dump-vars: profile/dump-vars:

View File

@ -14,13 +14,7 @@ all: $(GLOBAL_DEBUG)
mkdir -p $(TARGET) && \ mkdir -p $(TARGET) && \
cp -at $(TARGET) -- \ cp -at $(TARGET) -- \
$(addsuffix .directory,$(THE_GROUPS) $(MAIN_GROUPS)); \ $(addsuffix .directory,$(THE_GROUPS) $(MAIN_GROUPS)); \
if type -t git >&/dev/null && cd $(TARGET); then \ mp-commit "$(TARGET)" "requested $(SUFFIX) copied over"; \
if [ -n "`git status -s`" ]; then \
git add . && \
git commit -qam "requested $(SUFFIX) copied over"; \
fi; \
cd - >&/dev/null; \
fi; \
fi fi
debug: debug:

View File

@ -19,13 +19,7 @@ SUFFIX := pkg/lists
TARGET := $(BUILDDIR)/$(SUFFIX) TARGET := $(BUILDDIR)/$(SUFFIX)
all: $(TARGET) $(GLOBAL_DEBUG) $(DOTBASE) copy-lists copy-groups all: $(TARGET) $(GLOBAL_DEBUG) $(DOTBASE) copy-lists copy-groups
@if type -t git >&/dev/null && cd $(TARGET); then \ @mp-commit "$(TARGET)" "requested $(SUFFIX) copied over"
if [ -n "`git status -s`" ]; then \
git add . && \
git commit -qam "requested $(SUFFIX) copied over"; \
fi; \
cd - >&/dev/null; \
fi
copy-lists: copy-lists:
@# env | sort -u | grep _LISTS | xargs cp @# env | sort -u | grep _LISTS | xargs cp

View File

@ -14,13 +14,8 @@ all:
dst="$${sub#*/}" && \ dst="$${sub#*/}" && \
neq="$${src#$$dst}" && \ neq="$${src#$$dst}" && \
rsync -qa "$$src/" "$(BUILDDIR)/$$dst/" && \ rsync -qa "$$src/" "$(BUILDDIR)/$$dst/" && \
if type -t git >&/dev/null && cd "$(BUILDDIR)/$$dst/"; then \ mp-commit "$(BUILDDIR)/$$dst/" \
if [ -n "`git status -s`" ]; then \ "$$dst subprofile initialized$${neq:+ (using $$src)}"; \
git add . && \
git commit -qam "$$dst subprofile initialized$${neq:+ (using $$src)}"; \
fi; \
cd - >&/dev/null; \
fi; \
done done
clean: clean: