Re: [PATCH v4] diff.c: keep arrow(=) on show_stats()'s shortened filename part to make rename visible.

2013-10-15 Thread Felipe Contreras
On Tue, Oct 15, 2013 at 4:45 AM, Yoshioka Tsuneo
yoshiokatsu...@gmail.com wrote:

 git diff -M --stat can detect rename and show renamed file name like
 foofoofoo = barbarbar. But if destination filename is long, the line
 is shortened like ...barbarbar so there is no way to know whether the
 file is renamed or existed in the source commit.
 Make sure there is always an arrow, like ...foo = ...bar.
 The output can contains curly braces('{','}') for grouping.
 So, in general, the outpu format is pfx{mid_a = mid_b}sfx
 To keep arrow(=), try to omit pfx as long as possible at first
 because later part or changing part will be the more important part.
 If it is not enough, shorten mid_a, mid_b, and sfx trying to
 have the maximum length the same because those will be equaly important.

This has similar style issues as v1.

 -static char *pprint_rename(const char *a, const char *b)
 +static void pprint_rename_find_common_prefix_suffix(const char *a, const 
 char *b, struct strbuf *pfx, struct strbuf *a_mid, struct strbuf *b_mid, 
 struct strbuf *sfx)
  {
 const char *old = a;
 const char *new = b;
 -   struct strbuf name = STRBUF_INIT;
 int pfx_length, sfx_length;
 int pfx_adjust_for_slash;
 int len_a = strlen(a);
 @@ -1272,10 +1271,9 @@ static char *pprint_rename(const char *a, const char 
 *b)
 int qlen_b = quote_c_style(b, NULL, NULL, 0);

 if (qlen_a || qlen_b) {
 -   quote_c_style(a, name, NULL, 0);
 -   strbuf_addstr(name,  = );
 -   quote_c_style(b, name, NULL, 0);
 -   return strbuf_detach(name, NULL);
 +   quote_c_style(a, a_mid, NULL, 0);
 +   quote_c_style(b, b_mid, NULL, 0);
 +   return;
 }

 /* Find common prefix */
 @@ -1321,18 +1319,149 @@ static char *pprint_rename(const char *a, const char 
 *b)
 a_midlen = 0;
 if (b_midlen  0)
 b_midlen = 0;
 +
 +   strbuf_add(pfx, a, pfx_length);
 +   strbuf_add(a_mid, a + pfx_length, a_midlen);
 +   strbuf_add(b_mid, b + pfx_length, b_midlen);
 +   strbuf_add(sfx, a + len_a - sfx_length, sfx_length);
 +}

 -   strbuf_grow(name, pfx_length + a_midlen + b_midlen + sfx_length + 7);
 -   if (pfx_length + sfx_length) {
 -   strbuf_add(name, a, pfx_length);
 +/*
 + * Omit each parts to fix in name_width.
 + * Formatted string is pfx{a_mid = b_mid}sfx.
 + * At first, omit pfx as long as possible.
 + * If it is not enough, omit a_mid, b_mid, sfx by tring to set the 
 length of
 + * those 3 parts(including ...) to the same.
 + * Ex:
 + * foofoofoo = barbarbar
 + *   will be like
 + * ...foo = ...bar.
 + * long_parent{foofoofoo = barbarbar}longfilename
 + *   will be like
 + * ...parent{...foofoo = ...barbar}...lename
 + */
 +static void pprint_rename_omit(struct strbuf *pfx, struct strbuf *a_mid, 
 struct strbuf *b_mid, struct strbuf *sfx, int name_width)

Seems like this line needs to be broken.

 +{
 +
 +#define ARROW  = 
 +#define ELLIPSIS ...
 +#define swap(a,b) myswap((a),(b),sizeof(a))

I'm not entirely sure, but I think this should be:

#define swap(a, b) myswap((a), (b), sizeof(a))

 +
 +#define myswap(a, b, size) do {\
 +unsigned char mytmp[size]; \
 +memcpy(mytmp, a, size);   \
 +memcpy(a, b, size);  \
 +memcpy(b, mytmp, size);   \
 +} while (0)
 +
 +   int use_curly_braces = (pfx-len  0) || (sfx-len  0);
 +   size_t name_len;
 +   size_t len;
 +   size_t part_lengths[4];
 +   size_t max_part_len = 0;
 +   size_t remainder_part_len = 0;
 +   int i, j;
 +
 +   name_len = pfx-len + a_mid-len + b_mid-len + sfx-len + 
 strlen(ARROW) + (use_curly_braces?2:0);
 +
 +   if (name_len = name_width){

if () {

 +   /* Everthing fits in name_width */
 +   return;
 +   }
 +
 +   if(use_curly_braces){

Ditto.

 +   if(strlen(ELLIPSIS) + (name_len - pfx-len) = name_width){

Ditto.

 +   /*
 +Just omitting left of '{' is enough
 +Ex: ...aaa{foofoofoo = bar}file
 +*/
 +   strbuf_splice(pfx, name_len - pfx-len, name_width - 
 (name_len - pfx-len), ELLIPSIS, strlen(ELLIPSIS));
 +   return;
 +   }else{

} else {

 +   if (pfx-len  strlen(ELLIPSIS)) {
 +   /*
 +Just omitting left of '{' is not enough
 +name will be ...{SOMETHING}SOMETHING
 +*/
 +   strbuf_reset(pfx);
 +   strbuf_addstr(pfx, ELLIPSIS);
 +   }
 +   }
 +   }
 +
 +   /* available length for a_mid, b_mid and sfx */
 +   len = name_width - strlen(ARROW) - 

Re: [PATCH v4] diff.c: keep arrow(=) on show_stats()'s shortened filename part to make rename visible.

2013-10-15 Thread Yoshioka Tsuneo
Hello Felipe

Thank you for pointing out the style issue again.
I just fixed it and posted as [PATCH v5].

Thanks!

---
Tsuneo Yoshioka (吉岡 恒夫)
yoshiokatsu...@gmail.com




On Oct 15, 2013, at 1:07 PM, Felipe Contreras felipe.contre...@gmail.com 
wrote:

 On Tue, Oct 15, 2013 at 4:45 AM, Yoshioka Tsuneo
 yoshiokatsu...@gmail.com wrote:
 
 git diff -M --stat can detect rename and show renamed file name like
 foofoofoo = barbarbar. But if destination filename is long, the line
 is shortened like ...barbarbar so there is no way to know whether the
 file is renamed or existed in the source commit.
 Make sure there is always an arrow, like ...foo = ...bar.
 The output can contains curly braces('{','}') for grouping.
 So, in general, the outpu format is pfx{mid_a = mid_b}sfx
 To keep arrow(=), try to omit pfx as long as possible at first
 because later part or changing part will be the more important part.
 If it is not enough, shorten mid_a, mid_b, and sfx trying to
 have the maximum length the same because those will be equaly important.
 
 This has similar style issues as v1.
 
 -static char *pprint_rename(const char *a, const char *b)
 +static void pprint_rename_find_common_prefix_suffix(const char *a, const 
 char *b, struct strbuf *pfx, struct strbuf *a_mid, struct strbuf *b_mid, 
 struct strbuf *sfx)
 {
const char *old = a;
const char *new = b;
 -   struct strbuf name = STRBUF_INIT;
int pfx_length, sfx_length;
int pfx_adjust_for_slash;
int len_a = strlen(a);
 @@ -1272,10 +1271,9 @@ static char *pprint_rename(const char *a, const char 
 *b)
int qlen_b = quote_c_style(b, NULL, NULL, 0);
 
if (qlen_a || qlen_b) {
 -   quote_c_style(a, name, NULL, 0);
 -   strbuf_addstr(name,  = );
 -   quote_c_style(b, name, NULL, 0);
 -   return strbuf_detach(name, NULL);
 +   quote_c_style(a, a_mid, NULL, 0);
 +   quote_c_style(b, b_mid, NULL, 0);
 +   return;
}
 
/* Find common prefix */
 @@ -1321,18 +1319,149 @@ static char *pprint_rename(const char *a, const 
 char *b)
a_midlen = 0;
if (b_midlen  0)
b_midlen = 0;
 +
 +   strbuf_add(pfx, a, pfx_length);
 +   strbuf_add(a_mid, a + pfx_length, a_midlen);
 +   strbuf_add(b_mid, b + pfx_length, b_midlen);
 +   strbuf_add(sfx, a + len_a - sfx_length, sfx_length);
 +}
 
 -   strbuf_grow(name, pfx_length + a_midlen + b_midlen + sfx_length + 
 7);
 -   if (pfx_length + sfx_length) {
 -   strbuf_add(name, a, pfx_length);
 +/*
 + * Omit each parts to fix in name_width.
 + * Formatted string is pfx{a_mid = b_mid}sfx.
 + * At first, omit pfx as long as possible.
 + * If it is not enough, omit a_mid, b_mid, sfx by tring to set the 
 length of
 + * those 3 parts(including ...) to the same.
 + * Ex:
 + * foofoofoo = barbarbar
 + *   will be like
 + * ...foo = ...bar.
 + * long_parent{foofoofoo = barbarbar}longfilename
 + *   will be like
 + * ...parent{...foofoo = ...barbar}...lename
 + */
 +static void pprint_rename_omit(struct strbuf *pfx, struct strbuf *a_mid, 
 struct strbuf *b_mid, struct strbuf *sfx, int name_width)
 
 Seems like this line needs to be broken.
 
 +{
 +
 +#define ARROW  = 
 +#define ELLIPSIS ...
 +#define swap(a,b) myswap((a),(b),sizeof(a))
 
 I'm not entirely sure, but I think this should be:
 
 #define swap(a, b) myswap((a), (b), sizeof(a))
 
 +
 +#define myswap(a, b, size) do {\
 +unsigned char mytmp[size]; \
 +memcpy(mytmp, a, size);   \
 +memcpy(a, b, size);  \
 +memcpy(b, mytmp, size);   \
 +} while (0)
 +
 +   int use_curly_braces = (pfx-len  0) || (sfx-len  0);
 +   size_t name_len;
 +   size_t len;
 +   size_t part_lengths[4];
 +   size_t max_part_len = 0;
 +   size_t remainder_part_len = 0;
 +   int i, j;
 +
 +   name_len = pfx-len + a_mid-len + b_mid-len + sfx-len + 
 strlen(ARROW) + (use_curly_braces?2:0);
 +
 +   if (name_len = name_width){
 
 if () {
 
 +   /* Everthing fits in name_width */
 +   return;
 +   }
 +
 +   if(use_curly_braces){
 
 Ditto.
 
 +   if(strlen(ELLIPSIS) + (name_len - pfx-len) = name_width){
 
 Ditto.
 
 +   /*
 +Just omitting left of '{' is enough
 +Ex: ...aaa{foofoofoo = bar}file
 +*/
 +   strbuf_splice(pfx, name_len - pfx-len, name_width - 
 (name_len - pfx-len), ELLIPSIS, strlen(ELLIPSIS));
 +   return;
 +   }else{
 
 } else {
 
 +   if (pfx-len  strlen(ELLIPSIS)) {
 +   /*
 +Just omitting left of '{' is not enough
 +name will be ...{SOMETHING}SOMETHING
 +*/
 +