Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 2/4] Mechanical conversion to use prefixcmp()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:56

Junio C Hamano [off-list ref] writes:
This mechanically converts strncmp() to use prefixcmp(),
...
 * This was done by using this script in px.perl

   #!/usr/bin/perl -i.bak -p
   if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
           s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
   }
   if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
           s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
   }

   and running:

   $ git grep -l strncmp -- '*.c' | xargs perl px.perl
Two useless comments to add.

 (1) Yes, I have seen the "Oh, I lost my data doing this silly
     thing" thread that mentioned the risk of using xargs ;-).
     In general, piping output from git commands that give list
     of paths (e.g. "grep", "ls-files", "diff --name-only" and
     "ls-tree -r --name-only") to xargs should be a much safer
     practice, and people should get into the habit of doing so,
     instead of using "find | xargs".

 (2) This multi-step "mechanical conversion followed by manual
     fixup" is a trick I picked up from Linus.  The replacement
     regexp quoted above are designed to be stricter than
     necessary to catch only the safe conversion target, while
     accepting false negatives.  Doing the conversion this way,
     I do not have to worry too much about auditing 1800 lines
     of diff in [PATCH 2/4], as long as I make sure the above
     regexp is strict enough (although I did look at all 1800
     lines of diff before committing this).  Manual conversions
     in later steps do need to be looked at much more carefully
     than the result of this step, of course.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help