Re: [PATCH v9 0/3] http-backend: respect CONTENT_LENGTH as specified by rfc3875

2018-07-26 Thread Max Kirillov
Only the 3rd patch has changed


[PATCH v9 3/3] http-backend: respect CONTENT_LENGTH for receive-pack

2018-07-26 Thread Max Kirillov
Push passes to another commands, as described in
https://public-inbox.org/git/20171129032214.gb32...@sigill.intra.peff.net/

As it gets complicated to correctly track the data length, instead transfer
the data through parent process and cut the pipe as the specified length is
reached. Do it only when CONTENT_LENGTH is set, otherwise pass the input
directly to the forked commands.

Add tests for cases:

* CONTENT_LENGTH is set, script's stdin has more data, with all combinations
  of variations: fetch or push, plain or compressed body, correct or truncated
  input.

* CONTENT_LENGTH is specified to a value which does not fit into ssize_t.

Helped-by: Junio C Hamano 
Signed-off-by: Max Kirillov 
---
 help.c |   1 +
 http-backend.c |  32 -
 t/t5562-http-backend-content-length.sh | 155 +
 t/t5562/invoke-with-content-length.pl  |  37 ++
 4 files changed, 223 insertions(+), 2 deletions(-)
 create mode 100755 t/t5562-http-backend-content-length.sh
 create mode 100755 t/t5562/invoke-with-content-length.pl

diff --git a/help.c b/help.c
index dd35fcc133..e469f5731c 100644
--- a/help.c
+++ b/help.c
@@ -609,6 +609,7 @@ int cmd_version(int argc, const char **argv, const char 
*prefix)
else
printf("no commit associated with this build\n");
printf("sizeof-long: %d\n", (int)sizeof(long));
+   printf("sizeof-size_t: %d\n", (int)sizeof(size_t));
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
}
return 0;
diff --git a/http-backend.c b/http-backend.c
index d0b6cb1b09..e88d29f62b 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -373,6 +373,8 @@ static void inflate_request(const char *prog_name, int out, 
int buffer_input, ss
unsigned char in_buf[8192];
unsigned char out_buf[8192];
unsigned long cnt = 0;
+   int req_len_defined = req_len >= 0;
+   size_t req_remaining_len = req_len;
 
memset(, 0, sizeof(stream));
git_inflate_init_gzip_only();
@@ -387,8 +389,15 @@ static void inflate_request(const char *prog_name, int 
out, int buffer_input, ss
n = read_request(0, _request, req_len);
stream.next_in = full_request;
} else {
-   n = xread(0, in_buf, sizeof(in_buf));
+   ssize_t buffer_len;
+   if (req_len_defined && req_remaining_len <= 
sizeof(in_buf))
+   buffer_len = req_remaining_len;
+   else
+   buffer_len = sizeof(in_buf);
+   n = xread(0, in_buf, buffer_len);
stream.next_in = in_buf;
+   if (req_len_defined && n > 0)
+   req_remaining_len -= n;
}
 
if (n <= 0)
@@ -431,6 +440,23 @@ static void copy_request(const char *prog_name, int out, 
ssize_t req_len)
free(buf);
 }
 
+static void pipe_fixed_length(const char *prog_name, int out, size_t req_len)
+{
+   unsigned char buf[8192];
+   size_t remaining_len = req_len;
+
+   while (remaining_len > 0) {
+   size_t chunk_length = remaining_len > sizeof(buf) ? sizeof(buf) 
: remaining_len;
+   ssize_t n = xread(0, buf, chunk_length);
+   if (n < 0)
+   die_errno("Reading request failed");
+   write_to_child(out, buf, n, prog_name);
+   remaining_len -= n;
+   }
+
+   close(out);
+}
+
 static void run_service(const char **argv, int buffer_input)
 {
const char *encoding = getenv("HTTP_CONTENT_ENCODING");
@@ -457,7 +483,7 @@ static void run_service(const char **argv, int buffer_input)
 "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
 
cld.argv = argv;
-   if (buffer_input || gzipped_request)
+   if (buffer_input || gzipped_request || req_len >= 0)
cld.in = -1;
cld.git_cmd = 1;
if (start_command())
@@ -468,6 +494,8 @@ static void run_service(const char **argv, int buffer_input)
inflate_request(argv[0], cld.in, buffer_input, req_len);
else if (buffer_input)
copy_request(argv[0], cld.in, req_len);
+   else if (req_len >= 0)
+   pipe_fixed_length(argv[0], cld.in, req_len);
else
close(0);
 
diff --git a/t/t5562-http-backend-content-length.sh 
b/t/t5562-http-backend-content-length.sh
new file mode 100755
index 00..057dcb85d6
--- /dev/null
+++ b/t/t5562-http-backend-content-length.sh
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+test_description='test git-http-backend respects CONTENT_LENGTH'
+. ./test-lib.sh
+
+test_lazy_prereq GZIP 'gzip --version'
+
+verify_http_result() {
+   # some fatal errors still produce status 200
+   # so check if there 

[PATCH v9 0/3] http-backend: respect CONTENT_LENGTH as specified by rfc3875

2018-07-26 Thread Max Kirillov
* fix the gzip usage as suggested in 
https://public-inbox.org/git/xmqqk1quvegh@gitster-ct.c.googlers.com/
* better explanation of why status check is needed
* redirect only the helper call, not the whole shell function, also move more 
into the shell function

Max Kirillov (3):
  http-backend: cleanup writing to child process
  http-backend: respect CONTENT_LENGTH as specified by rfc3875
  http-backend: respect CONTENT_LENGTH for receive-pack

 config.c   |   2 +-
 config.h   |   1 +
 help.c |   1 +
 http-backend.c | 100 +---
 t/t5562-http-backend-content-length.sh | 155 +
 t/t5562/invoke-with-content-length.pl  |  37 ++
 6 files changed, 281 insertions(+), 15 deletions(-)
 create mode 100755 t/t5562-http-backend-content-length.sh
 create mode 100755 t/t5562/invoke-with-content-length.pl

-- 
2.17.0.1185.g782057d875



[PATCH v9 2/3] http-backend: respect CONTENT_LENGTH as specified by rfc3875

2018-07-26 Thread Max Kirillov
http-backend reads whole input until EOF. However, the RFC 3875 specifies
that a script must read only as many bytes as specified by CONTENT_LENGTH
environment variable. Web server may exercise the specification by not closing
the script's standard input after writing content. In that case http-backend
would hang waiting for the input. The issue is known to happen with
IIS/Windows, for example.

Make http-backend read only CONTENT_LENGTH bytes, if it's defined, rather than
the whole input until EOF. If the variable is not defined, keep older behavior
of reading until EOF because it is used to support chunked transfer-encoding.

This commit only fixes buffered input, whcih reads whole body before
processign it. Non-buffered input is going to be fixed in subsequent commit.

Signed-off-by: Florian Manschwetus 
[mk: fixed trivial build failures and polished style issues]
Helped-by: Junio C Hamano 
Signed-off-by: Max Kirillov 
Signed-off-by: Junio C Hamano 
---
 config.c   |  2 +-
 config.h   |  1 +
 http-backend.c | 54 +++---
 3 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/config.c b/config.c
index fbbf0f8e9f..158afa858b 100644
--- a/config.c
+++ b/config.c
@@ -921,7 +921,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)
return 1;
 }
 
-static int git_parse_ssize_t(const char *value, ssize_t *ret)
+int git_parse_ssize_t(const char *value, ssize_t *ret)
 {
intmax_t tmp;
if (!git_parse_signed(value, , 
maximum_signed_value_of_type(ssize_t)))
diff --git a/config.h b/config.h
index cdac2fc73e..7808413bd0 100644
--- a/config.h
+++ b/config.h
@@ -73,6 +73,7 @@ extern void git_config(config_fn_t fn, void *);
 extern int config_with_options(config_fn_t fn, void *,
   struct git_config_source *config_source,
   const struct config_options *opts);
+extern int git_parse_ssize_t(const char *, ssize_t *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
diff --git a/http-backend.c b/http-backend.c
index cefdfd6fc6..d0b6cb1b09 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -290,7 +290,7 @@ static void write_to_child(int out, const unsigned char 
*buf, ssize_t len, const
  * hit max_request_buffer we die (we'd rather reject a
  * maliciously large request than chew up infinite memory).
  */
-static ssize_t read_request(int fd, unsigned char **out)
+static ssize_t read_request_eof(int fd, unsigned char **out)
 {
size_t len = 0, alloc = 8192;
unsigned char *buf = xmalloc(alloc);
@@ -327,7 +327,46 @@ static ssize_t read_request(int fd, unsigned char **out)
}
 }
 
-static void inflate_request(const char *prog_name, int out, int buffer_input)
+static ssize_t read_request_fixed_len(int fd, ssize_t req_len, unsigned char 
**out)
+{
+   unsigned char *buf = NULL;
+   ssize_t cnt = 0;
+
+   if (max_request_buffer < req_len) {
+   die("request was larger than our maximum size (%lu): "
+   "%" PRIuMAX "; try setting GIT_HTTP_MAX_REQUEST_BUFFER",
+   max_request_buffer, (uintmax_t)req_len);
+   }
+
+   buf = xmalloc(req_len);
+   cnt = read_in_full(fd, buf, req_len);
+   if (cnt < 0) {
+   free(buf);
+   return -1;
+   }
+   *out = buf;
+   return cnt;
+}
+
+static ssize_t get_content_length(void)
+{
+   ssize_t val = -1;
+   const char *str = getenv("CONTENT_LENGTH");
+
+   if (str && !git_parse_ssize_t(str, ))
+   die("failed to parse CONTENT_LENGTH: %s", str);
+   return val;
+}
+
+static ssize_t read_request(int fd, unsigned char **out, ssize_t req_len)
+{
+   if (req_len < 0)
+   return read_request_eof(fd, out);
+   else
+   return read_request_fixed_len(fd, req_len, out);
+}
+
+static void inflate_request(const char *prog_name, int out, int buffer_input, 
ssize_t req_len)
 {
git_zstream stream;
unsigned char *full_request = NULL;
@@ -345,7 +384,7 @@ static void inflate_request(const char *prog_name, int out, 
int buffer_input)
if (full_request)
n = 0; /* nothing left to read */
else
-   n = read_request(0, _request);
+   n = read_request(0, _request, req_len);
stream.next_in = full_request;
} else {
n = xread(0, in_buf, sizeof(in_buf));
@@ -381,10 +420,10 @@ static void inflate_request(const char *prog_name, int 
out, int buffer_input)
free(full_request);
 }
 
-static void copy_request(const char *prog_name, int out)
+static void copy_request(const char *prog_name, int out, ssize_t req_len)
 {
unsigned char *buf;
-   ssize_t n = 

[PATCH v9 1/3] http-backend: cleanup writing to child process

2018-07-26 Thread Max Kirillov
As explained in [1], we should not assume the reason why the writing has
failed, and even if the reason is that child has existed not the reason
why it have done so. So instead just say that writing has failed.

[1] https://public-inbox.org/git/20180604044408.gd14...@sigill.intra.peff.net/

Signed-off-by: Max Kirillov 
Signed-off-by: Junio C Hamano 
---
 http-backend.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/http-backend.c b/http-backend.c
index adaef16fad..cefdfd6fc6 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -279,6 +279,12 @@ static struct rpc_service *select_service(struct strbuf 
*hdr, const char *name)
return svc;
 }
 
+static void write_to_child(int out, const unsigned char *buf, ssize_t len, 
const char *prog_name)
+{
+   if (write_in_full(out, buf, len) < 0)
+   die("unable to write to '%s'", prog_name);
+}
+
 /*
  * This is basically strbuf_read(), except that if we
  * hit max_request_buffer we die (we'd rather reject a
@@ -361,9 +367,8 @@ static void inflate_request(const char *prog_name, int out, 
int buffer_input)
die("zlib error inflating request, result %d", 
ret);
 
n = stream.total_out - cnt;
-   if (write_in_full(out, out_buf, n) < 0)
-   die("%s aborted reading request", prog_name);
-   cnt += n;
+   write_to_child(out, out_buf, stream.total_out - cnt, 
prog_name);
+   cnt = stream.total_out;
 
if (ret == Z_STREAM_END)
goto done;
@@ -382,8 +387,7 @@ static void copy_request(const char *prog_name, int out)
ssize_t n = read_request(0, );
if (n < 0)
die_errno("error reading request body");
-   if (write_in_full(out, buf, n) < 0)
-   die("%s aborted reading request", prog_name);
+   write_to_child(out, buf, n, prog_name);
close(out);
free(buf);
 }
-- 
2.17.0.1185.g782057d875



Greetings in the name of God, Business proposal in God we trust

2018-07-26 Thread Mrs, Suran Yoda
Greetings in the name of God

Dear Friend


Greetings in the name of God,please let this not sound strange to you
for my only surviving lawyer who would have done this died early this
year.I prayed and got your email id from your country guestbook. I am
Mrs Suran Yoda from London,I am 72 years old,i am suffering from a
long time cancer of the lungs which also affected my brain,from all
indication my conditions is really deteriorating and it is quite
obvious that,according to my doctors they have advised me that i may
not live for the next two months,this is because the cancer stage has
gotten to a very bad stage.I am married to (Dr Andrews Yoda) who
worked with the Embassy of United Kingdom in South

Africa for nine years,Before he died in 2004.

I was bred up from a motherless babies home and was married to my late
husband for Thirty years without a child,my husband died in a fatal
motor accident Before his death we were true believers.Since his death
I decided not to re-marry,I sold all my inherited belongings and
deposited all the sum of $6.5 Million dollars with Bank in South
Africa.Though what disturbs me mostly is the cancer. Having known my
condition I decided to donate this fund to church,i want you as God
fearing person,to also use this money to fund church,orphanages and
widows,I took this decision,before i rest in peace because my time
will so on be up.

The Bible made us to understand that blessed are the hands that
giveth. I took this decision because I don`t have any child that will
inherit this money and my husband's relatives are not Christians and I
don`t want my husband hard earned money to be misused by unbelievers.
I don`t want a situation where these money will be used in an ungodly
manner,hence the reason for taking this bold decision.I am not afraid
of death hence i know where am going.Presently,I'm with my laptop in a
hospital here in London where I have been undergoing treatment for
cancer of the lungs.

As soon as I receive your reply I shall give you the contact of the
Bank.I will also issue you a letter of authority that will prove you
as the new beneficiary of my fund.Please assure me that you will act
accordingly as I stated.Hoping to hear from you soon.

Remain blessed in the name of the Lord.

Yours in Christ,
Mrs Suran Yoda


Re: [PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread chen bin
Hi, Luke,
Running the hook after applying changes to P4 shadow repo might not be
a good idea.

When the hook is running *before* the changes are applied, I'm 100% sure it's
*only* my code's problem if the hook fails.

One reason we need this hook is sometimes developer is over confident
when applying
some quick one line fix.

The quick fix could be required by business guy before demo to senior
managers or customers.
So we might not want our fix being blocked by upstream commits.

Not everyone is our team is perforce/git expert. Someone only use
`git-p4 submit` and never use
 `git-p4 rebase`. If unit test fails and he could not submit code, he
would come to me for help. But I
want to reduce my workload.


Regards,
Chen


On Fri, Jul 27, 2018 at 7:09 AM, Luke Diamand  wrote:
> On 26 July 2018 at 10:21, Eric Sunshine  wrote:
>> On Wed, Jul 25, 2018 at 10:08 PM chen bin  wrote:
>>> The hook does not receive any information or input from git. The
>>> original requirement
>>> comes from my colleague. He want to run unit test automatically before
>>> submitting code
>>> to remote repository. Or else CI server will send the blame mail to the 
>>> manager.
>>
>> Okay, that seems in line with a hook such as pre-commit. Please do
>> update the documentation to mention that the hook takes no arguments
>> and nothing on standard input, and perhaps describe in the
>> documentation an example use-case (as you did here).
>>
>> I'm not a p4 or git-p4 user, but, out of curiosity, would there be any
>> information which could be supplied to the hook as arguments or
>> standard input (or both) which would help the hook author implement
>> the hook more easily? Perhaps such information would be fodder for a
>> future enhancement (not necessarily needed for this patch).
>
>
> I tried to think of a use-case for a hook requiring any more
> information, but I can't think of any. You're already chdir()'d to the
> P4 shadow repo which is what you really need.
>
> Anything where you just need the commit hash (e.g. checking the commit
> message) can already be done with one of the existing git hooks; I
> don't think git-p4 needs to duplicate that.
>
> And we can't write a commit hook that can know about the Perforce
> changelist, because we don't know what it is yet.
>
> However, looking at the code, it runs the hook at the point just
> *before* the changes are applied to the P4 shadow repo. Would it make
> more sense to run the hook *after* they have been applied (but before
> being P4 submitted) ?
>
> That way you can run your tests on the checked-out P4 shadow directory
> with your changes - as it stands, you can only run them on your git
> repo at this point, which might not be in sync with Perforce (and
> could be quite a long way out in fact).
>
> Luke
>
>
>>
>>> The hook actually stops the submit process from start instead of abort
>>> submit in midway.
>>> So nothing is touched when hook exits with status 1.
>>
>> This might be a good thing to add to the documentation, as well.
>>
>>> I'm not sure whether `git-p4` should print some "hook rejection" message.
>>> Current implementation is same as other hooks (`pre-commit`, for example).
>>> Only hook itself is responsible to print error messages.
>>>
>>> Personally I don't have opinion whether we should print out hook
>>> related message inside
>>> `git-p4.py`. I just try to following existing convention of git.
>>>
>>> What you guys think?
>>
>> Following existing practice makes sense. It can always be revisited
>> later if needed.
>>
>> Thanks.



-- 
help me, help you.


[RFC PATCH 0/3] Migrate the refs API to take the repository argument

2018-07-26 Thread Stefan Beller
The second patch is the real API proposal.
Unlike the lookup_* series, which caused a lot of integration pain to Junio,
I plan to structure this in a different way, by having multiple steps:

 (1) in this (later to be non-RFC) series, add the new API that passes thru
 the repository; for now do not replace refs_store argument by
 struct repository.
 (2) the last patch is a demo of converting one of the callers over
 to the new API; this would need to be done for all of them
 
 (3) After some time do a cleanup series to remove callers of the
 old API fromly introduced series that are currently in flight.
 (4) Remove the old API.

 (5) Introduce the final API removing the refs_store
 (6) convert all callers to the final API, using this same dual step approach
 (7) remove this API
 
Steps 1,2 will be done in this series (2 is done only as demo here
for one function, but the non-RFC would do it all)

Steps 3,4 would be done once there are no more series in flight using
the old API.

Before continuing on step (2), I would want to ask for your thoughts
of (1).

Also note that after step (1) before (4) refs.h looks messy as well as
between (5) and (7).

Thanks,
Stefan


Stefan Beller (3):
  refs.c: migrate internal ref iteration to pass thru repository
argument
  refs: introduce new API, wrap old API shallowly around new API
  replace: migrate to for_each_replace_repo_ref

 builtin/replace.c|   9 +-
 refs.c   | 187 ++
 refs.h   | 362 ++-
 refs/iterator.c  |   6 +-
 refs/refs-internal.h |   5 +-
 replace-object.c |   7 +-
 6 files changed, 464 insertions(+), 112 deletions(-)

-- 
2.18.0.345.g5c9ce644c3-goog



[PATCH 2/3] refs: introduce new API, wrap old API shallowly around new API

2018-07-26 Thread Stefan Beller
Currently the refs API takes a 'ref_store' as an argument to specify
which ref store to iterate over; however it is more useful to specify
the repository instead (or later a specific worktree of a repository).

Introduce a new API, that takes a repository struct instead of a ref store;
the repository argument is also passed through to the callback, which is
of type 'each_repo_ref_fn' that is introduced in a previous patch and is
an extension of the 'each_ref_fn' type with the additional repository
argument.

We wrap the old API as in a very shallow way around the new API,
by wrapping the callback and the callback data into a new callback
to translate between the 'each_ref_fn' and 'each_repo_ref_fn' type.

The wrapping implementation could be done either in refs.c or as presented
in this patch as a 'static inline' in the header file itself. This has the
advantage that the line of the old API is changed (and not just its
implementation in refs.c), such that it will show up in git-blame.

The new API is not perfect yet, as some of them take both a 'repository'
and 'ref_store' argument. This is done for an easy migration:
If the ref_store argument is non-NULL, prefer it over the repository
to compute which refs to iterate over. That way we can ensure that this
step of API migration doesn't confuse which ref store to work on.

Once all callers have migrated to this newly introduced API, we can
get rid of the old API; a second migration step in the future will remove
the then useless ref_store argument

Signed-off-by: Stefan Beller 
---
 refs.c | 158 +++---
 refs.h | 352 +++--
 2 files changed, 407 insertions(+), 103 deletions(-)

diff --git a/refs.c b/refs.c
index 2513f77acb3..27e3772fca9 100644
--- a/refs.c
+++ b/refs.c
@@ -217,7 +217,7 @@ char *resolve_refdup(const char *refname, int resolve_flags,
 /* The argument to filter_refs */
 struct ref_filter {
const char *pattern;
-   each_ref_fn *fn;
+   each_repo_ref_fn *fn;
void *cb_data;
 };
 
@@ -289,14 +289,15 @@ int ref_filter_match(const char *refname,
return 1;
 }
 
-static int filter_refs(const char *refname, const struct object_id *oid,
-  int flags, void *data)
+static int filter_refs(struct repository *r,
+  const char *refname, const struct object_id *oid,
+  int flags, void *data)
 {
struct ref_filter *filter = (struct ref_filter *)data;
 
if (wildmatch(filter->pattern, refname, 0))
return 0;
-   return filter->fn(refname, oid, flags, filter->cb_data);
+   return filter->fn(r, refname, oid, flags, filter->cb_data);
 }
 
 enum peel_status peel_object(const struct object_id *name, struct object_id 
*oid)
@@ -371,46 +372,50 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, 
const struct string_li
for_each_rawref(warn_if_dangling_symref, );
 }
 
-int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void 
*cb_data)
+int refs_for_each_tag_repo_ref(struct repository *r, each_repo_ref_fn fn, void 
*cb_data)
 {
-   return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data);
+   return refs_for_each_repo_ref_in(r, NULL, "refs/tags/", fn, cb_data);
 }
 
-int for_each_tag_ref(each_ref_fn fn, void *cb_data)
+int for_each_tag_repo_ref(struct repository *r, each_repo_ref_fn fn, void 
*cb_data)
 {
-   return refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, 
cb_data);
+   return refs_for_each_tag_repo_ref(r, fn, cb_data);
 }
 
-int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void 
*cb_data)
+int refs_for_each_branch_repo_ref(struct repository *r, struct ref_store *refs,
+ each_repo_ref_fn fn, void *cb_data)
 {
-   return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data);
+   return refs_for_each_repo_ref_in(r, refs, "refs/heads/", fn, cb_data);
 }
 
-int for_each_branch_ref(each_ref_fn fn, void *cb_data)
+int for_each_branch_repo_ref(struct repository *r, each_repo_ref_fn fn, void 
*cb_data)
 {
-   return refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, 
cb_data);
+   return refs_for_each_branch_repo_ref(r, NULL, fn, cb_data);
 }
 
-int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void 
*cb_data)
+int refs_for_each_remote_repo_ref(struct repository *r, struct ref_store *refs,
+ each_repo_ref_fn fn, void *cb_data)
 {
-   return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data);
+   return refs_for_each_repo_ref_in(r, refs, "refs/remotes/", fn, cb_data);
 }
 
-int for_each_remote_ref(each_ref_fn fn, void *cb_data)
+int for_each_remote_repo_ref(struct repository *r, each_repo_ref_fn fn, void 
*cb_data)
 {
-   return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, 
cb_data);
+   return 

[PATCH 3/3] replace: migrate to for_each_replace_repo_ref

2018-07-26 Thread Stefan Beller
By upgrading the replace mechanism works well for all repositories

Signed-off-by: Stefan Beller 
---
 builtin/replace.c | 9 +
 replace-object.c  | 7 ---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index ef22d724bbc..fd8a935eb77 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -39,7 +39,8 @@ struct show_data {
enum replace_format format;
 };
 
-static int show_reference(const char *refname, const struct object_id *oid,
+static int show_reference(struct repository *r, const char *refname,
+ const struct object_id *oid,
  int flag, void *cb_data)
 {
struct show_data *data = cb_data;
@@ -56,9 +57,9 @@ static int show_reference(const char *refname, const struct 
object_id *oid,
if (get_oid(refname, ))
return error("Failed to resolve '%s' as a valid 
ref.", refname);
 
-   obj_type = oid_object_info(the_repository, ,
+   obj_type = oid_object_info(r, ,
   NULL);
-   repl_type = oid_object_info(the_repository, oid, NULL);
+   repl_type = oid_object_info(r, oid, NULL);
 
printf("%s (%s) -> %s (%s)\n", refname, 
type_name(obj_type),
   oid_to_hex(oid), type_name(repl_type));
@@ -87,7 +88,7 @@ static int list_replace_refs(const char *pattern, const char 
*format)
 "valid formats are 'short', 'medium' and 'long'\n",
 format);
 
-   for_each_replace_ref(the_repository, show_reference, (void *));
+   for_each_replace_repo_ref(the_repository, show_reference, (void 
*));
 
return 0;
 }
diff --git a/replace-object.c b/replace-object.c
index 801b5c16789..c0457b8048c 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -6,7 +6,8 @@
 #include "repository.h"
 #include "commit.h"
 
-static int register_replace_ref(const char *refname,
+static int register_replace_ref(struct repository *r,
+   const char *refname,
const struct object_id *oid,
int flag, void *cb_data)
 {
@@ -25,7 +26,7 @@ static int register_replace_ref(const char *refname,
oidcpy(_obj->replacement, oid);
 
/* Register new object */
-   if (oidmap_put(the_repository->objects->replace_map, repl_obj))
+   if (oidmap_put(r->objects->replace_map, repl_obj))
die("duplicate replace ref: %s", refname);
 
return 0;
@@ -40,7 +41,7 @@ static void prepare_replace_object(struct repository *r)
xmalloc(sizeof(*r->objects->replace_map));
oidmap_init(r->objects->replace_map, 0);
 
-   for_each_replace_ref(r, register_replace_ref, NULL);
+   for_each_replace_repo_ref(r, register_replace_ref, NULL);
 }
 
 /* We allow "recursive" replacement. Only within reason, though */
-- 
2.18.0.345.g5c9ce644c3-goog



[PATCH 1/3] refs.c: migrate internal ref iteration to pass thru repository argument

2018-07-26 Thread Stefan Beller
In 60ce76d3581 (refs: add repository argument to for_each_replace_ref,
2018-04-11) and 0d296c57aec (refs: allow for_each_replace_ref to handle
arbitrary repositories, 2018-04-11), for_each_replace_ref learned how
to iterate over refs by a given arbitrary repository.
New attempts in the object store conversion have shown that it is useful
to have the repository handle available that the refs iteration is
currently iterating over.

To achieve this goal we will need to add a repository argument to
each_ref_fn in refs.h. However as many callers rely on the signature
such a patch would be too large.

So convert the internals of the ref subsystem first to pass through a
repository argument without exposing the change to the user. Assume
the_repository for the passed through repository, although it is not
used anywhere yet.

Signed-off-by: Stefan Beller 
---
 refs.c   | 39 +--
 refs.h   | 10 ++
 refs/iterator.c  |  6 +++---
 refs/refs-internal.h |  5 +++--
 4 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/refs.c b/refs.c
index fcfd3171e83..2513f77acb3 100644
--- a/refs.c
+++ b/refs.c
@@ -1390,17 +1390,50 @@ struct ref_iterator *refs_ref_iterator_begin(
  * non-zero value, stop the iteration and return that value;
  * otherwise, return 0.
  */
+static int do_for_each_repo_ref(struct repository *r, const char *prefix,
+   each_repo_ref_fn fn, int trim, int flags,
+   void *cb_data)
+{
+   struct ref_iterator *iter;
+   struct ref_store *refs = get_main_ref_store(r);
+
+   if (!refs)
+   return 0;
+
+   iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
+
+   return do_for_each_repo_ref_iterator(r, iter, fn, cb_data);
+}
+
+struct do_for_each_ref_help {
+   each_ref_fn *fn;
+   void *cb_data;
+};
+
+static int do_for_each_ref_helper(struct repository *r,
+ const char *refname,
+ const struct object_id *oid,
+ int flags,
+ void *cb_data)
+{
+   struct do_for_each_ref_help *hp = cb_data;
+
+   return hp->fn(refname, oid, flags, hp->cb_data);
+}
+
 static int do_for_each_ref(struct ref_store *refs, const char *prefix,
   each_ref_fn fn, int trim, int flags, void *cb_data)
 {
struct ref_iterator *iter;
+   struct do_for_each_ref_help hp = { fn, cb_data };
 
if (!refs)
return 0;
 
iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
 
-   return do_for_each_ref_iterator(iter, fn, cb_data);
+   return do_for_each_repo_ref_iterator(the_repository, iter,
+   do_for_each_ref_helper, );
 }
 
 int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
@@ -2029,10 +2062,12 @@ int refs_verify_refname_available(struct ref_store 
*refs,
 int refs_for_each_reflog(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
struct ref_iterator *iter;
+   struct do_for_each_ref_help hp = { fn, cb_data };
 
iter = refs->be->reflog_iterator_begin(refs);
 
-   return do_for_each_ref_iterator(iter, fn, cb_data);
+   return do_for_each_repo_ref_iterator(the_repository, iter,
+do_for_each_ref_helper, );
 }
 
 int for_each_reflog(each_ref_fn fn, void *cb_data)
diff --git a/refs.h b/refs.h
index cc2fb4c68c0..80eec8bbc68 100644
--- a/refs.h
+++ b/refs.h
@@ -274,6 +274,16 @@ struct ref_transaction;
 typedef int each_ref_fn(const char *refname,
const struct object_id *oid, int flags, void *cb_data);
 
+/*
+ * The same as each_ref_fn, but also with a repository argument that
+ * contains the repository associated with the callback.
+ */
+typedef int each_repo_ref_fn(struct repository *r,
+const char *refname,
+const struct object_id *oid,
+int flags,
+void *cb_data);
+
 /*
  * The following functions invoke the specified callback function for
  * each reference indicated.  If the function ever returns a nonzero
diff --git a/refs/iterator.c b/refs/iterator.c
index 2ac91ac3401..629e00a122a 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -407,15 +407,15 @@ struct ref_iterator *prefix_ref_iterator_begin(struct 
ref_iterator *iter0,
 
 struct ref_iterator *current_ref_iter = NULL;
 
-int do_for_each_ref_iterator(struct ref_iterator *iter,
-each_ref_fn fn, void *cb_data)
+int do_for_each_repo_ref_iterator(struct repository *r, struct ref_iterator 
*iter,
+ each_repo_ref_fn fn, void *cb_data)
 {
int retval = 0, ok;
struct ref_iterator *old_ref_iter = current_ref_iter;
 
current_ref_iter = iter;
while 

Dear Friend Please Read!!!

2018-07-26 Thread Shilvock Dora




 Dear Beloved,

 

 

My name is Shilvock Dora, I am 59 Years old  Born and brought up in Dallas Texas,USA but I am from Canada. I have lived all my life in the  USA. Last year I experienced restlessness and sleepless nights so my Doctor in New York USA sent me on a general Medical Check up at the Methodist hospital and I was finally diagnosed to have cancer of the Lungs. So my Doctor flew me back to my country Canada.

 

 

My late husbands brother wanted me dead so that he will inherit all the wealth and properties i and my late Husband suffered to build because we don't have a child. As a Christian I rather donate my money to the less privileged, orphanage homes and the Church than allow wicked people to take all when I die. Lately I discovered that my late husband??s relation know about the deposited money and they are happy that I will soon die so that they can take the money, so I will give the claim information to you before I pass on to glory.

 

 

I will give you all the details that will assist you in getting the Funds deposited with the security Company. We deposited the total of US$5,600.000.00 (Five  million Six Hundred Thousand united states dollars) in cash is with the security company in USA.As soon as you accept my offer I we direct you to my family Lawyer here in New Jersey, who will assist you get the money transfer into your bank account without any delay and he will provide you with the deposit certificate to the

fund.I want to have an assurance from you that even when I die,you will not use the money wrongly and will do your best to get it from the bank in USA. I will die happily if I know you will use my funds in a manner pleasing to humanity and God when you get it.I have to rest now due to my unusual weakness. Please pray for me my dear and respond urgently to my message so that I can be able to conclude the inheritance Hand over Authorization before I die.

 

I anxiously await your response my dear.Please Kindly reply to my private email address: shilvocksdo...@zoho.com

 

 

Best Regards,

Shilvock Dora




Admin Help Desk.

2018-07-26 Thread Christine Lawrence
Dear User,

All staffs/students email address has been authorized for transition from 
Microsoft Outlook interface, to Google’s Gmail interface. Please 

 
Click-Here
 to Fill and Submit, in order to upgrade your email account now.

Admin Help Desk.


Re: [PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread Eric Sunshine
On Thu, Jul 26, 2018 at 12:49 PM Junio C Hamano  wrote:
> Chen Bin  writes:
> > + git p4 submit --dry-run >out && grep "Would apply" out || 
> > echo "Abort submit"
>
> What is this last "|| echo I always succeed" about?
>
> Do you want to make sure "git p4 submit" exit with non-zero exit
> status *and* its output does not say "Would apply"?  The way to
> write that would be
>
> test_must_fail git p4 submit --dry-run >out &&
> ! grep "Would apply" out

I missed the 'test_must_fail' when I suggested this same rewrite[1],
which may explain why the suggestion wasn't used in the re-roll.
Sorry.

[1]: 
https://public-inbox.org/git/capig+cr2gyewotvbmrde35rn9ovsixeerbm5ijv+fmnoibw...@mail.gmail.com/


Re: [PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread Luke Diamand
On 26 July 2018 at 10:21, Eric Sunshine  wrote:
> On Wed, Jul 25, 2018 at 10:08 PM chen bin  wrote:
>> The hook does not receive any information or input from git. The
>> original requirement
>> comes from my colleague. He want to run unit test automatically before
>> submitting code
>> to remote repository. Or else CI server will send the blame mail to the 
>> manager.
>
> Okay, that seems in line with a hook such as pre-commit. Please do
> update the documentation to mention that the hook takes no arguments
> and nothing on standard input, and perhaps describe in the
> documentation an example use-case (as you did here).
>
> I'm not a p4 or git-p4 user, but, out of curiosity, would there be any
> information which could be supplied to the hook as arguments or
> standard input (or both) which would help the hook author implement
> the hook more easily? Perhaps such information would be fodder for a
> future enhancement (not necessarily needed for this patch).


I tried to think of a use-case for a hook requiring any more
information, but I can't think of any. You're already chdir()'d to the
P4 shadow repo which is what you really need.

Anything where you just need the commit hash (e.g. checking the commit
message) can already be done with one of the existing git hooks; I
don't think git-p4 needs to duplicate that.

And we can't write a commit hook that can know about the Perforce
changelist, because we don't know what it is yet.

However, looking at the code, it runs the hook at the point just
*before* the changes are applied to the P4 shadow repo. Would it make
more sense to run the hook *after* they have been applied (but before
being P4 submitted) ?

That way you can run your tests on the checked-out P4 shadow directory
with your changes - as it stands, you can only run them on your git
repo at this point, which might not be in sync with Perforce (and
could be quite a long way out in fact).

Luke


>
>> The hook actually stops the submit process from start instead of abort
>> submit in midway.
>> So nothing is touched when hook exits with status 1.
>
> This might be a good thing to add to the documentation, as well.
>
>> I'm not sure whether `git-p4` should print some "hook rejection" message.
>> Current implementation is same as other hooks (`pre-commit`, for example).
>> Only hook itself is responsible to print error messages.
>>
>> Personally I don't have opinion whether we should print out hook
>> related message inside
>> `git-p4.py`. I just try to following existing convention of git.
>>
>> What you guys think?
>
> Following existing practice makes sense. It can always be revisited
> later if needed.
>
> Thanks.


Re: [RFC PATCH 2/5] format-patch: add --range-diff option to embed diff in cover letter

2018-07-26 Thread Eric Sunshine
On Thu, Jul 26, 2018 at 6:56 AM Johannes Schindelin
 wrote:
> On Tue, 17 Jul 2018, Eric Sunshine wrote:
> > On Tue, Jul 17, 2018 at 6:31 AM Johannes Schindelin
> >  wrote:
> > > BTW I like to have an extra space in front of all the range-diff lines, to
> > > make it easier to discern them from the rest.
> >
> > I'm not sure what you mean. Perhaps I'm misreading your comment.
>
> Sorry, I was really unclear.
>
> In the cover letters sent out by GitGitGadget (or earlier, my
> mail-patch-series.sh command), I took pains to indent the entire
> range-diff (or interdiff) with a single space. That is, the footer
> "Range-diff vs v:" is not indented at all, but all subsequent lines of
> the range-diff have a leading space.
>
> The original reason was to stop confusing `git apply` when sending an
> interdiff as part of a single patch without a cover letter (in which case
> mail-patch-series.sh inserted the interdiff below the `---` marker, and
> the interdiff would have looked like the start of the real diff
> otherwise).

The new version[1] likewise indents the interdiff to avoid confusing
git-am / git-apply.

[1]: 
https://public-inbox.org/git/20180722095717.17912-1-sunsh...@sunshineco.com/

> In the meantime, I got used to this indentation so much that I do not want
> to miss it, it is a relatively easy and intuitive visual marker.
>
> This, however, will be harder to achieve now that you are using the
> libified range-diff.

I toyed with indenting the range-diff in both the cover letter and
below the "---" line in a patch. With the libified range-diff, doing
so involves modifying the range-diff implementation (rather than
having the consumer of the range-diff manage the indentation locally),
so it adds a bit of complexity to show_range_diff(), though perhaps
not too much.

However, I opted against it for a few reasons. First, "header" lines
apart, all lines of the range-diff are already indented, and the
existing indentation was sufficient (for me, at least) as a visual
marker. Second, range-diffs tend to be _wide_, especially the header
lines, and I was loath to make it wider by indenting more. Third, due
to the existing indentation of the diff proper, a range-diff won't
confuse git-am / git-apply, nor will the unindented header lines, so
extra indentation seemed superfluous.

> > > > @@ -1438,6 +1480,7 @@ int cmd_format_patch(int argc, const char **argv, 
> > > > const char *prefix)
> > > > + const char *range_diff = NULL;
> > >
> > > Maybe `range_diff_opt`? It's not exactly the range diff that is contained
> > > in this variable.
> >
> > I could, though I was trying to keep it shorter rather than longer.
> > This is still the same in the re-roll, but I can rename it if you
> > insist.
>
> I think it will confuse me in the future if I read `range_diff` and even
> the data type suggests that it could hold the output of a `git range-diff
> ` run.
>
> So I would like to insist.

In the new version[1], this variable is named 'rdiff_prev' (the
"previous" version against which the range-diff is to be generated).

> > > > +format_patch () {
> > > > + title=$1 &&
> > > > + range=$2 &&
> > > > + test_expect_success "format-patch --range-diff ($title)" '
> > > > + git format-patch --stdout --cover-letter 
> > > > --range-diff=$range \
> > > > + master..unmodified >actual &&
> > > > + grep "= 1: .* s/5/A" actual &&
> > > > + grep "= 2: .* s/4/A" actual &&
> > > > + grep "= 3: .* s/11/B" actual &&
> > > > + grep "= 4: .* s/12/B" actual
> > >
> > > I guess this might make sense if `format_patch` was not a function, but it
> > > is specifically marked as a function... so... shouldn't these `grep`s also
> > > be using function parameters?
> >
> > A later patch adds a second test which specifies the same ranges but
> > in a different way, so the result will be the same, hence the
> > hard-coded grep'ing. The function avoids repetition across the two
> > tests. I suppose I could do this a bit differently, though, to avoid
> > pretending it's a general-purpose function.
>
> If you can think of a way that would make this easier to read for, say,
> myself if I ever find myself debugging a regression caught by this test, I
> would appreciate that.

In the new version, the function is gone; it looks like this:

--- >8 ---
for prev in topic master..topic
do
test_expect_success "format-patch --range-diff=$prev" '
git format-patch --stdout --cover-letter --range-diff=$prev \
master..unmodified >actual &&
grep "= 1: .* s/5/A" actual &&
grep "= 2: .* s/4/A" actual &&
grep "= 3: .* s/11/B" actual &&
grep "= 4: .* s/12/B" actual
'
done
--- >8 ---


Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Jeff King
On Thu, Jul 26, 2018 at 09:57:42AM -0700, Junio C Hamano wrote:

> Jeff King  writes:
> 
> > On Wed, Jul 25, 2018 at 03:13:37PM -0700, Junio C Hamano wrote:
> >
> >> * jk/banned-function (2018-07-24) 5 commits
> >>  - banned.h: mark strncpy() as banned
> >>  - banned.h: mark sprintf() as banned
> >>  - banned.h: mark strcat() as banned
> >>  - automatically ban strcpy()
> >>  - Merge branch 'sb/blame-color' into jk/banned-function
> >> 
> >>  It is too easy to misuse system API functions such as strcat();
> >>  these selected functions are now forbidden in this codebase and
> >>  will cause a compilation failure.
> >> 
> >>  Will merge to 'next'.
> >
> > Eric nudged me over the fence to use a slightly different mechanism to
> > generate the error. See:
> >
> >   https://public-inbox.org/git/20180726072105.ga6...@sigill.intra.peff.net/
> >
> > It looks like sb/blame-color graduated, so this could also just be
> > applied directly on master now to avoid the funky merge.
> 
> OK.  Is it that "you cannot call a variable" thing?

We don't try to call it, but rather just mention it. It's just that the
compiler is more strict about undeclared variables than it is about
undeclared functions.

-Peff


Compliment of the day to you Dear Friend.

2018-07-26 Thread Mrs. Amina Kadi
 Compliment of the day to you Dear Friend.

Dear Friend.
 
  I am Mrs. Amina Kadi. am sending this brief letter to solicit your
partnership to transfer $5.5 million US Dollars. I shall send you
more information and procedures when I receive positive response from
you.

Mrs. Amina Kadi









Re: [PATCH v1 0/3] [RFC] Speeding up checkout (and merge, rebase, etc)

2018-07-26 Thread Junio C Hamano
Duy Nguyen  writes:

> I'm excited so I decided to try out anyway. This is what I've come up
> with. Switching trees on git.git shows it could skip plenty entries,
> so promising. It's ugly and it fails at t6020 though, there's still
> work ahead. But I think it'll stop here.

We are extremely shallow compared to projects like the kernel and
stuff from java land, so that is quite an interesting find.



Re: [PATCH v5 1/4] add -p: select individual hunk lines

2018-07-26 Thread Junio C Hamano
Phillip Wood  writes:

> +sub label_hunk_lines {
> + my $hunk = shift;
> + my $text = $hunk->{TEXT};
> + my (@line_flags, @lines);
> + my ($block, $label, $last_mode) = (0, 0, '');
> + for my $line (1..$#{$text}) {

$text is a ref to an array so @$text is the whole thing, $#{$text}
is the index of the last item in that array, and $text->[0] is the
first element of that array.  This for loop runs with $line == 1
thru $line == $#{$text}, so we are somehow excluding the very first
element?

> + $line_flags[$line] = 0;
> + my $mode = substr($text->[$line], 0, 1);
> + if ($mode eq '\\') {
> + $line_flags[$line - 1] |= NO_NEWLINE;
> + }
> + if ($mode eq '-' or $mode eq '+') {
> + $lines[++$label] = $line;
> + }
> + }
> + if ($label > 1) {


Re: [RFC PATCH v5 2/4] add -p: select modified lines correctly

2018-07-26 Thread Junio C Hamano
Phillip Wood  writes:

An interesting problem you are solving ;-)

> For example given the hunk
>   1 -* a longer description of the
>   2 -  first item
>   3 -* second
>   4 -* third
>   5 +* first
>   6 +  second item
>   7 +* the third item
>
> If the user selects 1,2,4–5,7 then we should generate
>   -* a longer description of the
>   -  first item
>   +* first
>* second
>   -* third
>   +* the third item

I understood this example as "3 that is removal and 6 that is
addition are excluded---we consider that these two lines (one in the
pre-image and the other in the post-image) are _matching".  As we
are excluding a deletion, it becomes the common context line, and
any removal or addition that appear before that must stay to happen
before the common context line (i.e. removal of 1 and 2, and
addition of 5, both precede common context line "second") and any
removal or addition that appear after that must stay after the
common context (i.e. removal of "third" and addition of "the third
item" come after "second").

But then it is not clear to me what you mean by "group" below.  What
groups does the above example have?  Ones before the retained
"second" (i.e. removal 1, 2, 4 and addition 5) form one group and
ones after it (i.e. removal 4 and addition 7) form another group?

> Reported-by: Ævar Arnfjörð Bjarmason 

Is this fixing any bug?  I usually see "Reported-by" only for a
bugfix patch but this seems to be adding a new feature (and lack of
feature is usually not a bug).


Re: [PATCH] negotiator/skipping: skip commits during fetch

2018-07-26 Thread Jonathan Tan
> Hi Jonathan,
> 
> On Mon, 16 Jul 2018, Jonathan Tan wrote:
> 
> >  t/t5552-skipping-fetch-negotiator.sh | 179 +++
> 
> This test seems to be failing consistently in the recent `pu` builds:
> 
> https://git-for-windows.visualstudio.com/git/_build/results?buildId=14337=logs
> 
> Could you have a look, please?

Hmm...on my Linux computer, this test passes on both pu (as of the time
of writing) and 838143aa5c ("Merge branch 'ab/newhash-is-sha256' into
pu", 2018-07-25) (pu at the time of that build, according to the website
you linked above). If you could rerun that test with additional code,
could you add a "cat trace" and show me what the client sends? When I do
that, the relevant parts are:

  packet:fetch> have 9ab46928dc282aa09f4dbf96893a252e058e7e8e
  packet:fetch> have dc824fafb05f3229aedf1f320bbe572e35364dfe
  packet:fetch> have caef059de69917b9119176a11b88afcef769331d
  packet:fetch> have 41bd8dc092ee110ba80e350a346ec507ab2e42a0
  packet:fetch> have e9a2c092a8e911567a377c881a7f6031e7f892ea
  packet:fetch> done

which is exactly as I (and the test) expect.

Two possible reasons for the discrepancy that I can think of offhand are
that (1) my computer generates different commits from your test system,
and (2) the priority queue pops commits in a different order. For (1),
that's not possible because the SHA-1s are the same (as can be seen by
comparing your link and the "have" lines I quoted above), and for (2),
the code seems OK:

  static int compare(const void *a_, const void *b_, void *unused)
  {
const struct entry *a = a_;
const struct entry *b = b_;
return compare_commits_by_commit_date(a->commit, b->commit, NULL);
  }

Let me know if you can observe the output of "cat trace" or if you have
any other ideas.


Re: [PATCH v1] checkout: optionally speed up "git checkout -b foo"

2018-07-26 Thread Eric Sunshine
On Thu, Jul 26, 2018 at 2:59 PM Eric Sunshine  wrote:
> On Thu, Jul 26, 2018 at 11:04 AM Junio C Hamano  wrote:
> > If there were a simple and futureproof way to tell the option
> > parsing loop to notice any feature other than "-b newbranch" was
> > used, then such a whitelisting may be a viable way [...]
>
> I'm wondering if a two-stage parse-options invocations could make this
> potential maintenance problem more manageable by altogether
> eliminating needs_working_tree_merge().

A downside of this approach is that it too becomes a nightmare if
git-checkout grows additional special cases like the proposed "-b", in
which case multi-stage or disjoint or intersecting parse-options
invocations might arise. Another downside is that this parse-options
idea is somewhat invasive, whereas, needs_working_tree_merge(),
despite its ugliness, is at least is self-contained and not at all
invasive.


Re: [PATCH v2] name_rev: add support for --cherry-picks

2018-07-26 Thread Junio C Hamano
Tejun Heo  writes:

> I should have explained the use case better.

No, you did not need to.  I was not saying the feature is not useful.
I was only saying that "explain where in the history X sits" command
(i.e. "name-rev X" and "describe X") did not look like a good place
to have that feature.

>   Upstream, it's v4.17-rc1
> Backported and released through v4.16-prod-r2
>   Also backported to v4.16-prod-r1 (cuz the fix happened while r1 was 
> going through rc's)
>
> So, it extends the description of how the original commit is released
> (or given name) so that releases through cherry-picks are also
> included.

Perhaps.  I am not yet 100% convinced, but having a less hard time
trying to convince myself now ;-)

Thanks.


Re: [PATCH v1] checkout: optionally speed up "git checkout -b foo"

2018-07-26 Thread Eric Sunshine
On Thu, Jul 26, 2018 at 11:04 AM Junio C Hamano  wrote:
> Ben Peart  writes:
> > I'm not thrilled with the long list either (the plethora of comments
> > probably makes it appear worse than it is) but I don't see how...
>
> If there were a simple and futureproof way to tell the option
> parsing loop to notice any feature other than "-b newbranch" was
> used, then such a whitelisting may be a viable way, but there is
> not, and the whitelist condition can become (over time---we are
> talking about futureproofing and not "a filter that happens to match
> today's feature set") just as complex as this blacklisting function
> is (e.g. feature A and feature B when used alone may be compatible
> with the optimization but not when used both), so if we were to use
> this optimization, I think this long list of special-case checks is
> the best we could do.

I'm wondering if a two-stage parse-options invocations could make this
potential maintenance problem more manageable by altogether
eliminating needs_working_tree_merge(). Something very roughly along
the lines of:

new_branch_and_passive_options = {
OPT_STRING('b', NULL, ...),
...options which can't impact "optimization" decision...
};
argc = parse_options(argc, argv, prefix,
new_branch_and_passive_options, NULL,
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);

can_optimize_new_branch = 1;
for (i = 0; i < argc; i++)
if (argv[i][0] == '-') {
can_optimize_new_branch = 0;
break;
}

options = {
...all other options...
}
argc = parse_options(argc, argv, prefix, options,
checkout_usage, PARSE_OPT_KEEP_DASHDASH);

...as before...

The can_optimize_new_branch check could, of course, be fooled by a
non-option which starts with a "-", but that would err toward safety
of not optimizing, so shouldn't be a worry.


Re: [PATCH] RFC Highlight keywords in remote sideband output.

2018-07-26 Thread Junio C Hamano
Han-Wen Nienhuys  writes:

> Supported keywords are "error", "warning", "hint" and "success".
>
> TODO:
>  * make the coloring optional? What variable to use?
>  * doc for the coloring option.
>  * how to test?

At the sideband layer, the sender only has the same level of
information as the receiver has regarding what the random bytes that
happens to be sent on the sideband, and that shows from the need to
guess with "keywords" in this code.  So if you are operating on the
sideband layer, I think the right way to do so would be to add the
coloring on the receiving end.  That way, talking to the same sender,
each receiver can decide if s/he prefers or capable of color.

Hold your objection a bit.  I'll come back to it soon ;-)

It theoretically may make more sense to color on the sender side,
but that is true only if done at a higher layer that prepares a
string and calls into the sideband code to send.  That code must
know what the bytes _mean_ a lot better than the code at the
sideband layer, so we do not have to guess.

Having written all the above, I think you are doing this at the
receiving end, so this actually makes quite a lot of sense.  I was
fooled greatly by "EMIT_sideband", which in reality does NOT emit at
all.  That function is badly misnamed.

The function is more like "color sideband payload"; actual
"emitting" is still done at the places the code originally "emitted"
them to the receiving user.

> Signed-off-by: Han-Wen Nienhuys 
> Change-Id: I090412a1288bc2caef0916447e28c2d0199da47d

That's an unusual trailer we do not use in this project.

> ---
>  sideband.c | 69 +++---
>  1 file changed, 60 insertions(+), 9 deletions(-)
>
> diff --git a/sideband.c b/sideband.c
> index 325bf0e97..c8b7cb6dd 100644
> --- a/sideband.c
> +++ b/sideband.c
> @@ -1,6 +1,53 @@
>  #include "cache.h"
>  #include "pkt-line.h"
>  #include "sideband.h"
> +#include "color.h"
> +
> +/*
> + * Optionally highlight some keywords in remote output if they appear at the
> + * start of the line.
> + */
> +void emit_sideband(struct strbuf *dest, const char *src, int n) {

Open brace on its own line.

> +// NOSUBMIT - maybe use transport.color property?

Avoid // comment.

> +int want_color = want_color_stderr(GIT_COLOR_AUTO);
> +
> +if (!want_color) {
> +strbuf_add(dest, src, n);
> +return;
> +}
> +
> +struct kwtable {
> +const char* keyword;
> +const char* color;

In our codebase in C, asterisk sticks to the variable not the type.

> +} keywords[] = {
> +{"hint", GIT_COLOR_YELLOW},
> +{"warning", GIT_COLOR_BOLD_YELLOW},
> +{"success", GIT_COLOR_BOLD_GREEN},
> +{"error", GIT_COLOR_BOLD_RED},
> +{},

Drop the last sentinel element, and instead stop iteration over the
array using (i < ARRAY_SIZE(keywords)).

> +};
> +
> +while (isspace(*src)) {
> +strbuf_addch(dest, *src);
> +src++;
> +n--;
> +}
> +
> +for (struct kwtable* p = keywords; p->keyword; p++) {

Does anybody know if we already use the variable decl inside the
"for (...)" construct like this?  I know we discussed the idea of
using it somewhere as a weather-balloon to see if people with exotic
environment would mind, and I certainly do not mind making this
patch serve as such a weather-baloon, but if that is what we are
doing, I want the commit log message clearly marked as such, so that
we can later "git log --grep=C99" to see how long ago such an
experiment started.  

Note that we did attempt to start such an experiment once

cf. https://public-inbox.org/git/20170719181956.15845-1-sbel...@google.com/

but failed.


> +int len = strlen(p->keyword);
> +if (!strncasecmp(p->keyword, src, len) && 
> !isalnum(src[len])) {
> +strbuf_addstr(dest, p->color);
> +strbuf_add(dest, src, len);
> +strbuf_addstr(dest, GIT_COLOR_RESET);
> +n -= len;
> +src += len;
> +break;
> +}
> +}
> +
> +strbuf_add(dest, src, n);
> +}
> +

I wonder how this interacts with exotics like the progress output,
which is essentially a single long line with many CRs sprinkled in,
sent on many packets?  I offhand do not think of a possible bad
interaction, but others may be able to think of some.

>  /*
>   * Receive multiplexed output stream over git native protocol.
> @@ -48,8 +95,10 @@ int recv_sideband(const char *me, int in_stream, int out)
>   len--;
>   switch (band) {
>   case 3:
> - strbuf_addf(, "%s%s%s", outbuf.len ? "\n" : "",
> - DISPLAY_PREFIX, buf + 1);
> + 

Re: [PATCH v2 0/6] git-submodule.sh: convert part of cmd_update to C

2018-07-26 Thread Stefan Beller
>
> To allow me to protest in a timely manner, I wanted to teach GitGitGadget
> (which is the main reason I work on range-diff, as you undoubtedly suspect
> by now) to warn me about such instances.

I did not suspect that GGG is the prime motivation for range diff; as it proves
useful (a) on its own, e.g. looking at the updates in pu and (b) is helping the
current workflow very much.


Re: [PATCH] sequencer.c: terminate the last line of author-script properly

2018-07-26 Thread Junio C Hamano
Johannes Schindelin  writes:

>> You're right, I'm not sure how I missed the calls to sq_quote_buf()
>> yesterday, sharing the am code with the sequencer would clean things up
>> nicely.
>
> No, actually Phillip was right. The `author-script` file written by
> `git-am` was always an implementation detail, and as there was no
> (intended) way to call shell scripts while running `git-am`, the only
> shell script to intentionally use `author-script` was `git-am` itself.

Well the thing is that you did not write "am".  When I wrote "am", I
did so with a deliberate design decision to keep the author-script
in the same format so that it can be read by shell.

You are behaving as if you made a silent decision to improve the
author-script by designing a better micro-format that deviates from
what shells read by doubling the backslash quoting and losing the
single quote at the end of the line for only the last one, and your
justification is that it does not matter how broken the new
micro-format is because it is an implementation detail nobody should
care.  And worse yet, you did that improvement without telling
anybody else why the new format is better.

That's just silly.

Just like everybody else, you are sometimes wrong and you sometimes
make mistakes.  The rest of time you are not wrong and your design
decisions are not mistaken, but trying to defend an obvious mistake
like this one with silly excuses is an easy way to lose credibility.



Re: [PATCH] RFC Highlight keywords in remote sideband output.

2018-07-26 Thread Stefan Beller
On Thu, Jul 26, 2018 at 10:18 AM Han-Wen Nienhuys  wrote:
>
> Supported keywords are "error", "warning", "hint" and "success".

Thanks for taking this upstream. :-)

>
> TODO:
>  * make the coloring optional? What variable to use?

This is the natural extension of the topic merged at a56fb3dcc09
(Merge branch 'js/colored-push-errors', 2018-05-08), which was merged
rather recently, so I'd think extending the color.transport option would be
useful here. (cc'd the authors of that series)

>  * doc for the coloring option.



>  * how to test?

I think the best way to get started with a test is to be inspired by
8301266afa4 (push: test to verify that push errors are colored,
2018-04-21) from that series.

> Signed-off-by: Han-Wen Nienhuys 
> Change-Id: I090412a1288bc2caef0916447e28c2d0199da47d

We do not do Change-Ids in git upstream. :/
As different workflows have different edges, everyone has their own
little script to deal with those. For example Brandon has
https://github.com/bmwill/dotfiles/blob/master/bin/check-patch
that contains a section to remove change ids

# Remove Change-Id from patch
sed -i "/Change-Id:/d" "$f"

> +void emit_sideband(struct strbuf *dest, const char *src, int n) {

Coding style: we start the brace in the next line for new functions
(but not after if/while/for)

Also I did not think hard enough in the internal review, as this function
is not emitting to the sideband. that is solely done by the xwrite
call in recv_sideband. So maybe prepare_sideband would be a better
name?


> +// NOSUBMIT - maybe use transport.color property?

Yes, that would be my suggestion (note that we do not use // comments)

> +int want_color = want_color_stderr(GIT_COLOR_AUTO);
> +
> +if (!want_color) {
> +strbuf_add(dest, src, n);
> +return;
> +}
> +
> +struct kwtable {
> +const char* keyword;
> +const char* color;
> +} keywords[] = {
> +{"hint", GIT_COLOR_YELLOW},
> +{"warning", GIT_COLOR_BOLD_YELLOW},
> +{"success", GIT_COLOR_BOLD_GREEN},
> +{"error", GIT_COLOR_BOLD_RED},
> +{},
> +};
> +
> +while (isspace(*src)) {
> +strbuf_addch(dest, *src);
> +src++;
> +n--;
> +}
> +
> +for (struct kwtable* p = keywords; p->keyword; p++) {
> +int len = strlen(p->keyword);
> +if (!strncasecmp(p->keyword, src, len) && 
> !isalnum(src[len])) {
> +strbuf_addstr(dest, p->color);
> +strbuf_add(dest, src, len);
> +strbuf_addstr(dest, GIT_COLOR_RESET);
> +n -= len;
> +src += len;
> +break;
> +}
> +}
> +
> +strbuf_add(dest, src, n);
> +}
> +
>
>  /*
>   * Receive multiplexed output stream over git native protocol.
> @@ -48,8 +95,10 @@ int recv_sideband(const char *me, int in_stream, int out)
> len--;
> switch (band) {
> case 3:
> -   strbuf_addf(, "%s%s%s", outbuf.len ? "\n" : "",
> -   DISPLAY_PREFIX, buf + 1);
> +   strbuf_addf(, "%s%s", outbuf.len ? "\n" : "",
> +   DISPLAY_PREFIX);
> +emit_sideband(, buf+1, len);
> +
> retval = SIDEBAND_REMOTE_ERROR;
> break;
> case 2:
> @@ -69,20 +118,22 @@ int recv_sideband(const char *me, int in_stream, int out)
> if (!outbuf.len)
> strbuf_addstr(, 
> DISPLAY_PREFIX);
> if (linelen > 0) {
> -   strbuf_addf(, "%.*s%s%c",
> -   linelen, b, suffix, *brk);
> -   } else {
> -   strbuf_addch(, *brk);
> +emit_sideband(, b, linelen);
> +strbuf_addstr(, suffix);
> }
> +
> +strbuf_addch(, *brk);
> xwrite(2, outbuf.buf, outbuf.len);
> strbuf_reset();
>
> b = brk + 1;
> }
>
> -   if (*b)
> -   strbuf_addf(, "%s%s", outbuf.len ?
> -   "" : DISPLAY_PREFIX, b);
> +   if (*b) {
> +   strbuf_addstr(, outbuf.len ?
> +   "" : DISPLAY_PREFIX);
> +emit_sideband(, b, strlen(b));
> +   

Re: [PATCH] sequencer.c: terminate the last line of author-script properly

2018-07-26 Thread Junio C Hamano
Johannes Schindelin  writes:

> Hi Junio,
>
> On Tue, 17 Jul 2018, Junio C Hamano wrote:
>
>> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
>> index 2d189da2f1..b0cef509ab 100755
>> --- a/t/t3404-rebase-interactive.sh
>> +++ b/t/t3404-rebase-interactive.sh
>> @@ -81,11 +81,13 @@ test_expect_success 'rebase -i writes out 
>> .git/rebase-merge/author-script in "ed
>
> You missed a very long line here.
>
>>  set_fake_editor &&
>>  FAKE_LINES="edit 1" git rebase -i HEAD^ &&
>>  test -f .git/rebase-merge/author-script &&
>
> Why do we need this, if we already have an `eval` later on?

You are commenting on a wrong version.  Comment on the original.


Re: [PATCH v3 1/4] automatically ban strcpy()

2018-07-26 Thread Junio C Hamano
Jeff King  writes:

> So here's a replacement for just patch 1 (I'm assuming this creates less
> work than re-posting them all, but it may not be if Junio prefers
> dealing with a whole new mbox rather than a "rebase -i", "reset --hard
> HEAD^", "git am" -- let me know if you'd prefer it the other way).

A single patch replacement that is clearly marked which one to
replace and which other ones to keep, like you did here, is fine.
The amount of work is about the same either way.

0) I would first do these to make sure that I can replace:

 $ git checkout jk/banned-functions
 $ git log --first-parent --oneline master..
 $ git log --first-parent --oneline next..

If 'next' has some patches that are not in 'master' from the topic,
I must refrain from replacing them (in this case, there is no such
issue).

1-a) With a wholesale replacement,

 $ git checkout master...   ;# try to keep the same base
 $ git am -s mbox   ;# on detached HEAD
 $ git tbdiff ..@{-1} @{-1}..   ;# or range-diff

If the range-/tbdiff tells me that earlier N patches are the same,
the above is followed by something like (pardon off-by-one)

 $ git rebase --onto @{-1}~N HEAD~N

to preserve as many original commits as possible.

1-b) With a single patch replacement, it is quite different.

 $ git checkout HEAD~4  ;# we are replacing 1/4 of the original
 $ git am -s mbox   ;# that single patch
 $ git show-branch HEAD @{-1}

That would give me something like this

* [HEAD] automatically ban strcpy()
 ! [@{-1}] banned.h: mark strncpy() as banned
--
*  [HEAD] automatically ban strcpy()
 + [@{-1}] banned.h: mark strncpy() as banned
 + [@{-1}^] banned.h: mark sprintf() as banned
 + [@{-1}~2] banned.h: mark strcat() as banned
 + [@{-1}~3] automatically ban strcpy()
-- [HEAD^] Merge branch 'sb/blame-color' into jk/banned-function

The most natural thing to do at this point is

 $ git cherry-pick -3 @{-1}

But we know range-pick is buggy and loses core.rewriteref, so
instead I did this, which I know carries the notes forward:

 $ git rebase --onto HEAD @{-1}~3 @{-1}^0

Side note: The point of last "^0" is that I do not want to lose
the topic branch jk/banned-functions not just yet.

If I need to re-apply separate pieces of the original history, it
becomes very painful to emulate these multiple cherry-picks with
multiple "rebase --onto", though.  That is where "the amount of work
is about the same" comes from.  If cherry-pick worked correctly,
selective replacement should be less work for me.

Anyway, we already preserved as many original commits, but unlike
1-a, did so manually when we decided to replace selective patches.
So there is no further rebasing with this approach.

2) I now have two diverged histories in HEAD and @{-1} that I can
compare with range-/tbdiff in either case: 

 $ git tbdiff ..@{-1} @{-1}..

After the usual inspection and testing, replacement is concluded by

 $ git checkout -B @{-1}

which takes me back to (an updated) jk/banned-functions topic.



[PATCH] RFC Highlight keywords in remote sideband output.

2018-07-26 Thread Han-Wen Nienhuys
Supported keywords are "error", "warning", "hint" and "success".

TODO:
 * make the coloring optional? What variable to use?
 * doc for the coloring option.
 * how to test?

Signed-off-by: Han-Wen Nienhuys 
Change-Id: I090412a1288bc2caef0916447e28c2d0199da47d
---
 sideband.c | 69 +++---
 1 file changed, 60 insertions(+), 9 deletions(-)

diff --git a/sideband.c b/sideband.c
index 325bf0e97..c8b7cb6dd 100644
--- a/sideband.c
+++ b/sideband.c
@@ -1,6 +1,53 @@
 #include "cache.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "color.h"
+
+/*
+ * Optionally highlight some keywords in remote output if they appear at the
+ * start of the line.
+ */
+void emit_sideband(struct strbuf *dest, const char *src, int n) {
+// NOSUBMIT - maybe use transport.color property?
+int want_color = want_color_stderr(GIT_COLOR_AUTO);
+
+if (!want_color) {
+strbuf_add(dest, src, n);
+return;
+}
+
+struct kwtable {
+const char* keyword;
+const char* color;
+} keywords[] = {
+{"hint", GIT_COLOR_YELLOW},
+{"warning", GIT_COLOR_BOLD_YELLOW},
+{"success", GIT_COLOR_BOLD_GREEN},
+{"error", GIT_COLOR_BOLD_RED},
+{},
+};
+
+while (isspace(*src)) {
+strbuf_addch(dest, *src);
+src++;
+n--;
+}
+
+for (struct kwtable* p = keywords; p->keyword; p++) {
+int len = strlen(p->keyword);
+if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
+strbuf_addstr(dest, p->color);
+strbuf_add(dest, src, len);
+strbuf_addstr(dest, GIT_COLOR_RESET);
+n -= len;
+src += len;
+break;
+}
+}
+
+strbuf_add(dest, src, n);
+}
+
 
 /*
  * Receive multiplexed output stream over git native protocol.
@@ -48,8 +95,10 @@ int recv_sideband(const char *me, int in_stream, int out)
len--;
switch (band) {
case 3:
-   strbuf_addf(, "%s%s%s", outbuf.len ? "\n" : "",
-   DISPLAY_PREFIX, buf + 1);
+   strbuf_addf(, "%s%s", outbuf.len ? "\n" : "",
+   DISPLAY_PREFIX);
+emit_sideband(, buf+1, len);
+
retval = SIDEBAND_REMOTE_ERROR;
break;
case 2:
@@ -69,20 +118,22 @@ int recv_sideband(const char *me, int in_stream, int out)
if (!outbuf.len)
strbuf_addstr(, DISPLAY_PREFIX);
if (linelen > 0) {
-   strbuf_addf(, "%.*s%s%c",
-   linelen, b, suffix, *brk);
-   } else {
-   strbuf_addch(, *brk);
+emit_sideband(, b, linelen);
+strbuf_addstr(, suffix);
}
+
+strbuf_addch(, *brk);
xwrite(2, outbuf.buf, outbuf.len);
strbuf_reset();
 
b = brk + 1;
}
 
-   if (*b)
-   strbuf_addf(, "%s%s", outbuf.len ?
-   "" : DISPLAY_PREFIX, b);
+   if (*b) {
+   strbuf_addstr(, outbuf.len ?
+   "" : DISPLAY_PREFIX);
+emit_sideband(, b, strlen(b));
+}
break;
case 1:
write_or_die(out, buf + 1, len);
-- 
2.18.0.233.g985f88cf7e-goog



Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Junio C Hamano
Jeff King  writes:

> On Wed, Jul 25, 2018 at 03:13:37PM -0700, Junio C Hamano wrote:
>
>> * jk/banned-function (2018-07-24) 5 commits
>>  - banned.h: mark strncpy() as banned
>>  - banned.h: mark sprintf() as banned
>>  - banned.h: mark strcat() as banned
>>  - automatically ban strcpy()
>>  - Merge branch 'sb/blame-color' into jk/banned-function
>> 
>>  It is too easy to misuse system API functions such as strcat();
>>  these selected functions are now forbidden in this codebase and
>>  will cause a compilation failure.
>> 
>>  Will merge to 'next'.
>
> Eric nudged me over the fence to use a slightly different mechanism to
> generate the error. See:
>
>   https://public-inbox.org/git/20180726072105.ga6...@sigill.intra.peff.net/
>
> It looks like sb/blame-color graduated, so this could also just be
> applied directly on master now to avoid the funky merge.

OK.  Is it that "you cannot call a variable" thing?


Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Junio C Hamano
Оля Тележная   writes:

> 2018-07-26 1:13 GMT+03:00 Junio C Hamano :
>>
>> * ot/ref-filter-object-info (2018-07-17) 5 commits
>>  - ref-filter: use oid_object_info() to get object
>>  - ref-filter: merge get_obj and get_object
>>  - ref-filter: initialize eaten variable
>>  - ref-filter: fill empty fields with empty values
>>  - ref-filter: add info_source to valid_atom
>>
>>  A few atoms like %(objecttype) and %(objectsize) in the format
>>  specifier of "for-each-ref --format=" can be filled without
>>  getting the full contents of the object, but just with the object
>>  header.  These cases have been optimzied by calling
>>  oid_object_info() API.
>>
>>  What's the doneness of this one?
>>
>
> It is ready. Thanks.

Thanks, the question was meant more to the reviewers and mentors
than the original author, though ;-)


Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Junio C Hamano
Junio C Hamano  writes:

> Stefan Beller  writes:
>
>>> * js/range-diff (2018-07-25) 21 commits
>
>> I think the current coloring is good enough to ship, but it still has
>> errors around corners, for example introduction of new files,
>> having lines in the inner diff as:
>>
>>  diff --git a/Makefile b/Makefile
>>  --- a/Makefile
>>  +++ b/Makefile
>>
>> will be colored white/red/green (in that order), but in the outer diff
>> these are all "context", but as these specific context lines happen
>> to start with +/- we color them.
>> If we want to be perfect, we rather need to parse
>> the inner diff on a more detailed level, but I would argue to leave
>> that to a later stage for another volunteer to step in and cleanup.
>
> I think the primary part of coloring i.e. "white is common, green is
> added, red is removed" together with "bold is new, dimmed is old" is
> quite usable and not broken.  

I just compared the output from the original tbdiff and the dual
color mode of range-diff; especially with that "new round is bold,
old round is dimmed", I find that the coloring makes it easier to
spot what kind of each line is than what tbdiff did.

Dscho, good job on that.




Re: [PATCH 2/2] travis-ci: fail if Coccinelle static analysis found something to transform

2018-07-26 Thread Junio C Hamano
SZEDER Gábor  writes:

> On Mon, Jul 23, 2018 at 3:02 PM SZEDER Gábor  wrote:
>
>> The only way to draw attention in such an automated setting is to fail
>> the build job.  Therefore, modify the 'ci/run-static-analysis.sh'
>> build script to check all the resulting '*.cocci.patch' files, and
>> fail the build job if any of them turns out to be not empty.  Include
>> those files' contents, i.e. Coccinelle's suggested transformations, in
>> the build job's trace log, so we'll know why it failed.
>
> And this is how it looks like "in action":
>
>   https://travis-ci.org/git/git/jobs/408269979#L570

;-)


Re: [PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread Junio C Hamano
Chen Bin  writes:

> +Hook for submit
> +~~~
> +Hook `p4-pre-submit` is executed if it exists and is executable.

Just a lang nit, but "git grep pre-commit" shows me lines like

  Documentation/git-commit.txt:   This option bypasses the pre-commit and 
commit-msg hooks.

to tell me that the above is better phrased like

The `p4-pre-submit` hook is executed...

The same comment applies to the patch title, the first sentence in
the log message and in-code ".description" field in git-py.py.

> +The hook takes no parameter and nothing from standard input. Exiting with
> +non-zero status from this script prevents `git-p4 submit` from launching.
> +So nothing is touched when it exits with non-zero status.

Isn't the last sentence redundant, saying only what the second
sentence already said?

> +
> +One usage scenario is to run unit tests in the hook.

Good thing to mention, I guess.

> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be changed.
> +See githooks(5) manpage for details about hooks.

I do not think this is particularly a good change; it forces us to
maintain this sentence copied from githooks.txt every time the
original has to change, and documentation for no other command
duplicates it.

> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
> index e3c283a17..22fcabbe2 100644
> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -485,6 +485,13 @@ The exit status determines whether git will use the data 
> from the
>  hook to limit its search.  On error, it will fall back to verifying
>  all files and folders.
>  
> +p4-pre-submit
> +~
> +
> +This hook is invoked by `git-p4 submit`. It takes no parameter and nothing
> +from standard input. Exiting with non-zero status from this script prevent
> +`git-p4 submit` from launching. Run `git-p4 submit --help` for details.
> +

Hmmm, OK.

>  GIT
>  ---
>  Part of the linkgit:git[1] suite
> diff --git a/git-p4.py b/git-p4.py
> index b449db1cc..f147a2d2f 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1494,7 +1494,17 @@ def __init__(self):
>  optparse.make_option("--disable-p4sync", 
> dest="disable_p4sync", action="store_true",
>   help="Skip Perforce sync of p4/master 
> after submit or shelve"),
>  ]
> -self.description = "Submit changes from git to the perforce depot."
> +self.description = """Submit changes from git to the perforce 
> depot.\n
> +Hook `p4-pre-submit` is executed if it exists and is executable.
> +The hook takes no parameter and nothing from standard input. Exiting with
> +non-zero status from this script prevents `git-p4 submit` from launching.
> +So nothing is touched when it exits with non-zero status.
> +
> +One usage scenario is to run unit tests in the hook.
> +
> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be 
> changed.
> +See githooks(5) manpage for details about hooks."""

How do you plan to keep this in sync with the documentation?
Perhaps the last sentence of the new paragraph you added to
Documentation/githooks.txt should read

See `git p4 --help` for details.

Then this hunk can be eliminated, I would think.

> @@ -2303,6 +2313,15 @@ def run(self, args):
>  sys.exit("number of commits (%d) must match number of shelved 
> changelist (%d)" %
>   (len(commits), num_shelves))
>  
> +hooks_path = gitConfig("core.hooksPath")
> +if len(hooks_path) > 0:
> +hook_file = os.path.join(hooks_path, "p4-pre-submit")
> +else:
> +hook_file = os.path.join(read_pipe("git rev-parse 
> --git-dir").strip(), "hooks", "p4-pre-submit")
> +

Isn't the GIT_DIR available as self.gitdir at this point in the
code, prepared by main() before this method is run?

It may be a style thing, but I somehow would find it easier to
understand if you wrote it like so:

hooks_path = gitConfig("...")
if len(hooks_path) <= 0:
hooks_path = os.path.join(self.gitdir, "hooks")
hook_file = os.path.join(hooks_path, "p4-pre-submit")

The point being hooks_path always point at the directory that holds
hooks with or without configuration, and hook_file is set based on
that to the same "p4-pre-submit" without any potential of typo
getting in to make the two cases diverge.

> +if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and 
> subprocess.call([hook_file]) != 0:
> +sys.exit(1)
> +
>  #
>  # Apply the commits, one at a time.  On failure, ask if should
>  # continue to try the rest of the patches, or quit.
> diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh
> index 4849edc4e..8457ff617 100755
> --- a/t/t9800-git-p4-basic.sh
> +++ b/t/t9800-git-p4-basic.sh
> @@ -261,6 +261,32 @@ test_expect_success 'unresolvable host in P4PORT should 
> display error' '
>   )
>  '
> 

Re: [PATCH v1 0/3] [RFC] Speeding up checkout (and merge, rebase, etc)

2018-07-26 Thread Duy Nguyen
On Wed, Jul 25, 2018 at 10:56 PM Ben Peart  wrote:
>
>
>
> On 7/24/2018 11:33 AM, Duy Nguyen wrote:
> > On Tue, Jul 24, 2018 at 6:20 AM Jeff King  wrote:
> >> At least that's my view of it. unpack_trees() has always been a
> >> terrifying beast that I've avoided looking too closely at.
> >
> > /me nods on the terrifying part.
> >
> >>> After a quick look at the code, the only place I can find that tries to 
> >>> use
> >>> cache_tree_matches_traversal() is in unpack_callback() and that only 
> >>> happens
> >>> if n == 1 and in the "git checkout" case, n == 2. Am I missing something?
> >
> > So we do not actually use cache-tree? Big optimization opportunity (if
> > we can make it!).
> >
>
> I agree!  Assuming we can figure out the technical issues around using
> the cache tree to optimize two way merges, another question I'm trying
> to answer is how we can enable this optimization without causing back
> compat issues?

If it works as I expect, then there's no compat issues at all (exactly
like the diff_index_cached optimization we already have). We simply
find a safe shortcut that does not add any side effects.
-- 
Duy


Re: [PATCH v1 0/3] [RFC] Speeding up checkout (and merge, rebase, etc)

2018-07-26 Thread Duy Nguyen
On Thu, Jul 26, 2018 at 07:30:20AM +0200, Duy Nguyen wrote:
> Let's get back to two-way merge. I suggest you read the two-way merge
> in git-read-tree.txt. That table could give you a pretty good idea
> what's going on. twoway_merge() will be given a tuple of three entries
> (I, H, M) of the same path name, for every path. I think what we need
> is determine the condition where the outcome is known in advance, so
> that we can just skip walking the index for one directory. One of the
> checks we could do quickly is I==M or I==H (using cache-tree) and H==M
> (using tree hash).
> 
> The first obvious cases that we can optimize are
> 
> clean (H==M)
>--
>  14 yes exists   exists   keep index
>  15 no  exists   exists   keep index
> 
> In other words if we know H==M, there's no much we need to do since
> we're keeping the index the same. But you don't really know how many
> entries are in this directory where H==M. You would need cache-tree
> for that, so in reality it's I==H==M.
> 
> The "clean" column is what fsmonitor comes in, though I'm not sure if
> it's actually needed. I haven't checked how '-u' flag works.
> 
> There's two other cases that we can also optimize, though I think it's
> less likely to happen:
> 
> clean I==H  I==M (H!=M)
>--
>  18 yes   noyes exists   exists   keep index
>  19 nonoyes exists   exists   keep index
> 
> Some other cases where I==H can benefit from the generic tree walk
> optimization above since we can skip parsing H.

I'm excited so I decided to try out anyway. This is what I've come up
with. Switching trees on git.git shows it could skip plenty entries,
so promising. It's ugly and it fails at t6020 though, there's still
work ahead. But I think it'll stop here.

A few notes after getting my hands dirty

- one big difference between diff --cached and checkout is, diff is a
  read-only operation while checkout actually creates new index.  One
  of the side effect is that cache-tree may be destroyed while we're
  walking the trees, i'm not so sure.

- I don't think we even need to a special twoway_merge_same()
  here. That function could just call twoway_merge() with the right
  "src" parameter and the outcome should still be the same. Which
  means it'll work for threeway merge too.

- i'm still scared of that cache_bottom switching to death. no idea
  how it works or if i broke anything by changing the condition there.

-- 8< --
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 28627650cd..276712af64 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -515,6 +515,7 @@ static int merge_working_tree(const struct checkout_opts 
*opts,
topts.gently = opts->merge && old_branch_info->commit;
topts.verbose_update = opts->show_progress;
topts.fn = twoway_merge;
+   topts.fn_same = twoway_merge_same;
if (opts->overwrite_ignore) {
topts.dir = xcalloc(1, sizeof(*topts.dir));
topts.dir->flags |= DIR_SHOW_IGNORED;
diff --git a/diff-lib.c b/diff-lib.c
index a9f38eb5a3..48e6c4ab0d 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -485,6 +485,15 @@ static int oneway_diff(const struct cache_entry * const 
*src,
return 0;
 }
 
+static int oneway_diff_cached(int pos, int nr, struct unpack_trees_options 
*options)
+{
+   /*
+* Nothing to do. Unpack-trees can safely skip the whole
+* nr_matches cache entries.
+*/
+   return 0;
+}
+
 static int diff_cache(struct rev_info *revs,
  const struct object_id *tree_oid,
  const char *tree_name,
@@ -501,8 +510,8 @@ static int diff_cache(struct rev_info *revs,
memset(, 0, sizeof(opts));
opts.head_idx = 1;
opts.index_only = cached;
-   opts.diff_index_cached = (cached &&
- !revs->diffopt.flags.find_copies_harder);
+   if (cached && !revs->diffopt.flags.find_copies_harder)
+   opts.fn_same = oneway_diff_cached;
opts.merge = 1;
opts.fn = oneway_diff;
opts.unpack_data = revs;
diff --git a/unpack-trees.c b/unpack-trees.c
index 66741130ae..01e3f38807 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -615,7 +615,7 @@ static void restore_cache_bottom(struct traverse_info 
*info, int bottom)
 {
struct unpack_trees_options *o = info->data;
 
-   if (o->diff_index_cached)
+   if (o->fn_same)
return;
o->cache_bottom = bottom;
 }
@@ -625,7 +625,7 @@ static int switch_cache_bottom(struct traverse_info *info)
struct unpack_trees_options *o = info->data;
int ret, pos;
 
-   if (o->diff_index_cached)
+   if (o->fn_same)
return 0;
ret = o->cache_bottom;
pos = find_cache_pos(info->prev, >name);
@@ -996,6 +996,43 @@ static void debug_unpack_callback(int n,
  

[PATCH v5 3/4] add -p: allow line selection to be inverted

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

If the list of lines to be selected begins with '-' select all the
lines except the ones listed.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |  3 ++-
 git-add--interactive.perl  | 19 +++
 t/t3701-add-interactive.sh |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 965e192a09..01ff4d7d24 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -342,7 +342,8 @@ deletion labelled with a number and you will be prompted to 
enter which
 lines you wish to select. Individual line numbers should be separated by
 a space or comma, to specify a range of lines use a dash between
 them. If the upper bound of a range of lines is omitted it defaults to
-the last line.
+the last line. To invert the selection prefix it with "-" so "-3-5,8"
+will select everything except lines 3, 4, 5 and 8.
 +
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 7e4daee2fc..63541d0f90 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1247,8 +1247,21 @@ sub parse_hunk_selection {
my ($hunk, $line) = @_;
my $lines = $hunk->{LABELS}->{LINES};
my $max_label = $#{$lines};
+   my $invert = undef;
my %selected;
my @fields = split(/[,\s]+/, $line);
+   if (my ($rest) = ($fields[0] =~ /^-(.*)/)) {
+   $invert = 1;
+   if ($rest ne '') {
+   $fields[0] = $rest;
+   } else {
+   shift @fields;
+   unless (@fields) {
+   error_msg __("no lines to invert\n");
+   return undef;
+   }
+   }
+   }
for my $f (@fields) {
if (my ($lo, $hi) = ($f =~ /^([0-9]+)-([0-9]*)$/)) {
if ($hi eq '') {
@@ -1268,6 +1281,12 @@ sub parse_hunk_selection {
return undef;
}
}
+   if ($invert) {
+   my %inverted;
+   undef @inverted{1..$max_label};
+   delete @inverted{keys(%selected)};
+   %selected = %inverted;
+   }
return process_hunk_selection($hunk, keys(%selected));
 }
 
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 1d917ad018..2fd456017f 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -457,7 +457,7 @@ test_expect_success 'setup expected diff' '
 '
 
 test_expect_success 'can reset individual lines of patch' '
-   printf "%s\n" l 4,1,3 |
+   printf "%s\n" l -6,2,5 |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&
-- 
2.18.0



[PATCH v5 1/4] add -p: select individual hunk lines

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

When I end up editing hunks it is almost always because I want to
stage a subset of the lines in the hunk. Doing this by editing the
hunk is inconvenient and error prone (especially so if the patch is
going to be reversed before being applied). Instead offer an option
for add -p to stage individual lines. When the user presses 'l' the
hunk is redrawn with labels by the insertions and deletions and they
are prompted to enter a list of the lines they wish to stage. Ranges
of lines may be specified using 'a-b' where 'b' may be omitted to mean
all lines from 'a' to the end of the hunk. Modified lines are not
handled correctly, that will be fixed in the next commit.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |   8 ++
 git-add--interactive.perl  | 181 +
 t/t3701-add-interactive.sh | 103 +
 3 files changed, 292 insertions(+)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index d50fa339dc..965e192a09 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -332,10 +332,18 @@ patch::
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
+   l - select hunk lines to use
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
 +
+If you press "l" then the hunk will be reprinted with each insertion or
+deletion labelled with a number and you will be prompted to enter which
+lines you wish to select. Individual line numbers should be separated by
+a space or comma, to specify a range of lines use a dash between
+them. If the upper bound of a range of lines is omitted it defaults to
+the last line.
++
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
 +
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8361ef45e7..cbc9e5698a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1013,6 +1013,171 @@ sub color_diff {
} @_;
 }
 
+use constant {
+   NO_NEWLINE => 1,
+};
+
+sub label_hunk_lines {
+   my $hunk = shift;
+   my $text = $hunk->{TEXT};
+   my (@line_flags, @lines);
+   my ($block, $label, $last_mode) = (0, 0, '');
+   for my $line (1..$#{$text}) {
+   $line_flags[$line] = 0;
+   my $mode = substr($text->[$line], 0, 1);
+   if ($mode eq '\\') {
+   $line_flags[$line - 1] |= NO_NEWLINE;
+   }
+   if ($mode eq '-' or $mode eq '+') {
+   $lines[++$label] = $line;
+   }
+   }
+   if ($label > 1) {
+   $hunk->{LABELS} = {
+   LINES => \@lines,
+   };
+   $hunk->{LINE_FLAGS} = \@line_flags;
+   return 1;
+   }
+   return 0;
+}
+
+sub select_hunk_lines {
+   my ($hunk, $selected) = @_;
+   my ($line_flags, $text) = @{$hunk}{qw(LINE_FLAGS TEXT)};
+   my ($i, $o_cnt, $n_cnt) = (0, 0, 0);
+   my @newtext;
+
+   my $select_lines = sub {
+   for my $i (@_) {
+   my $line = $text->[$i];
+   my $mode = substr($line, 0, 1);
+   push @newtext, $line;
+   if ($mode eq '+') {
+   $n_cnt++;
+   } elsif ($mode eq '-') {
+   $o_cnt++;
+   }
+   }
+   };
+
+   my ($lo, $hi) = splice(@$selected, 0, 2);
+   # Lines with this mode will become context lines if they are
+   # not selected
+   my $context_mode = $patch_mode_flavour{IS_REVERSE} ? '+' : '-';
+   for $i (1..$#{$text}) {
+   if ($lo <= $i and $i <= $hi) {
+   $select_lines->($i);
+   } else {
+   my $line = $text->[$i];
+   my $mode = substr($line, 0, 1);
+   if ($mode eq ' ' or $mode eq $context_mode) {
+   push @newtext, ' ' . substr($line, 1);
+   $o_cnt++; $n_cnt++;
+   if ($line_flags->[$i] & NO_NEWLINE) {
+   push @newtext, $text->[$i + 1];
+   }
+   }
+   }
+   if ($i == $hi) {
+   if (@$selected) {
+   ($lo, $hi) = splice(@$selected, 0, 2);
+   }
+   }
+   }
+   my ($o_ofs, $orig_o_cnt, $n_ofs, $orig_n_cnt) =
+   parse_hunk_header($text->[0]);
+   unshift @newtext, format_hunk_header($o_ofs, $o_cnt, $n_ofs, $n_cnt);
+   my $newhunk = {
+   

[PATCH v5 4/4] add -p: optimize line selection for short hunks

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

If there are fewer than ten changes in a hunk then make spaces
optional when selecting individual lines. This means that for short
hunks one can just type 1-357 to stage lines 1, 2, 3, 5 & 7.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |  9 +
 git-add--interactive.perl  | 26 ++
 t/t3701-add-interactive.sh |  2 +-
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 01ff4d7d24..f3c81dfb11 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -340,10 +340,11 @@ patch::
 If you press "l" then the hunk will be reprinted with each insertion or
 deletion labelled with a number and you will be prompted to enter which
 lines you wish to select. Individual line numbers should be separated by
-a space or comma, to specify a range of lines use a dash between
-them. If the upper bound of a range of lines is omitted it defaults to
-the last line. To invert the selection prefix it with "-" so "-3-5,8"
-will select everything except lines 3, 4, 5 and 8.
+a space or comma (these can be omitted if there are fewer than ten
+labelled lines), to specify a range of lines use a dash between them. If
+the upper bound of a range of lines is omitted it defaults to the last
+line. To invert the selection prefix it with "-" so "-3-5,8" will select
+everything except lines 3, 4, 5 and 8.
 +
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 63541d0f90..054c1168a7 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1243,6 +1243,29 @@ sub check_hunk_label {
return 1;
 }
 
+sub split_hunk_selection {
+   my @fields = @_;
+   my @ret;
+   for my $field (@fields) {
+   while ($field ne '') {
+   if ($field =~ /^[0-9]-$/) {
+   push @ret, $field;
+   last;
+   } elsif (my ($sel, $rest) =
+   ($field =~ /^([0-9](?:-[0-9])?)(.*)/)) {
+   push @ret, $sel;
+   $field = $rest;
+   } else {
+   error_msg sprintf
+   __("invalid hunk line '%s'\n"),
+   substr($field, 0, 1);
+   return ();
+   }
+   }
+   }
+   return @ret;
+}
+
 sub parse_hunk_selection {
my ($hunk, $line) = @_;
my $lines = $hunk->{LABELS}->{LINES};
@@ -1262,6 +1285,9 @@ sub parse_hunk_selection {
}
}
}
+   if ($max_label < 10) {
+   @fields = split_hunk_selection(@fields) or return undef;
+   }
for my $f (@fields) {
if (my ($lo, $hi) = ($f =~ /^([0-9]+)-([0-9]*)$/)) {
if ($hi eq '') {
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 2fd456017f..b2b808275c 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -457,7 +457,7 @@ test_expect_success 'setup expected diff' '
 '
 
 test_expect_success 'can reset individual lines of patch' '
-   printf "%s\n" l -6,2,5 |
+   printf "%s\n" l -625 |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&
-- 
2.18.0



[RFC PATCH v5 2/4] add -p: select modified lines correctly

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

When a set of lines is modified the hunk contains deletions followed
by insertions. To correctly stage a subset of the modified lines we
need to match up the selected deletions with the selected insertions
otherwise we end up with deletions and context lines followed by
insertions which is not what we want.

For example given the hunk
  1 -* a longer description of the
  2 -  first item
  3 -* second
  4 -* third
  5 +* first
  6 +  second item
  7 +* the third item

If the user selects 1,2,4–5,7 then we should generate
-* a longer description of the
-  first item
+* first
 * second
-* third
+* the third item

not
-* a longer description of the
-  first item
 * second
-* third
+* first
+* the third item

Currently the code can only cope with selections that contain the same
number of groups of insertions and deletions, though each group need
not contain the same number of insertions and deletions. If the user
wants to stage an unpaired deletion or insertion in a hunk where they
also want to stage modified lines they have to do it with two
invocations of 'git add -p'.

It would be possible to add some syntax to allow lines to be excluded
from groups to allow the user to stage such changes in a single
go. It may also be useful to allow users to explicitly group lines. If
in the example above the second item is deleted we have

  1 -* a longer description of the
  2 - first item
  3 -* second
  4 -* third
  5 +* first
  6 +* the third item

Selecting 1,2,4–6 will give an error. If lines could be grouped
explicitly then it would be possible to type something like
1,2,4,[5],6 to indicate that there are two groups of insertions giving

-* a longer description of the
- first item
+* first
 * second
-* third
+* the third item

We may want to be able to stage an insertion before an unselected
deletion to allow the user to stage a new paragraph before the
unmodified original in

  1 -original
  2 +a new paragraph before
  3 +original
  4 +
  5 +modified original

by specifying something like ^2-4 to give

+a new paragraph before
+original
+
 original

I'm not sure how common these cases are in real life and how much
effort it's worth putting into handling them at the moment when the
user can edit the hunk if need be. Perhaps it would be better to leave
it for future extensions when it becomes clearer what would be most
useful.

Reported-by: Ævar Arnfjörð Bjarmason 
Signed-off-by: Phillip Wood 
---
 git-add--interactive.perl  | 147 ++---
 t/t3701-add-interactive.sh | 108 ++-
 2 files changed, 242 insertions(+), 13 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index cbc9e5698a..7e4daee2fc 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1015,26 +1015,47 @@ sub color_diff {
 
 use constant {
NO_NEWLINE => 1,
+   LAST_ADD_DEL => 2,
+   FIRST_ADD => 4
 };
 
 sub label_hunk_lines {
my $hunk = shift;
my $text = $hunk->{TEXT};
-   my (@line_flags, @lines);
+   # A block contains the insertions and deletions occurring context
+   # lines.
+   my (@blocks, @line_flags, @lines, @modes);
my ($block, $label, $last_mode) = (0, 0, '');
for my $line (1..$#{$text}) {
$line_flags[$line] = 0;
my $mode = substr($text->[$line], 0, 1);
if ($mode eq '\\') {
$line_flags[$line - 1] |= NO_NEWLINE;
}
+   if ($mode ne '-' and $last_mode eq '-' or
+   $mode ne '+' and $last_mode eq '+') {
+   $line_flags[$line - 1] |= LAST_ADD_DEL;
+   }
+   if ($mode eq '+' and $last_mode ne '+') {
+   $line_flags[$line] |= FIRST_ADD;
+   }
if ($mode eq '-' or $mode eq '+') {
-   $lines[++$label] = $line;
+   $blocks[++$label] = $block;
+   $lines[$label] = $line;
+   $modes[$label] = $mode;
+   } elsif ($mode eq ' ' and $last_mode ne ' ') {
+   $block++;
}
+   $last_mode = $mode;
+   }
+   if ($last_mode eq '-' or $last_mode eq '+') {
+   $line_flags[-1] |= LAST_ADD_DEL;
}
if ($label > 1) {
$hunk->{LABELS} = {
+   BLOCKS => \@blocks,
LINES => \@lines,
+   MODES => \@modes
};
$hunk->{LINE_FLAGS} = \@line_flags;
return 1;
@@ -1061,11 +1082,14 @@ sub select_hunk_lines {
}
};
 
-   my ($lo, 

[RFC PATCH v5 0/4] add -p: select individual hunk lines

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

Unfortuantely v4 had test failures due to a suprious brace from a last
minute edit to a comment that I forgot to test. This version fixes
that, my applogies for the patch churn.

I've updated this series based on Ævar's feedback on v3 (to paraphrase
stop using '$_' so much and fix staging modified lines.). The first
patch is functionally equivalent to the previous version but with a
reworked implementation. Patch 2 is new, it implements correctly
staging modified lines with a couple of limitations - see the commit
message for more details, I'm keen to get some feedback on it. Patches
3 and 4 are essentially rebased and tweaked versions of patches 2 and
3 from the previous version.

This series is based on pw/add-p-recount (f4d35a6b49 "add -p: fix
counting empty context lines in edited patches")

The motivation for this series is summed up in the first commit
message:

"When I end up editing hunks it is almost always because I want to
stage a subset of the lines in the hunk. Doing this by editing the
hunk is inconvenient and error prone (especially so if the patch is
going to be reversed before being applied). Instead offer an option
for add -p to stage individual lines. When the user presses 'l' the
hunk is redrawn with labels by the insertions and deletions and they
are prompted to enter a list of the lines they wish to stage. Ranges
of lines may be specified using 'a-b' where either 'a' or 'b' may be
omitted to mean all lines from 'a' to the end of the hunk or all lines
from 1 upto and including 'b'."

Phillip Wood (4):
  add -p: select individual hunk lines
  add -p: select modified lines correctly
  add -p: allow line selection to be inverted
  add -p: optimize line selection for short hunks

 Documentation/git-add.txt  |  10 ++
 git-add--interactive.perl  | 349 +
 t/t3701-add-interactive.sh | 209 ++
 3 files changed, 568 insertions(+)

-- 
2.18.0



Re: [RFC PATCH 0/5] format-patch: automate cover letter range-diff

2018-07-26 Thread Johannes Schindelin
Hi Andrei,

On Thu, 26 Jul 2018, Andrei Rybak wrote:

> On 2018-05-30 10:03, Eric Sunshine wrote:
> > Dscho recently implemented a 'tbdiff' replacement as a Git builtin named
> > git-branch-diff[1] which computes differences between two versions of a
> > patch series. Such a diff can be a useful aid for reviewers when
> > inserted into a cover letter. However, doing so requires manual
> > generation (invoking git-branch-diff) and copy/pasting the result into
> > the cover letter.
> > 
> > This series fully automates the process by adding a --range-diff option
> > to git-format-patch. 
> 
> [...]
> 
> > 
> > Eric Sunshine (5):
> >   format-patch: allow additional generated content in
> > make_cover_letter()
> >   format-patch: add --range-diff option to embed diff in cover letter
> >   format-patch: extend --range-diff to accept revision range
> >   format-patch: teach --range-diff to respect -v/--reroll-count
> >   format-patch: add --creation-weight tweak for --range-diff
> > 
> >  Documentation/git-format-patch.txt |  18 +
> >  builtin/log.c  | 119 -
> >  t/t7910-branch-diff.sh |  16 
> >  3 files changed, 132 insertions(+), 21 deletions(-)
> 
> Would it make sense to mention new option in the cover letter section of
> Documentation/SubmittingPatches?

I would be hesitant to add it there already. Let's prove first that these
options are really as useful as we hope they are.

It might turn out that in many cases, the range-diff is just stupidly
unreadable, for example. Personally, I already miss the color coding when
looking at range-diffs sent via mails.

Ciao,
Johannes


Re: [PATCH v2] name_rev: add support for --cherry-picks

2018-07-26 Thread Tejun Heo
Hello, Junio.

On Thu, Jul 26, 2018 at 08:12:45AM -0700, Junio C Hamano wrote:
> Tejun Heo  writes:
> 
> > From a6a88c3da252d69547ac8b463098fc4f4c03f322 Mon Sep 17 00:00:00 2001
> > From: Tejun Heo 
> > Date: Thu, 26 Jul 2018 04:14:52 -0700
> > Subject: [PATCH] name_rev: add support for --cherry-picks
> 
> The above belongs to the mail header, not the body.

Ah, right, sorry about that.

> >   $ git name-rev --cherry-picks 10f7ce0a0e524279f022
> >   10f7ce0a0e524279f022 master~1
> > d433e3b4d5a19b3d29e2c8349fe88ceade5f6190 branch1
> >   82cddd79f962de0bb1e7cdd95d48b4865816 branch2
> > 58a8d36b2532feb0a14b4fc2a50d587e64f38324 branch3
> > fa8b79edc5dfff21753c2ccfc1a1828336c4c070 branch4~1
> 
> "git name-rev X" asks "I want to know about X".  And the first line
> of the above tells us that 10f7ce is the first parent of the master
> branch.  What does the second line tell us?  10f7ce was created by
> cherry picking d433e3b4 which sits at the tip of branch1?
> 
> It appears that you are showing the reverse (d433e3, 58a8d3 and
> fa8b79 sit next to each other, but it cannot be that 10f7ce was
> created by cherry-picking these three).  I do not mean to say that

So, it means that d433e, 58a8d and fa8b7 are created by cherry picking
10f7c and 72cdd is created by cherry picking d433e.

> the reverse information is not useful thing to learn about the
> commit (i.e. "X got cherry-picked to all these places") but I am
> having a hard time convincing myself that the feature sits well in
> "describe" and "name-rev".

I should have explained the use case better.  Let's say I'm forking
off and maintaining prod releases.  We branch it off of a major
upstream version and keeps developing / backporting on that branch
reguarly cutting releases.  A lot of commits get cherry-picked back
from master tracking upstream but some are also cherry picked to
sub-release branches for quick-fix releases.  e.g.

  v4.16
 oooAoo..o master
   \.ooA'oo.o v4.16-prod
  \  \.oo v4.16-prod-r2
   \ .oA'' v4.16-prod-r1

Given a commit, it's useful to find out through which version that got
released, which is where "git-describe --contains" helps.  However,
when commits are backported through cherry-picks to prod branches as
in above, that commit is released through multiple versions and it's a
bit painful to hunt them down.  This is what --cherry-picks helps
with, so if now I do "git describe --contains --cherry-picks A", it'll
tell me that...

  Upstream, it's v4.17-rc1
Backported and released through v4.16-prod-r2
  Also backported to v4.16-prod-r1 (cuz the fix happened while r1 was going 
through rc's)

So, it extends the description of how the original commit is released
(or given name) so that releases through cherry-picks are also
included.

Thanks.

-- 
tejun


Re: [PATCH v2] name_rev: add support for --cherry-picks

2018-07-26 Thread Junio C Hamano
Tejun Heo  writes:

> From a6a88c3da252d69547ac8b463098fc4f4c03f322 Mon Sep 17 00:00:00 2001
> From: Tejun Heo 
> Date: Thu, 26 Jul 2018 04:14:52 -0700
> Subject: [PATCH] name_rev: add support for --cherry-picks

The above belongs to the mail header, not the body.

> It's often useful to track cherry-picks of a given commit.  Add
> --cherry-picks support to git-name-rev.  When specified, name_rev also
> shows the commits cherry-picked from the listed target commits with
> indentations.
>
>   $ git name-rev --cherry-picks 10f7ce0a0e524279f022
>   10f7ce0a0e524279f022 master~1
> d433e3b4d5a19b3d29e2c8349fe88ceade5f6190 branch1
>   82cddd79f962de0bb1e7cdd95d48b4865816 branch2
> 58a8d36b2532feb0a14b4fc2a50d587e64f38324 branch3
> fa8b79edc5dfff21753c2ccfc1a1828336c4c070 branch4~1

"git name-rev X" asks "I want to know about X".  And the first line
of the above tells us that 10f7ce is the first parent of the master
branch.  What does the second line tell us?  10f7ce was created by
cherry picking d433e3b4 which sits at the tip of branch1?

It appears that you are showing the reverse (d433e3, 58a8d3 and
fa8b79 sit next to each other, but it cannot be that 10f7ce was
created by cherry-picking these three).  I do not mean to say that
the reverse information is not useful thing to learn about the
commit (i.e. "X got cherry-picked to all these places") but I am
having a hard time convincing myself that the feature sits well in
"describe" and "name-rev".

> Note that branch2 is further indented because it's a nested cherry
> pick from d433e3b4d5a1.
>
> "git-describe --contains" is a wrapper around git-name-rev.  Also add
> --cherry-picks support to git-describe.
>
> v2: - Remove a warning message for a malformed cherry-picked tag.
>   There isn't much user can do about it.
> - Continue scanning cherry-pick tags until a working one is found
>   instead of aborting after trying the last one.  It might miss
>   nesting but still better to show than miss the commit entirely.


Re: [PATCH v1] checkout: optionally speed up "git checkout -b foo"

2018-07-26 Thread Junio C Hamano
Ben Peart  writes:

[jc: it was a bit surprising that Eric covered all the bits I
covered while we were writing without peeking each other's ;-)]

>> This long list of special-case checks doesn't leave me too enthused,
>> however, that aside, this approach seems backward. Rather than erring
>> on the side of safety by falling back to the merging behavior, it errs
>> in the other direction, ...
>
> I'm not thrilled with the long list either (the plethora of comments
> probably makes it appear worse than it is) but I don't see how...

If there were a simple and futureproof way to tell the option
parsing loop to notice any feature other than "-b newbranch" was
used, then such a whitelisting may be a viable way, but there is
not, and the whitelist condition can become (over time---we are
talking about futureproofing and not "a filter that happens to match
today's feature set") just as complex as this blacklisting function
is (e.g. feature A and feature B when used alone may be compatible
with the optimization but not when used both), so if we were to use
this optimization, I think this long list of special-case checks is
the best we could do.

>>  if (!skip_worktree_merge(...))
>>  ret = merge_working_tree(...);
>>
>
> I personally agree, it was moved to its current location per feedback
> the first time around.  Perhaps with the addition of the config
> setting it will be better received moved out to the caller.

Sounds sensible.  I am still not enthused by the configuration
variable that is underdocumented.  You already said that we know
that this optimization does a wrong thing when sparse checkout is
used---any other cases?  I do not think of any myself, and if that
is true, I am wondering if it makes more sense to "do we have sparse
configuration?" as part of the blacklist condition.  That way, the
users do not have to set anything and they will get an optimization
benefit from an obvious change to skip "read-tree -m HEAD HEAD" that
ought to be a no-op.

Thanks.


[PATCH v2] name_rev: add support for --cherry-picks

2018-07-26 Thread Tejun Heo
>From a6a88c3da252d69547ac8b463098fc4f4c03f322 Mon Sep 17 00:00:00 2001
From: Tejun Heo 
Date: Thu, 26 Jul 2018 04:14:52 -0700
Subject: [PATCH] name_rev: add support for --cherry-picks

It's often useful to track cherry-picks of a given commit.  Add
--cherry-picks support to git-name-rev.  When specified, name_rev also
shows the commits cherry-picked from the listed target commits with
indentations.

  $ git name-rev --cherry-picks 10f7ce0a0e524279f022
  10f7ce0a0e524279f022 master~1
d433e3b4d5a19b3d29e2c8349fe88ceade5f6190 branch1
  82cddd79f962de0bb1e7cdd95d48b4865816 branch2
58a8d36b2532feb0a14b4fc2a50d587e64f38324 branch3
fa8b79edc5dfff21753c2ccfc1a1828336c4c070 branch4~1

Note that branch2 is further indented because it's a nested cherry
pick from d433e3b4d5a1.

"git-describe --contains" is a wrapper around git-name-rev.  Also add
--cherry-picks support to git-describe.

v2: - Remove a warning message for a malformed cherry-picked tag.
  There isn't much user can do about it.
- Continue scanning cherry-pick tags until a working one is found
  instead of aborting after trying the last one.  It might miss
  nesting but still better to show than miss the commit entirely.

Signed-off-by: Tejun Heo 
---
 Documentation/git-describe.txt   |   5 ++
 Documentation/git-name-rev.txt   |   4 ++
 builtin/describe.c   |   7 +-
 builtin/name-rev.c   | 115 +--
 t/t6121-describe-cherry-picks.sh |  63 +
 5 files changed, 188 insertions(+), 6 deletions(-)
 create mode 100755 t/t6121-describe-cherry-picks.sh

diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index e027fb8c4..13a229bd7 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -60,6 +60,11 @@ OPTIONS
the tag that comes after the commit, and thus contains it.
Automatically implies --tags.
 
+--cherry-picks::
+   Also show the commits cherry-picked from the target commits.
+   Cherry-picks are shown indented below their from-commmits.
+   Can only be used with --contains.
+
 --abbrev=::
Instead of using the default 7 hexadecimal digits as the
abbreviated object name, use  digits, or as many digits
diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt
index 5cb0eb085..df16c4a89 100644
--- a/Documentation/git-name-rev.txt
+++ b/Documentation/git-name-rev.txt
@@ -61,6 +61,10 @@ OPTIONS
 --always::
Show uniquely abbreviated commit object as fallback.
 
+--cherry-picks::
+   Also show the commits cherry-picked from the target commits.
+   Cherry-picks are shown indented below their from-commmits.
+
 EXAMPLES
 
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 1e87f68d5..94c84004d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -528,9 +528,10 @@ static void describe(const char *arg, int last_one)
 
 int cmd_describe(int argc, const char **argv, const char *prefix)
 {
-   int contains = 0;
+   int contains = 0, cherry_picks = 0;
struct option options[] = {
OPT_BOOL(0, "contains",   , N_("find the tag that 
comes after the commit")),
+   OPT_BOOL(0, "cherry-picks", _picks, N_("also include 
cherry-picks with --contains")),
OPT_BOOL(0, "debug",  , N_("debug search strategy on 
stderr")),
OPT_BOOL(0, "all",, N_("use any ref")),
OPT_BOOL(0, "tags",   , N_("use any tag, even 
unannotated")),
@@ -570,6 +571,8 @@ int cmd_describe(int argc, const char **argv, const char 
*prefix)
 
if (longformat && abbrev == 0)
die(_("--long is incompatible with --abbrev=0"));
+   if (cherry_picks && !contains)
+   die(_("--cherry-picks can only be used with --contains"));
 
if (contains) {
struct string_list_item *item;
@@ -579,6 +582,8 @@ int cmd_describe(int argc, const char **argv, const char 
*prefix)
argv_array_pushl(, "name-rev",
 "--peel-tag", "--name-only", "--no-undefined",
 NULL);
+   if (cherry_picks)
+   argv_array_push(, "--cherry-picks");
if (always)
argv_array_push(, "--always");
if (!all) {
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 0eb440359..adffae0fe 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -7,9 +7,13 @@
 #include "parse-options.h"
 #include "sha1-lookup.h"
 #include "commit-slab.h"
+#include "trailer.h"
+#include "object-store.h"
 
 #define CUTOFF_DATE_SLOP 86400 /* one day */
 
+static const char cherry_picked_prefix[] = "(cherry picked from commit ";
+
 typedef struct rev_name {
const char *tip_name;
timestamp_t taggerdate;
@@ -19,9 +23,12 @@ typedef struct rev_name {
 } rev_name;
 
 

Re: [PATCH] negotiator/skipping: skip commits during fetch

2018-07-26 Thread Johannes Schindelin
Hi Jonathan,

On Thu, 26 Jul 2018, Johannes Schindelin wrote:

> On Mon, 16 Jul 2018, Jonathan Tan wrote:
> 
> >  t/t5552-skipping-fetch-negotiator.sh | 179 +++
> 
> This test seems to be failing consistently in the recent `pu` builds:
> 
> https://git-for-windows.visualstudio.com/git/_build/results?buildId=14337=logs

It now also causes `next` builds to fail:

https://git-for-windows.visualstudio.com/git/_build/results?buildId=14345=logs

Please have a look,
Dscho

> Could you have a look, please?
> 
> Ciao,
> Dscho
> 
> P.S.: For your convenience, I will paste the last part of the output with
> `-i -v -x` here:
> 
> -- snipsnap --
> 2018-07-26T08:18:39.7864833Z expecting success: 
> 2018-07-26T08:18:39.7868553Z  rm -rf server client trace &&
> 2018-07-26T08:18:39.7869403Z  git init server &&
> 2018-07-26T08:18:39.7869606Z  test_commit -C server to_fetch &&
> 2018-07-26T08:18:39.7870066Z 
> 2018-07-26T08:18:39.7870281Z  git init client &&
> 2018-07-26T08:18:39.7870403Z 
> 2018-07-26T08:18:39.7870579Z  # 2 regular commits
> 2018-07-26T08:18:39.7870779Z  test_tick=20 &&
> 2018-07-26T08:18:39.7870943Z  test_commit -C client c1 &&
> 2018-07-26T08:18:39.7871103Z  test_commit -C client c2 &&
> 2018-07-26T08:18:39.7871228Z 
> 2018-07-26T08:18:39.7871419Z  # 4 old commits
> 2018-07-26T08:18:39.7871575Z  test_tick=10 &&
> 2018-07-26T08:18:39.7871734Z  git -C client checkout c1 &&
> 2018-07-26T08:18:39.7871916Z  test_commit -C client old1 &&
> 2018-07-26T08:18:39.7872081Z  test_commit -C client old2 &&
> 2018-07-26T08:18:39.7872396Z  test_commit -C client old3 &&
> 2018-07-26T08:18:39.7872598Z  test_commit -C client old4 &&
> 2018-07-26T08:18:39.7872743Z 
> 2018-07-26T08:18:39.7872918Z  # "c2" and "c1" are popped first, then "old4" 
> to "old1". "old1" would
> 2018-07-26T08:18:39.7873114Z  # normally be skipped, but is treated as a 
> commit without a parent here
> 2018-07-26T08:18:39.7873329Z  # and sent, because (due to clock skew) its 
> only parent has already been
> 2018-07-26T08:18:39.7873524Z  # popped off the priority queue.
> 2018-07-26T08:18:39.7873700Z  test_config -C client 
> fetch.negotiationalgorithm skipping &&
> 2018-07-26T08:18:39.7873908Z  GIT_TRACE_PACKET="$(pwd)/trace" git -C client 
> fetch "$(pwd)/server" &&
> 2018-07-26T08:18:39.7874091Z  have_sent c2 c1 old4 old2 old1 &&
> 2018-07-26T08:18:39.7874262Z  have_not_sent old3
> 2018-07-26T08:18:39.7874383Z 
> 2018-07-26T08:18:39.8353323Z ++ rm -rf server client trace
> 2018-07-26T08:18:40.3404166Z ++ git init server
> 2018-07-26T08:18:40.3756394Z Initialized empty Git repository in 
> D:/a/1/s/t/trash directory.t5552-skipping-fetch-negotiator/server/.git/
> 2018-07-26T08:18:40.3769512Z ++ test_commit -C server to_fetch
> 2018-07-26T08:18:40.3776271Z ++ notick=
> 2018-07-26T08:18:40.3777103Z ++ signoff=
> 2018-07-26T08:18:40.3777282Z ++ indir=
> 2018-07-26T08:18:40.3777465Z ++ test 3 '!=' 0
> 2018-07-26T08:18:40.3777648Z ++ case "$1" in
> 2018-07-26T08:18:40.3777801Z ++ indir=server
> 2018-07-26T08:18:40.3777948Z ++ shift
> 2018-07-26T08:18:40.3778093Z ++ shift
> 2018-07-26T08:18:40.3778493Z ++ test 1 '!=' 0
> 2018-07-26T08:18:40.3778921Z ++ case "$1" in
> 2018-07-26T08:18:40.3779072Z ++ break
> 2018-07-26T08:18:40.3779241Z ++ indir=server/
> 2018-07-26T08:18:40.3779431Z ++ file=to_fetch.t
> 2018-07-26T08:18:40.3779603Z ++ echo to_fetch
> 2018-07-26T08:18:40.3779923Z ++ git -C server/ add to_fetch.t
> 2018-07-26T08:18:40.4072248Z ++ test -z ''
> 2018-07-26T08:18:40.4072727Z ++ test_tick
> 2018-07-26T08:18:40.4072948Z ++ test -z set
> 2018-07-26T08:18:40.4073113Z ++ test_tick=1112913673
> 2018-07-26T08:18:40.4073758Z ++ GIT_COMMITTER_DATE='1112913673 -0700'
> 2018-07-26T08:18:40.4074001Z ++ GIT_AUTHOR_DATE='1112913673 -0700'
> 2018-07-26T08:18:40.4074178Z ++ export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
> 2018-07-26T08:18:40.4074357Z ++ git -C server/ commit -m to_fetch
> 2018-07-26T08:18:40.4485364Z [master (root-commit) ff85695] to_fetch
> 2018-07-26T08:18:40.4485997Z  Author: A U Thor 
> 2018-07-26T08:18:40.4486201Z  1 file changed, 1 insertion(+)
> 2018-07-26T08:18:40.4486414Z  create mode 100644 to_fetch.t
> 2018-07-26T08:18:40.4499970Z ++ git -C server/ tag to_fetch
> 2018-07-26T08:18:40.4809208Z ++ git init client
> 2018-07-26T08:18:40.5139949Z Initialized empty Git repository in 
> D:/a/1/s/t/trash directory.t5552-skipping-fetch-negotiator/client/.git/
> 2018-07-26T08:18:40.5158270Z ++ test_tick=20
> 2018-07-26T08:18:40.5158466Z ++ test_commit -C client c1
> 2018-07-26T08:18:40.5159077Z ++ notick=
> 2018-07-26T08:18:40.5159492Z ++ signoff=
> 2018-07-26T08:18:40.5159697Z ++ indir=
> 2018-07-26T08:18:40.5159855Z ++ test 3 '!=' 0
> 2018-07-26T08:18:40.5160010Z ++ case "$1" in
> 2018-07-26T08:18:40.5160209Z ++ indir=client
> 2018-07-26T08:18:40.5160362Z ++ shift
> 2018-07-26T08:18:40.5160507Z ++ shift
> 2018-07-26T08:18:40.5160657Z ++ test 1 '!=' 0
> 2018-07-26T08:18:40.5160831Z ++ case "$1" in
> 

[PATCH v2 2/2] doc hash-function-transition: pick SHA-256 as NewHash

2018-07-26 Thread Ævar Arnfjörð Bjarmason
>From a security perspective, it seems that SHA-256, BLAKE2, SHA3-256,
K12, and so on are all believed to have similar security properties.
All are good options from a security point of view.

SHA-256 has a number of advantages:

* It has been around for a while, is widely used, and is supported by
  just about every single crypto library (OpenSSL, mbedTLS, CryptoNG,
  SecureTransport, etc).

* When you compare against SHA1DC, most vectorized SHA-256
  implementations are indeed faster, even without acceleration.

* If we're doing signatures with OpenPGP (or even, I suppose, CMS),
  we're going to be using SHA-2, so it doesn't make sense to have our
  security depend on two separate algorithms when either one of them
  alone could break the security when we could just depend on one.

So SHA-256 it is. See the "Hash algorithm analysis" thread as of
[1]. Linus has come around to this choice and suggested Junio make the
final pick, and he's endorsed SHA-256 [3].

This follow-up change changes occurrences of "NewHash" to
"SHA-256" (or "sha256", depending on the context). The "Selection of a
New Hash" section has also been changed to note that historically we
used the the "NewHash" name while we didn't know what the new hash
function would be.

This leaves no use of "NewHash" anywhere in git.git except in the
aforementioned section (and as a variable name in t/t9700/test.pl, but
that use from 2008 has nothing to do with this transition plan).

1. 
https://public-inbox.org/git/20180720215220.gb18...@genre.crustytoothpaste.net/
2. 
https://public-inbox.org/git/ca+55afwse9bf8e0hlk9pp3fvd5lavy5grdsv3fbntgzekja...@mail.gmail.com/
3. https://public-inbox.org/git/xmqqzhygwd5o@gitster-ct.c.googlers.com/

Helped-by: Jonathan Nieder 
Helped-by: Junio C Hamano 
Signed-off-by: Ævar Arnfjörð Bjarmason 
---

On Wed, Jul 25 2018, Junio C Hamano wrote:
> Jonathan Nieder  writes:
> [...]
> All interesting ideas and good suggestions.  I'll leave 2/2 in the
> mail archive and take only 1/2 for now.  I'd expect the final
> version, not too soon after mulling over the suggestions raised
> here, but not in too distant future to prevent us from forgetting
> ;-)

Here's a v2 which uses the suggestions for both the commit message &
documentation from Jonathan and yourself. Thanks!

 .../technical/hash-function-transition.txt| 196 +-
 1 file changed, 99 insertions(+), 97 deletions(-)

diff --git a/Documentation/technical/hash-function-transition.txt 
b/Documentation/technical/hash-function-transition.txt
index 5ee4754adb..5041e57273 100644
--- a/Documentation/technical/hash-function-transition.txt
+++ b/Documentation/technical/hash-function-transition.txt
@@ -59,14 +59,11 @@ that are believed to be cryptographically secure.
 
 Goals
 -
-Where NewHash is a strong 256-bit hash function to replace SHA-1 (see
-"Selection of a New Hash", below):
-
-1. The transition to NewHash can be done one local repository at a time.
+1. The transition to SHA-256 can be done one local repository at a time.
a. Requiring no action by any other party.
-   b. A NewHash repository can communicate with SHA-1 Git servers
+   b. A SHA-256 repository can communicate with SHA-1 Git servers
   (push/fetch).
-   c. Users can use SHA-1 and NewHash identifiers for objects
+   c. Users can use SHA-1 and SHA-256 identifiers for objects
   interchangeably (see "Object names on the command line", below).
d. New signed objects make use of a stronger hash function than
   SHA-1 for their security guarantees.
@@ -79,7 +76,7 @@ Where NewHash is a strong 256-bit hash function to replace 
SHA-1 (see
 
 Non-Goals
 -
-1. Add NewHash support to Git protocol. This is valuable and the
+1. Add SHA-256 support to Git protocol. This is valuable and the
logical next step but it is out of scope for this initial design.
 2. Transparently improving the security of existing SHA-1 signed
objects.
@@ -87,26 +84,26 @@ Non-Goals
repository.
 4. Taking the opportunity to fix other bugs in Git's formats and
protocols.
-5. Shallow clones and fetches into a NewHash repository. (This will
-   change when we add NewHash support to Git protocol.)
-6. Skip fetching some submodules of a project into a NewHash
-   repository. (This also depends on NewHash support in Git
+5. Shallow clones and fetches into a SHA-256 repository. (This will
+   change when we add SHA-256 support to Git protocol.)
+6. Skip fetching some submodules of a project into a SHA-256
+   repository. (This also depends on SHA-256 support in Git
protocol.)
 
 Overview
 
 We introduce a new repository format extension. Repositories with this
-extension enabled use NewHash instead of SHA-1 to name their objects.
+extension enabled use SHA-256 instead of SHA-1 to name their objects.
 This affects both object names and object content --- both the names
 of objects and all references to other objects within an object are
 switched to the new hash function.
 

[PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread Chen Bin
Hook pre-p4-submit is executed before git-p4 actually submits code.
If the hook exits with non-zero value, submit process will abort.

Signed-off-by: Chen Bin 
---
 Documentation/git-p4.txt   | 12 
 Documentation/githooks.txt |  7 +++
 git-p4.py  | 21 -
 t/t9800-git-p4-basic.sh| 26 ++
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index f0de3b891..f5d428ddf 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -374,6 +374,18 @@ These options can be used to modify 'git p4 submit' 
behavior.
 been submitted. Implies --disable-rebase. Can also be set with
 git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
 
+Hook for submit
+~~~
+Hook `p4-pre-submit` is executed if it exists and is executable.
+The hook takes no parameter and nothing from standard input. Exiting with
+non-zero status from this script prevents `git-p4 submit` from launching.
+So nothing is touched when it exits with non-zero status.
+
+One usage scenario is to run unit tests in the hook.
+
+By default the hooks directory is `$GIT_DIR/hooks`, but that can be changed.
+See githooks(5) manpage for details about hooks.
+
 Rebase options
 ~~
 These options can be used to modify 'git p4 rebase' behavior.
diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index e3c283a17..22fcabbe2 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -485,6 +485,13 @@ The exit status determines whether git will use the data 
from the
 hook to limit its search.  On error, it will fall back to verifying
 all files and folders.
 
+p4-pre-submit
+~
+
+This hook is invoked by `git-p4 submit`. It takes no parameter and nothing
+from standard input. Exiting with non-zero status from this script prevent
+`git-p4 submit` from launching. Run `git-p4 submit --help` for details.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/git-p4.py b/git-p4.py
index b449db1cc..f147a2d2f 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1494,7 +1494,17 @@ def __init__(self):
 optparse.make_option("--disable-p4sync", 
dest="disable_p4sync", action="store_true",
  help="Skip Perforce sync of p4/master 
after submit or shelve"),
 ]
-self.description = "Submit changes from git to the perforce depot."
+self.description = """Submit changes from git to the perforce depot.\n
+Hook `p4-pre-submit` is executed if it exists and is executable.
+The hook takes no parameter and nothing from standard input. Exiting with
+non-zero status from this script prevents `git-p4 submit` from launching.
+So nothing is touched when it exits with non-zero status.
+
+One usage scenario is to run unit tests in the hook.
+
+By default the hooks directory is `$GIT_DIR/hooks`, but that can be 
changed.
+See githooks(5) manpage for details about hooks."""
+
 self.usage += " [name of git branch to submit into perforce depot]"
 self.origin = ""
 self.detectRenames = False
@@ -2303,6 +2313,15 @@ def run(self, args):
 sys.exit("number of commits (%d) must match number of shelved 
changelist (%d)" %
  (len(commits), num_shelves))
 
+hooks_path = gitConfig("core.hooksPath")
+if len(hooks_path) > 0:
+hook_file = os.path.join(hooks_path, "p4-pre-submit")
+else:
+hook_file = os.path.join(read_pipe("git rev-parse 
--git-dir").strip(), "hooks", "p4-pre-submit")
+
+if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and 
subprocess.call([hook_file]) != 0:
+sys.exit(1)
+
 #
 # Apply the commits, one at a time.  On failure, ask if should
 # continue to try the rest of the patches, or quit.
diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh
index 4849edc4e..8457ff617 100755
--- a/t/t9800-git-p4-basic.sh
+++ b/t/t9800-git-p4-basic.sh
@@ -261,6 +261,32 @@ test_expect_success 'unresolvable host in P4PORT should 
display error' '
)
 '
 
+# Test following scenarios:
+#   - Without hook ".git/hooks/p4-pre-submit", submit should continue
+#   - With hook returning 0, submit should continue
+#   - With hook returning 1, submit should abort
+test_expect_success 'run hook p4-pre-submit before submit' '
+   test_when_finished cleanup_git &&
+   git p4 clone --dest="$git" //depot &&
+   (
+   cd "$git" &&
+   echo "hello world" >hello.txt &&
+   git add hello.txt &&
+   git commit -m "add hello.txt" &&
+   git config git-p4.skipSubmitEdit true &&
+   git p4 submit --dry-run | grep "Would apply" &&
+   mkdir -p .git/hooks &&
+   write_script .git/hooks/p4-pre-submit <<-\EOF &&
+  

Re: [RFC PATCH 0/5] Add delta islands support

2018-07-26 Thread Johannes Schindelin
Hi Chris,


On Sun, 22 Jul 2018, Christian Couder wrote:

> This patch series is upstreaming work made by GitHub and available in:
> 
> https://github.com/peff/git/commits/jk/delta-islands
> 
> The patch in the above branch has been split into 5 patches with their
> own new commit message, but no other change has been made.
> 
> I kept Peff as the author and took the liberty to add his
> Signed-off-by to all the patches.
> 
> The patches look good to me except perhaps that "pack.islandCore" is
> not documented. Maybe something could be added in
> Documentation/technical/ too, or maybe improving commit messages could
> be enough.
> 
> Anyway I wanted to send this nearly "as is" first to get early
> feedback about what should be done.
> 
> This patch series is also available on GitHub in:
> 
> https://github.com/chriscool/git/commits/delta-islands

It might make sense to explain *somewhere* in the cover letter what the
patches are all about, i.e. what problem they are supposed to solve. I did
not see any indication here.

Ciao,
Dscho

> 
> Jeff King (5):
>   packfile: make get_delta_base() non static
>   Add delta-islands.{c,h}
>   pack-objects: add delta-islands support
>   repack: add delta-islands support
>   t: add t9930-delta-islands.sh
> 
>  Documentation/config.txt   |   8 +
>  Documentation/git-pack-objects.txt |  88 ++
>  Documentation/git-repack.txt   |   5 +
>  Makefile   |   1 +
>  builtin/pack-objects.c | 130 +---
>  builtin/repack.c   |   9 +
>  delta-islands.c| 490 +
>  delta-islands.h|  11 +
>  pack-objects.h |   4 +
>  packfile.c |  10 +-
>  packfile.h |   3 +
>  t/t9930-delta-islands.sh   | 143 +
>  12 files changed, 856 insertions(+), 46 deletions(-)
>  create mode 100644 delta-islands.c
>  create mode 100644 delta-islands.h
>  create mode 100755 t/t9930-delta-islands.sh
> 
> -- 
> 2.18.0.237.gffdb1dbdaa
> 
> 


Re: [PATCH] sequencer.c: terminate the last line of author-script properly

2018-07-26 Thread Johannes Schindelin
Hi Phillip,

On Thu, 19 Jul 2018, Phillip Wood wrote:

> On 18/07/18 18:17, Junio C Hamano wrote:
> > Phillip Wood  writes:
> > 
> >>> (I think we had code to do so in "git am"
> >>> that was rewritten in C first).
> >>
> >> The code in builtin/am.c doesn't try to write valid posix shell (if
> >> one assumes it is the only consumer of the author script then it
> >> doesn't need to) which results in simpler code, but external scripts
> >> cannot safely eval it anymore.
> > 
> > Are you sure about that? If so we probably should see if we can fix> the 
> > writer, and better yet, if we can share code with the writer
> > discussed here, as presumably we are fixing it in this thread.
> > 
> > But I do not see how builtin/am.c::write_author_script() would
> > produce something that would not eval correctly.  sq_quote_buf() was
> > introduced specifically to write correct string for shell's
> > consumption.
> 
> You're right, I'm not sure how I missed the calls to sq_quote_buf()
> yesterday, sharing the am code with the sequencer would clean things up
> nicely.

No, actually Phillip was right. The `author-script` file written by
`git-am` was always an implementation detail, and as there was no
(intended) way to call shell scripts while running `git-am`, the only
shell script to intentionally use `author-script` was `git-am` itself.

Ever since `git-am` is a builtin, the `author-script` file format could be
changed, because it is an implementation detail, no more nor less, and I
think it *should* be changed, too. We're spending useless cycles on
quoting and dequoting, when writing a NUL-separated list of var=value
pairs would be totally sufficient to our ends.

Ciao,
Dscho


Re: [RFC PATCH] sequencer: fix quoting in write_author_script

2018-07-26 Thread Johannes Schindelin
Hi Phillip,

On Wed, 18 Jul 2018, Phillip Wood wrote:

> From: Phillip Wood 
> 
> Single quotes should be escaped as \' not \\'. Note that this only
> affects authors that contain a single quote and then only external
> scripts that read the author script and users whose git is upgraded from
> the shell version of rebase -i while rebase was stopped. This is because
> the parsing in read_env_script() expected the broken version and for
> some reason sq_dequote() called by read_author_ident() seems to handle
> the broken quoting correctly.
> 
> Ideally write_author_script() would be rewritten to use
> split_ident_line() and sq_quote_buf() but this commit just fixes the
> immediate bug.
> 
> Signed-off-by: Phillip Wood 
> ---

Good catch.

> This is untested, unfortuantely I don't have really have time to write a test 
> or
> follow this up at the moment, if someone else want to run with it then please
> do.

I modified the test that was added by Akinori. As it was added very early,
and as there is still a test case *after* Akinori's that compares a
hard-coded SHA-1, I refrained from using `test_commit` (which would change
that SHA-1). See below.

> diff --git a/sequencer.c b/sequencer.c
> index 5354d4d51e..0b78d1f100 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -638,21 +638,21 @@ static int write_author_script(const char *message)
>   else if (*message != '\'')
>   strbuf_addch(, *(message++));
>   else
> - strbuf_addf(, "'%c'", *(message++));
> + strbuf_addf(, "'\\%c'", *(message++));
>   strbuf_addstr(, "'\nGIT_AUTHOR_EMAIL='");
>   while (*message && *message != '\n' && *message != '\r')
>   if (skip_prefix(message, "> ", ))
>   break;
>   else if (*message != '\'')
>   strbuf_addch(, *(message++));
>   else
> - strbuf_addf(, "'%c'", *(message++));
> + strbuf_addf(, "'\\%c'", *(message++));
>   strbuf_addstr(, "'\nGIT_AUTHOR_DATE='@");
>   while (*message && *message != '\n' && *message != '\r')
>   if (*message != '\'')
>   strbuf_addch(, *(message++));
>   else
> - strbuf_addf(, "'%c'", *(message++));
> + strbuf_addf(, "'\\%c'", *(message++));
>   res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);

I resolved the merge conflict with Akinori's patch. FWIW I pushed all of
this, including the fixup to Junio's fixup to the
`fix-t3404-author-script-test` branch at https://github.com/dscho/git.

>   strbuf_release();
>   return res;
> @@ -666,13 +666,21 @@ static int read_env_script(struct argv_array *env)
>  {
>   struct strbuf script = STRBUF_INIT;
>   int i, count = 0;
> - char *p, *p2;
> + const char *p2;
> + char *p;
>  
>   if (strbuf_read_file(, rebase_path_author_script(), 256) <= 0)
>   return -1;
>  
>   for (p = script.buf; *p; p++)
> - if (skip_prefix(p, "'''", (const char **)))
> + /*
> +  * write_author_script() used to escape "'" incorrectly as
> +  * "'''" rather than "'\\''" so we check for the correct
> +  * version the incorrect version in case git was upgraded while
> +  * rebase was stopped.
> +  */
> + if (skip_prefix(p, "'\\''", ) ||
> + skip_prefix(p, "'''", ))

I think in this form, it is possibly unsafe because it assumes that the
new code cannot generate output that would trigger that same code path.
Although I have to admit that I did not give this a great deal of thought.

In any case, if you have to think long and hard about some fix, it might
be better to go with something that is easier to reason about. So how
about this: we already know that the code is buggy, Akinori fixed the bug,
where the author-script missed its trailing single-quote. We can use this
as a tell-tale for *this* bug. Assuming that Junio will advance both your
and Akinori's fix in close proximity.

Again, this is pushed to the `fix-t3404-author-script-test` branch at
https://github.com/dscho/git; My fixup on top of your patch looks like
this (feel free to drop the sq_bug part and only keep the test part):

-- snipsnap --
diff --git a/sequencer.c b/sequencer.c
index 46c0b3e720f..7abe78dc78e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -573,13 +573,14 @@ static int write_author_script(const char *message)
 static int read_env_script(struct argv_array *env)
 {
struct strbuf script = STRBUF_INIT;
-   int i, count = 0;
+   int i, count = 0, sq_bug;
const char *p2;
char *p;
 
if (strbuf_read_file(, rebase_path_author_script(), 256) <= 0)
return -1;
 
+   sq_bug = script.len && script.buf[script.len - 1] != '\'';
for (p = script.buf; *p; p++)

[PATCH] name_rev: add support for --cherry-picks

2018-07-26 Thread Tejun Heo
>From aefa07bc66bb4a116eb84eb46d7f070f9632c990 Mon Sep 17 00:00:00 2001
From: Tejun Heo 
Date: Thu, 26 Jul 2018 04:14:52 -0700

It's often useful to track cherry-picks of a given commit.  Add
--cherry-picks support to git-name-rev.  When specified, name_rev also
shows the commits cherry-picked from the listed target commits with
indentations.

  $ git name-rev --cherry-picks 10f7ce0a0e524279f022
  10f7ce0a0e524279f022 master~1
d433e3b4d5a19b3d29e2c8349fe88ceade5f6190 branch1
  82cddd79f962de0bb1e7cdd95d48b4865816 branch2
58a8d36b2532feb0a14b4fc2a50d587e64f38324 branch3
fa8b79edc5dfff21753c2ccfc1a1828336c4c070 branch4~1

Note that branch2 is further indented because it's a nested cherry
pick from d433e3b4d5a1.

"git-describe --contains" is a wrapper around git-name-rev.  Also add
--cherry-picks support to git-describe.

Signed-off-by: Tejun Heo 
---
 Documentation/git-describe.txt   |   5 ++
 Documentation/git-name-rev.txt   |   4 ++
 builtin/describe.c   |   7 +-
 builtin/name-rev.c   | 117 +--
 t/t6121-describe-cherry-picks.sh |  63 +
 5 files changed, 190 insertions(+), 6 deletions(-)
 create mode 100755 t/t6121-describe-cherry-picks.sh

diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index e027fb8c4..13a229bd7 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -60,6 +60,11 @@ OPTIONS
the tag that comes after the commit, and thus contains it.
Automatically implies --tags.
 
+--cherry-picks::
+   Also show the commits cherry-picked from the target commits.
+   Cherry-picks are shown indented below their from-commmits.
+   Can only be used with --contains.
+
 --abbrev=::
Instead of using the default 7 hexadecimal digits as the
abbreviated object name, use  digits, or as many digits
diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt
index 5cb0eb085..df16c4a89 100644
--- a/Documentation/git-name-rev.txt
+++ b/Documentation/git-name-rev.txt
@@ -61,6 +61,10 @@ OPTIONS
 --always::
Show uniquely abbreviated commit object as fallback.
 
+--cherry-picks::
+   Also show the commits cherry-picked from the target commits.
+   Cherry-picks are shown indented below their from-commmits.
+
 EXAMPLES
 
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 1e87f68d5..94c84004d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -528,9 +528,10 @@ static void describe(const char *arg, int last_one)
 
 int cmd_describe(int argc, const char **argv, const char *prefix)
 {
-   int contains = 0;
+   int contains = 0, cherry_picks = 0;
struct option options[] = {
OPT_BOOL(0, "contains",   , N_("find the tag that 
comes after the commit")),
+   OPT_BOOL(0, "cherry-picks", _picks, N_("also include 
cherry-picks with --contains")),
OPT_BOOL(0, "debug",  , N_("debug search strategy on 
stderr")),
OPT_BOOL(0, "all",, N_("use any ref")),
OPT_BOOL(0, "tags",   , N_("use any tag, even 
unannotated")),
@@ -570,6 +571,8 @@ int cmd_describe(int argc, const char **argv, const char 
*prefix)
 
if (longformat && abbrev == 0)
die(_("--long is incompatible with --abbrev=0"));
+   if (cherry_picks && !contains)
+   die(_("--cherry-picks can only be used with --contains"));
 
if (contains) {
struct string_list_item *item;
@@ -579,6 +582,8 @@ int cmd_describe(int argc, const char **argv, const char 
*prefix)
argv_array_pushl(, "name-rev",
 "--peel-tag", "--name-only", "--no-undefined",
 NULL);
+   if (cherry_picks)
+   argv_array_push(, "--cherry-picks");
if (always)
argv_array_push(, "--always");
if (!all) {
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 0eb440359..7b21556ad 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -7,9 +7,13 @@
 #include "parse-options.h"
 #include "sha1-lookup.h"
 #include "commit-slab.h"
+#include "trailer.h"
+#include "object-store.h"
 
 #define CUTOFF_DATE_SLOP 86400 /* one day */
 
+static const char cherry_picked_prefix[] = "(cherry picked from commit ";
+
 typedef struct rev_name {
const char *tip_name;
timestamp_t taggerdate;
@@ -19,9 +23,12 @@ typedef struct rev_name {
 } rev_name;
 
 define_commit_slab(commit_rev_name, struct rev_name *);
+define_commit_slab(commit_cherry_picks, struct object_array *);
 
 static timestamp_t cutoff = TIME_MAX;
 static struct commit_rev_name rev_names;
+static struct commit_cherry_picks cherry_picks;
+static int do_cherry_picks = 0;
 
 /* How many generations are maximally preferred over _one_ merge traversal? */
 #define MERGE_TRAVERSAL_WEIGHT 65535
@@ 

fatal: could not read '': No such file or directory

2018-07-26 Thread NeckTwi
While committing a repo I get the error "fatal: could not read '': No such file 
or directory”.
The git repo is a samba share mounted with smb vers=1.0 in linux using 
cifs-utils.

I tried git rm —cached ./* && git add —all && git commit -a -m “commit msg”
It gives the error.

I suppose it's a bug.

… NeckTwi





Re: [PATCH] sequencer.c: terminate the last line of author-script properly

2018-07-26 Thread Johannes Schindelin
Hi Junio,

On Tue, 17 Jul 2018, Junio C Hamano wrote:

> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index 2d189da2f1..b0cef509ab 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -81,11 +81,13 @@ test_expect_success 'rebase -i writes out 
> .git/rebase-merge/author-script in "ed

You missed a very long line here.

>   set_fake_editor &&
>   FAKE_LINES="edit 1" git rebase -i HEAD^ &&
>   test -f .git/rebase-merge/author-script &&

Why do we need this, if we already have an `eval` later on?

> - unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
> - eval "$(cat .git/rebase-merge/author-script)" &&
> - test "$(git show --quiet --pretty=format:%an)" = "$GIT_AUTHOR_NAME" &&
> - test "$(git show --quiet --pretty=format:%ae)" = "$GIT_AUTHOR_EMAIL" &&
> - test "$(git show --quiet --date=raw --pretty=format:@%ad)" = 
> "$GIT_AUTHOR_DATE"
> + (
> + sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
> + eval "$(cat .git/rebase-merge/author-script)" &&

Why not

. .git/rebase-merge/author-script

instead? Less roundabout, easier to read, I think.

> + test "$(git show --quiet --pretty=format:%an)" = 
> "$GIT_AUTHOR_NAME" &&

How is this even working without `-s`?

*clicketyclick*

Ah, --quiet does this. Wait. `git show --quiet` is not even documented.

All of those lines are too long, though. I am surprised you did not catch
that.

Besides, this would be more compact, less repetitive, *and* more readable
as

test "$(git show -s --date=raw --format=%an,%ae,@%ad)" = \
"$GIT_AUTHOR_NAME,$GIT_AUTHOR_EMAIL,$GIT_AUTHOR_DATE"

t3404-rebase-interactive.sh already takes 8 minutes (last I checked,
anyway) to run on a *fast* machine. There is absolutely no need to
introduce even more spawning, not when it is so easily avoided.

> + test "$(git show --quiet --pretty=format:%ae)" = 
> "$GIT_AUTHOR_EMAIL" &&
> + test "$(git show --quiet --date=raw --pretty=format:@%ad)" = 
> "$GIT_AUTHOR_DATE"

It is a shame that we cannot use %at directly here.

> + )
>  '
>  
>  test_expect_success 'rebase -i with the exec command' '

Note: this is not a criticism of the original patch. It is a criticism of
the review which could really have been better.

I also saw that the test_when_finished uses a shell construct that shell
script aficionados might like, but these days it is a lot better to use
`test_might_fail` instead. Let's do this, then.

So here goes, the clean-up patch on top of your 843654e435e (why does it
have to be so darned tedious to get from a mail to the corresponding
commit in `pu`), in all its glory:

-- snipsnap --
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index b0cef509ab7..97f0b4bf881 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -75,18 +75,16 @@ test_expect_success 'rebase --keep-empty' '
test_line_count = 6 actual
 '
 
-test_expect_success 'rebase -i writes out .git/rebase-merge/author-script in 
"edit" that sh(1) can parse' '
-   test_when_finished "git rebase --abort ||:" &&
+test_expect_success 'rebase -i writes correct author-script' '
+   test_when_finished "test_might_fail git rebase --abort" &&
git checkout master &&
set_fake_editor &&
FAKE_LINES="edit 1" git rebase -i HEAD^ &&
-   test -f .git/rebase-merge/author-script &&
(
sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
-   eval "$(cat .git/rebase-merge/author-script)" &&
-   test "$(git show --quiet --pretty=format:%an)" = 
"$GIT_AUTHOR_NAME" &&
-   test "$(git show --quiet --pretty=format:%ae)" = 
"$GIT_AUTHOR_EMAIL" &&
-   test "$(git show --quiet --date=raw --pretty=format:@%ad)" = 
"$GIT_AUTHOR_DATE"
+   . .git/rebase-merge/author-script &&
+   test "$(git show -s --date=raw --format=%an,%ae,@%ad)" = \
+   "$GIT_AUTHOR_NAME,$GIT_AUTHOR_EMAIL,$GIT_AUTHOR_DATE"
)
 '
 


Re: [RFC PATCH 0/5] format-patch: automate cover letter range-diff

2018-07-26 Thread Andrei Rybak
On 2018-05-30 10:03, Eric Sunshine wrote:
> Dscho recently implemented a 'tbdiff' replacement as a Git builtin named
> git-branch-diff[1] which computes differences between two versions of a
> patch series. Such a diff can be a useful aid for reviewers when
> inserted into a cover letter. However, doing so requires manual
> generation (invoking git-branch-diff) and copy/pasting the result into
> the cover letter.
> 
> This series fully automates the process by adding a --range-diff option
> to git-format-patch. 

[...]

> 
> Eric Sunshine (5):
>   format-patch: allow additional generated content in
> make_cover_letter()
>   format-patch: add --range-diff option to embed diff in cover letter
>   format-patch: extend --range-diff to accept revision range
>   format-patch: teach --range-diff to respect -v/--reroll-count
>   format-patch: add --creation-weight tweak for --range-diff
> 
>  Documentation/git-format-patch.txt |  18 +
>  builtin/log.c  | 119 -
>  t/t7910-branch-diff.sh |  16 
>  3 files changed, 132 insertions(+), 21 deletions(-)

Would it make sense to mention new option in the cover letter section of
Documentation/SubmittingPatches?

--
Best regards, Andrei Rybak


Re: [RFC PATCH 2/5] format-patch: add --range-diff option to embed diff in cover letter

2018-07-26 Thread Johannes Schindelin
Hi Eric,

On Tue, 17 Jul 2018, Eric Sunshine wrote:

> On Tue, Jul 17, 2018 at 6:31 AM Johannes Schindelin
>  wrote:
> > On Wed, 30 May 2018, Eric Sunshine wrote:
> 
> > > + if (range_diff) {
> > > + struct argv_array ranges = ARGV_ARRAY_INIT;
> > > + infer_diff_ranges(, range_diff, head);
> > > + if (get_range_diff(, ))
> > > + die(_("failed to generate range-diff"));
> >
> > BTW I like to have an extra space in front of all the range-diff lines, to
> > make it easier to discern them from the rest.
> 
> I'm not sure what you mean. Perhaps I'm misreading your comment.

Sorry, I was really unclear.

In the cover letters sent out by GitGitGadget (or earlier, my
mail-patch-series.sh command), I took pains to indent the entire
range-diff (or interdiff) with a single space. That is, the footer
"Range-diff vs v:" is not indented at all, but all subsequent lines of
the range-diff have a leading space.

The original reason was to stop confusing `git apply` when sending an
interdiff as part of a single patch without a cover letter (in which case
mail-patch-series.sh inserted the interdiff below the `---` marker, and
the interdiff would have looked like the start of the real diff
otherwise).

In the meantime, I got used to this indentation so much that I do not want
to miss it, it is a relatively easy and intuitive visual marker.

This, however, will be harder to achieve now that you are using the
libified range-diff.

> > > @@ -1438,6 +1480,7 @@ int cmd_format_patch(int argc, const char **argv, 
> > > const char *prefix)
> > > + const char *range_diff = NULL;
> >
> > Maybe `range_diff_opt`? It's not exactly the range diff that is contained
> > in this variable.
> 
> I could, though I was trying to keep it shorter rather than longer.
> This is still the same in the re-roll, but I can rename it if you
> insist.

I think it will confuse me in the future if I read `range_diff` and even
the data type suggests that it could hold the output of a `git range-diff
` run.

So I would like to insist.

> > > +format_patch () {
> > > + title=$1 &&
> > > + range=$2 &&
> > > + test_expect_success "format-patch --range-diff ($title)" '
> > > + git format-patch --stdout --cover-letter 
> > > --range-diff=$range \
> > > + master..unmodified >actual &&
> > > + grep "= 1: .* s/5/A" actual &&
> > > + grep "= 2: .* s/4/A" actual &&
> > > + grep "= 3: .* s/11/B" actual &&
> > > + grep "= 4: .* s/12/B" actual
> >
> > I guess this might make sense if `format_patch` was not a function, but it
> > is specifically marked as a function... so... shouldn't these `grep`s also
> > be using function parameters?
> 
> A later patch adds a second test which specifies the same ranges but
> in a different way, so the result will be the same, hence the
> hard-coded grep'ing. The function avoids repetition across the two
> tests. I suppose I could do this a bit differently, though, to avoid
> pretending it's a general-purpose function.

If you can think of a way that would make this easier to read for, say,
myself if I ever find myself debugging a regression caught by this test, I
would appreciate that.

Ciao,
Dscho


Re: [PATCH v2 0/6] git-submodule.sh: convert part of cmd_update to C

2018-07-26 Thread Johannes Schindelin
Hi Stefan,

On Tue, 17 Jul 2018, Stefan Beller wrote:

> > A tangent.
> >
> > Because this "-- " is a conventional signature separator, MUAs like
> > Emacs message-mode seems to omit everything below it from the quote
> > while responding, making it cumbersome to comment on the tbdiff.
> >
> > Something to think about if somebody is contemplating on adding more
> > to format-patch's cover letter.
> 
> +cc Eric who needs to think about this tangent, then.
> https://public-inbox.org/git/20180530080325.37520-1-sunsh...@sunshineco.com/

I think this is just a natural fall-out from the users' choice of mail
program. Personally, I have no difficulty commenting on anything below the
`--` separator.

FWIW GitGitGadget follows the example of the `base-commit` footer and
places this information *above* the `--` separator.

> > >> 1:  d4e1ec45740 ! 1:  bbc8697a8ca git-submodule.sh: align error 
> > >> reporting for update mode to use path
> > >> @@ -6,7 +6,6 @@
> > >>  on its path, so let's do that for invalid update modes, too.
> > >>
> > >>  Signed-off-by: Stefan Beller 
> > >> -Signed-off-by: Junio C Hamano 
> > >>
> > >>  diff --git a/git-submodule.sh b/git-submodule.sh
> > >>  --- a/git-submodule.sh
> >
> > This is quite unfortunate.  I wonder if it is easy to tell
> > range-diff that certain differences in the log message are to be
> > ignored so that we can show that the first patch is unchanged in a
> > case like this.  This series has 4 really changed ones with 2
> > otherwise unchanged ones shown all as changed, which is not too bad,
> > but for a series like sb/diff-colro-move-more reroll that has 9
> > patches, out of only two have real updated patches, showing
> > otherwise unchanged 7 as changed like this hunk does would make the
> > cover letter useless.  It is a shame that adding range-diff to the
> > cover does have so much potential.
> 
> Actually I thought it was really cool, i.e. when using your queued branch
> instead of my last sent branch, I can see any edits *you* did
> (including fixing up typos or applying at slightly different bases).

This is probably a good indicator that the practice on insisting on signing
off on every patch, rather than just the merge commit, is something to
re-think.

Those are real changes relative to the original commit, after all, and if
they are not desired, they should not be made.

> The sign offs are a bit unfortunate as they are repetitive.
> I have two conflicting points of view on that:
> 
> (A) This sign off is inherent to the workflow. So we could
> change the workflow, i.e. you pull series instead of applying them.
> I think this "more in git, less in email" workflow would find supporters,
> such as DScho (cc'd).
> 
> The downside is that (1) you'd have to change your
> workflow, i.e. instead of applying the patches at the base you think is
> best for maintenance you'd have to tell the author "please rebase to $X";
> but that also has upsides, such as "If you want to have your series integrated
> please merge with $Y and $Z" (looking at the object store stuff).
> 
> The other (2) downside is that everyone else (authors, reviewers) have
> to adapt as well. For authors this might be easy to adapt (push instead
> of sending email sounds like a win). For reviewers we'd need to have
> an easy way to review things "stored in git" and not exposed via email,
> which is not obvious how to do.
> 
> (B) The other point of view that I can offer is that we teach range-diff
> to ignore certain patterns. Maybe in combination with interpret-trailers
> this can be an easy configurable thing, or even a default to ignore
> all sign offs?

I thought about that myself.

The reason: I was surprised, a couple of times, when I realized long after
the fact, that some of my patches were changed without my knowledge nor
blessing before being merged into `master`.

To allow me to protest in a timely manner, I wanted to teach GitGitGadget
(which is the main reason I work on range-diff, as you undoubtedly suspect
by now) to warn me about such instances.

The range-diff patch series has simmered too long at this stage, though,
and I did not try to address such a "ignore " feature
*specifically* so that the range-diff command could be available sooner
than later. I already missed one major version, please refrain from
forcing me to miss another one.

Ciao,
Dscho


Re: [PATCH] negotiator/skipping: skip commits during fetch

2018-07-26 Thread Johannes Schindelin
Hi Jonathan,

On Mon, 16 Jul 2018, Jonathan Tan wrote:

>  t/t5552-skipping-fetch-negotiator.sh | 179 +++

This test seems to be failing consistently in the recent `pu` builds:

https://git-for-windows.visualstudio.com/git/_build/results?buildId=14337=logs

Could you have a look, please?

Ciao,
Dscho

P.S.: For your convenience, I will paste the last part of the output with
`-i -v -x` here:

-- snipsnap --
2018-07-26T08:18:39.7864833Z expecting success: 
2018-07-26T08:18:39.7868553Zrm -rf server client trace &&
2018-07-26T08:18:39.7869403Zgit init server &&
2018-07-26T08:18:39.7869606Ztest_commit -C server to_fetch &&
2018-07-26T08:18:39.7870066Z 
2018-07-26T08:18:39.7870281Zgit init client &&
2018-07-26T08:18:39.7870403Z 
2018-07-26T08:18:39.7870579Z# 2 regular commits
2018-07-26T08:18:39.7870779Ztest_tick=20 &&
2018-07-26T08:18:39.7870943Ztest_commit -C client c1 &&
2018-07-26T08:18:39.7871103Ztest_commit -C client c2 &&
2018-07-26T08:18:39.7871228Z 
2018-07-26T08:18:39.7871419Z# 4 old commits
2018-07-26T08:18:39.7871575Ztest_tick=10 &&
2018-07-26T08:18:39.7871734Zgit -C client checkout c1 &&
2018-07-26T08:18:39.7871916Ztest_commit -C client old1 &&
2018-07-26T08:18:39.7872081Ztest_commit -C client old2 &&
2018-07-26T08:18:39.7872396Ztest_commit -C client old3 &&
2018-07-26T08:18:39.7872598Ztest_commit -C client old4 &&
2018-07-26T08:18:39.7872743Z 
2018-07-26T08:18:39.7872918Z# "c2" and "c1" are popped first, then "old4" 
to "old1". "old1" would
2018-07-26T08:18:39.7873114Z# normally be skipped, but is treated as a 
commit without a parent here
2018-07-26T08:18:39.7873329Z# and sent, because (due to clock skew) its 
only parent has already been
2018-07-26T08:18:39.7873524Z# popped off the priority queue.
2018-07-26T08:18:39.7873700Ztest_config -C client 
fetch.negotiationalgorithm skipping &&
2018-07-26T08:18:39.7873908ZGIT_TRACE_PACKET="$(pwd)/trace" git -C client 
fetch "$(pwd)/server" &&
2018-07-26T08:18:39.7874091Zhave_sent c2 c1 old4 old2 old1 &&
2018-07-26T08:18:39.7874262Zhave_not_sent old3
2018-07-26T08:18:39.7874383Z 
2018-07-26T08:18:39.8353323Z ++ rm -rf server client trace
2018-07-26T08:18:40.3404166Z ++ git init server
2018-07-26T08:18:40.3756394Z Initialized empty Git repository in 
D:/a/1/s/t/trash directory.t5552-skipping-fetch-negotiator/server/.git/
2018-07-26T08:18:40.3769512Z ++ test_commit -C server to_fetch
2018-07-26T08:18:40.3776271Z ++ notick=
2018-07-26T08:18:40.3777103Z ++ signoff=
2018-07-26T08:18:40.3777282Z ++ indir=
2018-07-26T08:18:40.3777465Z ++ test 3 '!=' 0
2018-07-26T08:18:40.3777648Z ++ case "$1" in
2018-07-26T08:18:40.3777801Z ++ indir=server
2018-07-26T08:18:40.3777948Z ++ shift
2018-07-26T08:18:40.3778093Z ++ shift
2018-07-26T08:18:40.3778493Z ++ test 1 '!=' 0
2018-07-26T08:18:40.3778921Z ++ case "$1" in
2018-07-26T08:18:40.3779072Z ++ break
2018-07-26T08:18:40.3779241Z ++ indir=server/
2018-07-26T08:18:40.3779431Z ++ file=to_fetch.t
2018-07-26T08:18:40.3779603Z ++ echo to_fetch
2018-07-26T08:18:40.3779923Z ++ git -C server/ add to_fetch.t
2018-07-26T08:18:40.4072248Z ++ test -z ''
2018-07-26T08:18:40.4072727Z ++ test_tick
2018-07-26T08:18:40.4072948Z ++ test -z set
2018-07-26T08:18:40.4073113Z ++ test_tick=1112913673
2018-07-26T08:18:40.4073758Z ++ GIT_COMMITTER_DATE='1112913673 -0700'
2018-07-26T08:18:40.4074001Z ++ GIT_AUTHOR_DATE='1112913673 -0700'
2018-07-26T08:18:40.4074178Z ++ export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
2018-07-26T08:18:40.4074357Z ++ git -C server/ commit -m to_fetch
2018-07-26T08:18:40.4485364Z [master (root-commit) ff85695] to_fetch
2018-07-26T08:18:40.4485997Z  Author: A U Thor 
2018-07-26T08:18:40.4486201Z  1 file changed, 1 insertion(+)
2018-07-26T08:18:40.4486414Z  create mode 100644 to_fetch.t
2018-07-26T08:18:40.4499970Z ++ git -C server/ tag to_fetch
2018-07-26T08:18:40.4809208Z ++ git init client
2018-07-26T08:18:40.5139949Z Initialized empty Git repository in 
D:/a/1/s/t/trash directory.t5552-skipping-fetch-negotiator/client/.git/
2018-07-26T08:18:40.5158270Z ++ test_tick=20
2018-07-26T08:18:40.5158466Z ++ test_commit -C client c1
2018-07-26T08:18:40.5159077Z ++ notick=
2018-07-26T08:18:40.5159492Z ++ signoff=
2018-07-26T08:18:40.5159697Z ++ indir=
2018-07-26T08:18:40.5159855Z ++ test 3 '!=' 0
2018-07-26T08:18:40.5160010Z ++ case "$1" in
2018-07-26T08:18:40.5160209Z ++ indir=client
2018-07-26T08:18:40.5160362Z ++ shift
2018-07-26T08:18:40.5160507Z ++ shift
2018-07-26T08:18:40.5160657Z ++ test 1 '!=' 0
2018-07-26T08:18:40.5160831Z ++ case "$1" in
2018-07-26T08:18:40.5161289Z ++ break
2018-07-26T08:18:40.5161582Z ++ indir=client/
2018-07-26T08:18:40.5161764Z ++ file=c1.t
2018-07-26T08:18:40.5161916Z ++ echo c1
2018-07-26T08:18:40.5162231Z ++ git -C client/ add c1.t
2018-07-26T08:18:40.5456318Z ++ test -z ''
2018-07-26T08:18:40.5460548Z ++ test_tick
2018-07-26T08:18:40.5461417Z ++ test -z set

Re: Hash algorithm analysis

2018-07-26 Thread Johannes Schindelin
Hi Joan,

On Sun, 22 Jul 2018, Joan Daemen wrote:

> I wanted to react to some statements I read in this discussion. But
> first let me introduce myself. I'm Joan Daemen and I'm working in
> symmetric cryptography since 1988. Vincent Rijmen and I designed
> Rijndael that was selected to become AES and Guido Bertoni, Michael
> Peeters and Gilles Van Assche and I (the Keccak team, later extended
> with Ronny Van Keer) designed Keccak that was selected to become SHA3.
> Of course as a member of the Keccak team I'm biased in this discussion
> but I'll try to keep it factual.

Thank you *so* much for giving your valuable time and expertise on this
subject.

I really would hate for the decision to be made due to opinions of people
who are overconfident in their abilities to judge cryptographic matters
despite clearly being out of their league (which includes me, I want to
add specifically).

On a personal note: back in the day, I have been following the Keccak with
a lot of interest, being intrigued by the deliberate deviation from the
standard primitives, and I am pretty much giddy about the fact that I am
talking to you right now.

> [... interesting, and thorough background information ...]
> 
> Anyway, these numbers support the opinion that the safety margins taken
> in K12 are better understood than those in SHA-256, SHA-512 and BLAKE2.

This is very, very useful information in my mind.

> Adam Langley continues:
> 
>   Thus I think the question is primarily concerned with performance and 
> implementation availability
> 
> 
> Table 2 in our ACNS paper on K12 (available at
> https://eprint.iacr.org/2016/770) shows that performance of K12 is quite
> competitive. Moreover, there is a lot of code available under CC0
> license in the Keccak Code Package on github
> https://github.com/gvanas/KeccakCodePackage. If there is shortage of
> code for some platforms in the short term, we will be happy to work on that.
> 
> In the long term, it is likely that the relative advantage of K12 will
> increase as it has more potential for hardware acceleration, e.g., by
> instruction set extension. This is thanks to the fact that it does not
> use addition, as opposed to so-called addition-xor-rotation (ARX)
> designs such as the SHA-2 and BLAKE2 families. This is already
> illustrated in our Table 2 I referred to above, in the transition from
> Skylake to SkylakeX.

I *really* hope that more accessible hardware acceleration for this
materializes at some stage. And by "more accessible", I mean commodity
hardware such as ARM or AMD/Intel processors: big hosters could relatively
easily develop appropriate FPGAs (we already do this for AI, after all).

> Maybe also interesting for this discussion are the two notes we (Keccak
> team) wrote on our choice to not go for ARX and the one on "open source
> crypto" at https://keccak.team/2017/not_arx.html and
> https://keccak.team/2017/open_source_crypto.html respectively.

I had read those posts when they came out, and still find them insightful.
Hopefully other readers of this mailing list will spend the time to read
them, too.

Again, thank you so much for a well-timed dose of domain expertise in
this thread.

Ciao,
Dscho


photos for your company

2018-07-26 Thread Jan

I would like to contact the person that manages your images for your
company?

We provide different services that makes your images and pictures to look
good. For the images to
be more attractive, we services such as background image cut out, clipping
path, shadow adding
(drop shadow, reflection shadow, natural shadow, mirror effect), image
masking, product image editing.
Image Manipulation / Clothes Neck-Joint and image retouching.

Also, we also use the most recent application as well as techniques such as
Adobe Photoshop.

The following are the kind of services together:

Clipping Path Service
Clipping Path, Cut out image,Image Clipping, Clip image
Photo Masking Service
Channel Masking,Photo Masking, Translucent Masking
Image Cropping Service
Crop image, Photo cut out,
Image Manipulation Service
Composite image, Neck Joint
Shadow Adding Services
Drop Shadow adding, Reflection shadow,Natural shadow
Photo Retouching Service
Photo Retouching, Glamour Retouching.

Our Service is 24-48 hours but we can deliver the images sooner in case of
emergency.

We can give you editing test on your photos.
We do unlimited revisions until you are satisfied with the work.

Thanks,
Jan Williams



[RFC PATCH v4 0/4] add -p: select individual hunk lines

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

I've updated this series based on Ævar's feedback on v3 (to paraphrase
stop using '$_' so much and fix staging modified lines.). The first
patch is functionally equivalent to the previous version but with a
reworked implementation. Patch 2 is new, it implements correctly
staging modified lines with a couple of limitations - see the commit
message for more details, I'm keen to get some feedback on it. Patches
3 and 4 are essentially rebased and tweaked versions of patches 2 and
3 from the previous version.

This series is based on pw/add-p-recount (f4d35a6b49 "add -p: fix
counting empty context lines in edited patches")

The motivation for this series is summed up in the first commit
message:

"When I end up editing hunks it is almost always because I want to
stage a subset of the lines in the hunk. Doing this by editing the
hunk is inconvenient and error prone (especially so if the patch is
going to be reversed before being applied). Instead offer an option
for add -p to stage individual lines. When the user presses 'l' the
hunk is redrawn with labels by the insertions and deletions and they
are prompted to enter a list of the lines they wish to stage. Ranges
of lines may be specified using 'a-b' where either 'a' or 'b' may be
omitted to mean all lines from 'a' to the end of the hunk or all lines
from 1 upto and including 'b'."

Phillip Wood (4):
  add -p: select individual hunk lines
  add -p: select modified lines correctly
  add -p: allow line selection to be inverted
  add -p: optimize line selection for short hunks

 Documentation/git-add.txt  |  10 ++
 git-add--interactive.perl  | 350 +
 t/t3701-add-interactive.sh | 209 ++
 3 files changed, 569 insertions(+)

-- 
2.18.0



[PATCH v4 4/4] add -p: optimize line selection for short hunks

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

If there are fewer than ten changes in a hunk then make spaces
optional when selecting individual lines. This means that for short
hunks one can just type 1-357 to stage lines 1, 2, 3, 5 & 7.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |  9 +
 git-add--interactive.perl  | 26 ++
 t/t3701-add-interactive.sh |  2 +-
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 01ff4d7d24..f3c81dfb11 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -340,10 +340,11 @@ patch::
 If you press "l" then the hunk will be reprinted with each insertion or
 deletion labelled with a number and you will be prompted to enter which
 lines you wish to select. Individual line numbers should be separated by
-a space or comma, to specify a range of lines use a dash between
-them. If the upper bound of a range of lines is omitted it defaults to
-the last line. To invert the selection prefix it with "-" so "-3-5,8"
-will select everything except lines 3, 4, 5 and 8.
+a space or comma (these can be omitted if there are fewer than ten
+labelled lines), to specify a range of lines use a dash between them. If
+the upper bound of a range of lines is omitted it defaults to the last
+line. To invert the selection prefix it with "-" so "-3-5,8" will select
+everything except lines 3, 4, 5 and 8.
 +
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 0b490cf1e9..56bc7ab496 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1244,6 +1244,29 @@ sub check_hunk_label {
return 1;
 }
 
+sub split_hunk_selection {
+   my @fields = @_;
+   my @ret;
+   for my $field (@fields) {
+   while ($field ne '') {
+   if ($field =~ /^[0-9]-$/) {
+   push @ret, $field;
+   last;
+   } elsif (my ($sel, $rest) =
+   ($field =~ /^([0-9](?:-[0-9])?)(.*)/)) {
+   push @ret, $sel;
+   $field = $rest;
+   } else {
+   error_msg sprintf
+   __("invalid hunk line '%s'\n"),
+   substr($field, 0, 1);
+   return ();
+   }
+   }
+   }
+   return @ret;
+}
+
 sub parse_hunk_selection {
my ($hunk, $line) = @_;
my $lines = $hunk->{LABELS}->{LINES};
@@ -1263,6 +1286,9 @@ sub parse_hunk_selection {
}
}
}
+   if ($max_label < 10) {
+   @fields = split_hunk_selection(@fields) or return undef;
+   }
for my $f (@fields) {
if (my ($lo, $hi) = ($f =~ /^([0-9]+)-([0-9]*)$/)) {
if ($hi eq '') {
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 2fd456017f..b2b808275c 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -457,7 +457,7 @@ test_expect_success 'setup expected diff' '
 '
 
 test_expect_success 'can reset individual lines of patch' '
-   printf "%s\n" l -6,2,5 |
+   printf "%s\n" l -625 |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&
-- 
2.18.0



[PATCH v4 1/4] add -p: select individual hunk lines

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

When I end up editing hunks it is almost always because I want to
stage a subset of the lines in the hunk. Doing this by editing the
hunk is inconvenient and error prone (especially so if the patch is
going to be reversed before being applied). Instead offer an option
for add -p to stage individual lines. When the user presses 'l' the
hunk is redrawn with labels by the insertions and deletions and they
are prompted to enter a list of the lines they wish to stage. Ranges
of lines may be specified using 'a-b' where 'b' may be omitted to mean
all lines from 'a' to the end of the hunk. Modified lines are not
handled correctly, that will be fixed in the next commit.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |   8 ++
 git-add--interactive.perl  | 181 +
 t/t3701-add-interactive.sh | 103 +
 3 files changed, 292 insertions(+)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index d50fa339dc..965e192a09 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -332,10 +332,18 @@ patch::
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
+   l - select hunk lines to use
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
 +
+If you press "l" then the hunk will be reprinted with each insertion or
+deletion labelled with a number and you will be prompted to enter which
+lines you wish to select. Individual line numbers should be separated by
+a space or comma, to specify a range of lines use a dash between
+them. If the upper bound of a range of lines is omitted it defaults to
+the last line.
++
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
 +
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8361ef45e7..cbc9e5698a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1013,6 +1013,171 @@ sub color_diff {
} @_;
 }
 
+use constant {
+   NO_NEWLINE => 1,
+};
+
+sub label_hunk_lines {
+   my $hunk = shift;
+   my $text = $hunk->{TEXT};
+   my (@line_flags, @lines);
+   my ($block, $label, $last_mode) = (0, 0, '');
+   for my $line (1..$#{$text}) {
+   $line_flags[$line] = 0;
+   my $mode = substr($text->[$line], 0, 1);
+   if ($mode eq '\\') {
+   $line_flags[$line - 1] |= NO_NEWLINE;
+   }
+   if ($mode eq '-' or $mode eq '+') {
+   $lines[++$label] = $line;
+   }
+   }
+   if ($label > 1) {
+   $hunk->{LABELS} = {
+   LINES => \@lines,
+   };
+   $hunk->{LINE_FLAGS} = \@line_flags;
+   return 1;
+   }
+   return 0;
+}
+
+sub select_hunk_lines {
+   my ($hunk, $selected) = @_;
+   my ($line_flags, $text) = @{$hunk}{qw(LINE_FLAGS TEXT)};
+   my ($i, $o_cnt, $n_cnt) = (0, 0, 0);
+   my @newtext;
+
+   my $select_lines = sub {
+   for my $i (@_) {
+   my $line = $text->[$i];
+   my $mode = substr($line, 0, 1);
+   push @newtext, $line;
+   if ($mode eq '+') {
+   $n_cnt++;
+   } elsif ($mode eq '-') {
+   $o_cnt++;
+   }
+   }
+   };
+
+   my ($lo, $hi) = splice(@$selected, 0, 2);
+   # Lines with this mode will become context lines if they are
+   # not selected
+   my $context_mode = $patch_mode_flavour{IS_REVERSE} ? '+' : '-';
+   for $i (1..$#{$text}) {
+   if ($lo <= $i and $i <= $hi) {
+   $select_lines->($i);
+   } else {
+   my $line = $text->[$i];
+   my $mode = substr($line, 0, 1);
+   if ($mode eq ' ' or $mode eq $context_mode) {
+   push @newtext, ' ' . substr($line, 1);
+   $o_cnt++; $n_cnt++;
+   if ($line_flags->[$i] & NO_NEWLINE) {
+   push @newtext, $text->[$i + 1];
+   }
+   }
+   }
+   if ($i == $hi) {
+   if (@$selected) {
+   ($lo, $hi) = splice(@$selected, 0, 2);
+   }
+   }
+   }
+   my ($o_ofs, $orig_o_cnt, $n_ofs, $orig_n_cnt) =
+   parse_hunk_header($text->[0]);
+   unshift @newtext, format_hunk_header($o_ofs, $o_cnt, $n_ofs, $n_cnt);
+   my $newhunk = {
+   

[RFC PATCH v4 2/4] add -p: select modified lines correctly

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

When a set of lines is modified the hunk contains deletions followed
by insertions. To correctly stage a subset of the modified lines we
need to match up the selected deletions with the selected insertions
otherwise we end up with deletions and context lines followed by
insertions which is not what we want.

For example given the hunk
  1 -* a longer description of the
  2 -  first item
  3 -* second
  4 -* third
  5 +* first
  6 +  second item
  7 +* the third item

If the user selects 1,2,4–5,7 then we should generate
-* a longer description of the
-  first item
+* first
 * second
-* third
+* the third item

not
-* a longer description of the
-  first item
 * second
-* third
+* first
+* the third item

Currently the code can only cope with selections that contain the same
number of groups of insertions and deletions, though each group need
not contain the same number of insertions and deletions. If the user
wants to stage an unpaired deletion or insertion in a hunk where they
also want to stage modified lines they have to do it with two
invocations of 'git add -p'.

It would be possible to add some syntax to allow lines to be excluded
from groups to allow the user to stage such changes in a single
go. It may also be useful to allow users to explicitly group lines. If
in the example above the second item is deleted we have

  1 -* a longer description of the
  2 - first item
  3 -* second
  4 -* third
  5 +* first
  6 +* the third item

Selecting 1,2,4–6 will give an error. If lines could be grouped
explicitly then it would be possible to type something like
1,2,4,[5],6 to indicate that there are two groups of insertions giving

-* a longer description of the
- first item
+* first
 * second
-* third
+* the third item

We may want to be able to stage an insertion before an unselected
deletion to allow the user to stage a new paragraph before the
unmodified original in

  1 -original
  2 +a new paragraph before
  3 +original
  4 +
  5 +modified original

by specifying something like ^2-4 to give

+a new paragraph before
+original
+
 original

I'm not sure how common these cases are in real life and how much
effort it's worth putting into handling them at the moment when the
user can edit the hunk if need be. Perhaps it would be better to leave
it for future extensions when it becomes clearer what would be most
useful.

Reported-by: Ævar Arnfjörð Bjarmason 
Signed-off-by: Phillip Wood 
---
 git-add--interactive.perl  | 148 ++---
 t/t3701-add-interactive.sh | 108 ++-
 2 files changed, 243 insertions(+), 13 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index cbc9e5698a..b7e3da0210 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1015,26 +1015,47 @@ sub color_diff {
 
 use constant {
NO_NEWLINE => 1,
+   LAST_ADD_DEL => 2,
+   FIRST_ADD => 4
 };
 
 sub label_hunk_lines {
my $hunk = shift;
my $text = $hunk->{TEXT};
-   my (@line_flags, @lines);
+   # A block contains the insertions and deletions occurring context
+   # lines.
+   my (@blocks, @line_flags, @lines, @modes);
my ($block, $label, $last_mode) = (0, 0, '');
for my $line (1..$#{$text}) {
$line_flags[$line] = 0;
my $mode = substr($text->[$line], 0, 1);
if ($mode eq '\\') {
$line_flags[$line - 1] |= NO_NEWLINE;
}
+   if ($mode ne '-' and $last_mode eq '-' or
+   $mode ne '+' and $last_mode eq '+') {
+   $line_flags[$line - 1] |= LAST_ADD_DEL;
+   }
+   if ($mode eq '+' and $last_mode ne '+') {
+   $line_flags[$line] |= FIRST_ADD;
+   }
if ($mode eq '-' or $mode eq '+') {
-   $lines[++$label] = $line;
+   $blocks[++$label] = $block;
+   $lines[$label] = $line;
+   $modes[$label] = $mode;
+   } elsif ($mode eq ' ' and $last_mode ne ' ') {
+   $block++;
}
+   $last_mode = $mode;
+   }
+   if ($last_mode eq '-' or $last_mode eq '+') {
+   $line_flags[-1] |= LAST_ADD_DEL;
}
if ($label > 1) {
$hunk->{LABELS} = {
+   BLOCKS => \@blocks,
LINES => \@lines,
+   MODES => \@modes
};
$hunk->{LINE_FLAGS} = \@line_flags;
return 1;
@@ -1061,11 +1082,14 @@ sub select_hunk_lines {
}
};
 
-   my ($lo, 

[PATCH v4 3/4] add -p: allow line selection to be inverted

2018-07-26 Thread Phillip Wood
From: Phillip Wood 

If the list of lines to be selected begins with '-' select all the
lines except the ones listed.

Signed-off-by: Phillip Wood 
---
 Documentation/git-add.txt  |  3 ++-
 git-add--interactive.perl  | 19 +++
 t/t3701-add-interactive.sh |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 965e192a09..01ff4d7d24 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -342,7 +342,8 @@ deletion labelled with a number and you will be prompted to 
enter which
 lines you wish to select. Individual line numbers should be separated by
 a space or comma, to specify a range of lines use a dash between
 them. If the upper bound of a range of lines is omitted it defaults to
-the last line.
+the last line. To invert the selection prefix it with "-" so "-3-5,8"
+will select everything except lines 3, 4, 5 and 8.
 +
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b7e3da0210..0b490cf1e9 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1248,8 +1248,21 @@ sub parse_hunk_selection {
my ($hunk, $line) = @_;
my $lines = $hunk->{LABELS}->{LINES};
my $max_label = $#{$lines};
+   my $invert = undef;
my %selected;
my @fields = split(/[,\s]+/, $line);
+   if (my ($rest) = ($fields[0] =~ /^-(.*)/)) {
+   $invert = 1;
+   if ($rest ne '') {
+   $fields[0] = $rest;
+   } else {
+   shift @fields;
+   unless (@fields) {
+   error_msg __("no lines to invert\n");
+   return undef;
+   }
+   }
+   }
for my $f (@fields) {
if (my ($lo, $hi) = ($f =~ /^([0-9]+)-([0-9]*)$/)) {
if ($hi eq '') {
@@ -1269,6 +1282,12 @@ sub parse_hunk_selection {
return undef;
}
}
+   if ($invert) {
+   my %inverted;
+   undef @inverted{1..$max_label};
+   delete @inverted{keys(%selected)};
+   %selected = %inverted;
+   }
return process_hunk_selection($hunk, keys(%selected));
 }
 
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 1d917ad018..2fd456017f 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -457,7 +457,7 @@ test_expect_success 'setup expected diff' '
 '
 
 test_expect_success 'can reset individual lines of patch' '
-   printf "%s\n" l 4,1,3 |
+   printf "%s\n" l -6,2,5 |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&
-- 
2.18.0



Re: Hash algorithm analysis

2018-07-26 Thread Johannes Schindelin
Hi Eric,

On Sun, 22 Jul 2018, Eric Deplagne wrote:

> On Sun, 22 Jul 2018 14:21:48 +, brian m. carlson wrote:
> > On Sun, Jul 22, 2018 at 11:34:42AM +0200, Eric Deplagne wrote:
> > > On Sat, 21 Jul 2018 23:59:41 +, brian m. carlson wrote:
> > > > I don't know your colleagues, and they haven't commented here.  One
> > > > person that has commented here is Adam Langley.  It is my impression
> > > > (and anyone is free to correct me if I'm incorrect) that he is indeed a
> > > > cryptographer.  To quote him[0]:
> > > > 
> > > >   I think this group can safely assume that SHA-256, SHA-512, BLAKE2,
> > > >   K12, etc are all secure to the extent that I don't believe that making
> > > >   comparisons between them on that axis is meaningful. Thus I think the
> > > >   question is primarily concerned with performance and implementation
> > > >   availability.
> > > > 
> > > >   […]
> > > > 
> > > >   So, overall, none of these choices should obviously be excluded. The
> > > >   considerations at this point are not cryptographic and the tradeoff
> > > >   between implementation ease and performance is one that the git
> > > >   community would have to make.
> > > 
> > >   Am I completely out of the game, or the statement that
> > > "the considerations at this point are not cryptographic"
> > >   is just the wrongest ?
> > > 
> > >   I mean, if that was true, would we not be sticking to SHA1 ?
> > 
> > I snipped a portion of the context, but AGL was referring to the
> > considerations involved in choosing from the proposed ones for NewHash.
> > In context, he meant that the candidates for NewHash “are all secure”
> > and are therefore a better choice than SHA-1.
> 
>   Maybe a little bit sensitive, but I really did read
> "we don't care if it's weak or strong, that's not the matter".

Thank you for your concern. I agree that we need to be careful in
considering the security implications. We made that mistake before (IIRC
there was a cryptographer who was essentially shouted off the list when he
suggested *not* to hard-code SHA-1), and we should absolutely refrain from
making that same mistake again.

> > I think we can all agree that SHA-1 is weak and should be replaced.

Indeed.

So at this point, we already excluded pretty much all the unsafe options
(although it does concern me that BLAKE2b has been weakened purposefully,
I understand the reasoning, but still).

Which means that by now, considering the security implications of the
cipher is no longer a criterion that helps us whittle down the candidates
further.

So from my point of view, there are two criterions that can help us
further:

- Which cipher is the least likely to be broken (or just weakened by new
  attacks)?

- As energy considerations not only ecologically inspired, but also in
  terms of money for elecricity: which cipher is most likely to get decent
  hardware support any time soon?

Even if my original degree (prime number theory) is closer to
cryptanalysis than pretty much all other prolific core Git contributors, I
do not want you to trust *my* word on answering those questions.

Therefore, I will ask my colleagues to enter the hornet's nest that is
this mailing list.

Ciao,
Dscho

Re: [PATCH v4 00/21] Add `range-diff`, a `tbdiff` lookalike

2018-07-26 Thread Johannes Schindelin
Hi Stefan,

On Mon, 23 Jul 2018, Stefan Beller wrote:

> On Sat, Jul 21, 2018 at 3:04 PM Johannes Schindelin via GitGitGadget
>  wrote:
> 
> > Range-diff vs v3:
> >
> >   1:  39272eefc !  1:  f7e70689e linear-assignment: a function to solve 
> > least-cost assignment problems
> >  @@ -223,9 +223,7 @@
> >   + BUG("negative j: %d", j);
> >   + i = pred[j];
> >   + column2row[j] = i;
> >  -+ k = j;
> >  -+ j = row2column[i];
> >  -+ row2column[i] = k;
> >  ++ SWAP(j, row2column[i]);
> 
> The dual color option (as a default) really helps here. Thanks for that!
> Does it have to be renamed though? (It's more than two colors; originally
> it was inverting the beginning signs)

I understand (and understood) the "dual" to mean that there are two
separate coloring methods, the coloring of the inner, and the coloring of
the outer diff. (And in my mind, the dimming is not so much an "inner"
diff things as an "outer" diff thing.)

> Maybe --color=emphasize-later assuming there will be other modes for
> coloring, such as "diff-only", which would correspond with
> --no-dual-color, or "none" that will correspond would be --no-color. I
> imagine there could be more fancy things, hence I would propose a mode
> rather than a switch.  (Feel free to push back if discussing naming here
> feels like bike shedding)

Your suggestion does not really feel like bike-shedding to me, here, I can
see the merit of it.

It's just that 1) overloading `--color` here would be cumbersome, as
`--color` is *already* a diff option that we actually use, and 2) I am not
all that certain that new fancy things will crop up anytime soon. It was
hard enough to think of the dimming feature, and then implementing it.

So while I think your idea has merit, I still think that we can do that
later. The --no-dual-color option can easily be deprecated in favor of,
say, --color-mode=, when (and if) new modes crop up.

> 2:  7f15b26d4ea !  82:  88134121d2a Introduce `range-diff` to compare
> iterations of a topic branch
> [...]
> >   diff --git a/Makefile b/Makefile
> >   --- a/Makefile
> >   +++ b/Makefile
> 
> The line starting with --- is red (default removed color) and the line
> with +++ is green (default add color).
> 
> Ideally these two lines and the third line above starting with "diff --git"
> would render in GIT_COLOR_BOLD ("METAINFO").

I see where you are coming from, but given how complicated it seems to me
to implement this (dual color mode gets away with working line-based for
the moment, and what you ask for would require state, and would not even
be fool-proof, as the `diff --git` line might not even be part of the
context.

Seeing how long this patch series has already simmered, I would want to
invoke that old adage "the perfect is the enemy of the good", and rather
see a version of range-diff enter Git's source code, if need be marked as
"EXPERIMENTAL" so that the maintainer can claim that it is okay to be
buggy, and then invite contributions from other sides than from me.

> >  16:  dfa7b1e71 <  -:  - range-diff --dual-color: work around bogus 
> > white-space warning
> >   -:  - > 16:  f4252f2b2 range-diff --dual-color: fix bogus 
> > white-space warning
> 
> Ah; here my initial assumption of only reviewing the range-diff breaks down 
> now.
> I'll dig into patch 16 separately.

Right. In this case, it is a total rewrite, anyway (and I'll have to ask
you to overlook my frustration with how complex and hard it is to work on
ws.c without breaking anything). For the sake of review, you should ignore
the old patch. Unless you find that the new version is so complex and
prone to introduce bugs (with which I would agree) that we should go back
to the original workaround, which is so easy to understand that there are
no obvious bugs lurking inside it.

> Maybe it is worth having an option to expand all "new" patches.

Sure. And I would love to have this in a separate patch series, as it is
well beyond the original purpose of this patch series to simply make
tbdiff a builtin.

I should have known better, of course, but I was really not keen on
improving range-diff *before* it enters the code base, to the point of
introducing new features that might very well introduce new regressions in
unrelated commands, too.

Essentially, I am declaring a feature-freeze on this patch series until it
enters `next`.

> (Given that the range-diff
> pr-1/dscho/branch-diff-v3...pr-1/dscho/branch-diff-v4 told me you used a
> different base, this is a hard problem, as I certainly would want to
> skip over all new base commits, but this one is interesting to look at.
> An easy way out: Maybe an option to expand any new commits/patches after
> the first expansion? Asking for opinions rather than implementing it)

Any fulfilled wish is immediately welcomed with offspring, it seems.

Again, 

Re: [PATCH 1/1] add hook pre-p4-submit

2018-07-26 Thread Eric Sunshine
On Wed, Jul 25, 2018 at 10:08 PM chen bin  wrote:
> The hook does not receive any information or input from git. The
> original requirement
> comes from my colleague. He want to run unit test automatically before
> submitting code
> to remote repository. Or else CI server will send the blame mail to the 
> manager.

Okay, that seems in line with a hook such as pre-commit. Please do
update the documentation to mention that the hook takes no arguments
and nothing on standard input, and perhaps describe in the
documentation an example use-case (as you did here).

I'm not a p4 or git-p4 user, but, out of curiosity, would there be any
information which could be supplied to the hook as arguments or
standard input (or both) which would help the hook author implement
the hook more easily? Perhaps such information would be fodder for a
future enhancement (not necessarily needed for this patch).

> The hook actually stops the submit process from start instead of abort
> submit in midway.
> So nothing is touched when hook exits with status 1.

This might be a good thing to add to the documentation, as well.

> I'm not sure whether `git-p4` should print some "hook rejection" message.
> Current implementation is same as other hooks (`pre-commit`, for example).
> Only hook itself is responsible to print error messages.
>
> Personally I don't have opinion whether we should print out hook
> related message inside
> `git-p4.py`. I just try to following existing convention of git.
>
> What you guys think?

Following existing practice makes sense. It can always be revisited
later if needed.

Thanks.


Re: [PATCH v1 03/25] structured-logging: add structured logging framework

2018-07-26 Thread SZEDER Gábor


> +void slog_set_command_name(const char *command_name)
> +{
> + /*
> +  * Capture the command name even if logging is not enabled
> +  * because we don't know if the config has been loaded yet by
> +  * the cmd_() and/or it may be too early to force a
> +  * lazy load.
> +  */
> + if (my__command_name)
> + free(my__command_name);
> + my__command_name = xstrdup(command_name);
> +}
> +
> +void slog_set_sub_command_name(const char *sub_command_name)
> +{
> + /*
> +  * Capture the sub-command name even if logging is not enabled
> +  * because we don't know if the config has been loaded yet by
> +  * the cmd_() and/or it may be too early to force a
> +  * lazy load.
> +  */
> + if (my__sub_command_name)
> + free(my__sub_command_name);

Please drop the condition in these two functions; free() handles NULL
arguments just fine.


(Sidenote: what's the deal with these 'my__' prefixes anyway?)



Re: [PATCH 2/2] travis-ci: fail if Coccinelle static analysis found something to transform

2018-07-26 Thread SZEDER Gábor
On Mon, Jul 23, 2018 at 3:02 PM SZEDER Gábor  wrote:

> The only way to draw attention in such an automated setting is to fail
> the build job.  Therefore, modify the 'ci/run-static-analysis.sh'
> build script to check all the resulting '*.cocci.patch' files, and
> fail the build job if any of them turns out to be not empty.  Include
> those files' contents, i.e. Coccinelle's suggested transformations, in
> the build job's trace log, so we'll know why it failed.

And this is how it looks like "in action":

  https://travis-ci.org/git/git/jobs/408269979#L570


Re: Git Help !!!

2018-07-26 Thread Vishwas Kamath
Awesome, thanks!

On Thu, 26 Jul 2018, 2:00 p.m. Eric Sunshine, 
wrote:

> On Thu, Jul 26, 2018 at 1:01 AM Vishwas Kamath 
> wrote:
> > I am unable to use Git (version 2.18 latest). Since i couldnt find any
> help/support/contact email on https://git-scm.com and i couldnt find the
> solution using Google as well i am directly contacting you as i need to get
> git working. Hope you can help me.
>
> It looks like you're experiencing a problem specific to Windows or the
> to Windows version of Git which is maintained as a separate
> project[1]. You may be able to get help for this specific problem on
> the project's mailing list[2] or by submitting a bug report[3].
>
> [1]: https://gitforwindows.org
> [2]: https://groups.google.com/forum/#!forum/git-for-windows
> [3]: https://github.com/git-for-windows/git/issues
>


Re: Git Help !!!

2018-07-26 Thread Eric Sunshine
On Thu, Jul 26, 2018 at 1:01 AM Vishwas Kamath  wrote:
> I am unable to use Git (version 2.18 latest). Since i couldnt find any 
> help/support/contact email on https://git-scm.com and i couldnt find the 
> solution using Google as well i am directly contacting you as i need to get 
> git working. Hope you can help me.

It looks like you're experiencing a problem specific to Windows or the
to Windows version of Git which is maintained as a separate
project[1]. You may be able to get help for this specific problem on
the project's mailing list[2] or by submitting a bug report[3].

[1]: https://gitforwindows.org
[2]: https://groups.google.com/forum/#!forum/git-for-windows
[3]: https://github.com/git-for-windows/git/issues


Re: [PATCH v2] pack-objects: fix performance issues on packing large deltas

2018-07-26 Thread Johannes Sixt

Am 22.07.2018 um 10:04 schrieb Nguyễn Thái Ngọc Duy:

+   if (size < pack->oe_delta_size_limit) {
+   e->delta_size_ = size;
+   e->delta_size_valid = 1;
+   } else {
+   packing_data_lock(pack);
+   if (!pack->delta_size)
+   ALLOC_ARRAY(pack->delta_size, pack->nr_alloc);
+   packing_data_unlock(pack);
+
+   pack->delta_size[e - pack->objects] = size;


My first thought was that this is wrong (falling prey to the same 
mistake as the double-checked locking pattern). But after thinking twice 
over it again, I think that this unprotected access of pack->delta_size 
is thread-safe.


Of course, I'm assuming that different threads never assign to the same 
array index.



+   e->delta_size_valid = 0;
+   }
  }


-- Hannes


Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Jeff King
On Wed, Jul 25, 2018 at 03:13:37PM -0700, Junio C Hamano wrote:

> * jk/banned-function (2018-07-24) 5 commits
>  - banned.h: mark strncpy() as banned
>  - banned.h: mark sprintf() as banned
>  - banned.h: mark strcat() as banned
>  - automatically ban strcpy()
>  - Merge branch 'sb/blame-color' into jk/banned-function
> 
>  It is too easy to misuse system API functions such as strcat();
>  these selected functions are now forbidden in this codebase and
>  will cause a compilation failure.
> 
>  Will merge to 'next'.

Eric nudged me over the fence to use a slightly different mechanism to
generate the error. See:

  https://public-inbox.org/git/20180726072105.ga6...@sigill.intra.peff.net/

It looks like sb/blame-color graduated, so this could also just be
applied directly on master now to avoid the funky merge.

-Peff


[PATCH v3 1/4] automatically ban strcpy()

2018-07-26 Thread Jeff King
On Thu, Jul 26, 2018 at 02:58:40AM -0400, Jeff King wrote:

> On Tue, Jul 24, 2018 at 01:20:58PM -0400, Eric Sunshine wrote:
> 
> > On Tue, Jul 24, 2018 at 5:26 AM Jeff King  wrote:
> > >   1. We'll only trigger with -Wimplicit-function-declaration
> > >  (and only stop compilation with -Werror). These are
> > >  generally enabled by DEVELOPER=1. If you _don't_ have
> > >  that set, we'll still catch the problem, but only at
> > >  link-time, with a slightly less useful message:
> > >
> > >  If instead we convert this to a reference to an
> > >  undefined variable, that always dies immediately. But
> > >  gcc seems to print the set of errors twice, which
> > >  clutters things up.
> > 
> > The above does a pretty good job of convincing me that this ought to
> > be implemented via an undefined variable rather than undefined
> > function, exactly because it is the newcomer or casual contributor who
> > is most likely to trip over a banned function, and almost certainly
> > won't have DEVELOPER=1 set. The gcc clutter seems a minor point
> > against the benefit this provides to that audience.
> 
> OK. I was on the fence, but it should be pretty trivial to switch. Let
> me see if I can just make a replacement for patch 1, or if the whole
> thing needs to be rebased on top.

The rest apply cleanly (because they're far enough away textually from
the definition of BANNED).

So here's a replacement for just patch 1 (I'm assuming this creates less
work than re-posting them all, but it may not be if Junio prefers
dealing with a whole new mbox rather than a "rebase -i", "reset --hard
HEAD^", "git am" -- let me know if you'd prefer it the other way).

-- >8 --
Subject: [PATCH] automatically ban strcpy()

There are a few standard C functions (like strcpy) which are
easy to misuse. E.g.:

  char path[PATH_MAX];
  strcpy(path, arg);

may overflow the "path" buffer. Sometimes there's an earlier
constraint on the size of "arg", but even in such a case
it's hard to verify that the code is correct. If the size
really is unbounded, you're better off using a dynamic
helper like strbuf:

  struct strbuf path = STRBUF_INIT;
  strbuf_addstr(path, arg);

or if it really is bounded, then use xsnprintf to show your
expectation (and get a run-time assertion):

  char path[PATH_MAX];
  xsnprintf(path, sizeof(path), "%s", arg);

which makes further auditing easier.

We'd usually catch undesirable code like this in a review,
but there's no automated enforcement. Adding that
enforcement can help us be more consistent and save effort
(and a round-trip) during review.

This patch teaches the compiler to report an error when it
sees strcpy (and will become a model for banning a few other
functions). This has a few advantages over a separate
linting tool:

  1. We know it's run as part of a build cycle, so it's
 hard to ignore. Whereas an external linter is an extra
 step the developer needs to remember to do.

  2. Likewise, it's basically free since the compiler is
 parsing the code anyway.

  3. We know it's robust against false positives (unlike a
 grep-based linter).

The two big disadvantages are:

  1. We'll only check code that is actually compiled, so it
 may miss code that isn't triggered on your particular
 system. But since presumably people don't add new code
 without compiling it (and if they do, the banned
 function list is the least of their worries), we really
 only care about failing to clean up old code when
 adding new functions to the list. And that's easy
 enough to address with a manual audit when adding a new
 function (which is what I did for the functions here).

  2. If this ends up generating false positives, it's going
 to be harder to disable (as opposed to a separate
 linter, which may have mechanisms for overriding a
 particular case).

 But the intent is to only ban functions which are
 obviously bad, and for which we accept using an
 alternative even when this particular use isn't buggy
 (e.g., the xsnprintf alternative above).

The implementation here is simple: we'll define a macro for
the banned function which replaces it with a reference to a
descriptively named but undeclared identifier.  Replacing it
with any invalid code would work (since we just want to
break compilation).  But ideally we'd meet these goals:

 - it should be portable; ideally this would trigger
   everywhere, and does not need to be part of a DEVELOPER=1
   setup (because unlike warnings which may depend on the
   compiler or system, this is a clear indicator of
   something wrong in the code).

 - it should generate a readable error that gives the
   developer a clue what happened

 - it should avoid generating too much other cruft that
   makes it hard to see the actual error

 - it should mention the original callsite in the error

The output with this patch looks like this (using gcc 7, on
a checkout with 022d2ac1f3 

Re: [PATCH v2 1/4] automatically ban strcpy()

2018-07-26 Thread Jeff King
On Tue, Jul 24, 2018 at 01:20:58PM -0400, Eric Sunshine wrote:

> On Tue, Jul 24, 2018 at 5:26 AM Jeff King  wrote:
> >   1. We'll only trigger with -Wimplicit-function-declaration
> >  (and only stop compilation with -Werror). These are
> >  generally enabled by DEVELOPER=1. If you _don't_ have
> >  that set, we'll still catch the problem, but only at
> >  link-time, with a slightly less useful message:
> >
> >  If instead we convert this to a reference to an
> >  undefined variable, that always dies immediately. But
> >  gcc seems to print the set of errors twice, which
> >  clutters things up.
> 
> The above does a pretty good job of convincing me that this ought to
> be implemented via an undefined variable rather than undefined
> function, exactly because it is the newcomer or casual contributor who
> is most likely to trip over a banned function, and almost certainly
> won't have DEVELOPER=1 set. The gcc clutter seems a minor point
> against the benefit this provides to that audience.

OK. I was on the fence, but it should be pretty trivial to switch. Let
me see if I can just make a replacement for patch 1, or if the whole
thing needs to be rebased on top.

-Peff


Re: [PATCH 5/6] pass st.st_size as hint for strbuf_readlink()

2018-07-26 Thread Jeff King
On Wed, Jul 25, 2018 at 08:41:00PM +0200, Torsten Bögershausen wrote:

> On Tue, Jul 24, 2018 at 06:51:39AM -0400, Jeff King wrote:
> > When we initially added the strbuf_readlink() function in
> > b11b7e13f4 (Add generic 'strbuf_readlink()' helper function,
> > 2008-12-17), the point was that we generally have a _guess_
> > as to the correct size based on the stat information, but we
> > can't necessarily trust it.
> > 
> > Over the years, a few callers have grown up that simply pass
> > in 0, even though they have the stat information. Let's have
> > them pass in their hint for consistency (and in theory
> > efficiency, since it may avoid an extra resize/syscall loop,
> > but neither location is probably performance critical).
> > 
> > Note that st.st_size is actually an off_t, so in theory we
> > need xsize_t() here. But none of the other callsites use it,
> > and since this is just a hint, it doesn't matter either way
> > (if we wrap we'll simply start with a too-small hint and
> > then eventually complain when we cannot allocate the
> > memory).
> 
> Thanks a lot for the series.
> 
>  For the last paragraph I would actually vote the other way around -
>  how about something like this ?
>  Note that st.st_size is actually an off_t, so we should use
>  xsize_t() here. In pratise we don't expect links to be large like that,
>  but let's give a good example in the source code and use xsize_t()
>  whenever an off_t is converted into size_t.
>  This will make live easier whenever someones diggs into 32/64 bit
>  "conversion safetyness"

I actually don't mind using xsize_t(), but if we're going into I think
we should do it consistently. I.e., as a patch on top with that
explanation.

-Peff


Re: What's cooking in git.git (Jul 2018, #03; Wed, 25)

2018-07-26 Thread Оля Тележная
2018-07-26 1:13 GMT+03:00 Junio C Hamano :
>
> * ot/ref-filter-object-info (2018-07-17) 5 commits
>  - ref-filter: use oid_object_info() to get object
>  - ref-filter: merge get_obj and get_object
>  - ref-filter: initialize eaten variable
>  - ref-filter: fill empty fields with empty values
>  - ref-filter: add info_source to valid_atom
>
>  A few atoms like %(objecttype) and %(objectsize) in the format
>  specifier of "for-each-ref --format=" can be filled without
>  getting the full contents of the object, but just with the object
>  header.  These cases have been optimzied by calling
>  oid_object_info() API.
>
>  What's the doneness of this one?
>

It is ready. Thanks.