# [fast-import] LF after reset not optional

3 messages from 2008-03-05 to 2008-03-08. Participants: Adeodato Simó, Shawn O. Pearce.
Thread: https://gitlist.dev/t/12526

## Adeodato Simó, 2008-03-05 21:07

Subject: [fast-import] LF after reset not optional
Message-ID: <20080305210715.GA10686@chistera.yi.org>
URL: https://gitlist.dev/e/20080305210715.GA10686%40chistera.yi.org

```
Hello.

Maybe I'm doing something wrong, but I can't get the "reset" command to
work as advertised in git-fast-import(1), without an extra LF at the
end.

This input:

-8<-
commit refs/heads/master
mark :1
committer Joe R. Developer <joe@random.com> 1204726629 +0100
data <<EOF
First commit.
EOF
M 644 inline foo.txt
data <<EOF
Hello, world!
EOF
reset refs/tags/tag1
from :1
reset refs/tags/tag2
from :1
-8<-

fails with:

  fatal: Unsupported command: from :1

Adding an extra LF before the second reset fixes the issue. I tested
this issue seems to present in the "next" branch in addition to 1.5.4.3.

Cheers,

-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
- I couldn't find anything in there for days. I kept reaching in for
  strawberries and coming up with liver -- that's not pleasant.
- I promise not to touch the fridge again.
                -- Sookie and Lorelai


```

## Adeodato Simó, 2008-03-07 20:22

Subject: [PATCH] Really make the LF after reset in fast-import optional
Message-ID: <1204921337-5204-1-git-send-email-dato@net.com.org.es>
URL: https://gitlist.dev/e/1204921337-5204-1-git-send-email-dato%40net.com.org.es
In-Reply-To: <20080305210715.GA10686@chistera.yi.org>

```
cmd_from() ends with a call to read_next_command(), which is needed
when using cmd_from() from commands where from is not the last element.

With reset, however, "from" is the last command, after which the flow
returns to the main loop, which calls read_next_command() again.

Because of this, always set unread_command_buf in cmd_reset_branch(),
even if cmd_from() was successful.

Add a test case for this in t9300-fast-import.sh.

Signed-off-by: Adeodato Simó <dato@net.com.org.es>
---
 fast-import.c          |    3 ++-
 t/t9300-fast-import.sh |    2 ++
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 7f197d5..655913d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2291,7 +2291,8 @@ static void cmd_reset_branch(void)
 	else
 		b = new_branch(sp);
 	read_next_command();
-	if (!cmd_from(b) && command_buf.len > 0)
+	cmd_from(b);
+	if (command_buf.len > 0)
 		unread_command_buf = 1;
 }
 
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index cceedbb..c4f4465 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -869,6 +869,8 @@ zcommits
 COMMIT
 reset refs/tags/O3-2nd
 from :5
+reset refs/tags/O3-3rd
+from :5
 INPUT_END
 
 cat >expect <<INPUT_END
-- 
1.5.4.3


```

## Shawn O. Pearce, 2008-03-08 02:12

Subject: Re: [PATCH] Really make the LF after reset in fast-import optional
Message-ID: <20080308021210.GX8410@spearce.org>
URL: https://gitlist.dev/e/20080308021210.GX8410%40spearce.org
In-Reply-To: <1204921337-5204-1-git-send-email-dato@net.com.org.es>

```
Adeodato Sim <dato@net.com.org.es> wrote:
> cmd_from() ends with a call to read_next_command(), which is needed
> when using cmd_from() from commands where from is not the last element.
> 
> With reset, however, "from" is the last command, after which the flow
> returns to the main loop, which calls read_next_command() again.
> 
> Because of this, always set unread_command_buf in cmd_reset_branch(),
> even if cmd_from() was successful.
> 
> Add a test case for this in t9300-fast-import.sh.
> 
> Signed-off-by: Adeodato Simó <dato@net.com.org.es>

Heh, this is awesome.  I got busy for a day and someone fixed
my bug for me.  Thanks.  :-)

Acked-by: Shawn O. Pearce <spearce@spearce.org>

>  fast-import.c          |    3 ++-
>  t/t9300-fast-import.sh |    2 ++
>  2 files changed, 4 insertions(+), 1 deletions(-)

-- 
Shawn.

```
