From: Yasushi SHOJI <yashi@atmark-techno.com>
To: git@vger.kernel.org
Subject: [RFC] describe: add option --dirty
Date: Mon, 23 Jul 2007 15:35:50 +0900 [thread overview]
Message-ID: <87odi3mxtl.wl@mail2.atmark-techno.com> (raw)
when --dirty is given, git describe will check the working tree and
append "-dirty" to describe string if the tree is dirty.
---
I'm not sure this is good idea or the current way (using diff-index in
shell script) is more prefered.
one thing I found out is that we s/-/./g the out put of describe
before we append "-dirty". this patch doesn't take care that. so with
this patch what we get is either
v1.5.3-rc2-840-g1c0e2-dirty, or
v1.5.3.rc2.840.g1c0e2.dirty
if we don't put more complecated sed command in GIT-VERSION-GEN.
anyway, comments welcome.
ps. another thing I don't like about this patch is that it changed to
pass prefix down to describe() as the last argument because I was lazy
to call cmd_diff_index() in describe(). if there is better way to do
it, please let me know.
Documentation/git-describe.txt | 5 ++++-
builtin-describe.c | 29 ++++++++++++++++++++++-------
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index f0bcb61..627c4d5 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -9,7 +9,7 @@ git-describe - Show the most recent tag that is reachable from a commit
SYNOPSIS
--------
'git-describe' [--all] [--tags] [--contains] [--abbrev=<n>]
- [--candidates=<n>] [--debug]
+ [--candidates=<n>] [--debug] [--dirty]
<committish>...
DESCRIPTION
@@ -53,6 +53,9 @@ OPTIONS
being employed to standard error. The tag name will still
be printed to standard out.
+--dirty::
+ Append "-dirty" to describe string if working tree is dirty.
+
EXAMPLES
--------
diff --git a/builtin-describe.c b/builtin-describe.c
index e94f867..bebc16b 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -9,11 +9,12 @@
#define MAX_TAGS (FLAG_BITS - 1)
static const char describe_usage[] =
-"git-describe [--all] [--tags] [--contains] [--abbrev=<n>] [--candidates] [--debug] <committish>*";
+"git-describe [--all] [--tags] [--contains] [--abbrev=<n>] [--candidates] [--debug] [--dirty] <committish>*";
static int debug; /* Display lots of verbose info */
static int all; /* Default to annotated tags only */
static int tags; /* But allow any tags if --tags is specified */
+static int check_dirty; /* Append "-dirty" to describe string if working tree is dirty */
static int abbrev = DEFAULT_ABBREV;
static int max_candidates = 10;
@@ -125,7 +126,7 @@ static unsigned long finish_depth_computation(
return seen_commits;
}
-static void describe(const char *arg, int last_one)
+static void describe(const char *arg, int last_one, const char *prefix)
{
unsigned char sha1[20];
struct commit *cmit, *gave_up_on = NULL;
@@ -135,6 +136,7 @@ static void describe(const char *arg, int last_one)
struct possible_tag all_matches[MAX_TAGS];
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
unsigned long seen_commits = 0;
+ char *dirty_string = "";
if (get_sha1(arg, sha1))
die("Not a valid object name %s", arg);
@@ -229,12 +231,23 @@ static void describe(const char *arg, int last_one)
sha1_to_hex(gave_up_on->object.sha1));
}
}
+ if (check_dirty) {
+ const char **args = xmalloc(5 * sizeof(char*));
+ args[0] = "diff-index";
+ args[1] = "--quiet";
+ args[2] = "--name-only";
+ args[3] = "HEAD";
+ args[4] = NULL;
+ if (cmd_diff_index(4, args, prefix))
+ dirty_string = "-dirty";
+ }
if (abbrev == 0)
- printf("%s\n", all_matches[0].name->path );
+ printf("%s%s\n", all_matches[0].name->path, dirty_string);
else
- printf("%s-%d-g%s\n", all_matches[0].name->path,
+ printf("%s-%d-g%s%s\n", all_matches[0].name->path,
all_matches[0].depth,
- find_unique_abbrev(cmit->object.sha1, abbrev));
+ find_unique_abbrev(cmit->object.sha1, abbrev),
+ dirty_string);
if (!last_one)
clear_commit_marks(cmit, -1);
@@ -250,6 +263,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
if (*arg != '-')
break;
+ else if (!strcmp(arg, "--dirty"))
+ check_dirty = 1;
else if (!strcmp(arg, "--contains"))
contains = 1;
else if (!strcmp(arg, "--debug"))
@@ -290,10 +305,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
}
if (argc <= i)
- describe("HEAD", 1);
+ describe("HEAD", 1, prefix);
else
while (i < argc) {
- describe(argv[i], (i == argc - 1));
+ describe(argv[i], (i == argc - 1), prefix);
i++;
}
--
1.5.3.rc2.4.g726f9
next reply other threads:[~2007-07-23 6:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-23 6:35 Yasushi SHOJI [this message]
2007-07-23 6:56 ` [RFC] describe: add option --dirty Junio C Hamano
2007-07-23 7:08 ` Shawn O. Pearce
2007-07-23 7:54 ` Yasushi SHOJI
2007-07-23 7:58 ` Shawn O. Pearce
2007-07-23 8:52 ` Yasushi SHOJI
2007-07-23 6:59 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87odi3mxtl.wl@mail2.atmark-techno.com \
--to=yashi@atmark-techno.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).