From: Yasushi SHOJI <yashi@atmark-techno.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [RFC] describe: add option --dirty
Date: Mon, 23 Jul 2007 17:52:54 +0900 [thread overview]
Message-ID: <87k5srmrh5.wl@mail2.atmark-techno.com> (raw)
In-Reply-To: <20070723075834.GK32566@spearce.org>
At Mon, 23 Jul 2007 03:58:34 -0400,
Shawn O. Pearce wrote:
>
> Yasushi SHOJI <yashi@atmark-techno.com> wrote:
> > From the comments I'd add an option "--workinig-tree" instead of
> > --dirty to describe the working tree. because that, the special case,
> > is what we want after all,
> >
> > synopsis would be:
> >
> > SYNOPSIS
> > --------
> > 'git-describe' [--all] [--tags] [--contains] [--abbrev=<n>]
> > [--candidates=<n>] [--debug]
> > --working-tree | <committish>...
> > :
> > :
> > --working-tree::
> > Describe the working tree instead of committishes. if the
> > working tree is dirty, the describe string will have "-dirty"
> > appended.
> >
> > As you can assume from the name, this option requires working
> > tree; running it on a bare repository will fail.
> >
> > what do you think?
>
> That's reasonable. It seems like a lot of work in core Git just
> to avoid a small chunk of shell, but I think almost everyone has
> that same small chunk of shell in their build scripts...
it's not that much. here it is. hope you like it.
>From 25acf0fad4866b87998b51f1e66f540f2bcc5f0d Mon Sep 17 00:00:00 2001
From: Yasushi SHOJI <yashi@atmark-techno.com>
Date: Mon, 23 Jul 2007 17:49:11 +0900
Subject: [PATCH] describe: add a new option --working-tree
Many people like to use git-describe for version number, and yet
people always tack in the -dirty if the directory is dirty according
to diff-index. So this patch tries to scratch the itchy.
With --working-tree, the command will describe the working tree
instead of committishes. If the working tree is dirty, the describe
string will have "-dirty" appended.
As you can assume from the name, this option requires working tree.
running it on a bare repository will fail.
Signed-off-by: Yasushi SHOJI <yashi@atmark-techno.com>
---
Documentation/git-describe.txt | 10 +++++++++-
builtin-describe.c | 38 +++++++++++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index f0bcb61..d9b1550 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
'git-describe' [--all] [--tags] [--contains] [--abbrev=<n>]
[--candidates=<n>] [--debug]
- <committish>...
+ --working-tree | <committish>...
DESCRIPTION
-----------
@@ -53,6 +53,14 @@ OPTIONS
being employed to standard error. The tag name will still
be printed to standard out.
+--working-tree::
+ Describe the working tree instead of committishes. if the
+ working tree is dirty, the describe string will have "-dirty"
+ appended.
+
+ As you can assume from the name, this option requires a
+ working tree. Running it on a bare repository will fail.
+
EXAMPLES
--------
diff --git a/builtin-describe.c b/builtin-describe.c
index e94f867..1c58480 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] --working-tree | <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 working_tree;/* describe the working tree instead of committish */
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, int dirty)
{
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 = dirty ? "-dirty" : "";
if (get_sha1(arg, sha1))
die("Not a valid object name %s", arg);
@@ -230,11 +232,12 @@ static void describe(const char *arg, int last_one)
}
}
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);
@@ -244,12 +247,15 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
{
int i;
int contains = 0;
+ int dirty = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (*arg != '-')
break;
+ else if (!strcmp(arg, "--working-tree"))
+ working_tree = 1;
else if (!strcmp(arg, "--contains"))
contains = 1;
else if (!strcmp(arg, "--debug"))
@@ -276,6 +282,24 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
save_commit_buffer = 0;
+ if (working_tree) {
+ const char **args;
+
+ if (!is_inside_work_tree() || is_inside_git_dir())
+ die("%s with --working-tree must be run in a working tree", argv[0]);
+ if (argc > i)
+ die("--working-tree doesn't take any committish\n");
+
+ 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 = 1;
+ }
+
if (contains) {
const char **args = xmalloc((4 + argc - i) * sizeof(char*));
args[0] = "name-rev";
@@ -290,10 +314,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
}
if (argc <= i)
- describe("HEAD", 1);
+ describe("HEAD", 1, dirty);
else
while (i < argc) {
- describe(argv[i], (i == argc - 1));
+ describe(argv[i], (i == argc - 1), dirty);
i++;
}
--
1.5.3.rc2.4.g726f9
next prev parent reply other threads:[~2007-07-23 8:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-23 6:35 [RFC] describe: add option --dirty Yasushi SHOJI
2007-07-23 6:56 ` 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 [this message]
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=87k5srmrh5.wl@mail2.atmark-techno.com \
--to=yashi@atmark-techno.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.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).