2006-09-08 16:05:34 +08:00
|
|
|
#ifndef STATUS_H
|
|
|
|
#define STATUS_H
|
|
|
|
|
2009-08-05 14:49:33 +08:00
|
|
|
#include "string-list.h"
|
2009-08-10 14:08:40 +08:00
|
|
|
#include "color.h"
|
2015-08-20 22:06:27 +08:00
|
|
|
#include "pathspec.h"
|
2018-01-10 02:50:16 +08:00
|
|
|
#include "remote.h"
|
2007-09-18 08:06:42 +08:00
|
|
|
|
2018-11-10 13:48:49 +08:00
|
|
|
struct repository;
|
2016-04-22 21:01:31 +08:00
|
|
|
struct worktree;
|
|
|
|
|
2006-09-08 16:05:34 +08:00
|
|
|
enum color_wt_status {
|
2009-08-10 14:08:40 +08:00
|
|
|
WT_STATUS_HEADER = 0,
|
2006-09-08 16:05:34 +08:00
|
|
|
WT_STATUS_UPDATED,
|
|
|
|
WT_STATUS_CHANGED,
|
|
|
|
WT_STATUS_UNTRACKED,
|
2008-05-22 20:50:02 +08:00
|
|
|
WT_STATUS_NOBRANCH,
|
2009-08-05 15:04:51 +08:00
|
|
|
WT_STATUS_UNMERGED,
|
2010-05-25 21:45:51 +08:00
|
|
|
WT_STATUS_LOCAL_BRANCH,
|
2010-11-18 07:40:05 +08:00
|
|
|
WT_STATUS_REMOTE_BRANCH,
|
|
|
|
WT_STATUS_ONBRANCH,
|
|
|
|
WT_STATUS_MAXSLOT
|
2006-09-08 16:05:34 +08:00
|
|
|
};
|
|
|
|
|
2008-06-05 16:31:19 +08:00
|
|
|
enum untracked_status_type {
|
2024-03-14 01:32:13 +08:00
|
|
|
SHOW_UNTRACKED_FILES_ERROR = -1,
|
|
|
|
SHOW_NO_UNTRACKED_FILES = 0,
|
2008-06-05 20:22:56 +08:00
|
|
|
SHOW_NORMAL_UNTRACKED_FILES,
|
2008-06-05 16:31:19 +08:00
|
|
|
SHOW_ALL_UNTRACKED_FILES
|
|
|
|
};
|
|
|
|
|
status: add option to show ignored files differently
Teach the status command more flexibility in how ignored files are
reported. Currently, the reporting of ignored files and untracked
files are linked. You cannot control how ignored files are reported
independently of how untracked files are reported (i.e. `all` vs
`normal`). This makes it impossible to show untracked files with the
`all` option, but show ignored files with the `normal` option.
This work 1) adds the ability to control the reporting of ignored
files independently of untracked files and 2) introduces the concept
of status reporting ignored paths that explicitly match an ignored
pattern. There are 2 benefits to these changes: 1) if a consumer needs
all untracked files but not all ignored files, there is a performance
benefit to not scanning all contents of an ignored directory and 2)
returning ignored files that explicitly match a path allow a consumer
to make more informed decisions about when a status result might be
stale.
This commit implements --ignored=matching with --untracked-files=all.
The following commit will implement --ignored=matching with
--untracked=files=normal.
As an example of where this flexibility could be useful is that our
application (Visual Studio) runs the status command and presents the
output. It shows all untracked files individually (e.g. using the
'--untracked-files==all' option), and would like to know about which
paths are ignored. It uses information about ignored paths to make
decisions about when the status result might have changed.
Additionally, many projects place build output into directories inside
a repository's working directory (e.g. in "bin/" and "obj/"
directories). Normal usage is to explicitly ignore these 2 directory
names in the .gitignore file (rather than or in addition to the *.obj
pattern).If an application could know that these directories are
explicitly ignored, it could infer that all contents are ignored as
well and make better informed decisions about files in these
directories. It could infer that any changes under these paths would
not affect the output of status. Additionally, there can be a
significant performance benefit by avoiding scanning through ignored
directories.
When status is set to report matching ignored files, it has the
following behavior. Ignored files and directories that explicitly
match an exclude pattern are reported. If an ignored directory matches
an exclude pattern, then the path of the directory is returned. If a
directory does not match an exclude pattern, but all of its contents
are ignored, then the contained files are reported instead of the
directory.
Signed-off-by: Jameson Miller <jamill@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-31 01:21:37 +08:00
|
|
|
enum show_ignored_type {
|
|
|
|
SHOW_NO_IGNORED,
|
|
|
|
SHOW_TRADITIONAL_IGNORED,
|
|
|
|
SHOW_MATCHING_IGNORED,
|
|
|
|
};
|
|
|
|
|
2011-02-20 12:12:29 +08:00
|
|
|
/* from where does this commit originate */
|
|
|
|
enum commit_whence {
|
|
|
|
FROM_COMMIT, /* normal */
|
|
|
|
FROM_MERGE, /* commit came from merge */
|
2019-12-07 00:06:10 +08:00
|
|
|
FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */
|
2019-12-07 00:06:12 +08:00
|
|
|
FROM_CHERRY_PICK_MULTI, /* commit came from a sequence of cherry-picks */
|
|
|
|
FROM_REBASE_PICK /* commit came from a pick/reword/edit */
|
2011-02-20 12:12:29 +08:00
|
|
|
};
|
|
|
|
|
2019-12-07 00:06:10 +08:00
|
|
|
static inline int is_from_cherry_pick(enum commit_whence whence)
|
|
|
|
{
|
|
|
|
return whence == FROM_CHERRY_PICK_SINGLE ||
|
|
|
|
whence == FROM_CHERRY_PICK_MULTI;
|
|
|
|
}
|
|
|
|
|
2019-12-07 00:06:12 +08:00
|
|
|
static inline int is_from_rebase(enum commit_whence whence)
|
|
|
|
{
|
|
|
|
return whence == FROM_REBASE_PICK;
|
|
|
|
}
|
|
|
|
|
2009-08-05 14:49:33 +08:00
|
|
|
struct wt_status_change_data {
|
|
|
|
int worktree_status;
|
|
|
|
int index_status;
|
|
|
|
int stagemask;
|
2016-08-11 22:45:57 +08:00
|
|
|
int mode_head, mode_index, mode_worktree;
|
|
|
|
struct object_id oid_head, oid_index;
|
2017-12-27 18:18:38 +08:00
|
|
|
int rename_status;
|
|
|
|
int rename_score;
|
|
|
|
char *rename_source;
|
2010-03-08 20:53:19 +08:00
|
|
|
unsigned dirty_submodule : 2;
|
|
|
|
unsigned new_submodule_commits : 1;
|
2009-08-05 14:49:33 +08:00
|
|
|
};
|
|
|
|
|
2016-08-06 06:00:27 +08:00
|
|
|
enum wt_status_format {
|
|
|
|
STATUS_FORMAT_NONE = 0,
|
|
|
|
STATUS_FORMAT_LONG,
|
|
|
|
STATUS_FORMAT_SHORT,
|
|
|
|
STATUS_FORMAT_PORCELAIN,
|
2016-08-11 22:45:57 +08:00
|
|
|
STATUS_FORMAT_PORCELAIN_V2,
|
2016-08-06 06:00:27 +08:00
|
|
|
|
|
|
|
STATUS_FORMAT_UNSPECIFIED
|
|
|
|
};
|
|
|
|
|
2020-06-19 04:49:57 +08:00
|
|
|
#define SPARSE_CHECKOUT_DISABLED -1
|
2021-07-14 21:12:36 +08:00
|
|
|
#define SPARSE_CHECKOUT_SPARSE_INDEX -2
|
2019-06-19 06:29:15 +08:00
|
|
|
|
2018-09-30 22:12:45 +08:00
|
|
|
struct wt_status_state {
|
|
|
|
int merge_in_progress;
|
|
|
|
int am_in_progress;
|
|
|
|
int am_empty_patch;
|
|
|
|
int rebase_in_progress;
|
|
|
|
int rebase_interactive_in_progress;
|
|
|
|
int cherry_pick_in_progress;
|
|
|
|
int bisect_in_progress;
|
|
|
|
int revert_in_progress;
|
|
|
|
int detached_at;
|
2020-06-19 04:49:57 +08:00
|
|
|
int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */
|
2018-09-30 22:12:45 +08:00
|
|
|
char *branch;
|
|
|
|
char *onto;
|
|
|
|
char *detached_from;
|
status: fix branch shown when not only bisecting
In 83c750acde (wt-status.*: better advice for git status added,
2012-06-05), git-status received new informative messages to describe
the ongoing work in a worktree.
These messages were enhanced in 0722c805d6 (status: show the branch name
if possible in in-progress info, 2013-02-03), to show, if possible, the
branch where the operation was initiated.
Since then, we show incorrect information when several operations are in
progress and one of them is bisect:
$ git checkout -b foo
$ GIT_SEQUENCE_EDITOR='echo break >' git rebase -i HEAD~
$ git checkout -b bar
$ git bisect start
$ git status
...
You are currently editing a commit while rebasing branch 'bar' on '...'.
You are currently bisecting, started from branch 'bar'.
...
Note that we erroneously say "while rebasing branch 'bar'" when we
should be referring to "foo".
This must have gone unnoticed for so long because it must be unusual to
start a bisection while another operation is in progress. And even less
usual to involve different branches.
It caught my attention reviewing a leak introduced in 8b87cfd000
(wt-status: move strbuf into read_and_strip_branch(), 2013-03-16).
A simple change to deal with this situation can be to record in struct
wt_status_state, the branch where the bisect starts separately from the
branch related to other operations.
Let's do it and so we'll be able to display correct information and
we'll avoid the leak as well.
Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-09-10 04:12:47 +08:00
|
|
|
char *bisecting_from;
|
2018-09-30 22:12:45 +08:00
|
|
|
struct object_id detached_oid;
|
|
|
|
struct object_id revert_head_oid;
|
|
|
|
struct object_id cherry_pick_head_oid;
|
|
|
|
};
|
|
|
|
|
2006-09-08 16:05:34 +08:00
|
|
|
struct wt_status {
|
2018-11-10 13:48:49 +08:00
|
|
|
struct repository *repo;
|
2006-09-08 16:05:34 +08:00
|
|
|
int is_initial;
|
|
|
|
char *branch;
|
|
|
|
const char *reference;
|
2013-07-14 16:35:39 +08:00
|
|
|
struct pathspec pathspec;
|
2006-09-08 16:05:34 +08:00
|
|
|
int verbose;
|
|
|
|
int amend;
|
2011-02-20 12:12:29 +08:00
|
|
|
enum commit_whence whence;
|
2007-12-13 11:09:16 +08:00
|
|
|
int nowarn;
|
2009-08-10 12:59:30 +08:00
|
|
|
int use_color;
|
2014-03-20 20:12:41 +08:00
|
|
|
int no_gettext;
|
2013-09-07 01:43:07 +08:00
|
|
|
int display_comment_prefix;
|
2009-08-10 12:59:30 +08:00
|
|
|
int relative_paths;
|
|
|
|
int submodule_summary;
|
status: add option to show ignored files differently
Teach the status command more flexibility in how ignored files are
reported. Currently, the reporting of ignored files and untracked
files are linked. You cannot control how ignored files are reported
independently of how untracked files are reported (i.e. `all` vs
`normal`). This makes it impossible to show untracked files with the
`all` option, but show ignored files with the `normal` option.
This work 1) adds the ability to control the reporting of ignored
files independently of untracked files and 2) introduces the concept
of status reporting ignored paths that explicitly match an ignored
pattern. There are 2 benefits to these changes: 1) if a consumer needs
all untracked files but not all ignored files, there is a performance
benefit to not scanning all contents of an ignored directory and 2)
returning ignored files that explicitly match a path allow a consumer
to make more informed decisions about when a status result might be
stale.
This commit implements --ignored=matching with --untracked-files=all.
The following commit will implement --ignored=matching with
--untracked=files=normal.
As an example of where this flexibility could be useful is that our
application (Visual Studio) runs the status command and presents the
output. It shows all untracked files individually (e.g. using the
'--untracked-files==all' option), and would like to know about which
paths are ignored. It uses information about ignored paths to make
decisions about when the status result might have changed.
Additionally, many projects place build output into directories inside
a repository's working directory (e.g. in "bin/" and "obj/"
directories). Normal usage is to explicitly ignore these 2 directory
names in the .gitignore file (rather than or in addition to the *.obj
pattern).If an application could know that these directories are
explicitly ignored, it could infer that all contents are ignored as
well and make better informed decisions about files in these
directories. It could infer that any changes under these paths would
not affect the output of status. Additionally, there can be a
significant performance benefit by avoiding scanning through ignored
directories.
When status is set to report matching ignored files, it has the
following behavior. Ignored files and directories that explicitly
match an exclude pattern are reported. If an ignored directory matches
an exclude pattern, then the path of the directory is returned. If a
directory does not match an exclude pattern, but all of its contents
are ignored, then the contained files are reported instead of the
directory.
Signed-off-by: Jameson Miller <jamill@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-31 01:21:37 +08:00
|
|
|
enum show_ignored_type show_ignored_mode;
|
2009-08-10 12:59:30 +08:00
|
|
|
enum untracked_status_type show_untracked_files;
|
2010-06-25 22:56:47 +08:00
|
|
|
const char *ignore_submodule_arg;
|
2010-11-18 07:40:05 +08:00
|
|
|
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
|
2012-05-08 03:35:03 +08:00
|
|
|
unsigned colopts;
|
2012-05-08 03:44:44 +08:00
|
|
|
int null_termination;
|
2017-06-22 02:16:14 +08:00
|
|
|
int commit_template;
|
2012-05-08 05:09:04 +08:00
|
|
|
int show_branch;
|
2017-06-18 06:30:51 +08:00
|
|
|
int show_stash;
|
2013-09-12 18:50:05 +08:00
|
|
|
int hints;
|
2018-01-10 02:50:16 +08:00
|
|
|
enum ahead_behind_flags ahead_behind_flags;
|
2018-05-11 23:38:58 +08:00
|
|
|
int detect_rename;
|
|
|
|
int rename_score;
|
|
|
|
int rename_limit;
|
2016-08-06 06:00:27 +08:00
|
|
|
enum wt_status_format status_format;
|
2024-02-27 17:16:09 +08:00
|
|
|
unsigned char added_cut_line; /* boolean */
|
2018-09-30 22:12:45 +08:00
|
|
|
struct wt_status_state state;
|
2019-08-19 04:04:21 +08:00
|
|
|
struct object_id oid_commit; /* when not Initial */
|
2016-08-06 06:00:27 +08:00
|
|
|
|
2007-01-11 06:25:03 +08:00
|
|
|
/* These are computed during processing of the individual sections */
|
2018-09-06 08:53:27 +08:00
|
|
|
int committable;
|
2007-01-11 06:25:03 +08:00
|
|
|
int workdir_dirty;
|
2007-09-18 08:06:43 +08:00
|
|
|
const char *index_file;
|
2007-09-18 08:06:42 +08:00
|
|
|
FILE *fp;
|
2007-11-12 01:35:41 +08:00
|
|
|
const char *prefix;
|
2009-08-05 14:49:33 +08:00
|
|
|
struct string_list change;
|
2009-08-10 15:36:33 +08:00
|
|
|
struct string_list untracked;
|
2010-04-10 15:11:53 +08:00
|
|
|
struct string_list ignored;
|
2013-03-13 20:59:16 +08:00
|
|
|
uint32_t untracked_in_ms;
|
2006-09-08 16:05:34 +08:00
|
|
|
};
|
|
|
|
|
interpret-trailers: honor the cut line
If a commit message is edited with the "verbose" option, the buffer
will have a cut line and diff after the log message, like so:
my subject
# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git a/foo.txt b/foo.txt
index 5716ca5..7601807 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-bar
+baz
"git interpret-trailers" is unaware of the cut line, and assumes the
trailer block would be at the end of the whole thing. This can easily
be seen with:
$ GIT_EDITOR='git interpret-trailers --in-place --trailer Acked-by:me' \
git commit --amend -v
Teach "git interpret-trailers" to notice the cut-line and ignore the
remainder of the input when looking for a place to add new trailer
block. This makes it consistent with how "git commit -v -s" inserts a
new Signed-off-by: line.
This can be done by the same logic as the existing helper function,
wt_status_truncate_message_at_cut_line(), uses, but it wants the caller
to pass a strbuf to it. Because the function ignore_non_trailer() used
by the command takes a <pointer, length> pair, not a strbuf, steal the
logic from wt_status_truncate_message_at_cut_line() to create a new
wt_status_locate_end() helper function that takes <pointer, length>
pair, and make ignore_non_trailer() call it to help "interpret-trailers".
Since there is only one caller of wt_status_truncate_message_at_cut_line()
in cmd_commit(), rewrite it to call wt_status_locate_end() helper instead
and remove the old helper that no longer has any caller.
Signed-off-by: Brian Malehorn <bmalehorn@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-16 14:06:49 +08:00
|
|
|
size_t wt_status_locate_end(const char *s, size_t len);
|
2019-04-17 18:23:27 +08:00
|
|
|
void wt_status_append_cut_line(struct strbuf *buf);
|
2024-02-27 17:16:09 +08:00
|
|
|
void wt_status_add_cut_line(struct wt_status *s);
|
2018-11-10 13:48:49 +08:00
|
|
|
void wt_status_prepare(struct repository *r, struct wt_status *s);
|
2016-08-06 06:00:27 +08:00
|
|
|
void wt_status_print(struct wt_status *s);
|
2009-08-10 15:36:33 +08:00
|
|
|
void wt_status_collect(struct wt_status *s);
|
wt-status: introduce wt_status_state_free_buffers()
When we have a `struct wt_status_state`, we manually free its `branch`,
`onto` and `detached_from`, or sometimes just one or two of them.
Provide a function `wt_status_state_free_buffers()` which does the
freeing.
The callers are still aware of these fields, e.g., they check whether
`branch` was populated or not. But this way, they don't need to know
about *all* of them, and if `struct wt_status_state` gets more fields,
they will not need to learn to free them.
Users of `struct wt_status` (which contains a `wt_status_state`) already
have `wt_status_collect_free_buffers()` (corresponding to
`wt_status_collect()`) which we can also teach to use this new helper.
Finally, note that we're currently leaving dangling pointers behind.
Some callers work on a stack-allocated struct, where this is obviously
ok. But for the users of `run_status()` in builtin/commit.c, there are
ample opportunities for someone to mistakenly use those dangling
pointers. We seem to be ok for now, but it's a use-after-free waiting to
happen. Let's leave NULL-pointers behind instead.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-09-27 21:15:43 +08:00
|
|
|
/*
|
|
|
|
* Frees the buffers allocated by wt_status_collect.
|
|
|
|
*/
|
2018-09-30 22:12:45 +08:00
|
|
|
void wt_status_collect_free_buffers(struct wt_status *s);
|
wt-status: introduce wt_status_state_free_buffers()
When we have a `struct wt_status_state`, we manually free its `branch`,
`onto` and `detached_from`, or sometimes just one or two of them.
Provide a function `wt_status_state_free_buffers()` which does the
freeing.
The callers are still aware of these fields, e.g., they check whether
`branch` was populated or not. But this way, they don't need to know
about *all* of them, and if `struct wt_status_state` gets more fields,
they will not need to learn to free them.
Users of `struct wt_status` (which contains a `wt_status_state`) already
have `wt_status_collect_free_buffers()` (corresponding to
`wt_status_collect()`) which we can also teach to use this new helper.
Finally, note that we're currently leaving dangling pointers behind.
Some callers work on a stack-allocated struct, where this is obviously
ok. But for the users of `run_status()` in builtin/commit.c, there are
ample opportunities for someone to mistakenly use those dangling
pointers. We seem to be ok for now, but it's a use-after-free waiting to
happen. Let's leave NULL-pointers behind instead.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-09-27 21:15:43 +08:00
|
|
|
/*
|
|
|
|
* Frees the buffers of the wt_status_state.
|
|
|
|
*/
|
|
|
|
void wt_status_state_free_buffers(struct wt_status_state *s);
|
2018-11-10 13:48:50 +08:00
|
|
|
void wt_status_get_state(struct repository *repo,
|
|
|
|
struct wt_status_state *state,
|
|
|
|
int get_detached_from);
|
2016-04-22 21:01:31 +08:00
|
|
|
int wt_status_check_rebase(const struct worktree *wt,
|
|
|
|
struct wt_status_state *state);
|
2016-04-22 21:01:34 +08:00
|
|
|
int wt_status_check_bisect(const struct worktree *wt,
|
|
|
|
struct wt_status_state *state);
|
2006-09-08 16:05:34 +08:00
|
|
|
|
2013-07-10 08:23:28 +08:00
|
|
|
__attribute__((format (printf, 3, 4)))
|
|
|
|
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
|
|
|
|
__attribute__((format (printf, 3, 4)))
|
|
|
|
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
|
2011-02-26 13:09:41 +08:00
|
|
|
|
2016-10-08 00:08:56 +08:00
|
|
|
/* The following functions expect that the caller took care of reading the index. */
|
2018-11-10 13:48:49 +08:00
|
|
|
int has_unstaged_changes(struct repository *repo,
|
|
|
|
int ignore_submodules);
|
|
|
|
int has_uncommitted_changes(struct repository *repo,
|
|
|
|
int ignore_submodules);
|
|
|
|
int require_clean_work_tree(struct repository *repo,
|
|
|
|
const char *action,
|
|
|
|
const char *hint,
|
|
|
|
int ignore_submodules,
|
|
|
|
int gently);
|
2016-10-08 00:08:38 +08:00
|
|
|
|
2006-09-08 16:05:34 +08:00
|
|
|
#endif /* STATUS_H */
|