mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxime Chretien <maxime.chretien@bootlin.com>
To: masahiroy@kernel.org, michal.lkml@markovi.net, corbet@lwn.net
Cc: linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Maxime Chretien <maxime.chretien@bootlin.com>
Subject: [PATCH] kconfig confdata: Add an option to keep all .config backups
Date: Wed,  8 Jul 2020 15:35:56 +0200	[thread overview]
Message-ID: <20200708133556.12934-1-maxime.chretien@bootlin.com> (raw)

When KCONFIG_KEEPALLBACKUPS is set in the environment,
instead of renaming the old .config to .config.old, kconfig puts it in
a folder named .config.backupdir that stores all backups
with the name .config.oldX where X is a number.

The latest backup is the one with the highest number.

This is useful to avoid doing a lot of manual backups to make sure to have
a working build when you make a lot of changes that can break everything.

Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
---
 Documentation/kbuild/kconfig.rst |  6 ++++++
 Makefile                         |  2 +-
 scripts/kconfig/confdata.c       | 15 ++++++++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst
index dce6801d66c9..0f1dac4f1fc2 100644
--- a/Documentation/kbuild/kconfig.rst
+++ b/Documentation/kbuild/kconfig.rst
@@ -46,6 +46,12 @@ KCONFIG_OVERWRITECONFIG
 If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not
 break symlinks when .config is a symlink to somewhere else.
 
+KCONFIG_KEEPALLBACKUPS
+-----------------------
+If you set KCONFIG_KEEPALLBACKUPS in the environment, Kconfig will save
+all .config.old as .config.oldX where X is a number (lower is older)
+inside a folder named .config.backupdir .
+
 `CONFIG_`
 ---------
 If you set `CONFIG_` in the environment, Kconfig will prefix all symbols
diff --git a/Makefile b/Makefile
index ac2c61c37a73..c74a18c60107 100644
--- a/Makefile
+++ b/Makefile
@@ -1437,7 +1437,7 @@ CLEAN_FILES += include/ksym vmlinux.symvers \
 MRPROPER_FILES += include/config include/generated          \
 		  arch/$(SRCARCH)/include/generated .tmp_objdiff \
 		  debian snap tar-install \
-		  .config .config.old .version \
+		  .config .config.old .config.backupdir .version \
 		  Module.symvers \
 		  signing_key.pem signing_key.priv signing_key.x509	\
 		  x509.genkey extra_certificates signing_key.x509.keyid	\
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index a39d93e3c6ae..a019752816a0 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -923,7 +923,20 @@ int conf_write(const char *name)
 			return 0;
 		}
 
-		snprintf(oldname, sizeof(oldname), "%s.old", name);
+		env = getenv("KCONFIG_KEEPALLBACKUPS");
+		if (env) {
+			i = 0;
+			do {
+				snprintf(oldname, sizeof(oldname),
+					 "%s.backupdir/%s.old%d", name, name, i);
+				i++;
+			} while(is_present(oldname));
+
+			if (make_parent_dir(oldname))
+				return -1;
+		} else {
+			snprintf(oldname, sizeof(oldname), "%s.old", name);
+		}
 		rename(name, oldname);
 		if (rename(tmpname, name))
 			return 1;
-- 
2.27.0


                 reply	other threads:[~2020-07-08 13:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200708133556.12934-1-maxime.chretien@bootlin.com \
    --to=maxime.chretien@bootlin.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=michal.lkml@markovi.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®