Request: better commit messages in fast-export

Currently, bk fast-export only exports the changeset comment, but not the individual file comments → these comments are lost when fast-importing to git.
Since git doesn’t support individual file comments, one could combine the changeset comment and the individual file comments into a single commit message, similar to the output of bk changes -v.

Yeah, I agree. It is a bit tricky because people often use the same comment for a collection of files so you want something like:

ChangeSet comments.

file1:
file1 comments

file2, file3:
identical comments on a couple files

Somewhere, I can’t remember where, we have code that does that grouping. Maybe it’s command line commit when the files are all pending with comments already?

bk sccslog’ does this type of comment grouping already. And we use this code when running ‘bk commit’ from the command line to give you a default commit message to edit.

Run bk changes -v --json

I’ve hacked the dspec file to look like this for this exact purpose:

If you put this in dspec-bk2git:

# dspec-v2
# Copyright 2008,2011,2016 BitMover, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is the dspec used when exporting changesets to Git. Git does not have
# per file comments so we export the cset and file comments into the Git
# cset comments as a json array.  That's lossless.
#
# $0 == 1 means we have a { to close for the changeset 
# $1 == 1 means we have a [ to close for the file list
# $2 == 1 means we need a comma before printing the next file
#         also means we need a newline so we do a \n on changeset/EOF
#         but ,\n on next file
# $3 == :USER: from the cset so we don't replicate in the file unless it changed
# $4 == :HOST: ditto

$begin {
        "# bk2git cset and file info in json because not having per file comments sucks\n"
        "[\n"
}

$if (:CHANGESET: && !:COMPONENT_V:) {
        $if($2 -eq 1) {
                "\n"
        }
        $if($1 -eq 1) {
                "  ]\n"
        }
        $if($0 -eq 1) {
                "\},\n"
        }
        "\{\n"
        "  \"user\": \":USER:\",\n"
        "  \"host\": \":HOST:\",\n"
        "  \"comments\": \"" $each(:C:){$json{(:C:)}\\n} "\",\n"
        $if (:TAGS:) {
                "  \"tags\": [ "
                $each(:TAGS:){:JOIN:"\""(:TAGS:)"\""}
                " ],\n"
        }
        "  \"deltas\":\n  [\n"
        ${0=1}                          # we need to close off the changeset
        ${1=1}                          # we need to close off the delta : [
        ${2=0}                          # don't need a comma yet
        ${3=:USER:}                     # skip printing below if not needed
        ${4=:HOST:}                     # skip printing below if not needed
} $else {
        $unless(:REV:=1.0) {
                $if($2 -eq 1) {
                        ",\n"
                }
                "    \{\n"
                "      \"path\": \":DPN:\",\n"
                $if($3 != :USER:) {
                        "      \"user\": \":USER:\",\n"
                }
                $if($4 != :HOST:) {
                        "      \"host\": \":HOST:\",\n"
                }
                "      \"comments\": \"" $each(:C:){$json{(:C:)}\\n} "\",\n"
                "    \}"
                ${2=1}                          # we need a comma
        }
}

$end {
        $if($2 -eq 1) {
                "\n"
        }
        $if($1 -eq 1) {
                "  ]\n"
        }
        $if($0 -eq 1) {
                "\}\n"
        }
        "]\n"
}

and then run

bk changes -v -1 --dspecf=dspec-bk2git

You get this:

# bk2git cset and file info in json because not having per file comments sucks
[
{
  "user": "georgn",
  "host": "odin.bitkeeper.com",
  "comments": "Parallel make bug hunt! Make sure you're wearing your hi-visibili
ty vest!\n\n - MacOS build of tcl could fail because of a race between the build
ing of\n   stuff that depended on the generated header tclDtrace.h.\n\n   I am q
uite certain that nobody here has ever used the dtrace support in\n   tcl so rat
her than alter the tcl tree, seemed easier to disable dtrace\n   support from ou
r upper-level makefile.\n\n- Add dependency for generated header (tkTable.tcl.h)
 to\n  prevent parallel make race.\n\n- Add dep for the tktable dynamic library 
to ensure that it correctly\n  ends up in the installation\n",
  "deltas":
  [
    {
      "path": "src/gui/ChangeSet",
      "comments": "Parallel make bug hunt! Make sure you're wearing your hi-visi
bility vest!\n\n - MacOS build of tcl could fail because of a race between the b
uilding of\n   stuff that depended on the generated header tclDtrace.h.\n\n   I 
am quite certain that nobody here has ever used the dtrace support in\n   tcl so
 rather than alter the tcl tree, seemed easier to disable dtrace\n   support fro
m our upper-level makefile.\n\n- Add dependency for generated header (tkTable.tc
l.h) to\n  prevent parallel make race.\n\n- Add dep for the tktable dynamic libr
ary to ensure that it correctly\n  ends up in the installation\n",
    },
    {
      "path": "src/gui/tcltk/Makefile",
      "comments": "Remove references to the various ChangeLog files.  These deps
\nare kind of a hangover from the pre-nested version of our repo.\n\nThis stops 
us from calling the populate recipe for each component\nin TCLTK (as evidenced b
y the \"Cloning TclTk repos\" message that\nwere printed 4 times each build).\n\
nDisable dtrace support in mac tcl build.\nWe don't use it and there's a build r
ace on the dtrace header\nwhen using parallel make.\n",
    },
    {
      "path": "src/gui/tcltk/tktable/ChangeSet",
      "comments": "Parallel make bug hunt! Make sure you're wearing your hi-visi
bility vest!\n\n - MacOS build of tcl could fail because of a race between the b
uilding of\n   stuff that depended on the generated header tclDtrace.h.\n\n   I 
am quite certain that nobody here has ever used the dtrace support in\n   tcl so
 rather than alter the tcl tree, seemed easier to disable dtrace\n   support fro
m our upper-level makefile.\n\n- Add dependency for generated header (tkTable.tc
l.h) to\n  prevent parallel make race.\n\n- Add dep for the tktable dynamic libr
ary to ensure that it correctly\n  ends up in the installation\n",
    },
    {
      "path": "src/gui/tcltk/tktable/Makefile.in",
      "comments": "MacOS parallel make on fix.  Without this, the tktable .dylib
 may not\nbe built when the rest of the stuff gets put into the application\nbun
dle.\n\nAdd dependency for generated header to prevent parallel make race.\n",
    }
  ]
}
]

which is useful in my opinion. I agree that we want to keep all the info we can.

I need to learn how to do code snippets here. I’ll put that stuff somewhere else as .txt files if people care.

Nevermind, Wayne fixed it.