[PATCH] tag: support configuring --sort via .gitconfig

2014-07-09 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Nguyễn Thái Ngọc Duy pclo...@gmail.com
Cc: Junio C Hamano gits...@pobox.com
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 Documentation/config.txt  |  7 +++
 Documentation/git-tag.txt |  3 ++-
 builtin/tag.c | 47 ---
 t/t7004-tag.sh| 21 +
 4 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..0152582445b0 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,13 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable is used to control the sort ordering of tags when
+   displayed via linkgit:git-tag[5]. The current supported types are
+   refname for lexicographic order (default) or version:refname or
+   v:refname for tag names treated as versions. You may prepend a - to
+   reverse the sort ordering.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..b338260f9f63 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,7 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. See configuration variable tag.sort for more details.
 
 --column[=options]::
 --no-column::
@@ -317,6 +317,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..e8ada8b716ee 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -18,6 +18,8 @@
 #include sha1-array.h
 #include column.h
 
+static char *configured_tag_sort;
+
 static const char * const git_tag_usage[] = {
N_(git tag [-a|-s|-u key-id] [-f] [-m msg|-F file] tagname 
[head]),
N_(git tag -d tagname...),
@@ -346,9 +348,28 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+static void set_configured_tag_sort(const char *key)
+{
+   free(configured_tag_sort);
+   configured_tag_sort = xstrdup(key);
+}
+
+static const char *get_configured_tag_sort(void)
+{
+   if (configured_tag_sort)
+   return configured_tag_sort;
+   return refname;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   set_configured_tag_sort(value);
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -519,9 +540,9 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
return 0;
 }
 
-static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
+static int parse_sort_string(const char *arg)
 {
-   int *sort = opt-value;
+   int sort = 0;
int flags = 0;
 
if (*arg == '-') {
@@ -529,16 +550,26 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
arg++;
}
if (starts_with(arg, version:)) {
-   *sort = VERCMP_SORT;
+   sort = VERCMP_SORT;
arg += 8;
} else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
+   sort = VERCMP_SORT;
arg += 2;
} else
-   *sort = STRCMP_SORT;
+   sort = STRCMP_SORT;
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
+   sort |= flags;
+
+   return sort;
+}
+
+static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
+{
+   int *sort = opt-value;
+
+   *sort = parse_sort_string(arg);
+
return 0;
 }
 
@@ -606,6 +637,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
memset(opt, 0, sizeof(opt));
 
+   sort = parse_sort_string(get_configured_tag_sort());
+
argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
if (keyid) {
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..1e8300f6ed7c 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1423,6 +1423,27 @@ EOF
test_cmp expect actual
 '
 
+test_expect_success 'configured lexical

[PATCH] makefile: add ability to run specific test files

2014-07-09 Thread Jacob Keller
Running a specific test file manually does not obtain the exact
environment setup by the Makefile. Add ability to run any of the tests
in the t/ directory so that a user can more quickly debug a failing
test. Otherwise, the entire test suite needs to be run, which can take a
vary long time.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 Makefile | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 07ea1058379a..86bdc4ed1ee9 100644
--- a/Makefile
+++ b/Makefile
@@ -2262,13 +2262,18 @@ export TEST_NO_MALLOC_CHECK
 
 ### Testing rules
 
+T = $(sort $(wildcard t/t[0-9][0-9][0-9][0-9]-*.sh))
+
+$(T):
+   $(MAKE) -C t $(notdir $@)
+
 test: all
$(MAKE) -C t/ all
 
 perf: all
$(MAKE) -C t/perf/ all
 
-.PHONY: test perf
+.PHONY: test perf $(T)
 
 test-ctype$X: ctype.o
 
-- 
2.0.1.475.g9b8d714

--
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 v2] tag: support configuring --sort via .gitconfig

2014-07-09 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Repost with changes suggested by Peff. These include fixing documentation to
remove duplicatation, and having git-config reference git-tag. Directly assign
a tag_sort global that we use for the config and option variable. 

 Documentation/config.txt  |  6 +
 Documentation/git-tag.txt |  1 +
 builtin/tag.c | 60 ++-
 t/t7004-tag.sh| 21 +
 4 files changed, 67 insertions(+), 21 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..ad8e75fed988 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,12 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable is used to control the sort ordering of tags. It is
+   interpreted precisely the same way as --sort=value. If --sort is
+   given on the command line it will override the selection chosen in the
+   configuration. See linkgit:git-tag[1] for more details.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..2d246725aeb5 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -317,6 +317,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..a679e32db866 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -18,6 +18,8 @@
 #include sha1-array.h
 #include column.h
 
+static int tag_sort = 0;
+
 static const char * const git_tag_usage[] = {
N_(git tag [-a|-s|-u key-id] [-f] [-m msg|-F file] tagname 
[head]),
N_(git tag -d tagname...),
@@ -346,9 +348,39 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+static int parse_sort_string(const char *arg)
+{
+   int sort = 0;
+   int flags = 0;
+
+   if (*arg == '-') {
+   flags |= REVERSE_SORT;
+   arg++;
+   }
+   if (starts_with(arg, version:)) {
+   sort = VERCMP_SORT;
+   arg += 8;
+   } else if (starts_with(arg, v:)) {
+   sort = VERCMP_SORT;
+   arg += 2;
+   } else
+   sort = STRCMP_SORT;
+   if (strcmp(arg, refname))
+   die(_(unsupported sort specification %s), arg);
+   sort |= flags;
+
+   return sort;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   tag_sort = parse_sort_string(value);
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,23 +554,9 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
 
-   if (*arg == '-') {
-   flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
-   *sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
-   *sort = STRCMP_SORT;
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
+   *sort = parse_sort_string(arg);
+
return 0;
 }
 
@@ -552,7 +570,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct create_tag_options opt;
char *cleanup_arg = NULL;
int annotate = 0, force = 0, lines = -1;
-   int cmdmode = 0, sort = 0;
+   int cmdmode = 0;
const char *msgfile = NULL, *keyid = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
struct commit_list *with_commit = NULL;
@@ -578,7 +596,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
OPT__FORCE(force, N_(replace the tag if exists)),
OPT_COLUMN(0, column, colopts, N_(show tag list in 
columns)),
{
-   OPTION_CALLBACK, 0, sort, sort, N_(type), N_(sort 
tags),
+   OPTION_CALLBACK, 0, sort, tag_sort, N_(type), 
N_(sort tags

[PATCH v4] linuxptp: add phc_ctl program to help debug PHC devices

2014-07-10 Thread Jacob Keller
This is an updated version of a script I wrote a couple years ago for
debugging the PHC when writing a new driver. I figured that it might be
handy for the LinuxPTP project to include, as it can give some insight
into the PHC directly. I have updated it to make use of the shared code
here, in order to reduce duplication. Hopefully this is of some use to
everyone.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
-v4
* fix manpage warnings and incorrect display
* add phc_ctl to .gitignore

 .gitignore |   1 +
 makefile   |   4 +-
 phc_ctl.8  | 108 
 phc_ctl.c  | 561 +
 4 files changed, 673 insertions(+), 1 deletion(-)
 create mode 100644 phc_ctl.8
 create mode 100644 phc_ctl.c

diff --git a/.gitignore b/.gitignore
index 098dcdfe1ea7..0ca22afe2b9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
 /phc2sys
 /pmc
 /ptp4l
+/phc_ctl
diff --git a/makefile b/makefile
index e36835b05d40..e9f2f8fcf416 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ CC= $(CROSS_COMPILE)gcc
 VER = -DVER=$(version)
 CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
 LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
-PRG= ptp4l pmc phc2sys hwstamp_ctl
+PRG= ptp4l pmc phc2sys hwstamp_ctl phc_ctl
 OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o fault.o \
  filter.o fsm.o linreg.o mave.o mmedian.o msg.o ntpshm.o phc.o \
  pi.o port.o print.o ptp4l.o raw.o servo.o sk.o stats.o tlv.o \
@@ -54,6 +54,8 @@ phc2sys: clockadj.o clockcheck.o linreg.o msg.o ntpshm.o 
phc.o phc2sys.o pi.o \
 
 hwstamp_ctl: hwstamp_ctl.o version.o
 
+phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
+
 version.o: .version version.sh $(filter-out version.d,$(DEPEND))
 
 .version: force
diff --git a/phc_ctl.8 b/phc_ctl.8
new file mode 100644
index ..06982690410e
--- /dev/null
+++ b/phc_ctl.8
@@ -0,0 +1,108 @@
+.TH PHC_CTL 8 June 2014 linuxptp
+.SH NAME
+phc_ctl \- directly control PHC device clock
+
+.SH SYNOPSIS
+.B phc_ctl
+[ options ] device [ commands ]
+
+.SH DESCRIPTION
+.B phc_ctl
+is a program which can be used to directly control a PHC clock device.
+Typically, it is used for debugging purposes, and has little use for general
+control of the device. For general control of PHC clock devices,
+.B phc2sys (8)
+should be preferred.
+
+device may be either CLOCK_REALTIME, any /dev/ptpX device, or any ethernet
+device which supports ethtool's get_ts_info ioctl.
+
+.SH OPTIONS
+.TP
+.BI \-l  print-level
+Set the maximum syslog level of messages which should be printed or sent to the
+system logger. The default is 6 (LOG_INFO).
+.TP
+.BI \-q
+Do not send messages to syslog. By default messages will be sent.
+.TP
+.BI \-Q
+Do not print messages to standard output. By default messages will be printed.
+.TP
+.BI \-h
+Display a help message.
+.TP
+.B \-v
+Prints the software version and exits.
+
+.SH COMMANDS
+
+.B phc_ctl
+is controlled by passing commands which take either an optional or required
+parameter. The commands (outlined below) will control aspects of the PHC clock
+device. These commands may be useful for inspecting or debugging the PHC
+driver, but may have adverse side effects on running instances of
+.B ptp4l (8)
+or
+.B phc2sys (8)
+
+.TP
+.BI set  seconds
+Set the PHC clock time to the value specified in seconds. Defaults to reading
+CLOCK_REALTIME if no value is provided.
+.TP
+.BI get
+Get the current time of the PHC clock device.
+.TP
+.BI adj  seconds
+Adjust the PHC clock by an amount of seconds provided. This argument is 
required.
+.TP
+.BI freq  ppb
+Adjust the frequency of the PHC clock by the specified parts per billion. If no
+argument is provided, it will attempt to read the current frequency and report
+it.
+.TP
+.BI cmp
+Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
+.TP
+.BI caps
+Display the device capabiltiies. This is the default command if no commands are
+provided.
+.TP
+.BI wait  seconds
+Sleep the process for the specified period of time, waking up and resuming
+afterwards. This command may be useful for sanity checking whether the PHC
+clock is running as expected.
+
+The arguments specified in seconds are read as double precision floating point
+values, and will scale to nanoseconds. This means providing a value of 5.5
+means 5 and one half seconds. This allows specifying fairly precise values for 
time.
+
+.SH EXAMPLES
+
+Read the current clock time from the device
+.RS
+\f(CWphc_ctl /dev/ptp0 get\fP
+.RE
+
+Set the PHC clock time to CLOCK_REALTIME
+.RS
+\f(CWphc_ctl /dev/ptp0 set\fP
+.RE
+
+Set PHC clock time to 0 (seconds since Epoch)
+.RS
+\f(CWphc_ctl /dev/ptp0 set 0.0\fP
+.RE
+
+Quickly sanity check frequency slewing by setting slewing frequency by positive
+10%, resetting clock to 0.0 time, waiting for 10 seconds, and then reading
+time. The time read back should be (roughly) 11 seconds, since the clock was
+slewed 10% faster.
+.RS
+\f

[PATCH] gitignore: add .version as this is generated during a make

2014-07-10 Thread Jacob Keller
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index e0710ad5b294..098dcdfe1ea7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 /*.d
 /*.o
+/.version
 /hwstamp_ctl
 /phc2sys
 /pmc
-- 
2.0.1.475.g9b8d714

--
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 1/2] tag: use skip_prefix instead of magic numbers

2014-07-10 Thread Jacob Keller
Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Authored-by: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 builtin/tag.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7ccb6f3c581b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,12 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
int *sort = opt-value;
int flags = 0;
 
-   if (*arg == '-') {
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
*sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
-   *sort = STRCMP_SORT;
+
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
*sort |= flags;
-- 
2.0.1.475.g9b8d714

--
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 2/2 v4] tag: support configuring --sort via .gitconfig

2014-07-10 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
- v4
* base on top of suggested change by Jeff King to use skip_prefix instead

 Documentation/config.txt  |  6 ++
 Documentation/git-tag.txt |  1 +
 builtin/tag.c | 46 --
 t/t7004-tag.sh| 21 +
 4 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..ad8e75fed988 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,12 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable is used to control the sort ordering of tags. It is
+   interpreted precisely the same way as --sort=value. If --sort is
+   given on the command line it will override the selection chosen in the
+   configuration. See linkgit:git-tag[1] for more details.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..2d246725aeb5 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -317,6 +317,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 7ccb6f3c581b..a53e27d4e7e4 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -18,6 +18,8 @@
 #include sha1-array.h
 #include column.h
 
+static int tag_sort = 0;
+
 static const char * const git_tag_usage[] = {
N_(git tag [-a|-s|-u key-id] [-f] [-m msg|-F file] tagname 
[head]),
N_(git tag -d tagname...),
@@ -346,9 +348,33 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+static int parse_sort_string(const char *arg)
+{
+   int sort = 0;
+   int flags = 0;
+
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
+   sort = VERCMP_SORT;
+
+   if (strcmp(arg, refname))
+   die(_(unsupported sort specification %s), arg);
+   sort |= flags;
+
+   return sort;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   tag_sort = parse_sort_string(value);
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,17 +548,9 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
 
-   if (skip_prefix(arg, -, arg))
-   flags |= REVERSE_SORT;
+   *sort = parse_sort_string(arg);
 
-   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
-   *sort = VERCMP_SORT;
-
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
return 0;
 }
 
@@ -546,7 +564,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct create_tag_options opt;
char *cleanup_arg = NULL;
int annotate = 0, force = 0, lines = -1;
-   int cmdmode = 0, sort = 0;
+   int cmdmode = 0;
const char *msgfile = NULL, *keyid = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
struct commit_list *with_commit = NULL;
@@ -572,7 +590,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
OPT__FORCE(force, N_(replace the tag if exists)),
OPT_COLUMN(0, column, colopts, N_(show tag list in 
columns)),
{
-   OPTION_CALLBACK, 0, sort, sort, N_(type), N_(sort 
tags),
+   OPTION_CALLBACK, 0, sort, tag_sort, N_(type), 
N_(sort tags),
PARSE_OPT_NONEG, parse_opt_sort
},
 
@@ -628,9 +646,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
copts.padding = 2;
run_column_filter(colopts, copts);
}
-   if (lines != -1  sort)
+   if (lines != -1  tag_sort)
die(_(--sort and -n are incompatible));
-   ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit, 
sort

[PATCH 2/3] tag: fix --sort tests to use cat-\EOF format

2014-07-11 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 1/3] tag: use skip_prefix instead of magic numbers

2014-07-11 Thread Jacob Keller
Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Authored-by: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 builtin/tag.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7ccb6f3c581b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,12 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
int *sort = opt-value;
int flags = 0;
 
-   if (*arg == '-') {
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
*sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
-   *sort = STRCMP_SORT;
+
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
*sort |= flags;
-- 
2.0.1.475.g9b8d714

--
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 2/3] tag: fix --sort tests to use cat-\EOF format

2014-07-11 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 3/3] tag: support configuring --sort via .gitconfig

2014-07-11 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Updated based on Junio's suggestions, as well as making sure that we don't bail
if we can't understand config's option. We still print error message followed
by a warning about using default order. In addition, added a few more tests to
ensure that these work as expected.

 Documentation/config.txt  |  5 
 Documentation/git-tag.txt |  5 +++-
 builtin/tag.c | 61 ++-
 t/t7004-tag.sh| 36 
 4 files changed, 90 insertions(+), 17 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..c55c22ab7be9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,11 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable controls the sort ordering of tags when displayed by
+   linkgit:git-tag[1]. Without the --sort=value option provided, the
+   value of this variable will be used as the default.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..320908369f06 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,9 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. When this option is not given, the sort order defaults to the
+   value configured for the 'tag.sort' variable if it exists, or
+   lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=options]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 7ccb6f3c581b..cb37b26159a6 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,6 +32,8 @@ static const char * const git_tag_usage[] = {
 #define SORT_MASK   0x7fff
 #define REVERSE_SORT0x8000
 
+static int tag_sort;
+
 struct tag_filter {
const char **patterns;
int lines;
@@ -346,9 +348,46 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+/*
+ * Parse a sort string, and return 0 if parsed successfully. Will return
+ * non-zero when the sort string does not parse into a known type.
+ */
+static int parse_sort_string(const char *arg, int *sort)
+{
+   int type = 0, flags = 0;
+
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
+   type = VERCMP_SORT;
+   else
+   type = STRCMP_SORT;
+
+   if (strcmp(arg, refname))
+   return error(_(unsupported sort specification %s), arg);
+
+   *sort = (type | flags);
+
+   return 0;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   if (!value)
+   return config_error_nonbool(var);
+   status = parse_sort_string(value, tag_sort);
+   if (status) {
+   warning(using default lexicographic sort order);
+   tag_sort = STRCMP_SORT;
+   }
+   return 0;
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,18 +561,8 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
 
-   if (skip_prefix(arg, -, arg))
-   flags |= REVERSE_SORT;
-
-   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
-   *sort = VERCMP_SORT;
-
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
-   return 0;
+   return parse_sort_string(arg, sort);
 }
 
 int cmd_tag(int argc, const char **argv, const char *prefix)
@@ -546,7 +575,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct create_tag_options opt;
char *cleanup_arg = NULL;
int annotate = 0, force

[PATCH 1/3] tag: use skip_prefix instead of magic numbers

2014-07-11 Thread Jacob Keller
From: Jeff King p...@peff.net

Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Signed-off-by: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Fixed authorship. I don't expect this version to be taken, but it helps me in
review, and I figured it is good to send the whole series.

 builtin/tag.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7ccb6f3c581b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,12 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
int *sort = opt-value;
int flags = 0;
 
-   if (*arg == '-') {
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
*sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
-   *sort = STRCMP_SORT;
+
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
*sort |= flags;
-- 
2.0.1.475.g9b8d714

--
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 2/3] tag: fix --sort tests to use cat-\EOF format

2014-07-11 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 1/3] tag: use skip_prefix instead of magic numbers

2014-07-11 Thread Jacob Keller
From: Jeff King p...@peff.net

Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Signed-off-by: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 builtin/tag.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7ccb6f3c581b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,12 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
int *sort = opt-value;
int flags = 0;
 
-   if (*arg == '-') {
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
*sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
-   *sort = STRCMP_SORT;
+
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
*sort |= flags;
-- 
2.0.1.475.g9b8d714

--
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 3/3 v7] tag: support configuring --sort via .gitconfig

2014-07-11 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Updated warning texts based on Jeff's feedback. Also added translate specifier
to the warning string.

 Documentation/config.txt  |  5 
 Documentation/git-tag.txt |  5 +++-
 builtin/tag.c | 61 ++-
 t/t7004-tag.sh| 36 
 4 files changed, 90 insertions(+), 17 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..c55c22ab7be9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,11 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable controls the sort ordering of tags when displayed by
+   linkgit:git-tag[1]. Without the --sort=value option provided, the
+   value of this variable will be used as the default.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..320908369f06 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,9 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. When this option is not given, the sort order defaults to the
+   value configured for the 'tag.sort' variable if it exists, or
+   lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=options]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 7ccb6f3c581b..6e0a8ed4d1f9 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,6 +32,8 @@ static const char * const git_tag_usage[] = {
 #define SORT_MASK   0x7fff
 #define REVERSE_SORT0x8000
 
+static int tag_sort;
+
 struct tag_filter {
const char **patterns;
int lines;
@@ -346,9 +348,46 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+/*
+ * Parse a sort string, and return 0 if parsed successfully. Will return
+ * non-zero when the sort string does not parse into a known type.
+ */
+static int parse_sort_string(const char *arg, int *sort)
+{
+   int type = 0, flags = 0;
+
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
+   type = VERCMP_SORT;
+   else
+   type = STRCMP_SORT;
+
+   if (strcmp(arg, refname))
+   return error(_(unsupported sort specification '%s'), arg);
+
+   *sort = (type | flags);
+
+   return 0;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   if (!value)
+   return config_error_nonbool(var);
+   status = parse_sort_string(value, tag_sort);
+   if (status) {
+   warning(_(ignoring configured sort specification from 
'tag.sort'));
+   tag_sort = STRCMP_SORT;
+   }
+   return 0;
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,18 +561,8 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
 
-   if (skip_prefix(arg, -, arg))
-   flags |= REVERSE_SORT;
-
-   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
-   *sort = VERCMP_SORT;
-
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
-   return 0;
+   return parse_sort_string(arg, sort);
 }
 
 int cmd_tag(int argc, const char **argv, const char *prefix)
@@ -546,7 +575,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct create_tag_options opt;
char *cleanup_arg = NULL;
int annotate = 0, force = 0, lines = -1;
-   int cmdmode = 0, sort = 0;
+   int cmdmode = 0;
const char *msgfile = NULL, *keyid = NULL;
struct

[PATCH 2/3] tag: fix --sort tests to use cat-\EOF format

2014-07-11 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 1/3] tag: use skip_prefix instead of magic numbers

2014-07-11 Thread Jacob Keller
From: Jeff King p...@peff.net

Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Signed-off-by: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Fixed issue with patch in that we dropped the reset to STRCMP_SORT, discovered
by Junio.

 builtin/tag.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..9d7643f127e7 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,14 @@ static int parse_opt_sort(const struct option *opt, const 
char *arg, int unset)
int *sort = opt-value;
int flags = 0;
 
-   if (*arg == '-') {
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
-   }
-   if (starts_with(arg, version:)) {
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
*sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
-   } else
+   else
*sort = STRCMP_SORT;
+
if (strcmp(arg, refname))
die(_(unsupported sort specification %s), arg);
*sort |= flags;
-- 
2.0.1.475.g9b8d714

--
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 v8 0/4] tag: configure default tag sort via .gitconfig

2014-07-15 Thread Jacob Keller
This patch series is hopefully the final version of a series of patches which
updates git-tag to allow the .gitconfig variable 'tag.sort' to be used as the
default sort parameter. This version uses a new set/pop error routine setup
which enables correctly modifying the error routine to handle the config vs the
command line.

In addition, I split the patch such that all the changes to the original
parse_opt_sort are shown, and the following patch which extracts this function
is just a function extraction with no changes, making it easier to review the
new changes. One other minor bug fix is included as well.

Jacob Keller (4):
  usage: make error functions a stack
  tag: fix --sort tests to use cat-\EOF format
  tag: update parsing to be more precise regarding errors
  tag: support configuring --sort via .gitconfig

 Documentation/config.txt  |  5 +++
 Documentation/git-tag.txt |  5 ++-
 builtin/tag.c | 97 ---
 git-compat-util.h |  1 +
 t/t7004-tag.sh| 76 +++--
 usage.c   | 29 --
 6 files changed, 167 insertions(+), 46 deletions(-)

-- 
2.0.1.475.g9b8d714

--
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 v8 1/4] usage: make error functions a stack

2014-07-15 Thread Jacob Keller
Let error routine be a stack of error functions so that callers can
temporarily override the error_routine and then pop their modification
off the stack. This enables customizing error for a small code segment.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
This is a modification of Peff's original idea for handling multiple error
routines. I simplified it by not having the collect and other routines. I only
modify set_error_routine to be a push operation, with pop_error_routine being
its opposite. I don't let pop_error_routine remove all the error routines,
instead only doing one with an assert check that we never call it too many 
times.

This enables temporarily modifying the error routine and then popping back to
the previous value.

 git-compat-util.h |  1 +
 usage.c   | 29 ++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 9de318071083..6d0416c90ad8 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -344,6 +344,7 @@ static inline int const_error(void)
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, 
va_list params));
 extern void set_error_routine(void (*routine)(const char *err, va_list 
params));
+extern void pop_error_routine(void);
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int starts_with(const char *str, const char *prefix);
diff --git a/usage.c b/usage.c
index ed146453cabe..fd9126a7ca0b 100644
--- a/usage.c
+++ b/usage.c
@@ -57,18 +57,41 @@ static int die_is_recursing_builtin(void)
  * (ugh), so keep things static. */
 static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = 
usage_builtin;
 static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = 
die_builtin;
-static void (*error_routine)(const char *err, va_list params) = error_builtin;
 static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
 static int (*die_is_recursing)(void) = die_is_recursing_builtin;
 
+struct error_func_list {
+   void (*func)(const char *, va_list);
+   struct error_func_list *next;
+};
+static struct error_func_list default_error_func = { error_builtin };
+static struct error_func_list *error_funcs = default_error_func;
+
 void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list 
params))
 {
die_routine = routine;
 }
 
+/* push error routine onto the error function stack */
 void set_error_routine(void (*routine)(const char *err, va_list params))
 {
-   error_routine = routine;
+   struct error_func_list *efl = xmalloc(sizeof(*efl));
+   efl-func = routine;
+   efl-next = error_funcs;
+   error_funcs = efl;
+}
+
+/* pop a single error routine off of the error function stack, thus reverting
+ * to previous error. Should always be paired with a set_error_routine */
+void pop_error_routine(void)
+{
+   assert(error_funcs != default_error_func);
+
+   struct error_func_list *efl = error_funcs;
+   if (efl-next) {
+   error_funcs = efl-next;
+   free(efl);
+   }
 }
 
 void set_die_is_recursing_routine(int (*routine)(void))
@@ -144,7 +167,7 @@ int error(const char *err, ...)
va_list params;
 
va_start(params, err);
-   error_routine(err, params);
+   error_funcs-func(err, params);
va_end(params);
return -1;
 }
-- 
2.0.1.475.g9b8d714

--
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 v8 4/4] tag: support configuring --sort via .gitconfig

2014-07-15 Thread Jacob Keller
Add support for configuring default sort specification for git tags.
Command line option will override the configured value. Both methods use
the same syntax. Make use of (set/pop)_error_routine to temporarily
modify error reporting when parsing as a configuration option.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 Documentation/config.txt  |   5 ++
 Documentation/git-tag.txt |   5 +-
 builtin/tag.c | 124 --
 t/t7004-tag.sh|  36 ++
 4 files changed, 120 insertions(+), 50 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..c55c22ab7be9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,11 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable controls the sort ordering of tags when displayed by
+   linkgit:git-tag[1]. Without the --sort=value option provided, the
+   value of this variable will be used as the default.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..320908369f06 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,9 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. When this option is not given, the sort order defaults to the
+   value configured for the 'tag.sort' variable if it exists, or
+   lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=options]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 7d82526e76be..603cf688368c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,6 +32,8 @@ static const char * const git_tag_usage[] = {
 #define SORT_MASK   0x7fff
 #define REVERSE_SORT0x8000
 
+static int tag_sort;
+
 struct tag_filter {
const char **patterns;
int lines;
@@ -346,9 +348,76 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+static int parse_sort_string(const char *arg, int *sort)
+{
+   char *value, *separator, *type, *atom;
+   int flags = 0, function = 0, err = 0;
+
+   /* skip the '-' prefix for reverse sort order first */
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   /* duplicate string so we can modify it in place */
+   value = xstrdup(arg);
+
+   /* determine the sort function and the sorting atom */
+   separator = strchr(value, ':');
+   if (separator) {
+   /* split the string at the separator with a NULL byte */
+   *separator = '\0';
+   type = value;
+   atom = separator + 1;
+   } else {
+   /* we have no separator, so assume the whole string is the * 
atom */
+   type = NULL;
+   atom = value;
+   }
+
+   if (type) {
+   if (!strcmp(type, version) || !strcmp(type, v))
+   function = VERCMP_SORT;
+   else {
+   err = error(_(unsupported sort function '%s'), type);
+   goto abort;
+   }
+
+   } else
+   function = STRCMP_SORT;
+
+   /* for now, only the refname is a valid atom */
+   if (atom  strcmp(atom, refname)) {
+   err = error(_(unsupported sort specification '%s'), atom);
+   goto abort;
+   }
+
+   *sort = (flags | function);
+
+abort:
+   free(value);
+   return err;
+}
+
+static void error_bad_sort_config(const char *err, va_list params)
+{
+   vreportf(warning: tag.sort has , err, params);
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   if (!value)
+   return config_error_nonbool(var);
+
+   set_error_routine(error_bad_sort_config);
+   parse_sort_string(value, tag_sort);
+   pop_error_routine();
+
+   return 0;
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,51 +591,8 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int

[PATCH v8 2/4] tag: fix --sort tests to use cat-\EOF format

2014-07-15 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 v8 3/4] tag: update parsing to be more precise regarding errors

2014-07-15 Thread Jacob Keller
Update the parsing of sort string specifications so that it is able to
properly detect errors in the function type and allowed atoms.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
This function should replace the one I think is already on one of the branches.
This version fully updates the parse_sort_opt to be like what will be the
parse_sort_string function. I have ensured that the next patch is purely a move
of this function, and does not contain modifications to make this easier to
review. Instead of using skip_prefix, I use strchr and check for the separator.

 builtin/tag.c | 55 +--
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7d82526e76be 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -522,24 +522,51 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
+   char *value, *separator, *type, *atom;
+   int flags = 0, function = 0, err = 0;
 
-   if (*arg == '-') {
+   /* skip the '-' prefix for reverse sort order first */
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
+
+   /* duplicate string so we can modify it in place */
+   value = xstrdup(arg);
+
+   /* determine the sort function and the sorting atom */
+   separator = strchr(value, ':');
+   if (separator) {
+   /* split the string at the separator with a NULL byte */
+   *separator = '\0';
+   type = value;
+   atom = separator + 1;
+   } else {
+   /* we have no separator, so assume the whole string is the * 
atom */
+   type = NULL;
+   atom = value;
}
-   if (starts_with(arg, version:)) {
-   *sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
+
+   if (type) {
+   if (!strcmp(type, version) || !strcmp(type, v))
+   function = VERCMP_SORT;
+   else {
+   err = error(_(unsupported sort function '%s'), type);
+   goto abort;
+   }
+
} else
-   *sort = STRCMP_SORT;
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
-   return 0;
+   function = STRCMP_SORT;
+
+   /* for now, only the refname is a valid atom */
+   if (atom  strcmp(atom, refname)) {
+   err = error(_(unsupported sort specification '%s'), atom);
+   goto abort;
+   }
+
+   *sort = (flags | function);
+
+abort:
+   free(value);
+   return err;
 }
 
 int cmd_tag(int argc, const char **argv, const char *prefix)
-- 
2.0.1.475.g9b8d714

--
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 v9 4/4] tag: support configuring --sort via .gitconfig

2014-07-15 Thread Jacob Keller
Add support for configuring default sort specification for git tags.
Command line option will override the configured value. Both methods use
the same syntax. Make use of (set/pop)_error_routine to temporarily
modify error reporting when parsing as a configuration option.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 Documentation/config.txt  |   5 ++
 Documentation/git-tag.txt |   5 +-
 builtin/tag.c | 124 --
 t/t7004-tag.sh|  36 ++
 4 files changed, 120 insertions(+), 50 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1d718bdb9662..c55c22ab7be9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2354,6 +2354,11 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable controls the sort ordering of tags when displayed by
+   linkgit:git-tag[1]. Without the --sort=value option provided, the
+   value of this variable will be used as the default.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..320908369f06 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,9 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. When this option is not given, the sort order defaults to the
+   value configured for the 'tag.sort' variable if it exists, or
+   lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=options]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 7d82526e76be..091536c61eab 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,6 +32,8 @@ static const char * const git_tag_usage[] = {
 #define SORT_MASK   0x7fff
 #define REVERSE_SORT0x8000
 
+static int tag_sort;
+
 struct tag_filter {
const char **patterns;
int lines;
@@ -346,9 +348,76 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+static int parse_sort_string(const char *arg, int *sort)
+{
+   char *value, *separator, *type, *atom;
+   int flags = 0, function = 0, err = 0;
+
+   /* skip the '-' prefix for reverse sort order first */
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   /* duplicate string so we can modify it in place */
+   value = xstrdup(arg);
+
+   /* determine the sort function and the sorting atom */
+   separator = strchr(value, ':');
+   if (separator) {
+   /* split the string at the separator with a NULL byte */
+   *separator = '\0';
+   type = value;
+   atom = separator + 1;
+   } else {
+   /* we have no separator, so assume the whole string is the * 
atom */
+   type = NULL;
+   atom = value;
+   }
+
+   if (type) {
+   if (!strcmp(type, version) || !strcmp(type, v))
+   function = VERCMP_SORT;
+   else {
+   err = error(_(unsupported sort function '%s'), type);
+   goto abort;
+   }
+
+   } else
+   function = STRCMP_SORT;
+
+   /* for now, only the refname is a valid atom */
+   if (atom  strcmp(atom, refname)) {
+   err = error(_(unsupported sort specification '%s'), atom);
+   goto abort;
+   }
+
+   *sort = (flags | function);
+
+abort:
+   free(value);
+   return err;
+}
+
+static void error_bad_sort_config(const char *err, va_list params)
+{
+   vreportf(warning: tag.sort has , err, params);
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   if (!value)
+   return config_error_nonbool(var);
+
+   push_error_routine(error_bad_sort_config);
+   parse_sort_string(value, tag_sort);
+   pop_error_routine();
+
+   return 0;
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,51 +591,8 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int

[PATCH v9 3/4] tag: update parsing to be more precise regarding errors

2014-07-15 Thread Jacob Keller
Update the parsing of sort string specifications so that it is able to
properly detect errors in the function type and allowed atoms.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 builtin/tag.c | 55 +--
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7d82526e76be 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -522,24 +522,51 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
+   char *value, *separator, *type, *atom;
+   int flags = 0, function = 0, err = 0;
 
-   if (*arg == '-') {
+   /* skip the '-' prefix for reverse sort order first */
+   if (skip_prefix(arg, -, arg))
flags |= REVERSE_SORT;
-   arg++;
+
+   /* duplicate string so we can modify it in place */
+   value = xstrdup(arg);
+
+   /* determine the sort function and the sorting atom */
+   separator = strchr(value, ':');
+   if (separator) {
+   /* split the string at the separator with a NULL byte */
+   *separator = '\0';
+   type = value;
+   atom = separator + 1;
+   } else {
+   /* we have no separator, so assume the whole string is the * 
atom */
+   type = NULL;
+   atom = value;
}
-   if (starts_with(arg, version:)) {
-   *sort = VERCMP_SORT;
-   arg += 8;
-   } else if (starts_with(arg, v:)) {
-   *sort = VERCMP_SORT;
-   arg += 2;
+
+   if (type) {
+   if (!strcmp(type, version) || !strcmp(type, v))
+   function = VERCMP_SORT;
+   else {
+   err = error(_(unsupported sort function '%s'), type);
+   goto abort;
+   }
+
} else
-   *sort = STRCMP_SORT;
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
-   return 0;
+   function = STRCMP_SORT;
+
+   /* for now, only the refname is a valid atom */
+   if (atom  strcmp(atom, refname)) {
+   err = error(_(unsupported sort specification '%s'), atom);
+   goto abort;
+   }
+
+   *sort = (flags | function);
+
+abort:
+   free(value);
+   return err;
 }
 
 int cmd_tag(int argc, const char **argv, const char *prefix)
-- 
2.0.1.475.g9b8d714

--
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 v9 2/4] tag: fix --sort tests to use cat-\EOF format

2014-07-15 Thread Jacob Keller
The --sort tests should use the better format for expect to maintain
indenting and ensure that no substitution is occurring. This makes
parsing and understanding the tests a bit easier.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
 t/t7004-tag.sh | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e4ab0f5b6419..66010b0e7066 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1385,41 +1385,41 @@ test_expect_success 'lexical sort' '
git tag foo1.6 
git tag foo1.10 
git tag -l --sort=refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.3
-foo1.6
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.3
+   foo1.6
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'version sort' '
git tag -l --sort=version:refname foo* actual 
-   cat expect EOF 
-foo1.3
-foo1.6
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.3
+   foo1.6
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse version sort' '
git tag -l --sort=-version:refname foo* actual 
-   cat expect EOF 
-foo1.10
-foo1.6
-foo1.3
-EOF
+   cat expect -\EOF 
+   foo1.10
+   foo1.6
+   foo1.3
+   EOF
test_cmp expect actual
 '
 
 test_expect_success 'reverse lexical sort' '
git tag -l --sort=-refname foo* actual 
-   cat expect EOF 
-foo1.6
-foo1.3
-foo1.10
-EOF
+   cat expect -\EOF 
+   foo1.6
+   foo1.3
+   foo1.10
+   EOF
test_cmp expect actual
 '
 
-- 
2.0.1.475.g9b8d714

--
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 v9 1/4] usage: make error functions a stack

2014-07-15 Thread Jacob Keller
Rename set_error_routine to be push_error_routine, and add a new
pop_error_routine. This allows temporary modifications of the error
routine over a small block of code.

Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
---
Renamed set_error_routine to push_error_routine in order to match the
pop_error_routine.

 git-compat-util.h |  3 ++-
 run-command.c |  2 +-
 usage.c   | 32 
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 9de318071083..b650e3cb6cdc 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -343,7 +343,8 @@ static inline int const_error(void)
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, 
va_list params));
-extern void set_error_routine(void (*routine)(const char *err, va_list 
params));
+extern void push_error_routine(void (*routine)(const char *err, va_list 
params));
+extern void pop_error_routine(void);
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int starts_with(const char *str, const char *prefix);
diff --git a/run-command.c b/run-command.c
index be07d4ad335b..a611b819c25d 100644
--- a/run-command.c
+++ b/run-command.c
@@ -360,7 +360,7 @@ fail_pipe:
set_cloexec(child_err);
}
set_die_routine(die_child);
-   set_error_routine(error_child);
+   push_error_routine(error_child);
 
close(notify_pipe[0]);
set_cloexec(notify_pipe[1]);
diff --git a/usage.c b/usage.c
index ed146453cabe..3fe26771f7e6 100644
--- a/usage.c
+++ b/usage.c
@@ -57,18 +57,42 @@ static int die_is_recursing_builtin(void)
  * (ugh), so keep things static. */
 static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = 
usage_builtin;
 static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = 
die_builtin;
-static void (*error_routine)(const char *err, va_list params) = error_builtin;
 static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
 static int (*die_is_recursing)(void) = die_is_recursing_builtin;
 
+struct error_func_list {
+   void (*func)(const char *, va_list);
+   struct error_func_list *next;
+};
+static struct error_func_list default_error_func = { error_builtin };
+static struct error_func_list *error_funcs = default_error_func;
+
 void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list 
params))
 {
die_routine = routine;
 }
 
-void set_error_routine(void (*routine)(const char *err, va_list params))
+/* push error routine onto the error function stack */
+void push_error_routine(void (*routine)(const char *err, va_list params))
 {
-   error_routine = routine;
+   struct error_func_list *efl = xmalloc(sizeof(*efl));
+   efl-func = routine;
+   efl-next = error_funcs;
+   error_funcs = efl;
+}
+
+/* pop a single error routine off of the error function stack, thus reverting
+ * to previous error. Should always be paired with a push_error_routine */
+void pop_error_routine(void)
+{
+   struct error_func_list *efl = error_funcs;
+
+   assert(error_funcs != default_error_func);
+
+   if (efl-next) {
+   error_funcs = efl-next;
+   free(efl);
+   }
 }
 
 void set_die_is_recursing_routine(int (*routine)(void))
@@ -144,7 +168,7 @@ int error(const char *err, ...)
va_list params;
 
va_start(params, err);
-   error_routine(err, params);
+   error_funcs-func(err, params);
va_end(params);
return -1;
 }
-- 
2.0.1.475.g9b8d714

--
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 v10] tag: support configuring --sort via .gitconfig

2014-07-16 Thread Jacob Keller
Add support for configuring default sort ordering for git tags. Command
line option will override this configured value, using the exact same
syntax.

Cc: Jeff King p...@peff.net
Signed-off-by: Jacob Keller jacob.e.kel...@intel.com
Signed-off-by: Junio C Hamano gits...@pobox.com
---
Based on what's in Junio's tree, this patch includes some minor changes to fix
up other non-error reporting changes included in previous versions. The other
patches in his tree already match so we can leave them as they are.

 Documentation/config.txt  |  5  
 Documentation/git-tag.txt |  5 +++-
 builtin/tag.c | 68 ++-
 t/t7004-tag.sh| 36 +
 4 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 9f467d3820a4..9d4f249606b3 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2351,6 +2351,11 @@ submodule.name.ignore::
--ignore-submodules option. The 'git submodule' commands are not
affected by this setting.
 
+tag.sort::
+   This variable controls the sort ordering of tags when displayed by
+   linkgit:git-tag[1]. Without the --sort=value option provided, the
+   value of this variable will be used as the default.
+
 tar.umask::
This variable can be used to restrict the permission bits of
tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index b424a1bc48bb..320908369f06 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,7 +99,9 @@ OPTIONS
Sort in a specific order. Supported type is refname
(lexicographic order), version:refname or v:refname (tag
names are treated as versions). Prepend - to reverse sort
-   order.
+   order. When this option is not given, the sort order defaults to the
+   value configured for the 'tag.sort' variable if it exists, or
+   lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=options]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
diff --git a/builtin/tag.c b/builtin/tag.c
index 1101c19596c5..e063035515d9 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,6 +32,8 @@ static const char * const git_tag_usage[] = {
 #define SORT_MASK   0x7fff
 #define REVERSE_SORT0x8000
 
+static int tag_sort;
+
 struct tag_filter {
const char **patterns;
int lines;
@@ -346,9 +348,51 @@ static const char tag_template_nocleanup[] =
Lines starting with '%c' will be kept; you may remove them
 yourself if you want to.\n);
 
+/*
+ * Parse a sort string, and return 0 if parsed successfully. Will return
+ * non-zero when the sort string does not parse into a known type. If var is
+ * given, the error message becomes a warning and includes information about
+ * the configuration value.
+ */
+static int parse_sort_string(const char *var, const char *arg, int *sort)
+{
+   int type = 0, flags = 0;
+
+   if (skip_prefix(arg, -, arg))
+   flags |= REVERSE_SORT;
+
+   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
+   type = VERCMP_SORT;
+   else
+   type = STRCMP_SORT;
+
+   if (strcmp(arg, refname)) {
+   if (!var)
+   return error(_(unsupported sort specification '%s'), 
arg);
+   else {
+   warning(_(unsupported sort specification '%s' in 
variable '%s'),
+   var, arg);
+   return -1;
+   }
+   }
+
+   *sort = (type | flags);
+
+   return 0;
+}
+
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
-   int status = git_gpg_config(var, value, cb);
+   int status;
+
+   if (!strcmp(var, tag.sort)) {
+   if (!value)
+   return config_error_nonbool(var);
+   parse_sort_string(var, value, tag_sort);
+   return 0;
+   }
+
+   status = git_gpg_config(var, value, cb);
if (status)
return status;
if (starts_with(var, column.))
@@ -522,20 +566,8 @@ static int parse_opt_points_at(const struct option *opt 
__attribute__((unused)),
 static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
 {
int *sort = opt-value;
-   int flags = 0;
 
-   if (skip_prefix(arg, -, arg))
-   flags |= REVERSE_SORT;
-
-   if (skip_prefix(arg, version:, arg) || skip_prefix(arg, v:, arg))
-   *sort = VERCMP_SORT;
-   else
-   *sort = STRCMP_SORT;
-
-   if (strcmp(arg, refname))
-   die(_(unsupported sort specification %s), arg);
-   *sort |= flags;
-   return 0;
+   return

refspecs with '*' as part of pattern

2015-07-06 Thread Jacob Keller
Hi,

I've been looking at the refspecs for git fetch, and noticed that
globs are partially supported. I wanted to use something like:

refs/tags/some-prefix-*:refs/tags/some-prefix-*

as a refspec, so that I can fetch only tags which have a specific
prefix. I know that I could use namespaces to separate tags, but
unfortunately, I am unable to fix the tag format. The specific
repository in question is also generating several tags which are not
relevant to me, in formats that are not really useful for human
consumption. I am also not able to fix this less than useful practice.

However, I noticed that refspecs only support * as a single component.
The match algorithm works perfectly fine, as documented in
abd2bde78bd9 (Support '*' in the middle of a refspec)

What is the reason for not allowing slightly more arbitrary
expressions? Obviously no more than one *...

It seems like the strict requirements, as in the above commit, but i
an unable to find what these requirements are, and why they can't
allow more expressions.

It's possible that users might not expect it to work, but maybe it
could be configured behind an extra option to prevent accidental use?
I think it's quite intuitive though.

Maybe because it allows some shenanagins to rename tags, but... that's
really the user's fault... Another reason for putting this behind an
option possibly?

Personally I would like to be able to use this as it allows much more
fine grained control over what I fetch, and lets me stick with the
un-namespaced tags which are something I can't change.

If this isn't something that can be done I would appreciate a good
explanation of what it might break and why it's a bad idea...

Regards,
Jake
--
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: refspecs with '*' as part of pattern

2015-07-06 Thread Jacob Keller
On Mon, Jul 6, 2015 at 4:01 PM, Junio C Hamano gits...@pobox.com wrote:
 Jacob Keller jacob.kel...@gmail.com writes:

 What is the reason for not allowing slightly more arbitrary
 expressions? Obviously no more than one *...

 I cannot seem to be able to find related discussions around that
 patch, so this is only my guess, but I suspect that this is to
 discourage people from doing something like:

 refs/tags/*:refs/tags/foo-*

 which would open can of worms (e.g. imagine you fetch with that
 pathspec and then push with refs/tags/*:refs/tags/* back there;
 would you now get foo-v1.0.0 and foo-foo-v1.0.0 for their v1.0.0
 tag?) we'd prefer not having to worry about.




That is what I assumed. Would some sort of fetch option you could set
in gitconfig be acceptable? Or possibly extending code to verify that
it doesn't do something too silly? Like extend it to verify that the
per-section path is actually the same?

Today you can get a similar issue with

refs/tags/*:refs/tags/foo/*

It just is easier to fix since they're all name-spaced into foo instead.

The issue I have is that I only want to download specific tag format,
instead of all tags.. Maybe there is a better way to handle this?

Basically, the automated build software that my team uses (I don't
have a choice here) generates tags like

scm_063015_050528

and then I re-generate human readable tags based on information so
they look like

driver-name-0-16-3

I don't want to ever pull scm_* tags because these are useless. I have
tried very much to change the behavior of the team running the build
software, but they refuse to budge (as this software works against
CVS/SVN etc, and supports some older work, and they don't want to
special case it if they can avoid it).

Basically, all I see in my git tags are useless scm tags, and I want
to not download them ever. (so that they don't show up as possible
refs at all)

Is there a possible better solution to this?

Regards,
Jake
--
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: refspecs with '*' as part of pattern

2015-07-06 Thread Jacob Keller
On Mon, Jul 6, 2015 at 7:20 PM, Daniel Barkalow
barka...@iabervon.iabervon.org wrote:
 On Mon, 6 Jul 2015, Junio C Hamano wrote:

 Jacob Keller jacob.kel...@gmail.com writes:

  I've been looking at the refspecs for git fetch, and noticed that
  globs are partially supported. I wanted to use something like:
 
  refs/tags/some-prefix-*:refs/tags/some-prefix-*
 
  as a refspec, so that I can fetch only tags which have a specific
  prefix. I know that I could use namespaces to separate tags, but
  unfortunately, I am unable to fix the tag format. The specific
  repository in question is also generating several tags which are not
  relevant to me, in formats that are not really useful for human
  consumption. I am also not able to fix this less than useful practice.
 
  However, I noticed that refspecs only support * as a single component.
  The match algorithm works perfectly fine, as documented in
  abd2bde78bd9 (Support '*' in the middle of a refspec)
 
  What is the reason for not allowing slightly more arbitrary
  expressions? Obviously no more than one *...

 I cannot seem to be able to find related discussions around that
 patch, so this is only my guess, but I suspect that this is to
 discourage people from doing something like:

   refs/tags/*:refs/tags/foo-*

 which would open can of worms (e.g. imagine you fetch with that
 pathspec and then push with refs/tags/*:refs/tags/* back there;
 would you now get foo-v1.0.0 and foo-foo-v1.0.0 for their v1.0.0
 tag?) we'd prefer not having to worry about.

 That wouldn't be it, since refs/tags/*:refs/tags/foo/* would have the same
 problem, assuming you didn't set up the push refspec carefully.

 I think it was mostly that it would be too easy to accidentally do
 something you don't want by having some other character instead of a
 slash, like refs/heads/*:refs/heads-*.

 Aside from the increased risk of hard-to-spot typos leading to very weird
 behavior, nothing actually goes wrong; in fact, I've been using git with
 that check removed for ages because I wanted a refspec like
 refs/heads/something-*:refs/heads/*. And it works fine as a local patch,
 since you don't need your refspec handling to interoperate with other
 repositories.

 -Daniel
 *This .sig left intentionally blank*


Which is why I suggested a patch that adds this behavior conditionally
and only for fetch. This way you don't have to use a local patch, and
it wouldn't hit normal users. Ideally we can add a flag that only
enables it for refspecs that don't interoperate.

Does this seem ok? If so I will go ahead and try to work up a patch

Regards,
Jake
--
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: Whether Git supports directory level access or not?

2015-07-07 Thread Jacob Keller
Hi

On Mon, Jul 6, 2015 at 11:40 PM,  saur...@stockal.com wrote:
 Hi,

 Please let me know whether Git supports directory level access or not.

 For example :- Consider the structure with one repository consisting of sub
 directories for each product.
 main_repo:
dir1 dir
dir2 dir
shared-dir dir
private dir
 One group(user) of developers has access to dir1 and shared-dir while the
 other group(user) has access to dir2 and shared-resources.
 Just for context, both dir1 and dir2 require shared-dir to be checked out
 for building the products.

 And private dir is only accessible by admin(repo owner).

 Regards
 Saurabh gaur
 --
 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

I do not believe this is possible with git. How would this even make
sense? You can do something with sub-repositories on the server end,
where each directory is its own repository with different access
rights (and servers like gerrit or other git server setups have
various controls which enable more complex access control beyond just
Unix paths)

However, in-repo per-directory permissions make no sense, as there
would be no way to generate commits.

Regards,
Jake
--
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: refspecs with '*' as part of pattern

2015-07-07 Thread Jacob Keller
On Mon, Jul 6, 2015 at 7:33 PM, Jacob Keller jacob.kel...@gmail.com wrote:
 On Mon, Jul 6, 2015 at 7:20 PM, Daniel Barkalow
 barka...@iabervon.iabervon.org wrote:
 On Mon, 6 Jul 2015, Junio C Hamano wrote:

 Jacob Keller jacob.kel...@gmail.com writes:

  I've been looking at the refspecs for git fetch, and noticed that
  globs are partially supported. I wanted to use something like:
 
  refs/tags/some-prefix-*:refs/tags/some-prefix-*
 
  as a refspec, so that I can fetch only tags which have a specific
  prefix. I know that I could use namespaces to separate tags, but
  unfortunately, I am unable to fix the tag format. The specific
  repository in question is also generating several tags which are not
  relevant to me, in formats that are not really useful for human
  consumption. I am also not able to fix this less than useful practice.
 
  However, I noticed that refspecs only support * as a single component.
  The match algorithm works perfectly fine, as documented in
  abd2bde78bd9 (Support '*' in the middle of a refspec)
 
  What is the reason for not allowing slightly more arbitrary
  expressions? Obviously no more than one *...

 I cannot seem to be able to find related discussions around that
 patch, so this is only my guess, but I suspect that this is to
 discourage people from doing something like:

   refs/tags/*:refs/tags/foo-*

 which would open can of worms (e.g. imagine you fetch with that
 pathspec and then push with refs/tags/*:refs/tags/* back there;
 would you now get foo-v1.0.0 and foo-foo-v1.0.0 for their v1.0.0
 tag?) we'd prefer not having to worry about.

 That wouldn't be it, since refs/tags/*:refs/tags/foo/* would have the same
 problem, assuming you didn't set up the push refspec carefully.

 I think it was mostly that it would be too easy to accidentally do
 something you don't want by having some other character instead of a
 slash, like refs/heads/*:refs/heads-*.

 Aside from the increased risk of hard-to-spot typos leading to very weird
 behavior, nothing actually goes wrong; in fact, I've been using git with
 that check removed for ages because I wanted a refspec like
 refs/heads/something-*:refs/heads/*. And it works fine as a local patch,
 since you don't need your refspec handling to interoperate with other
 repositories.

 -Daniel
 *This .sig left intentionally blank*


 Which is why I suggested a patch that adds this behavior conditionally
 and only for fetch. This way you don't have to use a local patch, and
 it wouldn't hit normal users. Ideally we can add a flag that only
 enables it for refspecs that don't interoperate.

 Does this seem ok? If so I will go ahead and try to work up a patch

 Regards,
 Jake

I am working up a patch to try and get this configurable. I'll
hopefully send it out tomorrow morning sometime.

Regards,
Jake
--
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: [RFC/PATCH 04/11] ref-filter: add 'ifexists' atom

2015-08-01 Thread Jacob Keller
On Fri, Jul 31, 2015 at 11:46 PM, Karthik Nayak karthik@gmail.com wrote:
 On Thu, Jul 30, 2015 at 2:51 AM, Matthieu Moy
 matthieu@grenoble-inp.fr wrote:
 Junio C Hamano gits...@pobox.com writes:

 Junio C Hamano gits...@pobox.com writes:

 Couldn't think of a better replacer, any suggestions would be welcome :)

 See below.
 ...
 One way to do all of the above is ...

 Note that is just one way, not the only or not necessarily the
 best.  It certainly is not the easiest, I think.

 %(if:atom)...%(endif)

 might be easier to implement.

 And I find it easier to read or write too. Nested parenthesis in a
 format string make them really tricky. That removes the need for
 escaping since the content of the if/endif is a format string like the
 others, it can use the same escaping rules (IIRC, %% to escape a %).


 THat's a really good point. Will work on this :)

 --
 Regards,
 Karthik Nayak
 --


Not sure how much work it would take to extent other atoms to this
behavior, such as %(padright) and %(align) and such, that way they
could operate on literals and so forth.

Maybe not worth it as part of this GSoC project, as it may be too
complicated, but maybe something to mark as a TODO for future or
something?

The only issue being that it might mean we have to keep the old
implementation too for backwards compatibility .. Maybe it's easier to
implement that I think, or maybe it's far more challenging than I
think

Regards,
Jake
--
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: [RFC/PATCH 07/11] branch: move 'current' check down to the presentation layer

2015-08-01 Thread Jacob Keller
On Fri, Jul 31, 2015 at 11:48 PM, Karthik Nayak karthik@gmail.com wrote:
 On Thu, Jul 30, 2015 at 2:57 AM, Matthieu Moy
 matthieu@grenoble-inp.fr wrote:
 Karthik Nayak karthik@gmail.com writes:

 What I was thinking of was something like this :

 struct strbuf format = STRBUF_INIT;
 char c = ' ';
 if (current)
 c = '*';
 strbuf_addf(format, %c, c, other format options...);
 show_ref_array_item(item, format.buf, quote_style, 0);
 strbuf_release(format);

 I think that would interact badly with verify_ref_format(). Usually, you
 have just one format string and call verify_ref_format() on it, not a
 different format string for each ref_array_item. That would probably be
 solvable.


 Good point! I just was wondering if we need another atom just to print a star.
 But your points certainly are valid. I'll implement this. Thanks :)

 This would remove the need of making the printing of the * to be
 needed by ref-filter. As this is only needed in branch.c

 If going on what you're saying we could have a %(starifcurrent) atom or
 something, but I don't see a general use for this.

 To have a really customizeable format, you would want to allow e.g.

   git branch --format '%(starifcurrent) %(objectname) %(refname)'

 if the user wants to get the sha1 before the refname, and still have the
 star in front. It's a bit frustrating to have a hardcoded format that
 the user can't reproduce with the --format option, since it means you
 can't easily make a small variation on it.


 Agreed. will have a starifcurrent atom :)

 --

Wonder if there is some sort of more generic atom that would work? I
can't think of anything obvious at all though... it may be worth
having this even though it definitely seems less useful generically,
as the reason above where --format should be at least as expressive as
the builtin formatting.

Regards,
Jake
--
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 v4 2/4] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-11 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.482.gfcd5645

--
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 v4 0/4] add notes strategy configuration options

2015-08-11 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

This series of patches implements notes.merge and notes.ref.merge
options for configuring notes merge strategy such that user may avoid
typing -s. It is (probably) most useful if the user wishes to always
enforce cat_sort_uniq strategy.

This series now uses git_config_get_string_const() instead of trying to
change the git_default_config setup. In addition, the 4th patch is much
smaller and avoids a lot of heavy cruft due to this change.

I tried to re-work everything I noticed from the email list, but please
shout if I did not manage to recall your suggestion.

The new version should be much simpler to understand.

Changes since v3:
* don't use hash table, instead just call git_config_get_string_const
* notes.ref.merge must always be fully qualified, (since notes doesn't
  enforce the refs to be always in refs/notes, so we shouldn't either)
* fixed documentation to reduce confusion over which strategies are
  accepted for options
* ensure tests cover notes.ref.merge overrides notes.merge

I also tried to make sure the reviewers were all Cc'ed on every patch
not just the first one this time.

Jacob Keller (4):
  notes: document cat_sort_uniq rewriteMode
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.merge option to select default strategy
  notes: teach git-notes about notes.ref.merge option

 Documentation/config.txt  | 17 +++--
 Documentation/git-notes.txt   | 23 ++--
 builtin/notes.c   | 49 -
 notes-merge.h | 16 +
 t/t3309-notes-merge-auto-resolve.sh   | 68 +++
 t/t3310-notes-merge-manual-resolve.sh | 12 +++
 6 files changed, 157 insertions(+), 28 deletions(-)

-- 
2.5.0.482.gfcd5645

--
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 v4 3/4] notes: add notes.merge option to select default strategy

2015-08-11 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.merge to select a general strategy for all
notes merges. This enables a user to always get expected merge strategy
such as cat_sort_uniq without having to pass the -s option manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 ++
 Documentation/git-notes.txt | 14 +++-
 builtin/notes.c | 44 +++--
 notes-merge.h   | 16 --
 t/t3309-notes-merge-auto-resolve.sh | 29 
 5 files changed, 86 insertions(+), 24 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index b3df1b16491c..488c2e8eec1b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1905,6 +1905,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..9c4f8536182f 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.merge configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.merge accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 63f95fc55439..3c705f5e26ff 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -737,6 +737,24 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
*strategy)
+{
+   if (!strcmp(arg, manual))
+   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(arg, ours))
+   *strategy = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(arg, theirs))
+   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(arg, union))
+   *strategy = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(arg, cat_sort_uniq))
+   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char *prefix)
 {
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
@@ -745,7 +763,7 @@ static int merge(int argc, const char **argv, const char 
*prefix)
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
int verbosity = 0, result;
-   const char *strategy = NULL;
+   const char *strategy = NULL, *configured_strategy = NULL;
struct option options[] = {
OPT_GROUP(N_(General options

[PATCH v4 4/4] notes: teach git-notes about notes.ref.merge option

2015-08-11 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new option notes.ref.merge option which specifies the merge
strategy for merging into a given notes ref. This option enables
selection of merge strategy for particular notes refs, rather than all
notes ref merges, as user may not want cat_sort_uniq for all refs, but
only some. Note that the ref is the local reference we are merging
into, not the remote ref we merged from. The assumption is that users
will mostly want to configure separate local ref merge strategies rather
than strategies depending on which remote ref they merge from. Also,
notes.ref.merge overrides the general behavior as it is more specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  6 ++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c |  7 +--
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 488c2e8eec1b..2c283ebc309e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1912,6 +1912,12 @@ notes.merge::
STRATEGIES section of linkgit:git-notes[1] for more information
on each strategy.
 
+notes.localref.merge::
+   Which merge strategy to choose if the local ref for a notes merge
+   matches localref, overriding notes.merge. localref just be a
+   fully qualified refname. See NOTES MERGE STRATEGIES section in
+   linkgit:git-notes[1] for more information on the available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 9c4f8536182f..68fae8d22555 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -322,6 +322,12 @@ notes.merge::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.localref.merge::
+   Which strategy to choose when merging into localref. The set of
+   allowed values is the same as notes.merge. localref must be a fully
+   qualified refname. See NOTES MERGE STRATEGIES section above for more
+   information about each strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 3c705f5e26ff..2f2d7e87ef47 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -757,7 +757,7 @@ static int parse_notes_strategy(const char *arg, enum 
notes_merge_strategy *stra
 
 static int merge(int argc, const char **argv, const char *prefix)
 {
-   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
+   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT, merge_key = 
STRBUF_INIT;
unsigned char result_sha1[20];
struct notes_tree *t;
struct notes_merge_options o;
@@ -813,7 +813,10 @@ static int merge(int argc, const char **argv, const char 
*prefix)
expand_notes_ref(remote_ref);
o.remote_ref = remote_ref.buf;
 
-   git_config_get_string_const(notes.merge, configured_strategy);
+   strbuf_addf(merge_key, notes.%s.merge, o.local_ref);
+
+   if (git_config_get_string_const(merge_key.buf, configured_strategy))
+   git_config_get_string_const(notes.merge, 
configured_strategy);
 
if (configured_strategy 
parse_notes_strategy(configured_strategy, o.strategy))
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index a773b01b73db..b0bbc0a6bac2 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.refs/notes/y.merge=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs
 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -534,6 +545,34 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with union strategy overriding per-ref 
configuration = Non-conflicting 3-way merge' '
+   git -c notes.refs/notes/y.merge=theirs notes merge --strategy=union z 

+   verify_notes y union
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y

Re: [PATCH v4 4/4] notes: teach git-notes about notes.ref.merge option

2015-08-12 Thread Jacob Keller
On Wed, Aug 12, 2015 at 12:16 PM, Jacob Keller jacob.kel...@gmail.com wrote:
 Oh interesting. I did a test. If you provide a fully qualified ref not
 inside refs/notes, then it assumes you meant refs/notes/refs/foo/y
 rather than refs/foo/y

 I need to do some more digging on this to determine the exact thing going 
 on...

 Regards,
 Jake

I did some more digging. If you pass a notes ref to --refs option,
that requires all notes to be bound to refs/notes/* and does not allow
passing of arbitrary refs. However, you can set the environment
variable GIT_NOTES_REF or core.notesRef to a fully qualified
reference.

That seems very arbitrary that --ref works by expanding notes and the
environment variable and configuration option do not... [1]

I think this inconsistency is very weird, because *most* people will
not use refs/notes/* etc. This makes it so that --refs forces you to
use refs/notes/* or it will prefix it for you... ie: you can use
notes/x, refs/notes/x, x, but if you use refs/tags/x it will DWIM into
refs/notes/refs/tags/x

I think this is very confusing that --refs doesn't behave the same as
other sections... either we should enforce this on all refs or we
should fix the DWIM-ery to be consistent.

that is, we should fix DWIM-ery to be:

(1) if it starts with refs/* leave it alone

(2) if it starts with notes/*, prefix it with refs/

(3) otherwise prefix it with refs/notes/

But that way, refs/some-other-notes/ will work fine instead of
becoming something else.

We should also fix reads of environment variable etc such taht we
enforce these values always are fully qualified and begin with refs.
Otherwise, use of --refs and the environment variable don't allow the
same formats.

Regards,
Jake

[1] 8ef313e1ec3b (builtin/notes.c: Split notes ref DWIMmery into a
separate function)
--
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 v4 4/4] notes: teach git-notes about notes.ref.merge option

2015-08-12 Thread Jacob Keller
On Wed, Aug 12, 2015 at 2:57 PM, Jacob Keller jacob.kel...@gmail.com wrote:
 On Wed, Aug 12, 2015 at 2:46 PM, Johan Herland jo...@herland.net wrote:
 If we don't already refuse to merge into a ref outside refs/notes, then
 I would consider that a bug to be fixed, and not some corner use case that
 we must preserve for all future.

 After all, we do already have a test in t3308 named 'fail to merge into
 various non-notes refs', where one of the non-notes ref being tested are:

   test_must_fail git -c core.notesRef=refs/heads/master notes merge x


 This test is checking if the ref pointed at by refs/heads/master *is*
 a note. But you could create a ref outside of refs/notes which is a
 note but which isn't inside refs/notes

 I did just find that we expand remote-ref using expand_notes_ref, and
 it does *not* currently let us reference refs outside of refs/notes..
 so we can merge IN to a ref not inside refs/notes (using the
 environment variable) but we can't merge FROM
 refs/tracking/origin/notes/y for example, which means currently all
 notes we merge from have to be located into refs/notes/*

 There are some weird issues here.

 Regards,
 Jake


I spoke to soon. We have an init_notes_check function which shows
that it does refuse to merge outside of refs/notes/* It prevents all
notes operations outside of refs/notes

Since this is the case, I would prefer to modify the DWIM to be as I
suggested, and use this DWIM for the notes.

We will need to modify the DWIM so that it doesn't change refs/* even
if this will fail later, as we use expand_notes_ref for the remote_ref
of a merge, and we probably want to allow notes refs to be located
somewhere outside of notes such as refs/tracking/origin/notes or
something in the future.

So we can make our config option take only unqualified values.

Thoughts?

Regards,
Jake
--
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 v4 4/4] notes: teach git-notes about notes.ref.merge option

2015-08-12 Thread Jacob Keller
On Wed, Aug 12, 2015 at 2:46 PM, Johan Herland jo...@herland.net wrote:
 If we don't already refuse to merge into a ref outside refs/notes, then
 I would consider that a bug to be fixed, and not some corner use case that
 we must preserve for all future.

 After all, we do already have a test in t3308 named 'fail to merge into
 various non-notes refs', where one of the non-notes ref being tested are:

   test_must_fail git -c core.notesRef=refs/heads/master notes merge x


This test is checking if the ref pointed at by refs/heads/master *is*
a note. But you could create a ref outside of refs/notes which is a
note but which isn't inside refs/notes

I did just find that we expand remote-ref using expand_notes_ref, and
it does *not* currently let us reference refs outside of refs/notes..
so we can merge IN to a ref not inside refs/notes (using the
environment variable) but we can't merge FROM
refs/tracking/origin/notes/y for example, which means currently all
notes we merge from have to be located into refs/notes/*

There are some weird issues here.

Regards,
Jake
--
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 v4 4/4] notes: teach git-notes about notes.ref.merge option

2015-08-12 Thread Jacob Keller
On Wed, Aug 12, 2015 at 3:41 PM, Junio C Hamano gits...@pobox.com wrote:
 Jacob Keller jacob.kel...@gmail.com writes:

 I spoke to soon. We have an init_notes_check function which shows
 that it does refuse to merge outside of refs/notes/* It prevents all
 notes operations outside of refs/notes

 OK.  Then it is OK to limit notes.ref.mergestrategy so that ref
 refers to what comes after refs/notes/, because we will not allow
 merging to happen outside the hierarchy.

 If you are planning to break that promise, however, ref must be
 always spelled fully (i.e. with refs/notes/ prefix for those inside
 the hierarchy) to avoid ambiguity.  Otherwise it will be hard to
 interpret a configuration that does something like this (note that
 these could come from multiple places, e.g. $HOME/.gitconfig and
 $GIT_DIR/config):


Agreed. Today, we do not allow any notes operations at all that
function outside of refs/notes/*

I suggest we enforce that all configs for merge strategy must be the
unqualified notation, and not allow the variance of refs/notes/* and
such that DWIM does on the command line.

 [notes commits]
 mergestrategy = concatenate
 [notes notes/commits]
 mergestrategy = cat_sort_uniq
 [notes refs/notes/commits]
 mergestrategy = overwrite

 The three entries in the above example obviously are all meant to
 refer to the same refs/notes/commits notes tree, and the usual last
 one wins rule should apply.  But with the recent git_config_get_*()
 interface, you cannot tell which one among them was given the last,
 overriding the previous entries.

Ya, I'd like to avoid this if possible.

Regards,
Jake
--
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 v11 12/13] tag.c: implement '--format' option

2015-08-17 Thread Jacob Keller
On Mon, Aug 17, 2015 at 12:14 PM, Karthik Nayak karthik@gmail.com wrote:
 On Tue, Aug 18, 2015 at 12:34 AM, Junio C Hamano gits...@pobox.com wrote:
 Karthik Nayak karthik@gmail.com writes:

 From: Karthik Nayak karthik@gmail.com

 Implement the '--format' option provided by 'ref-filter'.
 This lets the user list tags as per desired format similar
 to the implementation in 'git for-each-ref'.

 Add tests and documentation for the same.

 Hmm, do we want --format added to tag -l and branch -l in the
 first place?  Scriptors should be using for-each-ref plumbing in
 the first place, and the point of unifying these three is to share
 filtering features among them, which would make for-each-ref able
 to express what the other two can do.  I'd hesitate to add too much
 flexibility to branch -l and tag -l Porcelains to entice people
 to script around them.


 I'll leave that decision to you, but I see it as a good feature, when perhaps
 I just want to list tags with authors. Agreed `for-each-ref` can handle this 
 too
 but I don't see why `tag -l` shouldn't.

 --
 Regards,
 Karthik Nayak

I agree with Karthik,it doesn't really hurt to add it to tag, and will
allow users who aren't familiar with for-each-ref to be able to get
the --format for some use cases. I think it would increase visibility
and use of the format option if it's available on tag and branch.

Regards,
Jake
--
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 v9 3/6] note: extract parse_notes_merge_strategy to notes-utils

2015-08-17 Thread Jacob Keller
On Mon, Aug 17, 2015 at 3:38 PM, Junio C Hamano gits...@pobox.com wrote:
 Jacob Keller jacob.e.kel...@intel.com writes:

 From: Jacob Keller jacob.kel...@gmail.com

 Combining rewrite and notes-merge functionality has been left as an
 exercise for a future contributor.

 This comment is probably unnecessary; we haven't even established if
 such a combination is desirable AFAICT in the discussion.

 The patch itself looks very straightforward and obviously good.

 Thanks.


Feel free to fix that up if you want. Probably easier than me
respinning the whole series.

Regards,
Jake
--
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 v11 00/13] port tag.c to use ref-filter APIs

2015-08-16 Thread Jacob Keller
On Sat, Aug 15, 2015 at 11:00 AM, Karthik Nayak karthik@gmail.com wrote:


  align::
 -   Implement an `align` atom which left-, middle-, or
 -   right-aligns the content between %(align:..)  and
 -   %(end). Followed by `:position,width`, where the
 +   left-, middle-, or right-align the content between %(align:..)
 +   and %(end). Followed by `:position,width`, where the


Everywhere else in the code seems to now put position second now, but
the documentation here doesn't say this is allowed or required.

Regards,
Jake

 `position` is either left, right or middle and `width` is
 the total length of the content with alignment. If the
 contents length is more than the width then no alignment is
 -   performed. Currently nested alignment is not supported.
 +   performed.

--
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: Moved code detection with `git apply` a la `git blame -C -C`

2015-08-19 Thread Jacob Keller
Maybe something along the lines of a git-subtree merge. I am not sure
how to do that exactly, and I am not sure that it would be worth the
trouble to setup for a small case...

On Tue, Aug 18, 2015 at 1:11 PM, Anish Tondwalkar
tondwal...@virginia.edu wrote:
 I stashed some changes, then refactored my code to move the function
 they're in into a new file. Now, I want to apply it to the new file. I
 know git can figure out this relationship between the files, because
 `git blame -C -C` can find it, but is there a more idiomatic way to
 apply this diff than to have git spit out a diff, and edit it
 manually?

 --
 Anish
 --
 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
--
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 v8 4/8] notes: allow use of the rewrite terminology for merge strategies

2015-08-17 Thread Jacob Keller
Hi,

On Mon, Aug 17, 2015 at 5:54 AM, Johan Herland jo...@herland.net wrote:
 On Mon, Aug 17, 2015 at 10:46 AM, Jacob Keller jacob.e.kel...@intel.com 
 wrote:
 From: Jacob Keller jacob.kel...@gmail.com

 notes-merge.c already re-uses the same functions for the automatic merge
 strategies used by the rewrite functionality. Teach the -s/--strategy
 option how to interpret the equivalent rewrite terminology for
 consistency.

 I'm somewhat negative to this patch. IMHO, adding the rewrite modes as
 merge strategy synonyms adds no benefit - only potential confusion -
 to the existing merge strategies. Words that have a sensible meaning
 in the context of rewrite, do not necessarily have the same sensible
 meaning in the context of merge (and vice versa). I'd rather have the
 rewrite code map ignore/overwrite/concatenate to ours/theirs/union,
 without teaching the notes-merge code about these words. Or maybe even
 drop this patch (and the next?) entirely, and let the future author
 (who implements notes rewrite in terms of notes merge) decide how to
 deal with this? By committing to these synonyms now, you might
 actually be making things harder for the future author: once the
 synonyms are part of the user-visible and documented interface, they
 cannot easily be removed/changed again.

 ...Johan


I am ok dropping these, I really only added them after Junio brought
it up. I think that documenting union/concatenate is fine, but I think
that ours/theirs is very confusing. However, I think you're right that
a future author can deal with this when working on rewrite - merge. I
don't think we need to do this now.

I'll drop these patches, but I will leave the
parse_notes_merge_strategy in it's location here.

We could document concatenate as a synonym of union but I don't think
that is a big deal.

Regards,
Jake
--
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 v8 8/8] notes: teach git-notes about notes.ref.mergeStrategy option

2015-08-17 Thread Jacob Keller
Hi,

On Mon, Aug 17, 2015 at 6:21 AM, Johan Herland jo...@herland.net wrote:
 Allow me to suggest a different wording, somewhat inspired by the
 branch.name.* documentation...

 On Mon, Aug 17, 2015 at 10:46 AM, Jacob Keller jacob.e.kel...@intel.com 
 wrote:
 From: Jacob Keller jacob.kel...@gmail.com

 Add new option notes.ref.mergeStrategy option which specifies the merge
 strategy for merging into a given notes ref.

 Add new notes.name.mergeStrategy config, which specifies the merge
 strategy for notes merges into refs/notes/name.

 This option enables
 selection of merge strategy for particular notes refs, rather than all
 notes ref merges, as user may not want cat_sort_uniq for all refs, but
 only some. Note that the ref is the local reference we are merging

 s/ref/name/

 into, not the remote ref we merged from. The assumption is that users
 will mostly want to configure separate local ref merge strategies rather
 than strategies depending on which remote ref they merge from. Also,
 notes.ref.merge overrides the general behavior as it is more specific.

 same here

Agreed, will fix in the next respin.

Regards,
Jake
--
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 v9 1/6] notes: document cat_sort_uniq rewriteMode

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 75ec02e8e90a..de67ad1fdedf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1947,8 +1947,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..00c84be33ca9 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
@@ -368,7 +369,7 @@ does not match any refs is silently ignored.
 'GIT_NOTES_REWRITE_MODE'::
When copying notes during a rewrite, what to do if the target
commit already has a note.
-   Must be one of `overwrite`, `concatenate`, and `ignore`.
+   Must be one of `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
This overrides the `core.rewriteMode` setting.
 
 'GIT_NOTES_REWRITE_REF'::
-- 
2.5.0.280.g4aaba03

--
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 v9 0/6] implement notes.mergeStrategy

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

This series implements mergeStrategy configuration options which take
the same value as --strategy. This series does not change the allowed
refs to merge from or to. There is a known limitation that you cannot
merge from refs outside of refs/notes (precluding the use of such refs
as refs/tracking/origin/notes/ and so forth).

- Changes since v8 -
* drop the rewrite and merge option patches, since rewrite names are not
  really equivalent to merge names (ours/theirs is flipped)
* change docs on notes.name.mergeStrategy

This series does *not* deal with:
* changes to which refs can be merged, init_notes_check already prevents
  git-notes-merge into refs outside of refs/notes*
* use of rewrite names for merge strategies, including even concatenate

Hopefully a future contributor will have some time to look at making
re-write just use the notes merge instead of doing re-write by hand.
This would also potentially allow for manual merges. This series does
not begin down this road, since we do not want to limit what this future
author is allowed to do with regards to rewrite and merge strategy
names.

I think finally this series is good. It may be worth adding some
test_expect_failures around merging from refs/tracking/origin/notes if
we intend to ever allow notes merges from these sources.

Jacob Keller (6):
  notes: document cat_sort_uniq rewriteMode
  notes: extract enum notes_merge_strategy to notes-utils.h
  note: extract parse_notes_merge_strategy to notes-utils
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.mergeStrategy option to select default strategy
  notes: teach git-notes about notes.name.mergeStrategy option

 Documentation/config.txt  | 16 ++-
 Documentation/git-notes.txt   | 25 +--
 builtin/notes.c   | 43 +--
 notes-merge.h | 10 ++---
 notes-utils.c | 18 
 notes-utils.h |  9 
 t/t3309-notes-merge-auto-resolve.sh   | 79 +++
 t/t3310-notes-merge-manual-resolve.sh | 12 ++
 8 files changed, 187 insertions(+), 25 deletions(-)

-- 
2.5.0.280.g4aaba03

--
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 v9 5/6] notes: add notes.mergeStrategy option to select default strategy

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.mergeStrategy to select a general strategy
for all notes merges. This enables a user to always get expected merge
strategy such as cat_sort_uniq without having to pass the -s option
manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  6 ++
 Documentation/git-notes.txt | 14 -
 builtin/notes.c | 19 --
 t/t3309-notes-merge-auto-resolve.sh | 40 +
 4 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..2ff3ed64a4d4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1919,6 +1919,12 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.mergeStrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts.  Must be one of `manual`, `ours`, `theirs`, `union`, or
+   `cat_sort_uniq`.  Defaults to `manual`.  See NOTES MERGE STRATEGIES
+   section of linkgit:git-notes[1] for more information on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 00c84be33ca9..71453d4a700f 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.mergeStrategy configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.mergeStrategy accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.mergeStrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts.  Must be one of `manual`, `ours`, `theirs`, `union`, or
+   `cat_sort_uniq`.  Defaults to `manual`.  See NOTES MERGE STRATEGIES
+   section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 0e7aba98f4d7..91f7a6547b0f 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -738,6 +738,19 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int git_config_get_notes_strategy(const char *key,
+enum notes_merge_strategy *strategy)
+{
+   const char *value;
+
+   if (git_config_get_string_const(key, value))
+   return 1;
+   if (parse_notes_merge_strategy(value, strategy))
+   git_die_config(key, unknown notes merge strategy %s, value);
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char *prefix)
 {
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
@@ -796,15 +809,17 @@ static int merge(int argc, const char **argv, const char 
*prefix)
expand_notes_ref(remote_ref);
o.remote_ref = remote_ref.buf;
 
+   t = init_notes_check(merge);
+
if (strategy) {
if (parse_notes_merge_strategy(strategy, o.strategy)) {
error(Unknown -s/--strategy: %s, strategy);
usage_with_options(git_notes_merge_usage, options);
}
+   } else {
+   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
}
 
-   t = init_notes_check(merge);
-
strbuf_addf(msg, notes: Merged notes

[PATCH v9 6/6] notes: teach git-notes about notes.name.mergeStrategy option

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach notes about a new notes.name.mergeStrategy option for
configuring the notes merge strategy when merging into
refs/notes/name. This option allows for the selection of merge
strategy for particular notes refs, rather than all notes ref merges, as
user may not want cat_sort_uniq for all refs, but only some. Note that
the name is the local reference we are merging into, not the remote
ref we merged from. The assumption is that users will mostly want to
configure separate local ref merge strategies rather than strategies
depending on which remote ref they merge from.

notes.name.mergeStrategy overrides the general behavior as it is more
specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  6 ++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c | 14 -
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2ff3ed64a4d4..f60a9101df31 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1925,6 +1925,12 @@ notes.mergeStrategy::
`cat_sort_uniq`.  Defaults to `manual`.  See NOTES MERGE STRATEGIES
section of linkgit:git-notes[1] for more information on each strategy.
 
+notes.name.mergeStrategy::
+   Which merge strategy to choose when doing a notes merge into
+   refs/notes/name.  This overrides the more general
+   notes.mergeStrategy.  See the NOTES MERGE STRATEGIES section in
+   linkgit:git-notes[1] for more information on the available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 71453d4a700f..a9a916f360ec 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -322,6 +322,12 @@ notes.mergeStrategy::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.name.mergeStrategy::
+   Which merge strategy to choose when doing a notes merge into
+   refs/notes/name.  This overrides the more general
+   notes.mergeStrategy.  See the NOTES MERGE STRATEGIES section above
+   for more information on each available strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 91f7a6547b0f..3608c6478528 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -817,7 +817,19 @@ static int merge(int argc, const char **argv, const char 
*prefix)
usage_with_options(git_notes_merge_usage, options);
}
} else {
-   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
+   struct strbuf merge_key = STRBUF_INIT;
+   const char *short_ref = NULL;
+
+   if (!skip_prefix(o.local_ref, refs/notes/, short_ref))
+   die(BUG: local ref %s is outside of refs/notes/,
+   o.local_ref);
+
+   strbuf_addf(merge_key, notes.%s.mergeStrategy, short_ref);
+
+   if (git_config_get_notes_strategy(merge_key.buf, o.strategy))
+   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
+
+   strbuf_release(merge_key);
}
 
strbuf_addf(msg, notes: Merged notes from %s into %s,
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 1cd047f8d75f..14c2adf970d7 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.y.mergeStrategy=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs
 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -534,6 +545,34 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with union strategy overriding per-ref 
configuration = Non-conflicting 3-way merge' '
+   git -c notes.y.mergeStrategy=theirs notes merge --strategy=union z 
+   verify_notes y union
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state

[PATCH v9 3/6] note: extract parse_notes_merge_strategy to notes-utils

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Combining rewrite and notes-merge functionality has been left as an
exercise for a future contributor.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 builtin/notes.c | 12 +---
 notes-utils.c   | 18 ++
 notes-utils.h   |  1 +
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 042348082709..0e7aba98f4d7 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -797,17 +797,7 @@ static int merge(int argc, const char **argv, const char 
*prefix)
o.remote_ref = remote_ref.buf;
 
if (strategy) {
-   if (!strcmp(strategy, manual))
-   o.strategy = NOTES_MERGE_RESOLVE_MANUAL;
-   else if (!strcmp(strategy, ours))
-   o.strategy = NOTES_MERGE_RESOLVE_OURS;
-   else if (!strcmp(strategy, theirs))
-   o.strategy = NOTES_MERGE_RESOLVE_THEIRS;
-   else if (!strcmp(strategy, union))
-   o.strategy = NOTES_MERGE_RESOLVE_UNION;
-   else if (!strcmp(strategy, cat_sort_uniq))
-   o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
-   else {
+   if (parse_notes_merge_strategy(strategy, o.strategy)) {
error(Unknown -s/--strategy: %s, strategy);
usage_with_options(git_notes_merge_usage, options);
}
diff --git a/notes-utils.c b/notes-utils.c
index ccbf0737a34e..299e34bccc58 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -54,6 +54,24 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_release(buf);
 }
 
+int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s)
+{
+   if (!strcmp(v, manual))
+   *s = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(v, ours))
+   *s = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(v, theirs))
+   *s = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(v, union))
+   *s = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(v, cat_sort_uniq))
+   *s = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
 static combine_notes_fn parse_combine_notes_fn(const char *v)
 {
if (!strcasecmp(v, overwrite))
diff --git a/notes-utils.h b/notes-utils.h
index db5811e3f718..fa538e1d9502 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -37,6 +37,7 @@ struct notes_rewrite_cfg {
int mode_from_env;
 };
 
+int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
 struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
  const unsigned char *from_obj, const unsigned char 
*to_obj);
-- 
2.5.0.280.g4aaba03

--
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 v9 2/6] notes: extract enum notes_merge_strategy to notes-utils.h

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

A future patch will extract parsing of the --strategy string into a
helper function in notes.c and will require the enumeration definition.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 notes-merge.h | 10 +++---
 notes-utils.h |  8 
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/notes-merge.h b/notes-merge.h
index 1d01f6aacf54..0d890563b5f4 100644
--- a/notes-merge.h
+++ b/notes-merge.h
@@ -1,6 +1,8 @@
 #ifndef NOTES_MERGE_H
 #define NOTES_MERGE_H
 
+#include notes-utils.h
+
 #define NOTES_MERGE_WORKTREE NOTES_MERGE_WORKTREE
 
 enum notes_merge_verbosity {
@@ -13,13 +15,7 @@ struct notes_merge_options {
const char *remote_ref;
struct strbuf commit_msg;
int verbosity;
-   enum {
-   NOTES_MERGE_RESOLVE_MANUAL = 0,
-   NOTES_MERGE_RESOLVE_OURS,
-   NOTES_MERGE_RESOLVE_THEIRS,
-   NOTES_MERGE_RESOLVE_UNION,
-   NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ
-   } strategy;
+   enum notes_merge_strategy strategy;
unsigned has_worktree:1;
 };
 
diff --git a/notes-utils.h b/notes-utils.h
index 890ddb33e13a..db5811e3f718 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -19,6 +19,14 @@ void create_notes_commit(struct notes_tree *t, struct 
commit_list *parents,
 
 void commit_notes(struct notes_tree *t, const char *msg);
 
+enum notes_merge_strategy {
+   NOTES_MERGE_RESOLVE_MANUAL = 0,
+   NOTES_MERGE_RESOLVE_OURS,
+   NOTES_MERGE_RESOLVE_THEIRS,
+   NOTES_MERGE_RESOLVE_UNION,
+   NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ
+};
+
 struct notes_rewrite_cfg {
struct notes_tree **trees;
const char *cmd;
-- 
2.5.0.280.g4aaba03

--
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 v9 4/6] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.280.g4aaba03

--
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 v8 2/8] notes: extract enum notes_merge_strategy to notes-utils.h

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

A future patch will extract parsing of the --strategy string into a
helper function in notes.c and will require the enumeration definition.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 notes-merge.h | 10 +++---
 notes-utils.h |  8 
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/notes-merge.h b/notes-merge.h
index 1d01f6aacf54..0d890563b5f4 100644
--- a/notes-merge.h
+++ b/notes-merge.h
@@ -1,6 +1,8 @@
 #ifndef NOTES_MERGE_H
 #define NOTES_MERGE_H
 
+#include notes-utils.h
+
 #define NOTES_MERGE_WORKTREE NOTES_MERGE_WORKTREE
 
 enum notes_merge_verbosity {
@@ -13,13 +15,7 @@ struct notes_merge_options {
const char *remote_ref;
struct strbuf commit_msg;
int verbosity;
-   enum {
-   NOTES_MERGE_RESOLVE_MANUAL = 0,
-   NOTES_MERGE_RESOLVE_OURS,
-   NOTES_MERGE_RESOLVE_THEIRS,
-   NOTES_MERGE_RESOLVE_UNION,
-   NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ
-   } strategy;
+   enum notes_merge_strategy strategy;
unsigned has_worktree:1;
 };
 
diff --git a/notes-utils.h b/notes-utils.h
index 890ddb33e13a..db5811e3f718 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -19,6 +19,14 @@ void create_notes_commit(struct notes_tree *t, struct 
commit_list *parents,
 
 void commit_notes(struct notes_tree *t, const char *msg);
 
+enum notes_merge_strategy {
+   NOTES_MERGE_RESOLVE_MANUAL = 0,
+   NOTES_MERGE_RESOLVE_OURS,
+   NOTES_MERGE_RESOLVE_THEIRS,
+   NOTES_MERGE_RESOLVE_UNION,
+   NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ
+};
+
 struct notes_rewrite_cfg {
struct notes_tree **trees;
const char *cmd;
-- 
2.5.0.280.g4aaba03

--
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 v8 4/8] notes: allow use of the rewrite terminology for merge strategies

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

notes-merge.c already re-uses the same functions for the automatic merge
strategies used by the rewrite functionality. Teach the -s/--strategy
option how to interpret the equivalent rewrite terminology for
consistency.

Add tests for the new synonyms.

Teaching rewrite how to understand merge terminology is left for a
following patch.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/git-notes.txt |  6 +
 notes-utils.c   |  6 +
 t/t3309-notes-merge-auto-resolve.sh | 45 +
 3 files changed, 57 insertions(+)

diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 00c84be33ca9..5028e9355de5 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -250,13 +250,19 @@ When done, the user can either finalize the merge with
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
+ignore is an alternative spelling for ours.
+
 theirs automatically resolves notes conflicts in favor of the remote
 version (i.e. the given notes ref being merged into the current notes
 ref).
 
+overwrite is an alternative spelling for theirs.
+
 union automatically resolves notes conflicts by concatenating the
 local and remote versions.
 
+concatenate is an alternative spelling for union.
+
 cat_sort_uniq is similar to union, but in addition to concatenating
 the local and remote versions, this strategy also sorts the resulting
 lines, and removes duplicate lines from the result. This is equivalent
diff --git a/notes-utils.c b/notes-utils.c
index 299e34bccc58..656b0ea152e2 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -60,10 +60,16 @@ int parse_notes_merge_strategy(const char *v, enum 
notes_merge_strategy *s)
*s = NOTES_MERGE_RESOLVE_MANUAL;
else if (!strcmp(v, ours))
*s = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(v, ignore))
+   *s = NOTES_MERGE_RESOLVE_OURS;
else if (!strcmp(v, theirs))
*s = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(v, overwrite))
+   *s = NOTES_MERGE_RESOLVE_THEIRS;
else if (!strcmp(v, union))
*s = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(v, concatenate))
+   *s = NOTES_MERGE_RESOLVE_UNION;
else if (!strcmp(v, cat_sort_uniq))
*s = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
else
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 461fd84755d7..909900672446 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -365,6 +365,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ignore strategy = Non-conflicting 
3-way merge' '
+   git notes merge --strategy=ignore z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs
 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -432,6 +443,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with overwrite strategy = 
Non-conflicting 3-way merge' '
+   git notes merge --strategy=overwrite z 
+   verify_notes y theirs
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_union
 7c4e546efd0fe939f876beb262ece02797880b54 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -505,6 +527,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with concatenate strategy = 
Non-conflicting 3-way merge' '
+   git notes merge --strategy=concatenate z 
+   verify_notes y union
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_union2
 d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -579,6 +612,18 @@ test_expect_success 'reset to pre-merge state (z)' '
verify_notes z z
 '
 
+test_expect_success 'merge y into z with concatenate strategy = 
Non-conflicting 3-way merge' '
+   git config core.notesRef refs/notes/z 
+   git notes merge --strategy=concatenate y 
+   verify_notes z union2
+'
+
+test_expect_success 'reset to pre-merge state (z)' '
+   git update-ref refs/notes/z refs/notes/z^1 
+   # Verify pre-merge state

[PATCH v8 7/8] notes: add notes.mergeStrategy option to select default strategy

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.mergeStrategy to select a general strategy
for all notes merges. This enables a user to always get expected merge
strategy such as cat_sort_uniq without having to pass the -s option
manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +
 Documentation/git-notes.txt | 14 +-
 builtin/notes.c | 19 --
 t/t3309-notes-merge-auto-resolve.sh | 51 +
 4 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4daa804b1eab..56e20446f587 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1919,6 +1919,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.mergeStrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 678dadfdf3c3..66b5017939c6 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.mergeStrategy configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.mergeStrategy accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -316,6 +320,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.mergeStrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 0e7aba98f4d7..91f7a6547b0f 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -738,6 +738,19 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int git_config_get_notes_strategy(const char *key,
+enum notes_merge_strategy *strategy)
+{
+   const char *value;
+
+   if (git_config_get_string_const(key, value))
+   return 1;
+   if (parse_notes_merge_strategy(value, strategy))
+   git_die_config(key, unknown notes merge strategy %s, value);
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char *prefix)
 {
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
@@ -796,15 +809,17 @@ static int merge(int argc, const char **argv, const char 
*prefix)
expand_notes_ref(remote_ref);
o.remote_ref = remote_ref.buf;
 
+   t = init_notes_check(merge);
+
if (strategy) {
if (parse_notes_merge_strategy(strategy, o.strategy)) {
error(Unknown -s/--strategy: %s, strategy);
usage_with_options(git_notes_merge_usage, options);
}
+   } else {
+   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
}
 
-   t = init_notes_check(merge);
-
strbuf_addf(msg, notes: Merged notes from

[PATCH v8 8/8] notes: teach git-notes about notes.ref.mergeStrategy option

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new option notes.ref.mergeStrategy option which specifies the merge
strategy for merging into a given notes ref. This option enables
selection of merge strategy for particular notes refs, rather than all
notes ref merges, as user may not want cat_sort_uniq for all refs, but
only some. Note that the ref is the local reference we are merging
into, not the remote ref we merged from. The assumption is that users
will mostly want to configure separate local ref merge strategies rather
than strategies depending on which remote ref they merge from. Also,
notes.ref.merge overrides the general behavior as it is more specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c | 14 -
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 56e20446f587..a48c111d3ce0 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1926,6 +1926,13 @@ notes.mergeStrategy::
STRATEGIES section of linkgit:git-notes[1] for more information
on each strategy.
 
+notes.localref.mergeStrategy::
+   Which merge strategy to choose if the local ref for a notes merge
+   matches localref, overriding notes.mergeStrategy. localref must
+   be the short name of a ref under refs/notes/. See the NOTES MERGE
+   STRATEGIES section in linkgit:git-notes[1] for more information on the
+   available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 66b5017939c6..0167bc6e347b 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -328,6 +328,12 @@ notes.mergeStrategy::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.localref.mergeStrategy::
+   Which strategy to choose when merging into localref. The set of
+   allowed values is the same as notes.mergeStrategy. localref must be
+   the short name of a ref under refs/notes/. See the NOTES MERGE 
STRATEGIES
+   section above for more information about each strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 91f7a6547b0f..3608c6478528 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -817,7 +817,19 @@ static int merge(int argc, const char **argv, const char 
*prefix)
usage_with_options(git_notes_merge_usage, options);
}
} else {
-   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
+   struct strbuf merge_key = STRBUF_INIT;
+   const char *short_ref = NULL;
+
+   if (!skip_prefix(o.local_ref, refs/notes/, short_ref))
+   die(BUG: local ref %s is outside of refs/notes/,
+   o.local_ref);
+
+   strbuf_addf(merge_key, notes.%s.mergeStrategy, short_ref);
+
+   if (git_config_get_notes_strategy(merge_key.buf, o.strategy))
+   git_config_get_notes_strategy(notes.mergeStrategy, 
o.strategy);
+
+   strbuf_release(merge_key);
}
 
strbuf_addf(msg, notes: Merged notes from %s into %s,
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 1bd71d947e60..44898ffba9fb 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -405,6 +405,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.y.mergeStrategy=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs
 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
@@ -589,6 +600,34 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with union strategy overriding per-ref 
configuration = Non-conflicting 3-way merge' '
+   git -c notes.y.mergeStrategy=theirs notes merge --strategy=union z 
+   verify_notes y union
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state

[PATCH v8 6/8] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.280.g4aaba03

--
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 v8 3/8] note: extract parse_notes_merge_strategy to notes-utils

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Allow future code to re-use the parsing functionality.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 builtin/notes.c | 12 +---
 notes-utils.c   | 18 ++
 notes-utils.h   |  1 +
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 042348082709..0e7aba98f4d7 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -797,17 +797,7 @@ static int merge(int argc, const char **argv, const char 
*prefix)
o.remote_ref = remote_ref.buf;
 
if (strategy) {
-   if (!strcmp(strategy, manual))
-   o.strategy = NOTES_MERGE_RESOLVE_MANUAL;
-   else if (!strcmp(strategy, ours))
-   o.strategy = NOTES_MERGE_RESOLVE_OURS;
-   else if (!strcmp(strategy, theirs))
-   o.strategy = NOTES_MERGE_RESOLVE_THEIRS;
-   else if (!strcmp(strategy, union))
-   o.strategy = NOTES_MERGE_RESOLVE_UNION;
-   else if (!strcmp(strategy, cat_sort_uniq))
-   o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
-   else {
+   if (parse_notes_merge_strategy(strategy, o.strategy)) {
error(Unknown -s/--strategy: %s, strategy);
usage_with_options(git_notes_merge_usage, options);
}
diff --git a/notes-utils.c b/notes-utils.c
index ccbf0737a34e..299e34bccc58 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -54,6 +54,24 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_release(buf);
 }
 
+int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s)
+{
+   if (!strcmp(v, manual))
+   *s = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(v, ours))
+   *s = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(v, theirs))
+   *s = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(v, union))
+   *s = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(v, cat_sort_uniq))
+   *s = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
 static combine_notes_fn parse_combine_notes_fn(const char *v)
 {
if (!strcasecmp(v, overwrite))
diff --git a/notes-utils.h b/notes-utils.h
index db5811e3f718..fa538e1d9502 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -37,6 +37,7 @@ struct notes_rewrite_cfg {
int mode_from_env;
 };
 
+int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
 struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
  const unsigned char *from_obj, const unsigned char 
*to_obj);
-- 
2.5.0.280.g4aaba03

--
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 v8 0/8] implement notes.mergeStrategy option

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

- Changes since v7 -
* add patches to make rewrite and merge take same options
* camel case mergeStrategy
* move init_notes_check above reading git-config in merge()
  This is necessary as it ensures refs are inside refs/notes/*

It should be noted that git-notes already blocks all operations outside
of refs/notes, including merging from refs outside of refs/notes. This
series leaves the ability to merge from non-refs/notes refs as an
enhancement for a future author. However, git-notes also (correctly)
prevents merge (and any other option) into non refs/notes/* refs. You
may notice a BUG: print statement after skip_prefix, this is only as a
failsafe and is marked BUG since it should never be true.

Hopefully everything looks good now. I chose to add patches which
combine rewrite and notes-merge options to take the same parameters.
This does cause some weirdness since ours and theirs is swapped much
like in a rebase merge conflict.

If we dont' like this, I am ok with re-writing this to not document the
synonyms. However, I think that a good future direction would be to make
rewrite use the exact same flow as merge, and support the `manual` mode
as well using the full notes-merge harness.

Jacob Keller (8):
  notes: document cat_sort_uniq rewriteMode
  notes: extract enum notes_merge_strategy to notes-utils.h
  note: extract parse_notes_merge_strategy to notes-utils
  notes: allow use of the rewrite terminology for merge strategies
  notes: implement parse_combine_rewrite_fn using
parse_notes_merge_strategy
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.mergeStrategy option to select default strategy
  notes: teach git-notes about notes.ref.mergeStrategy option

 Documentation/config.txt  |  22 +-
 Documentation/git-notes.txt   |  43 +--
 builtin/notes.c   |  43 +++
 notes-merge.h |  10 +--
 notes-utils.c |  50 ++---
 notes-utils.h |   9 +++
 t/t3301-notes.sh  |  55 ++
 t/t3309-notes-merge-auto-resolve.sh   | 135 ++
 t/t3310-notes-merge-manual-resolve.sh |  12 +++
 9 files changed, 341 insertions(+), 38 deletions(-)

-- 
2.5.0.280.g4aaba03

--
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 v8 5/8] notes: implement parse_combine_rewrite_fn using parse_notes_merge_strategy

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach the rewrite combine notes to use the same names as git-notes
merge. This will support all current names plus a few new synonyms.

Update documentation to point to NOTES MERGE STRATEGIES to explain the
various rewrite options available.

Implementing rewrite functionality completely in terms of merging is
left as an exercise for a future contributor.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  8 ---
 Documentation/git-notes.txt | 18 ++-
 notes-utils.c   | 26 +
 t/t3301-notes.sh| 55 +
 4 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..4daa804b1eab 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1946,9 +1946,11 @@ notes.rewrite.command::
 notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
-   the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
-   Defaults to `concatenate`.
+   the target commit already has a note.  With the exception of `manual`,
+   any automatic merge strategy may be chosen.  Beware that in the
+   re-write context the typical notion of `ours` and `theirs` is reversed.
+   See the NOTES MERGE STRATEGIES section above for information on each
+   of the available strategies.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 5028e9355de5..678dadfdf3c3 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -336,9 +336,11 @@ environment variable.
 
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
-   commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
-   `concatenate`.
+   commit already has a note.  With the exception of `manual`, any
+   automatic merge strategy may be chosen.  Beware that in the re-write
+   context the typical notion of `ours` and `theirs` is reversed .  See
+   the NOTES MERGE STRATEGIES section above for information on each of
+   the available strategies.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
@@ -374,9 +376,13 @@ does not match any refs is silently ignored.
 
 'GIT_NOTES_REWRITE_MODE'::
When copying notes during a rewrite, what to do if the target
-   commit already has a note.
-   Must be one of `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
-   This overrides the `core.rewriteMode` setting.
+   commit already has a note.  With the exception of `manual`, any
+   automatic merge strategy may be chosen.  Beware that in the re-write
+   context the typical notion of `ours` and `theirs` is reversed .  See
+   the NOTES MERGE STRATEGIES section above for information on each of
+   the available strategies.
++
+Overrides the notes.rewriteMode configuration option.
 
 'GIT_NOTES_REWRITE_REF'::
When rewriting commits, which notes to copy from the original
diff --git a/notes-utils.c b/notes-utils.c
index 656b0ea152e2..8d4cc8909bcf 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -80,16 +80,24 @@ int parse_notes_merge_strategy(const char *v, enum 
notes_merge_strategy *s)
 
 static combine_notes_fn parse_combine_notes_fn(const char *v)
 {
-   if (!strcasecmp(v, overwrite))
-   return combine_notes_overwrite;
-   else if (!strcasecmp(v, ignore))
-   return combine_notes_ignore;
-   else if (!strcasecmp(v, concatenate))
-   return combine_notes_concatenate;
-   else if (!strcasecmp(v, cat_sort_uniq))
-   return combine_notes_cat_sort_uniq;
-   else
+   enum notes_merge_strategy s;
+
+   if (parse_notes_merge_strategy(v, s))
return NULL;
+
+   switch (s) {
+   case NOTES_MERGE_RESOLVE_OURS:
+   return combine_notes_ignore;
+   case NOTES_MERGE_RESOLVE_THEIRS:
+   return combine_notes_overwrite;
+   case NOTES_MERGE_RESOLVE_UNION:
+   return combine_notes_concatenate;
+   case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
+   return combine_notes_cat_sort_uniq;
+   case NOTES_MERGE_RESOLVE_MANUAL:
+   default:
+   return NULL;
+   }
 }
 
 static int notes_rewrite_config(const char *k, const char *v, void *cb)
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 8cffd35fb03d..eb1b5824a422 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -997,6 +997,26 @@ test_expect_success 'git notes copy --for-rewrite 
(overwrite

[PATCH v8 1/8] notes: document cat_sort_uniq rewriteMode

2015-08-17 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 75ec02e8e90a..de67ad1fdedf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1947,8 +1947,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..00c84be33ca9 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
@@ -368,7 +369,7 @@ does not match any refs is silently ignored.
 'GIT_NOTES_REWRITE_MODE'::
When copying notes during a rewrite, what to do if the target
commit already has a note.
-   Must be one of `overwrite`, `concatenate`, and `ignore`.
+   Must be one of `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
This overrides the `core.rewriteMode` setting.
 
 'GIT_NOTES_REWRITE_REF'::
-- 
2.5.0.280.g4aaba03

--
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: [RFC/PATCH 10/11] branch.c: use 'ref-filter' APIs

2015-07-28 Thread Jacob Keller
On Tue, Jul 28, 2015 at 12:11 AM, Karthik Nayak karthik@gmail.com wrote:
 Make 'branch.c' use 'ref-filter' APIs for iterating through refs
 sorting. This removes most of the code used in 'branch.c' replacing it
 with calls to the 'ref-filter' library.

 Make 'tag.c' use the 'filter_refs()' function provided by 'ref-filter'
 to filter out tags based on the options set.


This patch doesn't do anything to tag.c, so you should update the
commit message to remove this or replace it with s/tag/branch if it
was intended to be about branch.c?

Regards,
Jake
--
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: [RFC/PATCH 04/11] ref-filter: add 'ifexists' atom

2015-07-28 Thread Jacob Keller
On Mon, Jul 27, 2015 at 11:56 PM, Karthik Nayak karthik@gmail.com wrote:
 The 'ifexists' atom allows us to print a required format if the
 preceeding atom has a value. If the preceeding atom has no value then

Don't you mean following atom here? since you do document it as the
next atom below you should fix the commit message as well to match.
In any respect, this is a useful formatting atom :)

%(ifexists:[%s])%(atom) where the contents of atom will be placed into %s?

 the format given is not printed. e.g. to print [refname] we can
 now use the format %(ifexists:[%s])%(refname).

 Add documentation and test for the same.

 Mentored-by: Christian Couder christian.cou...@gmail.com
 Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
 Signed-off-by: Karthik Nayak karthik@gmail.com
 ---
  Documentation/git-for-each-ref.txt |  8 
  ref-filter.c   | 37 ++---
  ref-filter.h   |  5 +++--
  t/t6302-for-each-ref-filter.sh | 21 +
  4 files changed, 66 insertions(+), 5 deletions(-)

 diff --git a/Documentation/git-for-each-ref.txt 
 b/Documentation/git-for-each-ref.txt
 index 9dc02aa..4424020 100644
 --- a/Documentation/git-for-each-ref.txt
 +++ b/Documentation/git-for-each-ref.txt
 @@ -138,6 +138,14 @@ colornext::
 `:colorname`.  Not compatible with `padright` and resets any
 previous `color`, if set.

 +ifexists::
 +   Print required string only if the next atom specified in the
 +   '--format' option exists.
 +   e.g. --format=%(ifexists:[%s])%(symref) prints the symref
 +   like [symref] only if the ref has a symref.  This was
 +   incorporated to simulate the output of 'git branch -vv', where
 +   we need to display the upstream branch in square brackets.
 +

I suggest documenting that the atom will be placed into the contents
of ifexists via the %s indicator, as you do show an example but don't
explicitely say %s is the formatting character.

  In addition to the above, for commit and tag objects, the header
  field names (`tree`, `parent`, `object`, `type`, and `tag`) can
  be used to specify the value in the header field.
 diff --git a/ref-filter.c b/ref-filter.c
 index 3f40144..ff5a16b 100644
 --- a/ref-filter.c
 +++ b/ref-filter.c
 @@ -58,6 +58,7 @@ static struct {
 { color },
 { padright },
 { colornext },
 +   { ifexists },
  };

  /*
 @@ -722,6 +723,13 @@ static void populate_value(struct ref_array_item *ref)
 v-modifier_atom = 1;
 v-color_next = 1;
 continue;
 +   } else if (starts_with(name, ifexists:)) {
 +   skip_prefix(name, ifexists:, v-s);
 +   if (!*v-s)
 +   die(_(no string given with 'ifexists:'));
 +   v-modifier_atom = 1;
 +   v-ifexists = 1;
 +   continue;
 } else
 continue;

 @@ -1315,11 +1323,32 @@ static void apply_formatting_state(struct 
 ref_formatting_state *state,
  {
 if (state-color_next  state-pad_to_right)
 die(_(cannot use `colornext` and `padright` together));
 -   if (state-color_next) {
 +   if (state-pad_to_right  state-ifexists)
 +   die(_(cannot use 'align' and 'ifexists' together));
 +   if (state-color_next  !state-ifexists) {
 strbuf_addf(value, %s%s%s, state-color_next, v-s, 
 GIT_COLOR_RESET);
 return;
 -   }
 -   else if (state-pad_to_right) {
 +   } else if (state-ifexists) {
 +   const char *sp = state-ifexists;
 +
 +   while (*sp) {
 +   if (*sp != '%') {
 +   strbuf_addch(value, *sp++);
 +   continue;
 +   } else if (sp[1] == '%') {
 +   strbuf_addch(value, *sp++);
 +   continue;
 +   } else if (sp[1] == 's') {
 +   if (state-color_next)
 +   strbuf_addf(value, %s%s%s, 
 state-color_next, v-s, GIT_COLOR_RESET);
 +   else
 +   strbuf_addstr(value, v-s);
 +   sp += 2;
 +   }
 +   }
 +
 +   return;
 +   } else if (state-pad_to_right) {
 if (!is_utf8(v-s))
 strbuf_addf(value, %-*s, state-pad_to_right, v-s);
 else {
 @@ -1413,6 +1442,8 @@ static void store_formatting_state(struct 
 ref_formatting_state *state,
 state-color_next = atomv-s;
 if (atomv-pad_to_right)
 state-pad_to_right = atomv-ul;
 +   if (atomv-ifexists)
 +   state-ifexists = 

Re: [RFC/PATCH 11/11] branch: add '--points-at' option

2015-07-28 Thread Jacob Keller
On Tue, Jul 28, 2015 at 12:11 AM, Karthik Nayak karthik@gmail.com wrote:
 Add the '--points-at' option provided by 'ref-filter'. The option lets
 the user to list only branches which points at the given object.

 Add documentation and tests for the same.

 Mentored-by: Christian Couder christian.cou...@gmail.com
 Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
 Signed-off-by: Karthik Nayak karthik@gmail.com
 ---
  Documentation/git-branch.txt | 6 +-
  builtin/branch.c | 7 ++-
  t/t3203-branch-output.sh | 9 +
  3 files changed, 20 insertions(+), 2 deletions(-)

 diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
 index 897cd81..efa23a5 100644
 --- a/Documentation/git-branch.txt
 +++ b/Documentation/git-branch.txt
 @@ -11,7 +11,8 @@ SYNOPSIS
  'git branch' [--color[=when] | --no-color] [-r | -a]
 [--list] [-v [--abbrev=length | --no-abbrev]]
 [--column[=options] | --no-column]
 -   [(--merged | --no-merged | --contains) [commit]] [--sort=key] 
 [pattern...]
 +   [(--merged | --no-merged | --contains) [commit]] [--sort=key]
 +   [--points-at object] [pattern...]
  'git branch' [--set-upstream | --track | --no-track] [-l] [-f] branchname 
 [start-point]
  'git branch' (--set-upstream-to=upstream | -u upstream) [branchname]
  'git branch' --unset-upstream [branchname]
 @@ -237,6 +238,9 @@ start-point is either a local or remote-tracking branch.
 for-each-ref`. Sort order defaults to sorting based on branch
 type.

 +--points-at object::
 +   Only list tags of the given object.
 +

s/tags/branches/ ?? Since this is for the branch version, I think this
is just a copy-paste oversight.

  Examples
  

 diff --git a/builtin/branch.c b/builtin/branch.c
 index 75d8bfd..d25f43b 100644
 --- a/builtin/branch.c
 +++ b/builtin/branch.c
 @@ -26,6 +26,7 @@ static const char * const builtin_branch_usage[] = {
 N_(git branch [options] [-l] [-f] branch-name [start-point]),
 N_(git branch [options] [-r] (-d | -D) branch-name...),
 N_(git branch [options] (-m | -M) [old-branch] new-branch),
 +   N_(git branch [options] [-r | -a] [--points-at]),
 NULL
  };

 @@ -647,6 +648,10 @@ int cmd_branch(int argc, const char **argv, const char 
 *prefix)
 OPT_COLUMN(0, column, colopts, N_(list branches in 
 columns)),
 OPT_CALLBACK(0 , sort, sorting_tail, N_(key),
  N_(field name to sort on), 
 parse_opt_ref_sorting),
 +   {
 +   OPTION_CALLBACK, 0, points-at, filter.points_at, 
 N_(object),
 +   N_(print only tags of the object), 0, 
 parse_opt_object_name
 +   },

Same as above. s/tags/branches/

 OPT_END(),
 };

 @@ -675,7 +680,7 @@ int cmd_branch(int argc, const char **argv, const char 
 *prefix)
 if (!delete  !rename  !edit_description  !new_upstream  
 !unset_upstream  argc == 0)
 list = 1;

 -   if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE)
 +   if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || 
 filter.points_at.nr)
 list = 1;

 if (!!delete + !!rename + !!new_upstream +
 diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
 index 38c68bd..1deb7cb 100755
 --- a/t/t3203-branch-output.sh
 +++ b/t/t3203-branch-output.sh
 @@ -154,4 +154,13 @@ EOF
 test_i18ncmp expect actual
  '

 +test_expect_success 'git branch --points-at option' '
 +   cat expect EOF 
 +  master
 +  branch-one
 +EOF
 +   git branch --points-at=branch-one actual 
 +   test_cmp expect actual
 +'
 +
  test_done
 --
 2.4.6

 --
 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
--
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: builtin/tag.c issue with sort option

2015-07-28 Thread Jacob Keller
On Tue, Jul 28, 2015 at 3:27 PM, Jacob Keller jacob.kel...@gmail.com wrote:
 When passing -n on the command line, if you have configured sort
 manually, you get an error as it thinks you passed --sort and -n.

 It should automatically disable tag_sort if it wasn't passed from the
 command line, as you probably know what you are doing when passing -n

 I'm attempting to work up a patch for this fix, but I am having a
 little bit of trouble and want to make sure it's right to fix this
 behavior.

 Regards,
 Jake

Actually, the sort and -n imcompatability is going away with the
unification of tag using the ref-filter API, so I think this is
actually not worth it to bother trying to fix, since it will be
removed soon anyways.

Regards,
Jake
--
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


builtin/tag.c issue with sort option

2015-07-28 Thread Jacob Keller
When passing -n on the command line, if you have configured sort
manually, you get an error as it thinks you passed --sort and -n.

It should automatically disable tag_sort if it wasn't passed from the
command line, as you probably know what you are doing when passing -n

I'm attempting to work up a patch for this fix, but I am having a
little bit of trouble and want to make sure it's right to fix this
behavior.

Regards,
Jake
--
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: [RFC/PATCH 07/11] branch: move 'current' check down to the presentation layer

2015-07-28 Thread Jacob Keller
On Tue, Jul 28, 2015 at 1:12 PM, Karthik Nayak karthik@gmail.com wrote:
 On Tue, Jul 28, 2015 at 6:39 PM, Matthieu Moy
 matthieu@grenoble-inp.fr wrote:
 Karthik Nayak karthik@gmail.com writes:

 We check if given ref is the current branch in print_ref_list().  Move
 this check to print_ref_item() where it is checked right before
 printing.

 This means that the '*' and the different color are coded in C, hence
 it's not possible to mimick this using git for-each-ref --format 

 I do not consider this as blocking, but I think the ultimate goal should
 be to allow this, so that all the goodies of git branch can be made
 available to other ref-listing commands.


 Not sure what you mean here.


He means to make sure that any feature that was in tag, branch,
for-each-ref, etc should be available as part of ref-filter and in all
of them

Maybe he misunderstood code or maybe you misunderstood the comment here?

Regards,
Jake
--
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 v3 2/6] notes: replace pseudorefs with real refs

2015-07-28 Thread Jacob Keller
On Tue, Jul 28, 2015 at 5:56 PM, Michael Haggerty mhag...@alum.mit.edu wrote:
 Johan Herland jo...@herland.net writes:
 Here is where we start to differ. I would say that starting a notes
 merge is completely unrelated to your worktree. Consider this:

 It sounds like what a notes merge really wants is a new linked worktree
 that has branch refs/notes/foo checked out:

 * This would allow multiple notes merges to take place at the same time
 provided they target different merge references.

 * This would prevent multiple notes merges to the same notes reference
 at the same time by the same mechanism that prevents the same branch
 from being checked out in two linked worktrees at the same time.

 It's just a thought; I have no idea whether it is practical...

 Michael


That seems far more flexible and robust to me.

Regards,
Jake
--
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] git-am: flag suspiciously old or futuristic commits

2015-07-29 Thread Jacob Keller
On Wed, Jul 29, 2015 at 3:20 PM, Stefan Beller sbel...@google.com wrote:
 On Wed, Jul 29, 2015 at 3:01 PM, Paul Gortmaker
 paul.gortma...@windriver.com wrote:
 The linux kernel repository has some commits in it with dates from
 the year 1970 and also 2030 (and possibly others).  We probably shouldi
 warn people when the dates look suspect.

 For commits in the future,  note that a committer in Australia
 could commit on New Years Day, and send it to a maintainer in North
 America and that would trip the notification on the maintainer's
 New Years Eve.  But that is unlikely, and the note is still
 correct; that the commit is from a future year.

 For commits in the past, I chose a somewhat arbitrary 30 year
 limit, which will allow stuff from post 1985; the thought being
 that someone might want to import an old repo into git from some
 other SCM.  We could alternatively set it to 5, which would then
 catch computers with a dead CMOS battery, at the risk of pestering
 the hypothetical museum curator of old bits.

 Sample output:

 paul@builder:~/git/linux-head$ grep Date: *patch
 future.patch:Date: Sat, 18 Jul 2037 21:22:19 -0400
 past.patch:Date: Sat, 18 Jul 1977 21:22:19 -0400

 paul@builder:~/git/linux-head$ git am future.patch
 note: commit is from future year 2037.
 Applying: arch/sh: make heartbeat driver explicitly non-modular
 paul@builder:~/git/linux-head$ git reset --hard HEAD~  /dev/null
 paul@builder:~/git/linux-head$ git am past.patch
 note: commit is from implausibly old year 1977.
 Applying: arch/sh: make heartbeat driver explicitly non-modular
 paul@builder:~/git/linux-head$

 Signed-off-by: Paul Gortmaker paul.gortma...@windriver.com
 ---
  git-am.sh | 15 +++
  1 file changed, 15 insertions(+)

 diff --git a/git-am.sh b/git-am.sh

 [+cc paul tan, who rewrote am in c as a GSoC project.]

 index 3af351ffaaf3..ff6deb8047a4 100755
 --- a/git-am.sh
 +++ b/git-am.sh
 @@ -766,6 +766,21 @@ To restore the original branch and stop patching run 
 \\$cmdline --abort\.
 stop_here $this
 fi

 +   if test -n $GIT_AUTHOR_DATE
 +   then
 +   THIS_YEAR=`date +%Y`
 +   TOO_OLD=$(expr $THIS_YEAR - 30)
 +   TOO_NEW=$(expr $THIS_YEAR + 1)
 +   GIT_AUTHOR_YEAR=`date -d $GIT_AUTHOR_DATE +%Y`

 Would it make sense to not operate on year but on unix time, so the problem
 you mentioned in the commit message goes away?

 Another thought:
 Having this check in am seems a bit arbitrary to me (or rather
 workflow adapted ;) as
 we could also check in commit or pull (not sure if I actually mean the
 fetch or merge thereof)


I think this makes most sense in am, as it is most likely to show up,
in my mind, due to a format-patch mistake. If we do it during pull,
would we just warn? how would we reject commits? that doesn't really
fit..

We can't do it during commit, as obviously the broken machine will
likely not be able to notice it at all.. We could check remotes during
push but that doesn't solve this either..

Maybe just emitting a warning during a fetch or am (since am doesn't
use pull) would make the most sense?

I don't think we can reject things when doing a fetch though, but we could warn.

Regards,
Jake
--
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: [RFC/PATCH 02/11] ref-filter: add 'colornext' atom

2015-07-29 Thread Jacob Keller
On Wed, Jul 29, 2015 at 2:30 PM, Matthieu Moy
matthieu@grenoble-inp.fr wrote:
 Eric Sunshine sunsh...@sunshineco.com writes:

 Also, please explain here and in the commit message why this highly
 specialized colorizer ('colornext'), is needed even though a more
 general purpose one ('color') is already available.

 It is needed in the current form to allow
 %(colornext:blue)%(ifexists:[%s]) to color only the replacement of %s
 and not the [].

 But I now think that this would be more elegantly solved by Junio's
 %(if) %(endif) idea:

   %(if:atom) [ %(color:blue)%(atom)%(color:reset) ] %(endif)

 (I added spaces for clarity)


I agree, this style seems a lot more elegant and expressive while much
easier to understand. Same for doing this to the alignment atoms and
such as it solves the same problem(s) there.

I can't speak to how easy it is to implement tho.

Regards,
Jake
--
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 v2 2/2] notes: add notes.merge option to select default strategy

2015-08-02 Thread Jacob Keller
On Sun, Aug 2, 2015 at 1:01 AM, Eric Sunshine sunsh...@sunshineco.com wrote:
 Don't worry too much about it. Consider it something to keep in mind for
 future patches. I reviewed the change and it seemed okay. I mentioned it
 because one of the goals of patch submission, in addition to making an
 actual change, is to ease the review process. If Junio is okay with
 accepting it as is, then it's probably not worth spending more time
 trying to refine it.

 Having said that, I came up with the following for those two paragraphs,
 which gives a much less noisy diff and doesn't look too jagged:


Yea, I actually have re-worked it as well to something more suitable.
I'm re-sending anyways as I fixed some of the other style issues and
the one bug about not returning 0 on good read of the notes.merge
value.

Regards
Jake
--
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 v2 2/2] notes: add notes.merge option to select default strategy

2015-08-01 Thread Jacob Keller
On Sat, Aug 1, 2015 at 7:46 PM, Eric Sunshine sunsh...@sunshineco.com wrote:
 On Fri, Jul 31, 2015 at 7:12 PM, Jacob Keller jacob.e.kel...@intel.com 
 wrote:
 Teach git-notes about a new configuration option notes.merge for
 selecting the default notes merge strategy. Document the option in
 config.txt and git-notes.txt

 Add tests for the configuration option. Ensure that command line
 --strategy option overrides the configured value. Ensure that -s can't
 be passed with --commit or --abort. Ensure that --abort and --commit
 can't be used together.

 Signed-off-by: Jacob Keller jacob.kel...@gmail.com
 Cc: Johan Herland jo...@herland.net
 Cc: Michael Haggerty mhag...@alum.mit.edu
 Cc: Eric Sunshine sunsh...@sunshineco.com

 Thanks, this looks better than the previous round. A few comments below...

 diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
 index 674682b34b83..d8944f5aec60 100644
 --- a/Documentation/git-notes.txt
 +++ b/Documentation/git-notes.txt
 @@ -101,13 +101,13 @@ merge::
 any) into the current notes ref (called local).
  +
  If conflicts arise and a strategy for automatically resolving
 -conflicting notes (see the -s/--strategy option) is not given,
 -the manual resolver is used. This resolver checks out the
 -conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 -and instructs the user to manually resolve the conflicts there.
 -When done, the user can either finalize the merge with
 -'git notes merge --commit', or abort the merge with
 -'git notes merge --abort'.
 +conflicting notes (see the -s/--strategy option or notes.merge
 +config option) is not given, the manual resolver is used.
 +This resolver checks out the conflicting notes in a special
 +worktree (`.git/NOTES_MERGE_WORKTREE`), and instructs the user
 +to manually resolve the conflicts there. When done, the user
 +can either finalize the merge with 'git notes merge --commit',
 +or abort the merge with 'git notes merge --abort'.

 When you re-wrap the text like this, it's difficult to spot your one
 little change in all the diff noise. For the sake of review, it's
 often better to minimize the change, even if it leaves the text more
 jagged than you'd like.


Even if it leaves it incredibly jagged? That is one of the downsides
with diff of flowed text like this :(

  remove::
 Remove the notes for given objects (defaults to HEAD). When
 @@ -181,10 +181,10 @@ OPTIONS
  -s strategy::
  --strategy=strategy::
 When merging notes, resolve notes conflicts using the given
 -   strategy. The following strategies are recognized: manual
 -   (default), ours, theirs, union and cat_sort_uniq.
 -   See the NOTES MERGE STRATEGIES section below for more
 -   information on each notes merge strategy.
 +   strategy. Overrides notes.merge. The following strategies are
 +   recognized: `manual`, `ours`, `theirs`, `union` and
 +   `cat_sort_uniq`. See the `NOTES MERGE STRATEGIES` section below
 +   for more information on each notes merge strategy.

 Ditto.

  --commit::
 Finalize an in-progress 'git notes merge'. Use this option
 diff --git a/builtin/notes.c b/builtin/notes.c
 index 88fdafb32bc0..728980bc79bf 100644
 --- a/builtin/notes.c
 +++ b/builtin/notes.c
 @@ -741,6 +743,25 @@ static int merge_commit(struct notes_merge_options *o)
 return ret;
  }

 +static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
 *strategy)
 +{
 +   if (!strcmp(arg, manual))
 +   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
 +   else if (!strcmp(arg, ours))
 +   *strategy = NOTES_MERGE_RESOLVE_OURS;
 +   else if (!strcmp(arg, theirs))
 +   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
 +   else if (!strcmp(arg, union))
 +   *strategy = NOTES_MERGE_RESOLVE_UNION;
 +   else if (!strcmp(arg, cat_sort_uniq))
 +   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
 +   else {
 +   return 1;

 In this codebase, it's customary to return 0 on success and -1 on error


Fair enough.

 +   }

 Style: drop unnecessary braces

 +
 +   return 0;
 +}
 +
  static int merge(int argc, const char **argv, const char *prefix)
  {
 struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
 @@ -950,6 +961,18 @@ static int get_ref(int argc, const char **argv, const 
 char *prefix)
 return 0;
  }

 +static int git_notes_config(const char *var, const char *value, void *cb)
 +{
 +   if (!strcmp(var, notes.merge)) {
 +   if (!value)
 +   return config_error_nonbool(var);
 +   if (parse_notes_strategy(value, merge_strategy))
 +   return error(Unknown notes merge strategy: %s, 
 value);

 For the non-error case, don't you want to 'return 0' here to indicate
 that you handled the config variable rather than letting it fall
 through to git_default_config() below?


Makes sense, I can fix

[PATCH v3 3/4] notes: add notes.merge option to select default strategy

2015-08-02 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about a new configuration option notes.merge for
selecting the default notes merge strategy. Document the option in
config.txt and git-notes.txt

Add tests for use of the configuration option. Include a test to ensure
that --strategy correctly overrides the configured setting.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
Cc: Johan Herland jo...@herland.net
Cc: Michael Haggerty mhag...@alum.mit.edu
Cc: Eric Sunshine sunsh...@sunshineco.com
---
 Documentation/config.txt|  7 +
 Documentation/git-notes.txt | 14 +-
 builtin/notes.c | 56 ++---
 notes-merge.h   | 16 ++-
 t/t3309-notes-merge-auto-resolve.sh | 29 +++
 5 files changed, 98 insertions(+), 24 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4ce5c553e50f..0fa88a29dd65 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1911,6 +1911,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..9c4f8536182f 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.merge configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.merge accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 63f95fc55439..de0caa00df1b 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -92,6 +92,8 @@ static const char * const git_notes_get_ref_usage[] = {
 static const char note_template[] =
\nWrite/edit the notes for the following object:\n;
 
+static enum notes_merge_strategy merge_strategy;
+
 struct note_data {
int given;
int use_editor;
@@ -737,6 +739,24 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
*strategy)
+{
+   if (!strcmp(arg, manual))
+   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(arg, ours))
+   *strategy = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(arg, theirs))
+   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(arg, union))
+   *strategy = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(arg, cat_sort_uniq))
+   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char

[PATCH v3 0/4] notes: add support for notes.merge option

2015-08-02 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

This series incorporates the feedback from both Johan and Eric. In
addition, I included an RFC implementing suggestion from Johan regarding
per-ref merge strategies.

I split the tests for --merge/--commit/--strategy out into their own
patch to help review and keep the one commit = one change logic.

I am not certain the RFC is ready yet, but the first 3 patches (now
based on next) should be ready to go.

Jacob Keller (4):
  notes: document cat_sort_uniq rewriteMode
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.merge option to select default strategy
  notes: add per-ref configuration of merge strategy

 Documentation/config.txt  |  18 +++-
 Documentation/git-notes.txt   |  23 -
 builtin/notes.c   | 167 ++
 notes-merge.h |  16 ++--
 t/t3309-notes-merge-auto-resolve.sh   |  79 
 t/t3310-notes-merge-manual-resolve.sh |  12 +++
 6 files changed, 288 insertions(+), 27 deletions(-)

-- 
2.5.0.482.gfcd5645

--
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 2/2] notes: add notes.merge option to select default strategy

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about a new configuration option notes.merge for
selecting the default notes merge strategy. Document the option in
config.txt and git-notes.txt

Add tests for the configuration option. Ensure that command line
--strategy option overrides the configured value. Ensure that -s can't
be passed with --commit or --abort. Ensure that --abort and --commit
can't be used together.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt  |  7 
 Documentation/git-notes.txt   | 30 +-
 builtin/notes.c   | 75 +--
 notes-merge.h | 16 
 t/t3309-notes-merge-auto-resolve.sh   | 29 ++
 t/t3310-notes-merge-manual-resolve.sh | 12 ++
 6 files changed, 129 insertions(+), 40 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3c1e4df09beb..85c15126e4ce 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1937,6 +1937,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..d8944f5aec60 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,13 +101,13 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
-the manual resolver is used. This resolver checks out the
-conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
-and instructs the user to manually resolve the conflicts there.
-When done, the user can either finalize the merge with
-'git notes merge --commit', or abort the merge with
-'git notes merge --abort'.
+conflicting notes (see the -s/--strategy option or notes.merge
+config option) is not given, the manual resolver is used.
+This resolver checks out the conflicting notes in a special
+worktree (`.git/NOTES_MERGE_WORKTREE`), and instructs the user
+to manually resolve the conflicts there. When done, the user
+can either finalize the merge with 'git notes merge --commit',
+or abort the merge with 'git notes merge --abort'.
 
 remove::
Remove the notes for given objects (defaults to HEAD). When
@@ -181,10 +181,10 @@ OPTIONS
 -s strategy::
 --strategy=strategy::
When merging notes, resolve notes conflicts using the given
-   strategy. The following strategies are recognized: manual
-   (default), ours, theirs, union and cat_sort_uniq.
-   See the NOTES MERGE STRATEGIES section below for more
-   information on each notes merge strategy.
+   strategy. Overrides notes.merge. The following strategies are
+   recognized: `manual`, `ours`, `theirs`, `union` and
+   `cat_sort_uniq`. See the `NOTES MERGE STRATEGIES` section below
+   for more information on each notes merge strategy.
 
 --commit::
Finalize an in-progress 'git notes merge'. Use this option
@@ -310,6 +310,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 88fdafb32bc0..7123311b563e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -93,6 +93,9 @@ static const char * const git_notes_get_ref_usage[] = {
 static const char note_template[] =
\nWrite/edit the notes for the following object:\n;
 
+static int override_strategy = 0;
+static enum notes_merge_strategy strategy;
+
 struct note_data {
int given;
int use_editor;
@@ -741,6 +744,36 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *var, const char *arg,
+   enum notes_merge_strategy *strategy)
+{
+   if (!strcmp(arg, manual

[PATCH 0/2] add notes.merge configuration variable

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

This small series is a precursor to some thoughts I have for enabling
easier notes collaboration. First, make it so that users can configure
the default notes merge strategy. Mostly useful if you always want to
use cat_sort_uniq.

I also found that the rewriteMode supports cat_sort_uniq but does not
document this fact.

Jacob Keller (2):
  notes: document cat_sort_uniq rewriteMode
  notes: add notes.merge option to select default strategy

 Documentation/config.txt  | 11 -
 Documentation/git-notes.txt   | 33 +--
 builtin/notes.c   | 75 +--
 notes-merge.h | 16 
 t/t3309-notes-merge-auto-resolve.sh   | 29 ++
 t/t3310-notes-merge-manual-resolve.sh | 12 ++
 6 files changed, 133 insertions(+), 43 deletions(-)

-- 
2.5.0.482.gfcd5645

--
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 1/2] notes: document cat_sort_uniq rewriteMode

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6562c6ab09b9..3c1e4df09beb 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1965,8 +1965,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..674682b34b83 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
-- 
2.5.0.482.gfcd5645

--
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 v2 0/2] notes: add notes.merge strategy option

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

This series adds a default merge strategy option for git-notes, so that
the user does not have to type -s every time. It is overridden by the
-s option.

I also added some tests to ensure that the --abort --commit and -s
options must be independent. In addition, I found a small documentation
bug which is corrected in the first patch of the series.

I Cc'd a couple more people in this version of the patch in order to
hopefully get some more review. This is based on pu incase there were
any other conflicts, but I can easily rebase if necessary.

Jacob Keller (2):
  notes: document cat_sort_uniq rewriteMode
  notes: add notes.merge option to select default strategy

 Documentation/config.txt  | 11 +--
 Documentation/git-notes.txt   | 33 +
 builtin/notes.c   | 55 +--
 notes-merge.h | 16 +-
 t/t3309-notes-merge-auto-resolve.sh   | 29 ++
 t/t3310-notes-merge-manual-resolve.sh | 12 
 6 files changed, 119 insertions(+), 37 deletions(-)

-- 
2.5.0.482.gfcd5645

--
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 v2 1/2] notes: document cat_sort_uniq rewriteMode

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
Cc: Johan Herland jo...@herland.net
Cc: Michael Haggerty mhag...@alum.mit.edu
Cc: Eric Sunshine sunsh...@sunshineco.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6562c6ab09b9..3c1e4df09beb 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1965,8 +1965,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..674682b34b83 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
-- 
2.5.0.482.gfcd5645

--
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 v2 2/2] notes: add notes.merge option to select default strategy

2015-07-31 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about a new configuration option notes.merge for
selecting the default notes merge strategy. Document the option in
config.txt and git-notes.txt

Add tests for the configuration option. Ensure that command line
--strategy option overrides the configured value. Ensure that -s can't
be passed with --commit or --abort. Ensure that --abort and --commit
can't be used together.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
Cc: Johan Herland jo...@herland.net
Cc: Michael Haggerty mhag...@alum.mit.edu
Cc: Eric Sunshine sunsh...@sunshineco.com
---
 Documentation/config.txt  |  7 +
 Documentation/git-notes.txt   | 30 ---
 builtin/notes.c   | 55 +--
 notes-merge.h | 16 +-
 t/t3309-notes-merge-auto-resolve.sh   | 29 ++
 t/t3310-notes-merge-manual-resolve.sh | 12 
 6 files changed, 115 insertions(+), 34 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3c1e4df09beb..85c15126e4ce 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1937,6 +1937,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..d8944f5aec60 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,13 +101,13 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
-the manual resolver is used. This resolver checks out the
-conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
-and instructs the user to manually resolve the conflicts there.
-When done, the user can either finalize the merge with
-'git notes merge --commit', or abort the merge with
-'git notes merge --abort'.
+conflicting notes (see the -s/--strategy option or notes.merge
+config option) is not given, the manual resolver is used.
+This resolver checks out the conflicting notes in a special
+worktree (`.git/NOTES_MERGE_WORKTREE`), and instructs the user
+to manually resolve the conflicts there. When done, the user
+can either finalize the merge with 'git notes merge --commit',
+or abort the merge with 'git notes merge --abort'.
 
 remove::
Remove the notes for given objects (defaults to HEAD). When
@@ -181,10 +181,10 @@ OPTIONS
 -s strategy::
 --strategy=strategy::
When merging notes, resolve notes conflicts using the given
-   strategy. The following strategies are recognized: manual
-   (default), ours, theirs, union and cat_sort_uniq.
-   See the NOTES MERGE STRATEGIES section below for more
-   information on each notes merge strategy.
+   strategy. Overrides notes.merge. The following strategies are
+   recognized: `manual`, `ours`, `theirs`, `union` and
+   `cat_sort_uniq`. See the `NOTES MERGE STRATEGIES` section below
+   for more information on each notes merge strategy.
 
 --commit::
Finalize an in-progress 'git notes merge'. Use this option
@@ -310,6 +310,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.merge::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 88fdafb32bc0..728980bc79bf 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -93,6 +93,8 @@ static const char * const git_notes_get_ref_usage[] = {
 static const char note_template[] =
\nWrite/edit the notes for the following object:\n;
 
+static enum notes_merge_strategy merge_strategy;
+
 struct note_data {
int given;
int use_editor;
@@ -741,6 +743,25 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum

Re: Error pushing new branch: value too great for base (error token is...

2015-08-10 Thread Jacob Keller
On Mon, Aug 10, 2015 at 2:54 AM, Gaurav Chhabra
varuag.chha...@gmail.com wrote:
 Apologies for the delay in reply! I tried your suggestion and it
 works. Thanks! :)

 I'm curious why integer comparison is throwing error. Shouldn't i be
 comparing numbers with numeric operator?


Yes, but shell doesn't treat hex numbers as numbers. So it will work
only if the string is a decimal number.

Regards,
Jake
--
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 v5 3/4] notes: add notes.mergestrategy option to select default strategy

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.mergestrategy to select a general strategy
for all notes merges. This enables a user to always get expected merge
strategy such as cat_sort_uniq without having to pass the -s option
manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +++
 Documentation/git-notes.txt | 14 +-
 builtin/notes.c | 37 +
 notes-merge.h   | 16 +---
 t/t3309-notes-merge-auto-resolve.sh | 29 +
 5 files changed, 83 insertions(+), 20 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..5e3e03459de7 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1919,6 +1919,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..89c8829a0543 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.mergestrategy configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.mergestrategy accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 042348082709..97109f8d419c 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -738,6 +738,24 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
*strategy)
+{
+   if (!strcmp(arg, manual))
+   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(arg, ours))
+   *strategy = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(arg, theirs))
+   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(arg, union))
+   *strategy = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(arg, cat_sort_uniq))
+   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char *prefix)
 {
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
@@ -746,7 +764,7 @@ static int merge(int argc, const char **argv, const char 
*prefix)
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
int verbosity = 0, result;
-   const char *strategy = NULL;
+   const char *strategy = NULL, *configured_strategy = NULL;
struct option options

[PATCH v5 4/4] notes: teach git-notes about notes.ref.mergestrategy option

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new option notes.ref.mergestrategy option which specifies the merge
strategy for merging into a given notes ref. This option enables
selection of merge strategy for particular notes refs, rather than all
notes ref merges, as user may not want cat_sort_uniq for all refs, but
only some. Note that the ref is the local reference we are merging
into, not the remote ref we merged from. The assumption is that users
will mostly want to configure separate local ref merge strategies rather
than strategies depending on which remote ref they merge from. Also,
notes.ref.merge overrides the general behavior as it is more specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c | 13 ++---
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5e3e03459de7..47478311367e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1926,6 +1926,13 @@ notes.mergestrategy::
STRATEGIES section of linkgit:git-notes[1] for more information
on each strategy.
 
+notes.localref.mergestrategy::
+   Which merge strategy to choose if the local ref for a notes merge
+   matches localref, overriding notes.mergestrategy. localref must
+   be the short name of a ref under refs/notes/. See NOTES MERGE
+   STRATEGIES section in linkgit:git-notes[1] for more information on the
+   available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 89c8829a0543..b99809fc81a6 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -322,6 +322,12 @@ notes.mergestrategy::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.localref.mergestrategy::
+   Which strategy to choose when merging into localref. The set of
+   allowed values is the same as notes.mergestrategy. localref must be
+   the short name of a ref under refs/notes/. See NOTES MERGE STRATEGIES
+   section above for more information about each strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 97109f8d419c..00c9ae402bab 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -758,13 +758,13 @@ static int parse_notes_strategy(const char *arg, enum 
notes_merge_strategy *stra
 
 static int merge(int argc, const char **argv, const char *prefix)
 {
-   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
+   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT, merge_key = 
STRBUF_INIT;
unsigned char result_sha1[20];
struct notes_tree *t;
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
int verbosity = 0, result;
-   const char *strategy = NULL, *configured_strategy = NULL;
+   const char *strategy = NULL, *configured_strategy = NULL, *short_ref = 
NULL;
struct option options[] = {
OPT_GROUP(N_(General options)),
OPT__VERBOSITY(verbosity),
@@ -814,7 +814,14 @@ static int merge(int argc, const char **argv, const char 
*prefix)
expand_notes_ref(remote_ref);
o.remote_ref = remote_ref.buf;
 
-   git_config_get_string_const(notes.mergestrategy, 
configured_strategy);
+   if (!skip_prefix(o.local_ref, refs/notes/, short_ref))
+   die(Refusing to merge notes into %s (outside of refs/notes/),
+   o.local_ref);
+
+   strbuf_addf(merge_key, notes.%s.mergestrategy, short_ref);
+
+   if (git_config_get_string_const(merge_key.buf, configured_strategy))
+   git_config_get_string_const(notes.mergestrategy, 
configured_strategy);
 
if (strategy) {
if (parse_notes_strategy(strategy, o.strategy)) {
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 476b9f5306f1..560e75259798 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.y.mergestrategy=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat

[PATCH v5 1/4] notes: document cat_sort_uniq rewriteMode

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 75ec02e8e90a..de67ad1fdedf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1947,8 +1947,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..674682b34b83 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
-- 
2.5.0.280.g4aaba03

--
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 v5 2/4] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.280.g4aaba03

--
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 v5 0/4] notes mergestrategy configuration option

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

I have tried to cover all of the comments since the last sending of
this series. I am not 100% sure if I got everything, so please feel free
to respond again if I missed something.

This series implements the notes.mergestrategy option, as well as a
notes.ref.mergestrategy option which can be used to customize what
strategy is used to merge into a particular ref. I chose to use the
local ref instead of the remote reference, as it is most likely that you
will merge into a given ref with the same strategy rather than always
using the same strategy to merge from a ref.

The notes.ref.mergestrategy option uses the short name under
refs/notes/ and does not allow arbitrary references. Today git-notes
does not allow *any* arbitrary ref as a notes ref for either merge or
any other operation, (see init_notes_check!). Due to this, we can force
the config to use the shorthand name instead of the full name.

In the future we may wish to allow non-write operations to reference an
arbitrary ref (such as refs/remote-notes/* or refs/tracking/*/notes/)
but this is not today supported, and in anycase merge is a destructive
write operation so it should always require refs/notes/ references.


Changes since v4
* renamed option to mergestrategy for both per-ref and general option
  for consistency and to keep the notes.merge and notes.ref.merge
  available as keys for future notes enhancements

* use shortrefs for notes.ref.mergestrategy

Jacob Keller (4):
  notes: document cat_sort_uniq rewriteMode
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.mergestrategy option to select default strategy
  notes: teach git-notes about notes.ref.mergestrategy option

 Documentation/config.txt  | 18 --
 Documentation/git-notes.txt   | 23 ++--
 builtin/notes.c   | 46 +---
 notes-merge.h | 16 +
 t/t3309-notes-merge-auto-resolve.sh   | 68 +++
 t/t3310-notes-merge-manual-resolve.sh | 12 +++
 6 files changed, 159 insertions(+), 24 deletions(-)

-- 
2.5.0.280.g4aaba03

--
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 v6 3/4] notes: add notes.mergestrategy option to select default strategy

2015-08-14 Thread Jacob Keller
On Fri, Aug 14, 2015 at 2:06 PM, Eric Sunshine sunsh...@sunshineco.com wrote:
 const char *value;

 if (!git_config_get_string_const(key, value)) {
 if (parse_notes_strategy(value, strategy))
 git_die_config(key, unknown notes merge strategy '%s', value);
 return 0;
 }
 return 1;

 Or, the equivalent, but less indented:

 if (git_config_get_string_const(key, value))
 return 1;
 if (parse_notes_strategy(value, strategy))
 git_die_config(key, unknown notes merge strategy '%s', value);
 return 0;


I like it. Will do.
--
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 v7 4/4] notes: teach git-notes about notes.ref.mergestrategy option

2015-08-14 Thread Jacob Keller
On Fri, Aug 14, 2015 at 3:10 PM, Eric Sunshine sunsh...@sunshineco.com wrote:
 On Fri, Aug 14, 2015 at 6:01 PM, Junio C Hamano gits...@pobox.com wrote:
 Jacob Keller jacob.e.kel...@intel.com writes:
 diff --git a/builtin/notes.c b/builtin/notes.c
 index 12a42b583f98..bdfd9c7d29b4 100644
 --- a/builtin/notes.c
 +++ b/builtin/notes.c
 + strbuf_addf(merge_key, notes.%s.mergestrategy, short_ref);
 +
 + if (git_config_get_notes_strategy(merge_key.buf, o.strategy))
 + git_config_get_notes_strategy(notes.mergestrategy, 
 o.strategy);
   }

 I think you are leaking merge_key after you are done using it.

 In addition to fixing the leak, since 'merge_key' is only used within
 this block, it might also make sense to declare it in this block
 rather than at the top of the function.

I can do that.

How do you feel about having the duplicate check for the short_ref? We
*already* check this inside init_notes_check() which is called right
after this.

I think that we should keep it but can't find a consistent way to
avoid the duplication.

In addition, we already provide the tests for merging into and from
non-notes refs.

Regards,
Jake
--
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 v6 4/4] notes: teach git-notes about notes.ref.mergestrategy option

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new option notes.ref.mergestrategy option which specifies the merge
strategy for merging into a given notes ref. This option enables
selection of merge strategy for particular notes refs, rather than all
notes ref merges, as user may not want cat_sort_uniq for all refs, but
only some. Note that the ref is the local reference we are merging
into, not the remote ref we merged from. The assumption is that users
will mostly want to configure separate local ref merge strategies rather
than strategies depending on which remote ref they merge from. Also,
notes.ref.merge overrides the general behavior as it is more specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c | 13 ++---
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5e3e03459de7..47478311367e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1926,6 +1926,13 @@ notes.mergestrategy::
STRATEGIES section of linkgit:git-notes[1] for more information
on each strategy.
 
+notes.localref.mergestrategy::
+   Which merge strategy to choose if the local ref for a notes merge
+   matches localref, overriding notes.mergestrategy. localref must
+   be the short name of a ref under refs/notes/. See NOTES MERGE
+   STRATEGIES section in linkgit:git-notes[1] for more information on the
+   available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 89c8829a0543..b99809fc81a6 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -322,6 +322,12 @@ notes.mergestrategy::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.localref.mergestrategy::
+   Which strategy to choose when merging into localref. The set of
+   allowed values is the same as notes.mergestrategy. localref must be
+   the short name of a ref under refs/notes/. See NOTES MERGE STRATEGIES
+   section above for more information about each strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index d65134f89b40..00057b29e215 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -775,13 +775,13 @@ static int git_config_get_notes_strategy(const char *key,
 
 static int merge(int argc, const char **argv, const char *prefix)
 {
-   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
+   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT, merge_key = 
STRBUF_INIT;
unsigned char result_sha1[20];
struct notes_tree *t;
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
int verbosity = 0, result;
-   const char *strategy = NULL;
+   const char *strategy = NULL, *short_ref = NULL;
struct option options[] = {
OPT_GROUP(N_(General options)),
OPT__VERBOSITY(verbosity),
@@ -837,7 +837,14 @@ static int merge(int argc, const char **argv, const char 
*prefix)
usage_with_options(git_notes_merge_usage, options);
}
} else {
-   git_config_get_notes_strategy(notes.mergestrategy, 
o.strategy);
+   if (!skip_prefix(o.local_ref, refs/notes/, short_ref))
+   die(Refusing to merge notes into %s (outside of 
refs/notes/),
+   o.local_ref);
+
+   strbuf_addf(merge_key, notes.%s.mergestrategy, short_ref);
+
+   if (git_config_get_notes_strategy(merge_key.buf, o.strategy))
+   git_config_get_notes_strategy(notes.mergestrategy, 
o.strategy);
}
 
t = init_notes_check(merge);
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 476b9f5306f1..560e75259798 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.y.mergestrategy=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs

[PATCH v6 2/4] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.280.g4aaba03

--
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 v6 3/4] notes: add notes.mergestrategy option to select default strategy

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.mergestrategy to select a general strategy
for all notes merges. This enables a user to always get expected merge
strategy such as cat_sort_uniq without having to pass the -s option
manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 ++
 Documentation/git-notes.txt | 14 ++-
 builtin/notes.c | 49 -
 notes-merge.h   | 16 ++--
 t/t3309-notes-merge-auto-resolve.sh | 29 ++
 5 files changed, 96 insertions(+), 19 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..5e3e03459de7 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1919,6 +1919,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..89c8829a0543 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.mergestrategy configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.mergestrategy accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 042348082709..d65134f89b40 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -738,6 +738,41 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
*strategy)
+{
+   if (!strcmp(arg, manual))
+   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(arg, ours))
+   *strategy = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(arg, theirs))
+   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(arg, union))
+   *strategy = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(arg, cat_sort_uniq))
+   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
+static int git_config_get_notes_strategy(const char *key,
+enum notes_merge_strategy *strategy)
+{
+   const char *value = NULL;
+
+   git_config_get_string_const(key, value);
+
+   if (value) {
+   if (parse_notes_strategy(value, strategy))
+   git_die_config(key, unknown notes merge strategy 
'%s', value);
+   else
+   return 0;
+   }
+
+   return 1;
+}
+
 static int merge(int

[PATCH v6 0/4] notes.mergestrategy config option

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Changes since v6:

* use a static git_config_get_notes_strategy function
* use git_die_config to display useful information about which
  configuration failed.

This should address Eric's concern. It also makes it so that we don't
even read the configuration at all unless we need to.

Jacob Keller (4):
  notes: document cat_sort_uniq rewriteMode
  notes: add tests for --commit/--abort/--strategy exclusivity
  notes: add notes.mergestrategy option to select default strategy
  notes: teach git-notes about notes.ref.mergestrategy option

 Documentation/config.txt  | 18 --
 Documentation/git-notes.txt   | 23 ++--
 builtin/notes.c   | 60 ---
 notes-merge.h | 16 +
 t/t3309-notes-merge-auto-resolve.sh   | 68 +++
 t/t3310-notes-merge-manual-resolve.sh | 12 +++
 6 files changed, 173 insertions(+), 24 deletions(-)

-- 
2.5.0.280.g4aaba03

--
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 v6 1/4] notes: document cat_sort_uniq rewriteMode

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 75ec02e8e90a..de67ad1fdedf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1947,8 +1947,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..674682b34b83 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
-- 
2.5.0.280.g4aaba03

--
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 v7 1/4] notes: document cat_sort_uniq rewriteMode

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach documentation about the cat_sort_uniq rewriteMode that got added
at the same time as the equivalent merge strategy.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt| 4 ++--
 Documentation/git-notes.txt | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 75ec02e8e90a..de67ad1fdedf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1947,8 +1947,8 @@ notes.rewriteMode::
When copying notes during a rewrite (see the
notes.rewrite.command option), determines what to do if
the target commit already has a note.  Must be one of
-   `overwrite`, `concatenate`, or `ignore`.  Defaults to
-   `concatenate`.
+   `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+   Defaults to `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 851518d531b5..674682b34b83 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -331,7 +331,8 @@ environment variable.
 notes.rewriteMode::
When copying notes during a rewrite, what to do if the target
commit already has a note.  Must be one of `overwrite`,
-   `concatenate`, and `ignore`.  Defaults to `concatenate`.
+   `concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
+   `concatenate`.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
-- 
2.5.0.280.g4aaba03

--
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 v7 3/4] notes: add notes.mergestrategy option to select default strategy

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Teach git-notes about notes.mergestrategy to select a general strategy
for all notes merges. This enables a user to always get expected merge
strategy such as cat_sort_uniq without having to pass the -s option
manually.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 ++
 Documentation/git-notes.txt | 14 +++-
 builtin/notes.c | 45 -
 notes-merge.h   | 16 +++--
 t/t3309-notes-merge-auto-resolve.sh | 29 
 5 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..5e3e03459de7 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1919,6 +1919,13 @@ mergetool.writeToTemp::
 mergetool.prompt::
Prompt before each invocation of the merge resolution program.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section of linkgit:git-notes[1] for more information
+   on each strategy.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 674682b34b83..89c8829a0543 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -101,7 +101,7 @@ merge::
any) into the current notes ref (called local).
 +
 If conflicts arise and a strategy for automatically resolving
-conflicting notes (see the -s/--strategy option) is not given,
+conflicting notes (see the NOTES MERGE STRATEGIES section) is not given,
 the manual resolver is used. This resolver checks out the
 conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`),
 and instructs the user to manually resolve the conflicts there.
@@ -183,6 +183,7 @@ OPTIONS
When merging notes, resolve notes conflicts using the given
strategy. The following strategies are recognized: manual
(default), ours, theirs, union and cat_sort_uniq.
+   This option overrides the notes.mergestrategy configuration setting.
See the NOTES MERGE STRATEGIES section below for more
information on each notes merge strategy.
 
@@ -247,6 +248,9 @@ When done, the user can either finalize the merge with
 'git notes merge --commit', or abort the merge with
 'git notes merge --abort'.
 
+Users may select an automated merge strategy from among the following using
+either -s/--strategy option or configuring notes.mergestrategy accordingly:
+
 ours automatically resolves conflicting notes in favor of the local
 version (i.e. the current notes ref).
 
@@ -310,6 +314,14 @@ core.notesRef::
This setting can be overridden through the environment and
command line.
 
+notes.mergestrategy::
+   Which merge strategy to choose by default when resolving notes
+   conflicts. Must be one of `manual`, `ours`, `theirs`, `union`,
+   or `cat_sort_uniq`. Defaults to `manual`. See NOTES MERGE
+   STRATEGIES section above for more information on each strategy.
++
+This setting can be overridden by passing the `--strategy` option.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 042348082709..12a42b583f98 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -738,6 +738,37 @@ static int merge_commit(struct notes_merge_options *o)
return ret;
 }
 
+static int parse_notes_strategy(const char *arg, enum notes_merge_strategy 
*strategy)
+{
+   if (!strcmp(arg, manual))
+   *strategy = NOTES_MERGE_RESOLVE_MANUAL;
+   else if (!strcmp(arg, ours))
+   *strategy = NOTES_MERGE_RESOLVE_OURS;
+   else if (!strcmp(arg, theirs))
+   *strategy = NOTES_MERGE_RESOLVE_THEIRS;
+   else if (!strcmp(arg, union))
+   *strategy = NOTES_MERGE_RESOLVE_UNION;
+   else if (!strcmp(arg, cat_sort_uniq))
+   *strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
+   else
+   return -1;
+
+   return 0;
+}
+
+static int git_config_get_notes_strategy(const char *key,
+enum notes_merge_strategy *strategy)
+{
+   const char *value;
+
+   if (git_config_get_string_const(key, value))
+   return 1;
+   if (parse_notes_strategy(value, strategy))
+   git_die_config(key, unknown notes merge strategy %s, value);
+
+   return 0;
+}
+
 static int merge(int argc, const char **argv, const char *prefix)
 {
struct strbuf remote_ref

[PATCH v7 4/4] notes: teach git-notes about notes.ref.mergestrategy option

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new option notes.ref.mergestrategy option which specifies the merge
strategy for merging into a given notes ref. This option enables
selection of merge strategy for particular notes refs, rather than all
notes ref merges, as user may not want cat_sort_uniq for all refs, but
only some. Note that the ref is the local reference we are merging
into, not the remote ref we merged from. The assumption is that users
will mostly want to configure separate local ref merge strategies rather
than strategies depending on which remote ref they merge from. Also,
notes.ref.merge overrides the general behavior as it is more specific.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 Documentation/config.txt|  7 +++
 Documentation/git-notes.txt |  6 ++
 builtin/notes.c | 13 ++---
 t/t3309-notes-merge-auto-resolve.sh | 39 +
 4 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5e3e03459de7..47478311367e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1926,6 +1926,13 @@ notes.mergestrategy::
STRATEGIES section of linkgit:git-notes[1] for more information
on each strategy.
 
+notes.localref.mergestrategy::
+   Which merge strategy to choose if the local ref for a notes merge
+   matches localref, overriding notes.mergestrategy. localref must
+   be the short name of a ref under refs/notes/. See NOTES MERGE
+   STRATEGIES section in linkgit:git-notes[1] for more information on the
+   available strategies.
+
 notes.displayRef::
The (fully qualified) refname from which to show notes when
showing commit messages.  The value of this variable can be set
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 89c8829a0543..b99809fc81a6 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -322,6 +322,12 @@ notes.mergestrategy::
 +
 This setting can be overridden by passing the `--strategy` option.
 
+notes.localref.mergestrategy::
+   Which strategy to choose when merging into localref. The set of
+   allowed values is the same as notes.mergestrategy. localref must be
+   the short name of a ref under refs/notes/. See NOTES MERGE STRATEGIES
+   section above for more information about each strategy.
+
 notes.displayRef::
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by `core.notesRef` or
diff --git a/builtin/notes.c b/builtin/notes.c
index 12a42b583f98..bdfd9c7d29b4 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -771,13 +771,13 @@ static int git_config_get_notes_strategy(const char *key,
 
 static int merge(int argc, const char **argv, const char *prefix)
 {
-   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
+   struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT, merge_key = 
STRBUF_INIT;
unsigned char result_sha1[20];
struct notes_tree *t;
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
int verbosity = 0, result;
-   const char *strategy = NULL;
+   const char *strategy = NULL, *short_ref = NULL;
struct option options[] = {
OPT_GROUP(N_(General options)),
OPT__VERBOSITY(verbosity),
@@ -833,7 +833,14 @@ static int merge(int argc, const char **argv, const char 
*prefix)
usage_with_options(git_notes_merge_usage, options);
}
} else {
-   git_config_get_notes_strategy(notes.mergestrategy, 
o.strategy);
+   if (!skip_prefix(o.local_ref, refs/notes/, short_ref))
+   die(Refusing to merge notes into %s (outside of 
refs/notes/),
+   o.local_ref);
+
+   strbuf_addf(merge_key, notes.%s.mergestrategy, short_ref);
+
+   if (git_config_get_notes_strategy(merge_key.buf, o.strategy))
+   git_config_get_notes_strategy(notes.mergestrategy, 
o.strategy);
}
 
t = init_notes_check(merge);
diff --git a/t/t3309-notes-merge-auto-resolve.sh 
b/t/t3309-notes-merge-auto-resolve.sh
index 476b9f5306f1..560e75259798 100755
--- a/t/t3309-notes-merge-auto-resolve.sh
+++ b/t/t3309-notes-merge-auto-resolve.sh
@@ -383,6 +383,17 @@ test_expect_success 'reset to pre-merge state (y)' '
verify_notes y y
 '
 
+test_expect_success 'merge z into y with ours per-ref configuration option 
= Non-conflicting 3-way merge' '
+   git -c notes.y.mergestrategy=ours notes merge z 
+   verify_notes y ours
+'
+
+test_expect_success 'reset to pre-merge state (y)' '
+   git update-ref refs/notes/y refs/notes/y^1 
+   # Verify pre-merge state
+   verify_notes y y
+'
+
 cat EOF | sort expect_notes_theirs

[PATCH v7 2/4] notes: add tests for --commit/--abort/--strategy exclusivity

2015-08-14 Thread Jacob Keller
From: Jacob Keller jacob.kel...@gmail.com

Add new tests to ensure that --commit, --abort, and --strategy are
mutually exclusive.

Signed-off-by: Jacob Keller jacob.kel...@gmail.com
---
 t/t3310-notes-merge-manual-resolve.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t3310-notes-merge-manual-resolve.sh 
b/t/t3310-notes-merge-manual-resolve.sh
index 195bb97f859d..d5572121da69 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -314,6 +314,18 @@ y and z notes on 1st commit
 
 EOF
 
+test_expect_success 'do not allow mixing --commit and --abort' '
+   test_must_fail git notes merge --commit --abort
+'
+
+test_expect_success 'do not allow mixing --commit and --strategy' '
+   test_must_fail git notes merge --commit --strategy theirs
+'
+
+test_expect_success 'do not allow mixing --abort and --strategy' '
+   test_must_fail git notes merge --abort --strategy theirs
+'
+
 test_expect_success 'finalize conflicting merge (z = m)' '
# Resolve conflicts and finalize merge
cat .git/NOTES_MERGE_WORKTREE/$commit_sha1 EOF 
-- 
2.5.0.280.g4aaba03

--
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


  1   2   3   4   5   6   7   8   9   10   >