summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-05-24 08:11:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-01 17:10:16 (GMT)
commit1ffec303ab043c392e480d37df2b34e40f3d4bd0 (patch)
tree5271dc8138bdebd96a6b6b3efb71b180b4ca5c45 /builtin
parent10a9ddba2c3478c8080acc1b2c83d75d09ee2492 (diff)
downloadgit-1ffec303ab043c392e480d37df2b34e40f3d4bd0.zip
git-1ffec303ab043c392e480d37df2b34e40f3d4bd0.tar.gz
git-1ffec303ab043c392e480d37df2b34e40f3d4bd0.tar.bz2
builtin/apply: move 'max_change' and 'max_len' into 'struct apply_state'
To libify the apply functionality the 'max_change' and 'max_len' variables should not be static and global to the file. Let's move them into 'struct apply_state'. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/apply.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index e5bc9cc..9e7d181 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -73,6 +73,14 @@ struct apply_state {
struct string_list limit_by_name;
int has_include;
+ /*
+ * For "diff-stat" like behaviour, we keep track of the biggest change
+ * we've seen, and the longest filename. That allows us to do simple
+ * scaling.
+ */
+ int max_change;
+ int max_len;
+
/* These control whitespace errors */
enum ws_error_action ws_error_action;
enum ws_ignore ws_ignore_action;
@@ -142,13 +150,6 @@ static void set_default_whitespace_mode(struct apply_state *state)
}
/*
- * For "diff-stat" like behaviour, we keep track of the biggest change
- * we've seen, and the longest filename. That allows us to do simple
- * scaling.
- */
-static int max_change, max_len;
-
-/*
* Various "current state", notably line numbers and what
* file (and how) we're patching right now.. The "is_xxxx"
* things are flags, where -1 means "don't know yet".
@@ -2172,7 +2173,7 @@ static const char pluses[] =
static const char minuses[]=
"----------------------------------------------------------------------";
-static void show_stats(struct patch *patch)
+static void show_stats(struct apply_state *state, struct patch *patch)
{
struct strbuf qname = STRBUF_INIT;
char *cp = patch->new_name ? patch->new_name : patch->old_name;
@@ -2183,7 +2184,7 @@ static void show_stats(struct patch *patch)
/*
* "scale" the filename
*/
- max = max_len;
+ max = state->max_len;
if (max > 50)
max = 50;
@@ -2206,13 +2207,13 @@ static void show_stats(struct patch *patch)
/*
* scale the add/delete
*/
- max = max + max_change > 70 ? 70 - max : max_change;
+ max = max + state->max_change > 70 ? 70 - max : state->max_change;
add = patch->lines_added;
del = patch->lines_deleted;
- if (max_change > 0) {
- int total = ((add + del) * max + max_change / 2) / max_change;
- add = (add * max + max_change / 2) / max_change;
+ if (state->max_change > 0) {
+ int total = ((add + del) * max + state->max_change / 2) / state->max_change;
+ add = (add * max + state->max_change / 2) / state->max_change;
del = total - add;
}
printf("%5d %.*s%.*s\n", patch->lines_added + patch->lines_deleted,
@@ -4038,7 +4039,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
discard_index(&result);
}
-static void stat_patch_list(struct patch *patch)
+static void stat_patch_list(struct apply_state *state, struct patch *patch)
{
int files, adds, dels;
@@ -4046,7 +4047,7 @@ static void stat_patch_list(struct patch *patch)
files++;
adds += patch->lines_added;
dels += patch->lines_deleted;
- show_stats(patch);
+ show_stats(state, patch);
}
print_stat_summary(stdout, files, adds, dels);
@@ -4144,25 +4145,25 @@ static void summary_patch_list(struct patch *patch)
}
}
-static void patch_stats(struct patch *patch)
+static void patch_stats(struct apply_state *state, struct patch *patch)
{
int lines = patch->lines_added + patch->lines_deleted;
- if (lines > max_change)
- max_change = lines;
+ if (lines > state->max_change)
+ state->max_change = lines;
if (patch->old_name) {
int len = quote_c_style(patch->old_name, NULL, NULL, 0);
if (!len)
len = strlen(patch->old_name);
- if (len > max_len)
- max_len = len;
+ if (len > state->max_len)
+ state->max_len = len;
}
if (patch->new_name) {
int len = quote_c_style(patch->new_name, NULL, NULL, 0);
if (!len)
len = strlen(patch->new_name);
- if (len > max_len)
- max_len = len;
+ if (len > state->max_len)
+ state->max_len = len;
}
}
@@ -4519,7 +4520,7 @@ static int apply_patch(struct apply_state *state,
if (state->apply_in_reverse)
reverse_patches(patch);
if (use_patch(state, patch)) {
- patch_stats(patch);
+ patch_stats(state, patch);
*listp = patch;
listp = &patch->next;
}
@@ -4563,7 +4564,7 @@ static int apply_patch(struct apply_state *state,
build_fake_ancestor(list, state->fake_ancestor);
if (state->diffstat)
- stat_patch_list(list);
+ stat_patch_list(state, list);
if (state->numstat)
numstat_patch_list(state, list);