From: Junio C Hamano Date: Sat, 25 Feb 2012 00:07:04 +0000 (-0800) Subject: Merge branches zj/decimal-width, zj/term-columns and jc/diff-stat-scaler X-Git-Tag: v1.7.10-rc0~9^2~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/db65f0fc3b1e16d5cc4ebf00f5af56c91546d839?ds=inline;hp=-c Merge branches zj/decimal-width, zj/term-columns and jc/diff-stat-scaler --- db65f0fc3b1e16d5cc4ebf00f5af56c91546d839 diff --combined cache.h index 24732e6caf,79c612fc2f,c7e3b4d49e..deaa35a700 --- a/cache.h +++ b/cache.h @@@@ -35,7 -35,6 -35,6 +35,7 @@@@ int git_inflate(git_zstream *, int flus void git_deflate_init(git_zstream *, int level); void git_deflate_init_gzip(git_zstream *, int level); void git_deflate_end(git_zstream *); ++int git_deflate_abort(git_zstream *); int git_deflate_end_gently(git_zstream *); int git_deflate(git_zstream *, int flush); unsigned long git_deflate_bound(git_zstream *, unsigned long); @@@@ -307,7 -306,7 -306,7 +307,7 @@@@ static inline unsigned int canon_mode(u } #define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7) --#define cache_entry_size(len) flexible_size(cache_entry,len) ++#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) #define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len) #define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len) @@@@ -317,6 -316,7 -316,7 +317,6 @@@@ struct index_state struct string_list *resolve_undo; struct cache_tree *cache_tree; struct cache_time timestamp; -- void *alloc; unsigned name_hash_initialized : 1, initialized : 1; struct hash_table name_hash; @@@@ -598,7 -598,6 -598,6 +598,7 @@@@ extern size_t packed_git_window_size extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern unsigned long big_file_threshold; ++extern unsigned long pack_size_limit_cfg; extern int read_replace_refs; extern int fsync_object_files; extern int core_preload_index; @@@@ -833,9 -832,7 -832,7 +833,9 @@@@ static inline int get_sha1_with_context extern int get_sha1_hex(const char *hex, unsigned char *sha1); extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ --extern int read_ref(const char *filename, unsigned char *sha1); ++extern int read_ref_full(const char *refname, unsigned char *sha1, ++ int reading, int *flags); ++extern int read_ref(const char *refname, unsigned char *sha1); /* * Resolve a reference, recursively following symbolic refererences. @@@@ -867,8 -864,7 -864,7 +867,8 @@@@ * * errno is sometimes set on errors, but not always. */ --extern const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag); ++extern const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag); ++extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag); extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); @@@@ -877,7 -873,7 -873,7 +877,7 @@@@ extern int get_sha1_mb(const char *str extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); extern const char *ref_rev_parse_rules[]; --extern const char *ref_fetch_rules[]; ++#define ref_fetch_rules ref_rev_parse_rules extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg); extern int validate_headref(const char *ref); @@@@ -1028,6 -1024,7 -1024,7 +1028,6 @@@@ struct ref extern struct ref *find_ref_by_name(const struct ref *list, const char *name); #define CONNECT_VERBOSE (1u << 0) --extern char *git_getpass(const char *prompt); extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); extern int finish_connect(struct child_process *conn); extern int git_connection_is_socket(struct child_process *conn); @@@@ -1037,7 -1034,6 -1034,6 +1037,7 @@@@ struct extra_have_objects }; extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *); extern int server_supports(const char *feature); ++extern const char *parse_feature_request(const char *features, const char *feature); extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path); @@@@ -1176,7 -1172,6 -1172,7 +1176,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 diff.c index 7e154265f7,74db18846f,374ecf3b48..e0590a3056 --- a/diff.c +++ b/diff.c @@@@ -1113,15 -1113,6 -1113,6 +1113,15 @@@@ static void fn_out_consume(void *priv, diff_words_append(line, len, &ecbdata->diff_words->plus); return; ++ } else if (!prefixcmp(line, "\\ ")) { ++ /* ++ * Eat the "no newline at eof" marker as if we ++ * saw a "+" or "-" line with nothing on it, ++ * and return without diff_words_flush() to ++ * defer processing. If this is the end of ++ * preimage, more "+" lines may come after it. ++ */ ++ return; } diff_words_flush(ecbdata); if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) { @@@@ -1276,13 -1267,15 -1267,13 +1276,15 @@@@ const char mime_boundary_leader[] = "-- static int scale_linear(int it, int width, int max_change) { + + if (!it) + + return 0; /* - - * make sure that at least one '-' is printed if there were deletions, - - * and likewise for '+'. + + * make sure that at least one '-' or '+' is printed if + + * there is any change to this path. The easiest way is to + + * scale linearly as if the alloted width is one column shorter + + * than it is, and then add 1 to the result. */ - - if (max_change < 2) - - return it; - - return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1); + + return 1 + (it * (width - 1) / max_change); } static void show_name(FILE *file, @@@@ -1449,8 -1442,19 -1440,8 +1451,19 @@@@ static void show_stats(struct diffstat_ dels += del; if (width <= max_change) { - - add = scale_linear(add, width, max_change); - - del = scale_linear(del, width, max_change); + + int total = add + del; + + + + total = scale_linear(add + del, width, max_change); + + if (total < 2 && add && del) + + /* width >= 2 due to the sanity check */ + + total = 2; + + if (add < del) { + + add = scale_linear(add, width, max_change); + + del = total - add; + + } else { + + del = scale_linear(del, width, max_change); + + add = total - del; + + } } fprintf(options->file, "%s", line_prefix); show_name(options->file, prefix, name, len); diff --combined pager.c index 96c07babbd,975955ba82,b7909678f4..05584dead6 --- a/pager.c +++ b/pager.c @@@@ -76,6 -76,6 -76,12 +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 */ @@@@ -110,15 -110,3 -116,34 +116,46 @@@@ int pager_in_use(void env = getenv("GIT_PAGER_IN_USE"); 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; ++}