Re: [RESEND][PATCH 00/15] Towards a more awesome git branch

2013-07-13 Thread Duy Nguyen
On Tue, Jul 09, 2013 at 04:02:11PM +0530, Ramkumar Ramachandra wrote:
> Hi,
> 
> I'm sending this out in the hope of attracting some reviews.  It's an
> unedited resend, and there were zero conflicts from the rebase.

I still don't like my callback idea. How about this? It's refactoring
a bit so that you can now extract the color parsing and alignment code
from pretty.c and add them to for-each-ref as new atoms in --format.
As this is simply extending --format, the syntax unification idea is
put back on the shelf and won't hinder your work.

parse_color() can be used to generate color escape sequences. For
alignment, you can do something like this:

pad_an_item();
process_following_atom_after_the_alignment_atom();
align_an_item();

I'm afraid it needs a bit more work on the for-each-ref side and may
even need some fixups (I tested t4205 only and it passed, but I may
have left some bugs)

-- 8< --
diff --git a/pretty.c b/pretty.c
index 9e43154..40a30a4 100644
--- a/pretty.c
+++ b/pretty.c
@@ -766,19 +766,23 @@ enum trunc_type {
trunc_right
 };
 
+struct alignment {
+   enum flush_type flush_type;
+   enum trunc_type truncate;
+   int padding;
+};
+
 struct format_commit_context {
const struct commit *commit;
const struct pretty_print_context *pretty_ctx;
unsigned commit_header_parsed:1;
unsigned commit_message_parsed:1;
struct signature_check signature_check;
-   enum flush_type flush_type;
-   enum trunc_type truncate;
char *message;
char *commit_encoding;
size_t width, indent1, indent2;
int auto_color;
-   int padding;
+   struct alignment alignment;
 
/* These offsets are relative to the start of the commit message. */
struct chunk author;
@@ -957,7 +961,7 @@ static int format_reflog_person(struct strbuf *sb,
 
 static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
  const char *placeholder,
- struct format_commit_context *c)
+ int color_setting)
 {
if (placeholder[1] == '(') {
const char *begin = placeholder + 2;
@@ -967,7 +971,7 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
if (!end)
return 0;
if (!prefixcmp(begin, "auto,")) {
-   if (!want_color(c->pretty_ctx->color))
+   if (!want_color(color_setting))
return end - placeholder + 1;
begin += 5;
}
@@ -995,7 +999,7 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
 
 static size_t parse_padding_placeholder(struct strbuf *sb,
const char *placeholder,
-   struct format_commit_context *c)
+   struct alignment *c)
 {
const char *ch = placeholder;
enum flush_type flush_type;
@@ -1076,7 +1080,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in 
UTF-8 */
c->auto_color = 1;
return 7; /* consumed 7 bytes, "C(auto)" */
} else {
-   int ret = parse_color(sb, placeholder, c);
+   int ret = parse_color(sb, placeholder,
+ c->pretty_ctx->color);
if (ret)
c->auto_color = 0;
/*
@@ -1126,7 +1131,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in 
UTF-8 */
 
case '<':
case '>':
-   return parse_padding_placeholder(sb, placeholder, c);
+   return parse_padding_placeholder(sb, placeholder, 
&c->alignment);
}
 
/* these depend on the commit */
@@ -1291,12 +1296,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in 
UTF-8 */
return 0;   /* unknown placeholder */
 }
 
-static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
-   const char *placeholder,
-   struct format_commit_context *c)
+static int pad_an_item(struct strbuf *sb, int padding)
 {
-   struct strbuf local_sb = STRBUF_INIT;
-   int total_consumed = 0, len, padding = c->padding;
if (padding < 0) {
const char *start = strrchr(sb->buf, '\n');
int occupied;
@@ -1305,9 +1306,17 @@ static size_t format_and_pad_commit(struct strbuf *sb, 
/* in UTF-8 */
occupied = utf8_strnwidth(start, -1, 1);
padding = (-padding) - occupied;
}
+   return padding;
+}
+
+static int format_an_item(const char *placeholder,
+ struct strbuf *local_sb,
+ struct format_commit_context *c)
+{
+   int total_consumed = 0;
while (1) {
int modifier 

[RESEND][PATCH 00/15] Towards a more awesome git branch

2013-07-09 Thread Ramkumar Ramachandra
Hi,

I'm sending this out in the hope of attracting some reviews.  It's an
unedited resend, and there were zero conflicts from the rebase.

Thanks.

Nguyễn Thái Ngọc Duy (8):
  for-each-ref, quote: convert *_quote_print -> *_quote_buf
  for-each-ref: don't print out elements directly
  pretty: extend pretty_print_context with callback
  pretty: allow passing NULL commit to format_commit_message()
  for-each-ref: get --pretty using format_commit_message()
  for-each-ref: teach verify_format() about pretty's syntax
  for-each-ref: introduce format specifier %>(*) and %<(*)
  for-each-ref: improve responsiveness of %(upstream:track)

Ramkumar Ramachandra (7):
  tar-tree: remove dependency on sq_quote_print()
  quote: remove sq_quote_print()
  pretty: limit recursion in format_commit_one()
  for-each-ref: introduce %(HEAD) marker
  for-each-ref: introduce %(upstream:track[short])
  pretty: introduce get_pretty_userformat
  for-each-ref: use get_pretty_userformat in --pretty

 Documentation/git-for-each-ref.txt |  43 +-
 builtin/for-each-ref.c | 279 ++---
 builtin/tar-tree.c |  11 +-
 commit.h   |   9 ++
 pretty.c   |  77 +-
 quote.c|  61 +++-
 quote.h|   8 +-
 t/t6300-for-each-ref.sh| 143 +++
 8 files changed, 521 insertions(+), 110 deletions(-)

-- 
1.8.3.2.736.g869de25

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/15] Towards a more awesome git-branch

2013-06-05 Thread Ramkumar Ramachandra
Duy Nguyen wrote:
> I'm still hung up one the detached HEAD thing. It's a bit quirky to
> put in for-each-ref, but for-each-ref can't truly replace branch
> --list until it can display detached HEAD. But I think we can finish
> this part and get it in first. Should be useful for some people
> already.

Right.  The branch is called hot-branch; let's polish it for
inclusion, and rebase for-each-ref-pretty onto it when it's done (no
need to stall work there).

> Signed-off-by:
> me for the whole series.

Thanks.  Will add in the re-roll.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/15] Towards a more awesome git-branch

2013-06-04 Thread Duy Nguyen
On Tue, Jun 4, 2013 at 7:35 PM, Ramkumar Ramachandra  wrote:
> Hi,
>
> Duy and I have been working on this topic for some time now.  Here's a
> review candidate.

I'm still hung up one the detached HEAD thing. It's a bit quirky to
put in for-each-ref, but for-each-ref can't truly replace branch
--list until it can display detached HEAD. But I think we can finish
this part and get it in first. Should be useful for some people
already.

> Duy is currently writing code to factor out -v[v] and adding --sort,
> --count to git-branch, but I'm having a lot of difficulty working with
> a series of this size.  I'm leaning towards getting this merged before
> tackling branch (who wants to review a 40-part series?).  Especially
> after [14/15] and [15/15], git for-each-ref should be usable in its
> own right.

Agreed (a bit of concern about 14 and 15/15, though). Signed-off-by:
me for the whole series.
--
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/15] Towards a more awesome git-branch

2013-06-04 Thread Ramkumar Ramachandra
Hi,

Duy and I have been working on this topic for some time now.  Here's a
review candidate.  Duy did most of the chunky work, and I mostly
did review/documentation.  The key patches are:

[5/15]  is a brilliant patch that made this entire thing possible.
[10/15] is another brilliant patch to auto-calculate widths.

Duy is currently writing code to factor out -v[v] and adding --sort,
--count to git-branch, but I'm having a lot of difficulty working with
a series of this size.  I'm leaning towards getting this merged before
tackling branch (who wants to review a 40-part series?).  Especially
after [14/15] and [15/15], git for-each-ref should be usable in its
own right.  I currently have:

[pretty]
hot = %C(red)%(HEAD)%C(reset) 
%C(green)%(refname:short)%C(reset)%(upstream:trackshort)
[alias]
hot = for-each-ref --pretty=hot --count 10 --sort='-committerdate' refs/heads

Which is really useful and manageable until we port these options to
branch and get nice configuration variables.

Nguyễn Thái Ngọc Duy (8):
  for-each-ref, quote: convert *_quote_print -> *_quote_buf
  for-each-ref: don't print out elements directly
  pretty: extend pretty_print_context with callback
  pretty: allow passing NULL commit to format_commit_message()
  for-each-ref: get --pretty using format_commit_message
  for-each-ref: teach verify_format() about pretty's syntax
  for-each-ref: introduce format specifier %>(*) and %<(*)
  for-each-ref: improve responsiveness of %(upstream:track)

Ramkumar Ramachandra (7):
  tar-tree: remove dependency on sq_quote_print()
  quote: remove sq_quote_print()
  pretty: limit recursion in format_commit_one()
  for-each-ref: introduce %(HEAD) marker
  for-each-ref: introduce %(upstream:track[short])
  pretty: introduce get_pretty_userformat
  for-each-ref: use get_pretty_userformat in --pretty

 Documentation/git-for-each-ref.txt |  42 +-
 builtin/for-each-ref.c | 274 ++---
 builtin/tar-tree.c |  11 +-
 commit.h   |   9 ++
 pretty.c   |  77 ++-
 quote.c|  61 +++--
 quote.h|   8 +-
 7 files changed, 372 insertions(+), 110 deletions(-)

-- 
1.8.3.GIT

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html