Fossil Forum

Merge branch lost empty lines and line breaks in the code
Login

Merge branch lost empty lines and line breaks in the code

Merge branch lost empty lines and line breaks in the code

(1.1) By medfav on 2023-12-18 11:43:04 edited from 1.0 [link] [source]

I don't know if it's a program error or my settings error. Merge branch lost empty lines and line breaks in the code. Please refer to the following for specific details. This is before the merger.The content at the end of the file is the end of the file, and there are no blank lines at the end of the file:

// read cookie
function getCookie(name) {
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

This is after the merger(Maekdown code block '+' preview not working properly, use '\+' instead '+'):

  // read cookie
  function getCookie(name) {
      var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
      if(arr=document.cookie.match(reg))
          return unescape(arr[2]);
      else
          return null;
\+ }function saveLogToFile() {
\+     let receivedMsg = document.getElementById("receivedMsg");
\+     let log = receivedMsg.value;
\+     const blob = new Blob([log], {type: "text/plain;charset=utf-8"});
\+     const url = URL.createObjectURL(blob);
\+     const aTag = document.createElement('a');
\+     aTag.href = url;
\+     aTag.download = "log.txt";
\+     aTag.click();
\+     URL.revokeObjectURL(url);
  }
The correct result should be as follows:

  // read cookie
  function getCookie(name) {
      var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
      if(arr=document.cookie.match(reg))
          return unescape(arr[2]);
      else
          return null;
   }

\+  function saveLogToFile() {
\+     let receivedMsg = document.getElementById("receivedMsg");
\+     let log = receivedMsg.value;
\+     const blob = new Blob([log], {type: "text/plain;charset=utf-8"});
\+     const url = URL.createObjectURL(blob);
\+     const aTag = document.createElement('a');
\+     aTag.href = url;
\+     aTag.download = "log.txt";
\+     aTag.click();
\+     URL.revokeObjectURL(url);
\+  }

My file is encoded as "UTF-8" and the line break is "CRLF".

(2) By Stephan Beal (stephan) on 2023-12-18 14:18:29 in reply to 1.1 [link] [source]

Please refer to the following for specific details.

Can you tell us what version of fossil you're using and on what platform?

This is the first report of this particular problem and no changes have been made to the merge-related code in years, so it would be very useful for debugging this if you can provide us with a copy of the repository and show us which version can reproduce this problem.

Is the line really missing in the merged copy, or is perhaps the diff command showing the line as missing but the line is really there?

(3) By medfav on 2023-12-18 15:29:39 in reply to 2 [link] [source]

I am currently at home, and the repository where the problem occurred is on the company computer. I cannot remember some of the projects clearly.

I am experimenting with using Fossil in a simple web project. If possible, I can also provide you with the entire repository, but it will take at least 10 hours for me to start work, and my time zone is UTC+8.

Platform: Windows 10
Fossil version: 2.22 or 2.23
The command I am using is: fossil merge -- cherrypick [Version]

(4) By Stephan Beal (stephan) on 2023-12-18 19:25:44 in reply to 3 [link] [source]

If possible, I can also provide you with the entire repository, but it will take at least 10 hours for me to start work, and my time zone is UTC+8.

That would be great. There's no hurry.

The command I am using is: fossil merge -- cherrypick Version

When you provide the repo, please be sure to tell us which version you're working from and which one you're cherrypicking.

(5) By medfav on 2023-12-19 08:53:14 in reply to 4 [link] [source]

I'm sorry for being available so late.

https://www.mediafire.com/file/a58n2gg4wpp9qcc/fossil_websocket.zip/file
This is the Fossil repository where I encountered issues.

I merged "trunk[3b14e633fe]" into the ShenTong branch at "ShenTong[e133cc3a8d]" (commit log written incorrectly), and then found that the websocket.js file at the end of the ShenTong branch had an abnormal format.

Operating system: Windows 10 1909

Fossil version: 2.23

Merge command:fossil merge --cherrypick 3b14e633fe

(6) By Preben Guldberg (preben) on 2023-12-19 10:31:57 in reply to 5 [link] [source]

Thanks for providing the repository.

Looking at the progression of the file through the branches, my immediate thought is that the issue is related to the lack of line terminator at end of file (which is sometimes there, sometimes not). That, and the fact that the merge adds a new function at the end of the file.

(7) By medfav on 2023-12-19 11:33:23 in reply to 6 [link] [source]

It's what you said, and I also think it might have something to do with the end-of-file character. I'll try to find the cause of the missing end-of-file character and try to avoid that.

(8) By Stephan Beal (stephan) on 2023-12-19 12:42:50 in reply to 7 [link] [source]

I also think it might have something to do with the end-of-file character. I'll try to find the cause of the missing end-of-file character and try to avoid that.

There shouldn't be an explicit EOF character but there should definitely be an EOL/CRNL at the end of the last line. Without that, lots of tools will behave like fossil did for those inputs.

(9) By Preben Guldberg (preben) on 2023-12-19 12:48:09 in reply to 7 [link] [source]

I managed to reproduce this (with a small difference) on my macOS using trunk. I use standard Unix LF newlines here, not CRLF.

The steps to reproduce:

  1. Create a file in trunk without a final newline (10 line function "func1 {\n...\n}")
  2. Add a final newline and commit to a new branch X ("func1 {\n...\n}\n")
  3. Rename the function in branch X, still with a final newline ("func_xxx {\n...\n}\n"")
  4. Switch back to trunk
  5. Add a new 5 line function and a final newline with two newlines between the functions ("func1 {\n...\n}\n\nfunc2 {\n...\n}\n")
  6. Switch to the X branch
  7. Merge in change trunk (with or without --cherrypick)
  8. Results is missing one newline between the functions ("func_xxx {\n...\n}\nfunc2 {\n...\n}\n")

In my case, the spacing between the function is now gone (I have one instead of two newlines) where in your case both are gone.

(10) By Andy Bradford (andybradford) on 2023-12-19 14:46:18 in reply to 9 [link] [source]

I'm not sure this is a bug in Fossil per se. I see this kind of behavior
all the  time also with Git,  especially when some committers  are using
"fancy" editors that don't understand that lines end with \n or \r\n.

Said "fancy" editors  typically leave off the last EOL  on the last line
of the file. Quite annoying.

Andy

(12) By medfav on 2023-12-19 14:59:03 in reply to 9 [link] [source]

I used the "fossil diff" command to compare the two versions that had merge errors:

fossil diff webSocket.js --from e133cc3a8d --to 3b14e633fe

The comparison results are as follows:

     if(arr=document.cookie.match(reg))
         return unescape(arr[2]);
     else
         return null;
+}
+
+function saveLogToFile() {
+    let receivedMsg = document.getElementById("receivedMsg");
+    let log = receivedMsg.value;
+    const blob = new Blob([log], {type: "text/plain;charset=utf-8"});
+    const url = URL.createObjectURL(blob);
+    const aTag = document.createElement('a');
+    aTag.href = url;
+    aTag.download = "log.txt";
+    aTag.click();
+    URL.revokeObjectURL(url);
 }

That's a good result.

(11) By Andy Bradford (andybradford) on 2023-12-19 14:55:31 in reply to 5 [link] [source]

> and then found  that the websocket.js file at the  end of the ShenTong
> branch had an abnormal format.

Your file  still has an abnormal  format even after you  "fixed" it. The
last line of the file is still missing proper EOL termination:

$ hexdump -C webSocket.js | tail -4
00001790  28 29 3b 0d 0a 20 20 20  20 55 52 4c 2e 72 65 76  |();..    URL.rev|
000017a0  6f 6b 65 4f 62 6a 65 63  74 55 52 4c 28 75 72 6c  |okeObjectURL(url|
000017b0  29 3b 0d 0a 7d                                    |);..}|
000017b5

Notice that the last '}' in  the file, represented as 7d in hexadecimal,
is not followed by 0d 0a as  it should. Whatever editor you are using is
leaving off the EOL characters for your OS (Windows).

Andy

(13) By medfav on 2023-12-19 15:15:03 in reply to 11 [source]

I don't remember what editor I started out with, but I generally use VSCode and I didn't notice the missing EOL.

I just tried creating another file with VScode and there is no EOL at the end of the file either. There must be a blank line at the end of the file to not lose the EOL character.

(14) By Daniel Dumitriu (danield) on 2023-12-20 12:54:13 in reply to 13 [link] [source]

For VSCode, take a look at the following settings:

  "files.insertFinalNewline": true,     // re. "there is no EOL at the end of the file"
  "editor.renderFinalNewline": "dimmed" // re. "I didn't notice the missing EOL"

While I do understand the POSIX take on this (text files and lines thereof) and find it generally a good idea - also in connection with the C standard (A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.) - Windows e.g. not being POSIX-compliant is here less strict and this is pretty bound to happen, so tools should be prepared for this.

This is the cause that leads to a rather unfortunate discrepancy in the file contents, as visible in the two diffs:

fossil diff -i --from e133 --to 3b14 webSocket.js
shows the change as expected, preserving the two newlines, but
fossil diff -i --from e133 --to 6707 webSocket.js
does not.

I'd call this at best an inconsistency, at worst a bug, since content of the file as of check-in 3b14 is not being carried forward on merge.

(15) By medfav on 2023-12-20 13:44:52 in reply to 14 [link] [source]

For VSCode, take a look at the following settings:

Thanks for the instruction.

I'd call this at best an inconsistency, at worst a bug, since content of the file as of check-in 3b14 is not being carried forward on merge.

I agree with you, and it's hard to find errors in this case when there are more files to modify.

(16.1) By Andy Bradford (andybradford) on 2023-12-21 18:21:20 edited from 16.0 in reply to 14 [link] [source]

> I'd call this at best an inconsistency, at worst a bug, 

I'm  still trying  to see  how. If  I checkout  [17495e44d8]---where the
"\r\n\r\n" was added---then run "fossil  merge [e133cc3a8d]", I get told
there are conflicts:

$ fossil up 17495e44d8      
-------------------------------------------------------------------------------
checkout:     17495e44d8f1bb6bcd08e0eab28a6e109d5310c2 2023-12-15 10:43:43 UTC
tags:         trunk
comment:      Remove useless comments (user: 51096)
changes:      None. Already up-to-date

$ fossil merge e133cc3a8d
MERGE webSocket.js
***** 2 merge conflicts in webSocket.js
WARNING: 1 merge conflicts
 "fossil undo" is available to undo changes to the working checkout.

$ tail -4 webSocket.js | hexdump -C
00000000  20 20 20 20 65 6c 73 65  0d 0a 20 20 20 20 20 20  |    else..      |
00000010  20 20 72 65 74 75 72 6e  20 6e 75 6c 6c 3b 0d 0a  |  return null;..|
00000020  7d 0d 0a 0d 0a                                    |}....|
00000025

I still see the "\r\n\r\n" in that file.

I suspect that  the OP must have  removed the newlines in  an attempt to
correct the merge conflict before committing to get [98398ce8c1].

[EDIT: This conclusion  was wrong as I was looking  at the wrong commits
and even  [98398ce8c1] shows  that the "\r\n\r\n"  were included  in the
commit.]

(17) By Andy Bradford (andybradford) on 2023-12-21 17:47:36 in reply to 16.0 [link] [source]

> I'm still  trying to see  how. If I checkout  [17495e44d8]---where the
> "\r\n\r\n"  was added---then  run "fossil  merge [e133cc3a8d]",  I get
> told there are conflicts:

Hmm, it seems I was looking at the wrong merges.

Andy

(18.2) By Andy Bradford (andybradford) on 2023-12-21 19:41:37 edited from 18.1 in reply to 14 [link] [source]

> since content  of the file  as of check-in  3b14 is not  being carried
> forward on merge.

I  think this  is going  to come  down to  the merge  algorithm and  how
parentage  of commits  is determined.  Notice that  the common  ancestor
between [3b14e633fe] and [e133cc3a8d] is [bf82e6cbcb72]

$ fossil test-ancestor-path 3b14e633fe e133cc3a8d
   1:    16 e133cc3a8d60 2023-12-15 10:49:54 VERSION2
   2:    12 4502b2cfb8af 2023-12-15 08:59:01
   3:     8 034882ad20d9 2023-12-15 07:51:26
   4:     6 85e74543f522 2023-12-15 07:44:05
   5:     4 bf82e6cbcb72 2023-12-15 03:40:58 PIVOT
   6:    10 38a2a417d820 2023-12-15 08:26:56
   7:    14 17495e44d8f1 2023-12-15 10:43:43
   8:    18 98398ce8c143 2023-12-15 10:54:59
   9:    21 3b14e633fe4d 2023-12-18 07:46:54 VERSION1

This means that  the merge that happened to produce  [6707d71c38] has no
knowledge of the "\r\n\r\n" commit. I believe what's missing is that the
OP  should have  merged  [17495e44d8] into  the  ShenTong branch  before
attempting to merge the branch back to trunk. This would then have reset
the pivot point for the merge and it would have merged as expected.

See my sequence of commits here:

http://fossil.bradfords.org:11072/WebscoketWeb/timeline

Notice that when I merged trunk into ShenTong to produce [e93867ea30] it
"carried forward" the  "\r\n\r\n" change into the  ShenTong branch. Then
when  I merge  [ef2aa5686d] back  into  the branch  at [e93867ea30],  no
"\r\n\r\n" are  lost at all. You  can see also that  the common ancestor
between [ef2aa5686d] and [e93867ea30] is [17495e44d8]:

$ fossil test-ancestor-path ef3090d191 e93867ea  
   1:    29 ef3090d191a6 2023-12-21 18:38:23 VERSION1
   2:    14 17495e44d8f1 2023-12-15 10:43:43 PIVOT
   3:    28 e93867ea30cc 2023-12-21 18:35:32 VERSION2

[EDIT:  I just  now realized  that the  OP is  using merge  --cherrypick
instead of just merge which explains  why the common ancestor for the OP
is [bf82e6cbcb72], but I still believe that the correct thing is for the
OP to merge in trunk into the branch or cherrypick everything that needs
to be  there for correctly merging  back into trunk. The  "\r\n\r\n" was
not able to be merged in because it was never in the branch.]

Andy

(20.1) By Andy Bradford (andybradford) on 2023-12-21 20:31:28 edited from 20.0 in reply to 18.2 [link] [source]

> See my sequence of commits here:

Also note  that if the  OP had just  merged trunk [3b14e633fe]  into the
branch [e133cc3a8d],  the "\r\n\r\n"  would have been  "carried forward"
and perhaps even discovered while editing the conflicted files:

$ fossil up 6707d71c38
-------------------------------------------------------------------------------
checkout:     6707d71c383010caa216d1e22843f0036cefcca2 2023-12-18 07:53:00 UTC
tags:         ShenTong
comment:      Merge ShenTong[3b14e633fe] to this branch (user: 51096)
changes:      None. Already up-to-date

$ fossil merge 3b14e633
MERGE webSocket.js
***** 2 merge conflicts in webSocket.js
MERGE websocket.html
WARNING: 1 merge conflicts
 "fossil undo" is available to undo changes to the working checkout.

At  this point,  in  editing the  files with  conflicts,  it would  have
"carried forward" the "\r\n\r\n" (represented here as ^M and a newline):

<<<<<<< BEGIN MERGE CONFLICT: local copy shown first <<<<<<<<<<<< (line 172)^M
}function saveLogToFile() {^M
    let receivedMsg = document.getElementById("receivedMsg");^M
    let log = receivedMsg.value;^M
    const blob = new Blob([log], {type: "text/plain;charset=utf-8"});^M
    const url = URL.createObjectURL(blob);^M
    const aTag = document.createElement('a');^M
    aTag.href = url;^M
    aTag.download = "log.txt";^M
    aTag.click();^M
    URL.revokeObjectURL(url);^M
}^M
||||||| COMMON ANCESTOR content follows ||||||||||||||||||||||||| (line 171)^M
}^M
======= MERGED IN content follows =============================== (line 168)^M
}^M
^M
function saveLogToFile() {^M
    let receivedMsg = document.getElementById("receivedMsg");^M
    let log = receivedMsg.value;^M
    const blob = new Blob([log], {type: "text/plain;charset=utf-8"});^M
    const url = URL.createObjectURL(blob);^M
    const aTag = document.createElement('a');^M
    aTag.href = url;^M
    aTag.download = "log.txt";^M
    aTag.click();^M
    URL.revokeObjectURL(url);^M
}^M
>>>>>>> END MERGE CONFLICT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>^M

I  still  think  Fossil  is  working  correctly  and  that  there  is  a
misunderstanding   about   how   "fossil  merge"   and   "fossil   merge
--cherrypick" differ and when one might want to use one or the other.

Andy

(19.1) By Andy Bradford (andybradford) on 2023-12-21 20:14:54 edited from 19.0 in reply to 5 [link] [source]

When  you use  "fossil merge  --cherrypick"  it only  gets the  specific
changes to code from 3b14e633fe. It  does not "inherit" all the previous
commits up to the pivot (aka common ancestor), just that one commit.

Is  there  a  particular  reason   that  you  are  using  "fossil  merge
--cherrypick" instead of just "fossil merge"?

As documented:

  --cherrypick            Do a cherrypick merge VERSION into the current
                          check-out.  A cherrypick merge pulls in the changes
                          of the single check-in VERSION, rather than all
                          changes back to the nearest common ancestor.

Thanks,

Andy

(21) By medfav on 2023-12-22 01:37:34 in reply to 19.1 [link] [source]

As you say, here I used fossil merge --cherrypick by mistake.
I incorrectly assumed that neither the trunk branch nor the ShenTong branch had 'rnrn' at the end of the file, but I just looked at trunk[98398ce8c1] and ShenTong[e133cc3a8d], and I see that 'trunk[98398ce8c1]' does have 'rnrn' at the end of the file (this difference was introduced in trunk[17495e44d8]).
cherrypick's version of trunk[3b14e633fe] changes as follows:

    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

+function saveLogToFile() {
+    let receivedMsg = document.getElementById("receivedMsg");
+    let log = receivedMsg.value;
+    const blob = new Blob([log], {type: "text/plain;charset=utf-8"});
+    const url = URL.createObjectURL(blob);
+    const aTag = document.createElement('a');
+    aTag.href = url;
+    aTag.download = "log.txt";
+    aTag.click();
+    URL.revokeObjectURL(url);
+}

So fossil merge --cherrypick results are as expected.

Sorry, this was is my mistake.

Think you!