Re: [GUILT v2 15/29] Produce legal patch names in guilt-import-commit.

2014-05-15 Thread Jeff Sipek
On Tue, May 13, 2014 at 10:30:51PM +0200, Per Cederqvist wrote:
 Try harder to create patch names that adhere to the rules in
 git-check-ref-format(1) when deriving a patch name from the commit
 message.  Verify that the derived name using git check-ref-format,
 and as a final fallback simply use the patch name x (to ensure that
 the code is future-proof in case new rules are added in the future).
 
 Always append a .patch suffix to the patch name.
 
 Added test cases.

Also very nice.

Thanks,

Jeff.

Signed-off-by: Josef 'Jeff' Sipek jef...@josefsipek.net

-- 
We have joy, we have fun, we have Linux on a Sun...
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[GUILT v2 15/29] Produce legal patch names in guilt-import-commit.

2014-05-13 Thread Per Cederqvist
Try harder to create patch names that adhere to the rules in
git-check-ref-format(1) when deriving a patch name from the commit
message.  Verify that the derived name using git check-ref-format,
and as a final fallback simply use the patch name x (to ensure that
the code is future-proof in case new rules are added in the future).

Always append a .patch suffix to the patch name.

Added test cases.

Signed-off-by: Per Cederqvist ced...@opera.com
---
 guilt-import-commit  |  20 +-
 regression/t-034.out | 567 +++
 regression/t-034.sh  |  71 +++
 3 files changed, 656 insertions(+), 2 deletions(-)
 create mode 100644 regression/t-034.out
 create mode 100755 regression/t-034.sh

diff --git a/guilt-import-commit b/guilt-import-commit
index f14647c..6260c56 100755
--- a/guilt-import-commit
+++ b/guilt-import-commit
@@ -28,19 +28,35 @@ disp Current head: `git rev-parse \`git_branch\`` 2
 for rev in `git rev-list $rhash`; do
s=`git log --pretty=oneline -1 $rev | cut -c 42-`
 
+   # Try to convert the first line of the commit message to a
+   # valid patch name.
fname=`echo $s | sed -e s//and/g -e s/[ :]/_/g -e s,[/\\],-,g \
-e s/['\\[{}]//g -e 's/]//g' -e 's/\*/-/g' \
-   -e 's/\?/-/g' | tr A-Z a-z`
+   -e 's/\?/-/g' -e 's/\.\.\.*/./g' -e 's/^\.//' \
+   -e 's/\.patch$//' -e 's/\.$//' | tr A-Z a-z`
+
+   if ! valid_patchname $fname; then
+   # Try harder to make it a legal commit name by
+   # removing all but a few safe characters.
+   fname=`echo $fname|tr -d -c _a-zA-Z0-9---/\\n`
+   fi
+   if ! valid_patchname $fname; then
+   # If we failed to derive a legal patch name, use the
+   # name x.  (If this happens, we likely have to
+   # append a suffix to make the name unique.)
+   fname=x
+   fi
 
disp Converting `echo $rev | cut -c 1-8` as $fname
 
mangle_prefix=1
fname_base=$fname
-   while [ -f $GUILT_DIR/$branch/$fname ]; do
+   while [ -f $GUILT_DIR/$branch/$fname.patch ]; do
fname=$fname_base-$mangle_prefix
mangle_prefix=`expr $mangle_prefix + 1`
disp Patch under that name exists...trying '$fname'
done
+   fname=$fname.patch
 
(
do_make_header $rev
diff --git a/regression/t-034.out b/regression/t-034.out
new file mode 100644
index 000..7bc9459
--- /dev/null
+++ b/regression/t-034.out
@@ -0,0 +1,567 @@
+% setup_git_repo
+% git tag base
+% create_commit a The sequence /. is forbidden.
+[master eebb76e] The sequence /. is forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+ create mode 100644 a
+% create_commit a The sequence .lock/ is forbidden.
+[master 45e81b5] The sequence .lock/ is forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a A/component/may/not/end/in/foo.lock
+[master bbf3f59] A/component/may/not/end/in/foo.lock
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Two consecutive dots (..) is forbidden.
+[master 1535e67] Two consecutive dots (..) is forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Check/multiple/../dots/./foo..patch
+[master 48eb60c] Check/multiple/../dots/./foo..patch
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Space is forbidden.
+[master 10dea83] Space is forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Tilde~is~forbidden.
+[master 70a83b7] Tilde~is~forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Caret^is^forbidden.
+[master ee6ef2c] Caret^is^forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Colon:is:forbidden.
+[master c077fe2] Colon:is:forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Delisforbidden.
+[master 589ee30] Delisforbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% git branch some-branch
+% git tag some-tag
+% create_commit a Ctrlisforbidden.
+[master e63cdde] Ctrlisforbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a CR
is
also
forbidden.
+[master 21ad093] CR
is
also
forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Question-mark?is?forbidden.
+[master be2fa9b] Question-mark?is?forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Asterisk*is*forbidden.
+[master af7b50f] Asterisk*is*forbidden.
+ Author: Author Name author@email
+ 1 file changed, 1 insertion(+)
+% create_commit a Open[bracket[is[forbidden.
+[master 689f618]