[PATCH v3] sequencer: use configured comment character

2018-07-15 Thread Aaron Schrab
At 10:15 -0700 12 Jul 2018, Junio C Hamano  wrote:
>Aaron Schrab  writes:
>> Note that the comment_line_char has already been resolved by this point,
>> even if the user has configured the comment character to be selected
>> automatically.
>
>Isn't this a slight lie?

Looking into that a bit further, it does seem like my explanation above 
was incorrect.  Here's another attempt to explain why setting 
core.commentChar=auto isn't a problem for this change.

8< -

Use the configured comment character when generating comments about
branches in a todo list.  Failure to honor this configuration causes a
failure to parse the resulting todo list.

Setting core.commentChar to "auto" will not be honored here, and the
previously configured or default value will be used instead. But, since
the todo list will consist of only generated content, there should not
be any non-comment lines beginning with that character.

Signed-off-by: Aaron Schrab 
---
 sequencer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sequencer.c b/sequencer.c
index 4034c0461b..caf91af29d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3991,7 +3991,7 @@ static int make_script_with_merges(struct 
pretty_print_context *pp,
entry = oidmap_get(, >object.oid);
 
if (entry)
-   fprintf(out, "\n# Branch %s\n", entry->string);
+   fprintf(out, "\n%c Branch %s\n", comment_line_char, 
entry->string);
else
fprintf(out, "\n");
 
-- 
2.18.0.419.gfe4b301394



[PATCH v2 01/16] cache: update object ID functions for the_hash_algo

2018-07-15 Thread brian m. carlson
Most of our code has been converted to use struct object_id for object
IDs.  However, there are some places that still have not, and there are
a variety of places that compare equivalently sized hashes that are not
object IDs.  All of these hashes are artifacts of the internal hash
algorithm in use, and when we switch to NewHash for object storage, all
of these uses will also switch.

Update the hashcpy, hashclr, and hashcmp functions to use the_hash_algo,
since they are used in a variety of places to copy and manipulate
buffers that need to move data into or out of struct object_id.  This
has the effect of making the corresponding oid* functions use
the_hash_algo as well.

Signed-off-by: brian m. carlson 
---
 cache.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index d49092d94d..f00cc810bc 100644
--- a/cache.h
+++ b/cache.h
@@ -972,7 +972,7 @@ extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
-   return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+   return memcmp(sha1, sha2, the_hash_algo->rawsz);
 }
 
 static inline int oidcmp(const struct object_id *oid1, const struct object_id 
*oid2)
@@ -992,7 +992,7 @@ static inline int is_null_oid(const struct object_id *oid)
 
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char 
*sha_src)
 {
-   memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
+   memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
 }
 
 static inline void oidcpy(struct object_id *dst, const struct object_id *src)
@@ -1009,7 +1009,7 @@ static inline struct object_id *oiddup(const struct 
object_id *src)
 
 static inline void hashclr(unsigned char *hash)
 {
-   memset(hash, 0, GIT_SHA1_RAWSZ);
+   memset(hash, 0, the_hash_algo->rawsz);
 }
 
 static inline void oidclr(struct object_id *oid)


[PATCH v2 14/16] log-tree: switch GIT_SHA1_HEXSZ to the_hash_algo->hexsz

2018-07-15 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 log-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log-tree.c b/log-tree.c
index d3a43e29cd..9655de8ad7 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -545,7 +545,7 @@ void show_log(struct rev_info *opt)
struct strbuf msgbuf = STRBUF_INIT;
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
-   int abbrev_commit = opt->abbrev_commit ? opt->abbrev : GIT_SHA1_HEXSZ;
+   int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 
the_hash_algo->hexsz;
const char *extra_headers = opt->extra_headers;
struct pretty_print_context ctx = {0};
 


[PATCH v2 03/16] hex: switch to using the_hash_algo

2018-07-15 Thread brian m. carlson
Instead of using the GIT_SHA1_* constants, switch to using the_hash_algo
to convert object IDs to and from hex format.

Signed-off-by: brian m. carlson 
---
 hex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hex.c b/hex.c
index 8df2d63728..10af1a29e8 100644
--- a/hex.c
+++ b/hex.c
@@ -50,7 +50,7 @@ int hex_to_bytes(unsigned char *binary, const char *hex, 
size_t len)
 int get_sha1_hex(const char *hex, unsigned char *sha1)
 {
int i;
-   for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
+   for (i = 0; i < the_hash_algo->rawsz; i++) {
int val = hex2chr(hex);
if (val < 0)
return -1;
@@ -69,7 +69,7 @@ int parse_oid_hex(const char *hex, struct object_id *oid, 
const char **end)
 {
int ret = get_oid_hex(hex, oid);
if (!ret)
-   *end = hex + GIT_SHA1_HEXSZ;
+   *end = hex + the_hash_algo->hexsz;
return ret;
 }
 
@@ -79,7 +79,7 @@ char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
char *buf = buffer;
int i;
 
-   for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
+   for (i = 0; i < the_hash_algo->rawsz; i++) {
unsigned int val = *sha1++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];


[PATCH v2 09/16] builtin/update-index: simplify parsing of cacheinfo

2018-07-15 Thread brian m. carlson
Switch from using get_oid_hex to parse_oid_hex to simplify pointer
operations and avoid the need for a hash-related constant.

Signed-off-by: brian m. carlson 
---
 builtin/update-index.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 031cef5229..3206c5ad45 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -827,6 +827,7 @@ static int parse_new_style_cacheinfo(const char *arg,
 {
unsigned long ul;
char *endp;
+   const char *p;
 
if (!arg)
return -1;
@@ -837,9 +838,9 @@ static int parse_new_style_cacheinfo(const char *arg,
return -1; /* not a new-style cacheinfo */
*mode = ul;
endp++;
-   if (get_oid_hex(endp, oid) || endp[GIT_SHA1_HEXSZ] != ',')
+   if (parse_oid_hex(endp, oid, ) || *p != ',')
return -1;
-   *path = endp + GIT_SHA1_HEXSZ + 1;
+   *path = p + 1;
return 0;
 }
 


[PATCH v2 12/16] builtin/merge-recursive: make hash independent

2018-07-15 Thread brian m. carlson
Use GIT_MAX_HEXSZ instead of GIT_SHA1_HEXSZ for an allocation so that it
is sufficiently large.  Switch a comparison to use the_hash_algo to
determine the length of a hex object ID.

Signed-off-by: brian m. carlson 
---
 builtin/merge-recursive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index 0dd9021958..9b2f707c29 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
 
 static const char *better_branch_name(const char *branch)
 {
-   static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
+   static char githead_env[8 + GIT_MAX_HEXSZ + 1];
char *name;
 
-   if (strlen(branch) != GIT_SHA1_HEXSZ)
+   if (strlen(branch) != the_hash_algo->hexsz)
return branch;
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
name = getenv(githead_env);


[PATCH v2 10/16] builtin/fmt-merge-msg: make hash independent

2018-07-15 Thread brian m. carlson
Convert several uses of GIT_SHA1_HEXSZ into references to the_hash_algo.
Switch other uses into a use of parse_oid_hex and uses of its computed
pointer.

Signed-off-by: brian m. carlson 
---
 builtin/fmt-merge-msg.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index bd680be687..e8c13a2c03 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -108,14 +108,15 @@ static int handle_line(char *line, struct merge_parents 
*merge_parents)
struct string_list_item *item;
int pulling_head = 0;
struct object_id oid;
+   const unsigned hexsz = the_hash_algo->hexsz;
 
-   if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
+   if (len < hexsz + 3 || line[hexsz] != '\t')
return 1;
 
-   if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
+   if (starts_with(line + hexsz + 1, "not-for-merge"))
return 0;
 
-   if (line[GIT_SHA1_HEXSZ + 1] != '\t')
+   if (line[hexsz + 1] != '\t')
return 2;
 
i = get_oid_hex(line, );
@@ -130,7 +131,7 @@ static int handle_line(char *line, struct merge_parents 
*merge_parents)
 
if (line[len - 1] == '\n')
line[len - 1] = 0;
-   line += GIT_SHA1_HEXSZ + 2;
+   line += hexsz + 2;
 
/*
 * At this point, line points at the beginning of comment e.g.
@@ -342,7 +343,7 @@ static void shortlog(const char *name,
const struct object_id *oid = _data->oid;
int limit = opts->shortlog_len;
 
-   branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
+   branch = deref_tag(parse_object(oid), oid_to_hex(oid), 
the_hash_algo->hexsz);
if (!branch || branch->type != OBJ_COMMIT)
return;
 
@@ -545,6 +546,7 @@ static void find_merge_parents(struct merge_parents *result,
int len;
char *p = in->buf + pos;
char *newline = strchr(p, '\n');
+   const char *q;
struct object_id oid;
struct commit *parent;
struct object *obj;
@@ -552,10 +554,9 @@ static void find_merge_parents(struct merge_parents 
*result,
len = newline ? newline - p : strlen(p);
pos += len + !!newline;
 
-   if (len < GIT_SHA1_HEXSZ + 3 ||
-   get_oid_hex(p, ) ||
-   p[GIT_SHA1_HEXSZ] != '\t' ||
-   p[GIT_SHA1_HEXSZ + 1] != '\t')
+   if (parse_oid_hex(p, , ) ||
+   q[0] != '\t' ||
+   q[1] != '\t')
continue; /* skip not-for-merge */
/*
 * Do not use get_merge_parent() here; we do not have


[PATCH v2 16/16] pretty: switch hard-coded constants to the_hash_algo

2018-07-15 Thread brian m. carlson
Switch several hard-coded constants into expressions based either on
GIT_MAX_HEXSZ or the_hash_algo.

Signed-off-by: brian m. carlson 
---
 pretty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pretty.c b/pretty.c
index 703fa6ff7b..b0e653ff25 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1575,7 +1575,7 @@ static void pp_header(struct pretty_print_context *pp,
}
 
if (starts_with(line, "parent ")) {
-   if (linelen != 48)
+   if (linelen != the_hash_algo->hexsz + 8)
die("bad parent line in commit");
continue;
}
@@ -1583,7 +1583,7 @@ static void pp_header(struct pretty_print_context *pp,
if (!parents_shown) {
unsigned num = commit_list_count(commit->parents);
/* with enough slop */
-   strbuf_grow(sb, num * 50 + 20);
+   strbuf_grow(sb, num * (GIT_MAX_HEXSZ + 10) + 20);
add_merge_info(pp, sb, commit);
parents_shown = 1;
}


[PATCH v2 11/16] builtin/merge: switch to use the_hash_algo

2018-07-15 Thread brian m. carlson
Switch uses of GIT_SHA1_HEXSZ to use the_hash_algo instead.

Signed-off-by: brian m. carlson 
---
 builtin/merge.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 4a4c09496c..916c9f0569 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1034,6 +1034,7 @@ static void handle_fetch_head(struct commit_list 
**remotes, struct strbuf *merge
const char *filename;
int fd, pos, npos;
struct strbuf fetch_head_file = STRBUF_INIT;
+   const unsigned hexsz = the_hash_algo->hexsz;
 
if (!merge_names)
merge_names = _head_file;
@@ -1059,16 +1060,16 @@ static void handle_fetch_head(struct commit_list 
**remotes, struct strbuf *merge
else
npos = merge_names->len;
 
-   if (npos - pos < GIT_SHA1_HEXSZ + 2 ||
+   if (npos - pos < hexsz + 2 ||
get_oid_hex(merge_names->buf + pos, ))
commit = NULL; /* bad */
-   else if (memcmp(merge_names->buf + pos + GIT_SHA1_HEXSZ, 
"\t\t", 2))
+   else if (memcmp(merge_names->buf + pos + hexsz, "\t\t", 2))
continue; /* not-for-merge */
else {
-   char saved = merge_names->buf[pos + GIT_SHA1_HEXSZ];
-   merge_names->buf[pos + GIT_SHA1_HEXSZ] = '\0';
+   char saved = merge_names->buf[pos + hexsz];
+   merge_names->buf[pos + hexsz] = '\0';
commit = get_merge_parent(merge_names->buf + pos);
-   merge_names->buf[pos + GIT_SHA1_HEXSZ] = saved;
+   merge_names->buf[pos + hexsz] = saved;
}
if (!commit) {
if (ptr)


[PATCH v2 06/16] sha1-name: use the_hash_algo when parsing object names

2018-07-15 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 sha1-name.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 60d9ef3c7e..ba6a5a689f 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -310,7 +310,7 @@ static int init_object_disambiguation(const char *name, int 
len,
 {
int i;
 
-   if (len < MINIMUM_ABBREV || len > GIT_SHA1_HEXSZ)
+   if (len < MINIMUM_ABBREV || len > the_hash_algo->hexsz)
return -1;
 
memset(ds, 0, sizeof(*ds));
@@ -576,6 +576,8 @@ int find_unique_abbrev_r(char *hex, const struct object_id 
*oid, int len)
struct disambiguate_state ds;
struct min_abbrev_data mad;
struct object_id oid_ret;
+   const unsigned hexsz = the_hash_algo->hexsz;
+
if (len < 0) {
unsigned long count = approximate_object_count();
/*
@@ -599,8 +601,8 @@ int find_unique_abbrev_r(char *hex, const struct object_id 
*oid, int len)
}
 
oid_to_hex_r(hex, oid);
-   if (len == GIT_SHA1_HEXSZ || !len)
-   return GIT_SHA1_HEXSZ;
+   if (len == hexsz || !len)
+   return hexsz;
 
mad.init_len = len;
mad.cur_len = len;
@@ -706,7 +708,7 @@ static int get_oid_basic(const char *str, int len, struct 
object_id *oid,
int refs_found = 0;
int at, reflog_len, nth_prior = 0;
 
-   if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
+   if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
refs_found = dwim_ref(str, len, _oid, _ref);
if (refs_found > 0) {
@@ -750,7 +752,7 @@ static int get_oid_basic(const char *str, int len, struct 
object_id *oid,
int detached;
 
if (interpret_nth_prior_checkout(str, len, ) > 0) {
-   detached = (buf.len == GIT_SHA1_HEXSZ && 
!get_oid_hex(buf.buf, oid));
+   detached = (buf.len == the_hash_algo->hexsz && 
!get_oid_hex(buf.buf, oid));
strbuf_release();
if (detached)
return 0;


[PATCH v2 04/16] commit: express tree entry constants in terms of the_hash_algo

2018-07-15 Thread brian m. carlson
Specify these constants in terms of the size of the hash algorithm
currently in use.

Signed-off-by: brian m. carlson 
---
 commit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commit.c b/commit.c
index 0c3b75aeff..ff05d04570 100644
--- a/commit.c
+++ b/commit.c
@@ -364,8 +364,8 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
struct object_id parent;
struct commit_list **pptr;
struct commit_graft *graft;
-   const int tree_entry_len = GIT_SHA1_HEXSZ + 5;
-   const int parent_entry_len = GIT_SHA1_HEXSZ + 7;
+   const int tree_entry_len = the_hash_algo->hexsz + 5;
+   const int parent_entry_len = the_hash_algo->hexsz + 7;
 
if (item->object.parsed)
return 0;


[PATCH v2 08/16] builtin/update-index: convert to using the_hash_algo

2018-07-15 Thread brian m. carlson
Switch from using GIT_SHA1_HEXSZ to the_hash_algo to make the parsing of
the index information hash independent.

Signed-off-by: brian m. carlson 
---
 builtin/update-index.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index a8709a26ec..031cef5229 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -492,6 +492,7 @@ static void update_one(const char *path)
 
 static void read_index_info(int nul_term_line)
 {
+   const int hexsz = the_hash_algo->hexsz;
struct strbuf buf = STRBUF_INIT;
struct strbuf uq = STRBUF_INIT;
strbuf_getline_fn getline_fn;
@@ -529,7 +530,7 @@ static void read_index_info(int nul_term_line)
mode = ul;
 
tab = strchr(ptr, '\t');
-   if (!tab || tab - ptr < GIT_SHA1_HEXSZ + 1)
+   if (!tab || tab - ptr < hexsz + 1)
goto bad_line;
 
if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
@@ -542,8 +543,8 @@ static void read_index_info(int nul_term_line)
ptr = tab + 1; /* point at the head of path */
}
 
-   if (get_oid_hex(tab - GIT_SHA1_HEXSZ, ) ||
-   tab[-(GIT_SHA1_HEXSZ + 1)] != ' ')
+   if (get_oid_hex(tab - hexsz, ) ||
+   tab[-(hexsz + 1)] != ' ')
goto bad_line;
 
path_name = ptr;
@@ -571,7 +572,7 @@ static void read_index_info(int nul_term_line)
 * ptr[-1] points at tab,
 * ptr[-41] is at the beginning of sha1
 */
-   ptr[-(GIT_SHA1_HEXSZ + 2)] = ptr[-1] = 0;
+   ptr[-(hexsz + 2)] = ptr[-1] = 0;
if (add_cacheinfo(mode, , path_name, stage))
die("git update-index: unable to update %s",
path_name);


[PATCH v2 02/16] tree-walk: replace hard-coded constants with the_hash_algo

2018-07-15 Thread brian m. carlson
Remove the hard-coded 20-based values and replace them with uses of
the_hash_algo.

Signed-off-by: brian m. carlson 
---
 tree-walk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tree-walk.c b/tree-walk.c
index 8f5090862b..c1f27086a9 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -26,8 +26,9 @@ static int decode_tree_entry(struct tree_desc *desc, const 
char *buf, unsigned l
 {
const char *path;
unsigned int mode, len;
+   const unsigned hashsz = the_hash_algo->rawsz;
 
-   if (size < 23 || buf[size - 21]) {
+   if (size < hashsz + 3 || buf[size - (hashsz + 1)]) {
strbuf_addstr(err, _("too-short tree object"));
return -1;
}


[PATCH v2 07/16] refs/files-backend: use the_hash_algo for writing refs

2018-07-15 Thread brian m. carlson
In order to ensure we write the correct amount, use the_hash_algo to
find the correct number of bytes for the current hash.

Signed-off-by: brian m. carlson 
---
 refs/files-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index a9a066dcfb..c546ffbf5d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1676,7 +1676,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
return -1;
}
fd = get_lock_file_fd(>lk);
-   if (write_in_full(fd, oid_to_hex(oid), GIT_SHA1_HEXSZ) < 0 ||
+   if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
write_in_full(fd, , 1) < 0 ||
close_ref_gently(lock) < 0) {
strbuf_addf(err,
@@ -3070,7 +3070,7 @@ static int files_reflog_expire(struct ref_store 
*ref_store,
rollback_lock_file(_lock);
} else if (update &&
   (write_in_full(get_lock_file_fd(>lk),
-   oid_to_hex(_kept_oid), GIT_SHA1_HEXSZ) 
< 0 ||
+   oid_to_hex(_kept_oid), 
the_hash_algo->hexsz) < 0 ||
write_str_in_full(get_lock_file_fd(>lk), 
"\n") < 0 ||
close_ref_gently(lock) < 0)) {
status |= error("couldn't write %s",


[PATCH v2 00/16] object_id part 14

2018-07-15 Thread brian m. carlson
This is the fourteenth series of patches to switch to using struct
object_id and the_hash_algo.  This series converts several core pieces
to use struct object_id, including the oid* and hex functions.

All of these patches have been tested with both SHA-1 and a 256-bit
hash.

Most of these patches are fixes for things that will clearly cause
segfaults or other very obvious breakage on a Git with a 256-bit hash.

Changes from v1:
* Drop patch that's been replaced by one from Ben Peart.
* Update patch handling hash* and oid* functions.

tbdiff output below.

brian m. carlson (16):
  cache: update object ID functions for the_hash_algo
  tree-walk: replace hard-coded constants with the_hash_algo
  hex: switch to using the_hash_algo
  commit: express tree entry constants in terms of the_hash_algo
  strbuf: allocate space with GIT_MAX_HEXSZ
  sha1-name: use the_hash_algo when parsing object names
  refs/files-backend: use the_hash_algo for writing refs
  builtin/update-index: convert to using the_hash_algo
  builtin/update-index: simplify parsing of cacheinfo
  builtin/fmt-merge-msg: make hash independent
  builtin/merge: switch to use the_hash_algo
  builtin/merge-recursive: make hash independent
  diff: switch GIT_SHA1_HEXSZ to use the_hash_algo
  log-tree: switch GIT_SHA1_HEXSZ to the_hash_algo->hexsz
  sha1-file: convert constants to uses of the_hash_algo
  pretty: switch hard-coded constants to the_hash_algo

 builtin/fmt-merge-msg.c   | 19 ++-
 builtin/merge-recursive.c |  4 ++--
 builtin/merge.c   | 11 ++-
 builtin/update-index.c| 14 --
 cache.h   |  6 +++---
 commit.c  |  4 ++--
 diff.c|  6 +++---
 hex.c |  6 +++---
 log-tree.c|  2 +-
 pretty.c  |  4 ++--
 refs/files-backend.c  |  4 ++--
 sha1-file.c   |  8 
 sha1-name.c   | 12 +++-
 strbuf.c  |  2 +-
 tree-walk.c   |  3 ++-
 15 files changed, 56 insertions(+), 49 deletions(-)

tbdiff output:

 1: e8209cc180 !  1: cad74b3d9b cache: update object ID functions for 
the_hash_algo
@@ -2,10 +2,18 @@
 
 cache: update object ID functions for the_hash_algo
 
-Update the hashcpy and hashclr functions to use the_hash_algo, since
-they are used in a variety of places to copy and manipulate buffers 
that
-need to move data into or out of struct object_id.  Update oidcmp so
-that it is implemented on its own and similarly uses the_hash_algo.
+Most of our code has been converted to use struct object_id for object
+IDs.  However, there are some places that still have not, and there are
+a variety of places that compare equivalently sized hashes that are not
+object IDs.  All of these hashes are artifacts of the internal hash
+algorithm in use, and when we switch to NewHash for object storage, all
+of these uses will also switch.
+
+Update the hashcpy, hashclr, and hashcmp functions to use 
the_hash_algo,
+since they are used in a variety of places to copy and manipulate
+buffers that need to move data into or out of struct object_id.  This
+has the effect of making the corresponding oid* functions use
+the_hash_algo as well.
 
 Signed-off-by: brian m. carlson 
 
@@ -14,13 +22,13 @@
 +++ b/cache.h
 @@
  
- static inline int oidcmp(const struct object_id *oid1, const struct 
object_id *oid2)
+ static inline int hashcmp(const unsigned char *sha1, const unsigned char 
*sha2)
  {
--  return hashcmp(oid1->hash, oid2->hash);
-+  return memcmp(oid1->hash, oid2->hash, the_hash_algo->rawsz);
+-  return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
++  return memcmp(sha1, sha2, the_hash_algo->rawsz);
  }
  
- static inline int is_null_sha1(const unsigned char *sha1)
+ static inline int oidcmp(const struct object_id *oid1, const struct 
object_id *oid2)
 @@
  
  static inline void hashcpy(unsigned char *sha_dst, const unsigned char 
*sha_src)
 2: d0bf993bc5 =  2: 2d2229b112 tree-walk: replace hard-coded constants with 
the_hash_algo
 3: 718ff26cb3 =  3: e2ea848e69 hex: switch to using the_hash_algo
 4: 9c387dc7b4 =  4: a2ba0e70ac commit: express tree entry constants in terms 
of the_hash_algo
 5: efbae0c278 =  5: 7cd0a1600e strbuf: allocate space with GIT_MAX_HEXSZ
 6: e37fa26cf7 =  6: b89147f48b sha1-name: use the_hash_algo when parsing 
object names
 7: b7ef5b65fc < --:  --- commit: increase commit message buffer size
 8: 309c452bd7 =  7: 6d2efbfdb0 refs/files-backend: use the_hash_algo for 
writing refs
 9: 08684a629e =  8: 745d8c1e5f builtin/update-index: convert to using 
the_hash_algo
10: 36c7de8d9a =  9: a9e4fe9a49 builtin/update-index: simplify parsing of 
cacheinfo
11: cfa93658a1 = 10: 3618c468cb 

[PATCH v2 15/16] sha1-file: convert constants to uses of the_hash_algo

2018-07-15 Thread brian m. carlson
Convert one use of 20 and several uses of GIT_SHA1_HEXSZ into references
to the_hash_algo.

Signed-off-by: brian m. carlson 
---
 sha1-file.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-file.c b/sha1-file.c
index de4839e634..1f66b9594f 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -336,7 +336,7 @@ int raceproof_create_file(const char *path, create_file_fn 
fn, void *cb)
 static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
 {
int i;
-   for (i = 0; i < 20; i++) {
+   for (i = 0; i < the_hash_algo->rawsz; i++) {
static char hex[] = "0123456789abcdef";
unsigned int val = sha1[i];
strbuf_addch(buf, hex[val >> 4]);
@@ -1473,7 +1473,7 @@ void *read_object_with_reference(const struct object_id 
*oid,
}
ref_length = strlen(ref_type);
 
-   if (ref_length + GIT_SHA1_HEXSZ > isize ||
+   if (ref_length + the_hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
get_oid_hex((char *) buffer + ref_length, _oid)) {
free(buffer);
@@ -2062,9 +2062,9 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
namelen = strlen(de->d_name);
strbuf_setlen(path, baselen);
strbuf_add(path, de->d_name, namelen);
-   if (namelen == GIT_SHA1_HEXSZ - 2 &&
+   if (namelen == the_hash_algo->hexsz - 2 &&
!hex_to_bytes(oid.hash + 1, de->d_name,
- GIT_SHA1_RAWSZ - 1)) {
+ the_hash_algo->rawsz - 1)) {
if (obj_cb) {
r = obj_cb(, path->buf, data);
if (r)


[PATCH v2 13/16] diff: switch GIT_SHA1_HEXSZ to use the_hash_algo

2018-07-15 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 diff.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index 639eb646b9..485ff6c264 100644
--- a/diff.c
+++ b/diff.c
@@ -3832,7 +3832,7 @@ static const char *diff_abbrev_oid(const struct object_id 
*oid, int abbrev)
char *hex = oid_to_hex(oid);
if (abbrev < 0)
abbrev = FALLBACK_DEFAULT_ABBREV;
-   if (abbrev > GIT_SHA1_HEXSZ)
+   if (abbrev > the_hash_algo->hexsz)
BUG("oid abbreviation out of range: %d", abbrev);
if (abbrev)
hex[abbrev] = '\0';
@@ -4947,7 +4947,7 @@ const char *diff_aligned_abbrev(const struct object_id 
*oid, int len)
const char *abbrev;
 
/* Do we want all 40 hex characters? */
-   if (len == GIT_SHA1_HEXSZ)
+   if (len == the_hash_algo->hexsz)
return oid_to_hex(oid);
 
/* An abbreviated value is fine, possibly followed by an ellipsis. */
@@ -4977,7 +4977,7 @@ const char *diff_aligned_abbrev(const struct object_id 
*oid, int len)
 * the automatic sizing is supposed to give abblen that ensures
 * uniqueness across all objects (statistically speaking).
 */
-   if (abblen < GIT_SHA1_HEXSZ - 3) {
+   if (abblen < the_hash_algo->hexsz - 3) {
static char hex[GIT_MAX_HEXSZ + 1];
if (len < abblen && abblen <= len + 2)
xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, 
len+3-abblen, "..");


[PATCH v2 05/16] strbuf: allocate space with GIT_MAX_HEXSZ

2018-07-15 Thread brian m. carlson
In order to be sure we have enough space to use with any hash algorithm,
use GIT_MAX_HEXSZ to allocate space.

Signed-off-by: brian m. carlson 
---
 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/strbuf.c b/strbuf.c
index b0716ac585..030556111d 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -921,7 +921,7 @@ void strbuf_add_unique_abbrev(struct strbuf *sb, const 
struct object_id *oid,
  int abbrev_len)
 {
int r;
-   strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
+   strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len);
strbuf_setlen(sb, sb->len + r);
 }


[PATCH v3 1/3] t7501: add merge conflict tests for dry run

2018-07-15 Thread Samuel Lijin
The behavior of git commit when doing a dry run changes if there are
unfixed/fixed merge conflits, but the test suite currently only asserts
that `git commit --dry-run` succeeds when all merge conflicts are fixed.

Add tests to document the behavior of all flags which imply a dry run
when (1) there is at least one unfixed merge conflict and (2) when all
merge conflicts are all fixed.

Signed-off-by: Samuel Lijin 
---
 t/t7501-commit.sh | 45 -
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index fa61b1a4e..be087e73f 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -652,7 +652,8 @@ test_expect_success '--only works on to-be-born branch' '
test_cmp expected actual
 '
 
-test_expect_success '--dry-run with conflicts fixed from a merge' '
+# set up env for tests of --dry-run given fixed/unfixed merge conflicts
+test_expect_success 'setup env with unfixed merge conflicts' '
# setup two branches with conflicting information
# in the same file, resolve the conflict,
# call commit with --dry-run
@@ -665,11 +666,45 @@ test_expect_success '--dry-run with conflicts fixed from 
a merge' '
git checkout -b branch-2 HEAD^1 &&
echo "commit-2-state" >test-file &&
git commit -m "commit 2" -i test-file &&
-   ! $(git merge --no-commit commit-1) &&
-   echo "commit-2-state" >test-file &&
+   test_expect_code 1 git merge --no-commit commit-1
+'
+
+test_expect_success '--dry-run with unfixed merge conflicts' '
+   test_expect_code 1 git commit --dry-run
+'
+
+test_expect_success '--short with unfixed merge conflicts' '
+   test_expect_code 1 git commit --short
+'
+
+test_expect_success '--porcelain with unfixed merge conflicts' '
+   test_expect_code 1 git commit --porcelain
+'
+
+test_expect_success '--long with unfixed merge conflicts' '
+   test_expect_code 1 git commit --long
+'
+
+test_expect_success '--dry-run with conflicts fixed from a merge' '
+   echo "merge-conflicts-fixed" >test-file &&
git add test-file &&
-   git commit --dry-run &&
-   git commit -m "conflicts fixed from merge."
+   git commit --dry-run
+'
+
+test_expect_failure '--short with conflicts fixed from a merge' '
+   git commit --short
+'
+
+test_expect_failure '--porcelain with conflicts fixed from a merge' '
+   git commit --porcelain
+'
+
+test_expect_success '--long with conflicts fixed from a merge' '
+   git commit --long
+'
+
+test_expect_success '--message with conflicts fixed from a merge' '
+   git commit --message "conflicts fixed from merge."
 '
 
 test_done
-- 
2.18.0



[PATCH v3 2/3] wt-status: teach wt_status_collect about merges in progress

2018-07-15 Thread Samuel Lijin
To fix the breakages documented by t7501, the next patch in this series
will teach wt_status_collect() to set the committable bit, instead of
having wt_longstatus_print_updated() and show_merge_in_progress() set it
(which is what currently happens). Unfortunately, wt_status_collect()
needs to know whether or not there is a merge in progress to set the bit
correctly, so teach its (two) callers to create, initialize, and pass
in instances of wt_status_state, which records this metadata.

Since wt_longstatus_print() and show_merge_in_progress() are in the same
callpaths and currently create and init copies of wt_status_state,
remove that logic and instead pass wt_status_state through.

Make wt_status_get_state easier to use, add a helper method to clean up
wt_status_state, const-ify as many struct pointers in method signatures
as possible, and add a FIXME for a struct pointer which should be const
but isn't (that this patch series will not address).

Signed-off-by: Samuel Lijin 
---
 builtin/commit.c |  32 
 ref-filter.c |   3 +-
 wt-status.c  | 188 +++
 wt-status.h  |  13 ++--
 4 files changed, 120 insertions(+), 116 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 37fcb55ab..79ef4f11a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -463,6 +463,7 @@ static const char *prepare_index(int argc, const char 
**argv, const char *prefix
 static int run_status(FILE *fp, const char *index_file, const char *prefix, 
int nowarn,
  struct wt_status *s)
 {
+   struct wt_status_state state;
struct object_id oid;
 
if (s->relative_paths)
@@ -482,10 +483,12 @@ static int run_status(FILE *fp, const char *index_file, 
const char *prefix, int
s->status_format = status_format;
s->ignore_submodule_arg = ignore_submodule_arg;
 
-   wt_status_collect(s);
-   wt_status_print(s);
+   wt_status_get_state(s, );
+   wt_status_collect(s, );
+   wt_status_print(s, );
+   wt_status_clear_state();
 
-   return s->commitable;
+   return s->committable;
 }
 
 static int is_a_merge(const struct commit *current_head)
@@ -631,7 +634,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
 {
struct stat statbuf;
struct strbuf committer_ident = STRBUF_INIT;
-   int commitable;
+   int committable;
struct strbuf sb = STRBUF_INIT;
const char *hook_arg1 = NULL;
const char *hook_arg2 = NULL;
@@ -848,7 +851,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
 
saved_color_setting = s->use_color;
s->use_color = 0;
-   commitable = run_status(s->fp, index_file, prefix, 1, s);
+   committable = run_status(s->fp, index_file, prefix, 1, s);
s->use_color = saved_color_setting;
} else {
struct object_id oid;
@@ -866,7 +869,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
for (i = 0; i < active_nr; i++)
if (ce_intent_to_add(active_cache[i]))
ita_nr++;
-   commitable = active_nr - ita_nr > 0;
+   committable = active_nr - ita_nr > 0;
} else {
/*
 * Unless the user did explicitly request a submodule
@@ -882,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
if (ignore_submodule_arg &&
!strcmp(ignore_submodule_arg, "all"))
flags.ignore_submodules = 1;
-   commitable = index_differs_from(parent, , 1);
+   committable = index_differs_from(parent, , 1);
}
}
strbuf_release(_ident);
@@ -894,7 +897,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
 * explicit --allow-empty. In the cherry-pick case, it may be
 * empty due to conflict resolution, which the user should okay.
 */
-   if (!commitable && whence != FROM_MERGE && !allow_empty &&
+   if (!committable && whence != FROM_MERGE && !allow_empty &&
!(amend && is_a_merge(current_head))) {
s->display_comment_prefix = old_display_comment_prefix;
run_status(stdout, index_file, prefix, 0, s);
@@ -1164,14 +1167,14 @@ static int parse_and_validate_options(int argc, const 
char *argv[],
 static int dry_run_commit(int argc, const char **argv, const char *prefix,
  const struct commit *current_head, struct wt_status 
*s)
 {
-   int commitable;
+   int committable;
const char *index_file;
 
index_file = prepare_index(argc, argv, prefix, current_head, 1);
-   commitable = run_status(stdout, 

[PATCH v3 3/3] commit: fix exit code for --short/--porcelain

2018-07-15 Thread Samuel Lijin
In wt-status.c, the s->commitable bit is set only in the call tree of
wt_longstatus_print(), which means that when there are changes to be
committed or all merge conflicts have been resolved, --dry-run and
--long return the correct exit code, but --short and --porcelain do not,
even though they both imply --dry-run.

Teach wt_status_collect() to set s->committable correctly so that
--short and --porcelain return the correct exit code in the above
described situations and mark the documenting tests as fixed.

Also stop setting s->committable in wt_longstatus_print_updated() and
show_merge_in_progress(), and const-ify wt_status_state in the method
signatures in those callpaths.

Signed-off-by: Samuel Lijin 
---
 t/t7501-commit.sh |  8 ++---
 wt-status.c   | 82 +--
 2 files changed, 55 insertions(+), 35 deletions(-)

diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index be087e73f..b6492322f 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -87,12 +87,12 @@ test_expect_success '--dry-run with stuff to commit returns 
ok' '
git commit -m next -a --dry-run
 '
 
-test_expect_failure '--short with stuff to commit returns ok' '
+test_expect_success '--short with stuff to commit returns ok' '
echo bongo bongo bongo >>file &&
git commit -m next -a --short
 '
 
-test_expect_failure '--porcelain with stuff to commit returns ok' '
+test_expect_success '--porcelain with stuff to commit returns ok' '
echo bongo bongo bongo >>file &&
git commit -m next -a --porcelain
 '
@@ -691,11 +691,11 @@ test_expect_success '--dry-run with conflicts fixed from 
a merge' '
git commit --dry-run
 '
 
-test_expect_failure '--short with conflicts fixed from a merge' '
+test_expect_success '--short with conflicts fixed from a merge' '
git commit --short
 '
 
-test_expect_failure '--porcelain with conflicts fixed from a merge' '
+test_expect_success '--porcelain with conflicts fixed from a merge' '
git commit --porcelain
 '
 
diff --git a/wt-status.c b/wt-status.c
index 75d389944..4ba657978 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -718,6 +718,39 @@ static void wt_status_collect_untracked(struct wt_status 
*s)
s->untracked_in_ms = (getnanotime() - t_begin) / 100;
 }
 
+static int has_unmerged(const struct wt_status *s)
+{
+   int i;
+
+   for (i = 0; i < s->change.nr; i++) {
+   struct wt_status_change_data *d;
+   d = s->change.items[i].util;
+   if (d->stagemask)
+   return 1;
+   }
+   return 0;
+}
+
+static void wt_status_mark_committable(
+   struct wt_status *s, const struct wt_status_state *state)
+{
+   int i;
+
+   if (state->merge_in_progress && !has_unmerged(s)) {
+   s->committable = 1;
+   return;
+   }
+
+   for (i = 0; i < s->change.nr; i++) {
+   struct wt_status_change_data *d = (s->change.items[i]).util;
+
+   if (d->index_status && d->index_status != DIFF_STATUS_UNMERGED) 
{
+   s->committable = 1;
+   return;
+   }
+   }
+}
+
 void wt_status_collect(struct wt_status *s, const struct wt_status_state 
*state)
 {
wt_status_collect_changes_worktree(s);
@@ -728,6 +761,8 @@ void wt_status_collect(struct wt_status *s, const struct 
wt_status_state *state)
wt_status_collect_changes_index(s);
 
wt_status_collect_untracked(s);
+
+   wt_status_mark_committable(s, state);
 }
 
 static void wt_longstatus_print_unmerged(const struct wt_status *s)
@@ -753,28 +788,28 @@ static void wt_longstatus_print_unmerged(const struct 
wt_status *s)
 
 }
 
-static void wt_longstatus_print_updated(struct wt_status *s)
+static void wt_longstatus_print_updated(const struct wt_status *s)
 {
-   int shown_header = 0;
int i;
 
+   if (!s->committable) {
+   return;
+   }
+
+   wt_longstatus_print_cached_header(s);
+
for (i = 0; i < s->change.nr; i++) {
struct wt_status_change_data *d;
struct string_list_item *it;
it = &(s->change.items[i]);
d = it->util;
-   if (!d->index_status ||
-   d->index_status == DIFF_STATUS_UNMERGED)
-   continue;
-   if (!shown_header) {
-   wt_longstatus_print_cached_header(s);
-   s->committable = 1;
-   shown_header = 1;
+   if (d->index_status &&
+   d->index_status != DIFF_STATUS_UNMERGED) {
+   wt_longstatus_print_change_data(s, WT_STATUS_UPDATED, 
it);
}
-   wt_longstatus_print_change_data(s, WT_STATUS_UPDATED, it);
}
-   if (shown_header)
-   wt_longstatus_print_trailer(s);
+
+   wt_longstatus_print_trailer(s);
 }
 

[PATCH v3 0/3] Fix --short/--porcelain options for git commit

2018-07-15 Thread Samuel Lijin
Take 3. Addressed the issue that Junio turned up the last time I sent
this out for review.

I'm not entirely sure I like the way I added the tests in the first
patch, but it's unclear to me if there's actually a pattern for setting
up and tearing down the same env for multiple test methods. There are
also other tests in t7501 that rely on state left from earlier tests, so
it's not really clear to me what the best thing to do here is.

Also added a FIXME in the second patch for something I think should be
fixed, but doesn't make sense to fix in this patch series.

Samuel Lijin (3):
  t7501: add merge conflict tests for dry run
  wt-status: teach wt_status_collect about merges in progress
  commit: fix exit code for --short/--porcelain

 builtin/commit.c  |  32 +++---
 ref-filter.c  |   3 +-
 t/t7501-commit.sh |  49 +++--
 wt-status.c   | 260 +-
 wt-status.h   |  13 +--
 5 files changed, 208 insertions(+), 149 deletions(-)

-- 
2.18.0



Proposal

2018-07-15 Thread Miss Victoria Mehmet
Hello

I have a business proposal of mutual benefits i would like to discuss with 
you,i asked before and i still await your positive response thanks.


PRIVATO

2018-07-15 Thread giorgio bugatto
Good day , my name is Giorgio Bugatto , i sent you a mail and there
was no response , please confirm that you did get this mail for more
details.

Regards.

Giorgio Bugatto


Re: [PATCH v3 04/11] rerere: mark strings for translation

2018-07-15 Thread Simon Ruderich
On Sat, Jul 14, 2018 at 10:44:36PM +0100, Thomas Gummerer wrote:
> 'git rerere' is considered a plumbing command and as such its output

s/plumbing/porcelain/?

Regards
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9