Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeba Waly <heba.waly@gmail.com>2020-03-02 23:01:59 +0300
committerJunio C Hamano <gitster@pobox.com>2020-03-05 17:15:02 +0300
commitb3b18d1621315fb187689ee6c759bdbbea214eb8 (patch)
tree71cdc12a22546b811b17a8b73e8c8e9ec349d3f9 /advice.h
parentfef0c76f1802c42f1d1f3b6344deb182a3600625 (diff)
advice: revamp advise API
Currently it's very easy for the advice library's callers to miss checking the visibility step before printing an advice. Also, it makes more sense for this step to be handled by the advice library. Add a new advise_if_enabled function that checks the visibility of advice messages before printing. Add a new helper advise_enabled to check the visibility of the advice if the caller needs to carry out complicated processing based on that value. A list of advice_settings is added to cache the config variables names and values, it's intended to replace advice_config[] and the global variables once we migrate all the callers to use the new APIs. Signed-off-by: Heba Waly <heba.waly@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'advice.h')
-rw-r--r--advice.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/advice.h b/advice.h
index b706780614..d72ab4a06c 100644
--- a/advice.h
+++ b/advice.h
@@ -32,9 +32,60 @@ extern int advice_checkout_ambiguous_remote_branch_name;
extern int advice_nested_tag;
extern int advice_submodule_alternate_error_strategy_die;
+/*
+ * To add a new advice, you need to:
+ * Define a new advice_type.
+ * Add a new entry to advice_setting array.
+ * Add the new config variable to Documentation/config/advice.txt.
+ * Call advise_if_enabled to print your advice.
+ */
+ enum advice_type {
+ ADVICE_ADD_EMBEDDED_REPO,
+ ADVICE_AM_WORK_DIR,
+ ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
+ ADVICE_COMMIT_BEFORE_MERGE,
+ ADVICE_DETACHED_HEAD,
+ ADVICE_FETCH_SHOW_FORCED_UPDATES,
+ ADVICE_GRAFT_FILE_DEPRECATED,
+ ADVICE_IGNORED_HOOK,
+ ADVICE_IMPLICIT_IDENTITY,
+ ADVICE_NESTED_TAG,
+ ADVICE_OBJECT_NAME_WARNING,
+ ADVICE_PUSH_ALREADY_EXISTS,
+ ADVICE_PUSH_FETCH_FIRST,
+ ADVICE_PUSH_NEEDS_FORCE,
+ ADVICE_PUSH_NON_FF_CURRENT,
+ ADVICE_PUSH_NON_FF_MATCHING,
+ ADVICE_PUSH_UNQUALIFIED_REF_NAME,
+ ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
+ ADVICE_PUSH_UPDATE_REJECTED,
+ ADVICE_RESET_QUIET_WARNING,
+ ADVICE_RESOLVE_CONFLICT,
+ ADVICE_RM_HINTS,
+ ADVICE_SEQUENCER_IN_USE,
+ ADVICE_SET_UPSTREAM_FAILURE,
+ ADVICE_STATUS_AHEAD_BEHIND_WARNING,
+ ADVICE_STATUS_HINTS,
+ ADVICE_STATUS_U_OPTION,
+ ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE,
+ ADVICE_WAITING_FOR_EDITOR,
+};
+
int git_default_advice_config(const char *var, const char *value);
__attribute__((format (printf, 1, 2)))
void advise(const char *advice, ...);
+
+/**
+ * Checks if advice type is enabled (can be printed to the user).
+ * Should be called before advise().
+ */
+int advice_enabled(enum advice_type type);
+
+/**
+ * Checks the visibility of the advice before printing.
+ */
+void advise_if_enabled(enum advice_type type, const char *advice, ...);
+
int error_resolve_conflict(const char *me);
void NORETURN die_resolve_conflict(const char *me);
void NORETURN die_conclude_merge(void);