Code

Merge branch 'zj/decimal-width'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2012 08:15:11 +0000 (00:15 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2012 08:15:11 +0000 (00:15 -0800)
* zj/decimal-width:
  make lineno_width() from blame reusable for others

Conflicts:
cache.h
pager.c

1  2 
builtin/blame.c
cache.h
pager.c

diff --combined builtin/blame.c
index 01956c80815a4f330ae27b77b4d21d263a887d1b,f028e8aec82d0936951418f936123041c3b516ad..b35bd6249de66d02b7f33eb7aae4866193447156
@@@ -1828,18 -1828,6 +1828,6 @@@ static int read_ancestry(const char *gr
        return 0;
  }
  
- /*
-  * How many columns do we need to show line numbers in decimal?
-  */
- static int lineno_width(int lines)
- {
-       int i, width;
-       for (width = 1, i = 10; i <= lines; width++)
-               i *= 10;
-       return width;
- }
  /*
   * How many columns do we need to show line numbers, authors,
   * and filenames?
@@@ -1880,9 -1868,9 +1868,9 @@@ static void find_alignment(struct score
                if (largest_score < ent_score(sb, e))
                        largest_score = ent_score(sb, e);
        }
-       max_orig_digits = lineno_width(longest_src_lines);
-       max_digits = lineno_width(longest_dst_lines);
-       max_score_digits = lineno_width(largest_score);
+       max_orig_digits = decimal_width(longest_src_lines);
+       max_digits = decimal_width(longest_dst_lines);
+       max_score_digits = decimal_width(largest_score);
  }
  
  /*
@@@ -2050,8 -2038,14 +2038,8 @@@ static int git_blame_config(const char 
                return 0;
        }
  
 -      switch (userdiff_config(var, value)) {
 -      case 0:
 -              break;
 -      case -1:
 +      if (userdiff_config(var, value) < 0)
                return -1;
 -      default:
 -              return 0;
 -      }
  
        return git_default_config(var, value, cb);
  }
diff --combined cache.h
index 3a8e1258e7a15e5ffba52ad400d9ae23cedb0982,24732e6caf8ba30b44a5aa5f40eb5756d164daf4..422c5cfcb374259b46a7f92fc2a08b726f54f77a
+++ b/cache.h
@@@ -432,7 -432,6 +432,7 @@@ extern char *git_work_tree_cfg
  extern int is_inside_work_tree(void);
  extern int have_git_dir(void);
  extern const char *get_git_dir(void);
 +extern int is_git_directory(const char *path);
  extern char *get_object_directory(void);
  extern char *get_index_file(void);
  extern char *get_graft_file(void);
@@@ -1177,7 -1176,7 +1177,8 @@@ extern void setup_pager(void)
  extern const char *pager_program;
  extern int pager_in_use(void);
  extern int pager_use_color;
 +extern int term_columns(void);
+ extern int decimal_width(int);
  
  extern const char *editor_program;
  extern const char *askpass_program;
diff --combined pager.c
index b7909678f459d90d1c8907c78bb5fcb512fe558d,96c07babbd7756a59fb5e891bf78f9c4396fed13..05584dead6728ceff818630fbccaa91bb6c6b686
+++ b/pager.c
@@@ -76,12 -76,6 +76,12 @@@ void setup_pager(void
        if (!pager)
                return;
  
 +      /*
 +       * force computing the width of the terminal before we redirect
 +       * the standard output to the pager.
 +       */
 +      (void) term_columns();
 +
        setenv("GIT_PAGER_IN_USE", "true", 1);
  
        /* spawn the pager */
@@@ -117,33 -111,14 +117,45 @@@ int pager_in_use(void
        return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
  }
  
 +/*
 + * Return cached value (if set) or $COLUMNS environment variable (if
 + * set and positive) or ioctl(1, TIOCGWINSZ).ws_col (if positive),
 + * and default to 80 if all else fails.
 + */
 +int term_columns(void)
 +{
 +      static int term_columns_at_startup;
 +
 +      char *col_string;
 +      int n_cols;
 +
 +      if (term_columns_at_startup)
 +              return term_columns_at_startup;
 +
 +      term_columns_at_startup = 80;
 +
 +      col_string = getenv("COLUMNS");
 +      if (col_string && (n_cols = atoi(col_string)) > 0)
 +              term_columns_at_startup = n_cols;
 +#ifdef TIOCGWINSZ
 +      else {
 +              struct winsize ws;
 +              if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col)
 +                      term_columns_at_startup = ws.ws_col;
 +      }
 +#endif
 +
 +      return term_columns_at_startup;
 +}
++
+ /*
+  * How many columns do we need to show this number in decimal?
+  */
+ int decimal_width(int number)
+ {
+       int i, width;
+       for (width = 1, i = 10; i <= number; width++)
+               i *= 10;
+       return width;
+ }