# [PATCH 0/4] add write-tree --missing OK, fix cogito -N options

5 messages from 2005-07-11 to 2005-07-11. Participants: Bryan Larsen.
Thread: https://gitlist.dev/t/1198

## Bryan Larsen, 2005-07-11 03:53

Subject: [PATCH 0/4] add write-tree --missing OK, fix cogito -N options
Message-ID: <20050711035305.22229.87752.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050711035305.22229.87752.sendpatchset%40bryan-larsens-ibook-g4.local

```
All of my patches have been applied to git and cogito except for the
first one, the patch that adds the --no-check option to
git-write-tree.  This is problematic because one of the patches that
Petr applied to cogito requires git-write-tree --no-check.

As well, there are two bugs in cg-init:  the one that Joel Becker
found, plus the -N option needs to be passed to cg-commit.

Finally, Junio suggested that the --no-check option be renamed to
--missing-ok.

These patches fix the situation up.

1/4: bugfix for cg-init ARGV
2/4: bugfix for cg-init.
3/4: add --missing-ok option to git-write-tree.
4/4: change cg-commit to use --missing-ok instead of --no-check.

```

## Bryan Larsen, 2005-07-11 03:53

Subject: [PATCH 1/4] bugfix for cg-init: ARGV
Message-ID: <20050711035316.22229.64951.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050711035316.22229.64951.sendpatchset%40bryan-larsens-ibook-g4.local
In-Reply-To: <20050711035305.22229.87752.sendpatchset@bryan-larsens-ibook-g4.local>

```
Bugfix: nasty typo (ARGV instead of ARGS) in my last patch to cg-init.

Signed off by: Bryan Larsen <bryan.larsen@gmail.com>
---

diff --git a/cg-init b/cg-init
--- a/cg-init
+++ b/cg-init
@@ -33,7 +33,7 @@ while optparse; do
 	fi
 done
 
-uri=$ARGV
+uri=$ARGS
 
 [ -e $_git ] && die "$_git already exists"
 

```

## Bryan Larsen, 2005-07-11 03:53

Subject: [PATCH 2/4] bugfix for cg-init -N: pass -N to cg-commit
Message-ID: <20050711035327.22229.20563.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050711035327.22229.20563.sendpatchset%40bryan-larsens-ibook-g4.local
In-Reply-To: <20050711035305.22229.87752.sendpatchset@bryan-larsens-ibook-g4.local>

```
Bugfix for cg-init -N:  the -N option needs to be passed down into cg-commit as well.

Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
---

diff --git a/cg-init b/cg-init
--- a/cg-init
+++ b/cg-init
@@ -56,7 +56,7 @@ if [ "$uri" ]; then
 else
 	git-read-tree # Seed the dircache
 	find * \( -type f -o -type l \) -print0 | xargs -0r cg-add ${infoonly}
-	cg-commit -C -m"Initial commit" -E
+	cg-commit -C -m"Initial commit" -E ${infoonly}
 fi
 
 trap "" SIGTERM EXIT

```

## Bryan Larsen, 2005-07-11 03:53

Subject: [PATCH 3/4] add --missing-ok option to write-tree
Message-ID: <20050711035338.22229.47651.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050711035338.22229.47651.sendpatchset%40bryan-larsens-ibook-g4.local
In-Reply-To: <20050711035305.22229.87752.sendpatchset@bryan-larsens-ibook-g4.local>

```
Add --missing-ok option to git-write.tree.  This option allows a write-tree even if the referenced objects are not in the database.

Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
---

diff --git a/Documentation/git-write-tree.txt b/Documentation/git-write-tree.txt
--- a/Documentation/git-write-tree.txt
+++ b/Documentation/git-write-tree.txt
@@ -10,6 +10,7 @@ git-write-tree - Creates a tree from the
 SYNOPSIS
 --------
 'git-write-tree'
+		[--missing-ok]
 
 DESCRIPTION
 -----------
@@ -23,7 +24,11 @@ In order to have that match what is actu
 now, you need to have done a "git-update-cache" phase before you did the
 "git-write-tree".
 
-
+OPTIONS
+-------
+--missing-ok::
+	Normally "git-write-tree" ensures that the objects referenced by the
+	directory exist in the object database.  This option disables this check.
 
 
 ////////////////////////////////////////////////////////////////
diff --git a/write-tree.c b/write-tree.c
--- a/write-tree.c
+++ b/write-tree.c
@@ -5,6 +5,8 @@
  */
 #include "cache.h"
 
+static int missing_ok = 0;
+
 static int check_valid_sha1(unsigned char *sha1)
 {
 	int ret;
@@ -61,7 +63,7 @@ static int write_tree(struct cache_entry
 			sha1 = subdir_sha1;
 		}
 
-		if (check_valid_sha1(sha1) < 0)
+		if (!missing_ok && check_valid_sha1(sha1) < 0)
 			exit(1);
 
 		entrylen = pathlen - baselen;
@@ -86,6 +88,16 @@ int main(int argc, char **argv)
 	int i, funny;
 	int entries = read_cache();
 	unsigned char sha1[20];
+	
+	if (argc==2) {
+		if (!strcmp(argv[1], "--missing-ok"))
+			missing_ok = 1;
+		else
+			die("unknown option %s", argv[1]);
+	}
+	
+	if (argc>2)
+		die("too many options");
 
 	if (entries < 0)
 		die("git-write-tree: error reading cache");

```

## Bryan Larsen, 2005-07-11 03:53

Subject: [PATCH 4/4] switch cg-commit -N to use --missing-ok instead of --no-check
Message-ID: <20050711035349.22229.2989.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050711035349.22229.2989.sendpatchset%40bryan-larsens-ibook-g4.local
In-Reply-To: <20050711035305.22229.87752.sendpatchset@bryan-larsens-ibook-g4.local>

```
Make cg-commit aware of the rename of git-write-tree --no-check to --missing-ok.

Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
---

diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -111,13 +111,13 @@ forceeditor=
 ignorecache=
 infoonly=
 commitalways=
-nocheck=
+missingok=
 msgs=()
 while optparse; do
 	if optparse -C; then
 		ignorecache=1
 	elif optparse -N; then
-		nocheck=--no-check
+		missingok=--missing-ok
 		infoonly=--info-only
 	elif optparse -e; then
 		forceeditor=1
@@ -311,7 +311,7 @@ if [ -s "$_git/HEAD" ]; then
 	oldheadstr="-p $oldhead"
 fi
 
-treeid=$(git-write-tree ${nocheck})
+treeid=$(git-write-tree ${missingok})
 [ "$treeid" ] || die "git-write-tree failed"
 if [ ! "$force" ] && [ ! "$merging" ] && [ "$oldhead" ] &&
    [ "$treeid" = "$(tree-id)" ]; then

```
