Re: [PATCH v4] git: treat -C treat as a no-op when path is empty

2015-03-07 Thread Junio C Hamano
Eric Sunshine sunsh...@sunshineco.com writes:

 On Sat, Mar 7, 2015 at 5:49 AM, karthik nayak karthik@gmail.com wrote:

 Also *(*argv)[1] seems more readable to me, maybe more of a perspective?

 I also had considered suggesting (*argv)[1][0] as more readable, but
 it is primarily personal taste, and I didn't want to bike-shed the
 issue.

I didn't mention that in earlier review rounds for the same reason,
but I saw Andreas Schwab also independently made the same comment,
so that makes three of us.

That does not change the fact that this is merely a matter of
preference; I wouldn't even call this one a taste (use of which
implies that there are judgement involved, as in good taste and
bad taste).

But because it is preference, the only time we can discuss is when
a new code is submitted and is under review.  Once it is in the
tree, it is not really worth extra patch noise to go and change.

As everybody knows, POINTER[0] and *POINTER are equivalent.  We have
quite a few places where we say let's treat passing an empty string
the same as not passing an argument at all with

if (!POINTER || !*POINTER)
; /* no-op */
else {
/* do something with POINTER */
fn(POINTER);
}

and we could say !POINTER[0] instead of !*POINTER, interchangeably.

We tend to prefer (again, I do not think this is particularly a
taste thing) *POINTER over POINTER[0] when POINTER is just a
single variable in the above pattern we often see in our code.

But when POINTER is an expression like (*argv)[1], where you unwrap
the operators according to their precedences, it often is easier to
read if you do not have to flip your eyes left and right too often.

You first look at argv, then notice the prefix * (you have to
move your eyes to the left here) and know argv points at a location
that holds a pointer.  Then you notice the suffix [1] (now to the
right) and know that pointer points at an array and the expression
is talking about in its second element.

Now, you want to say that second element is actually a pointer to a
string and want to talk about the beginning of that string.  If you
express it as *(*argv)[1], it forces the reader to go back to the
left end once more.  If you write it as (*argv)[1][0], the reader
can keep going to the right, starting from the last thing the reader
read and understood (which is the [1] at the right end).

At least, that is how I analyze _my_ preference---the latter feels
easier on my eyes.

But as I said this is a mere preference thing.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] configure: support HAVE_BSD_SYSCTL option

2015-03-07 Thread Kyle J. McKay
On BSD-compatible systems some information such as the number
of available CPUs may only be available via the sysctl function.

Add support for a HAVE_BSD_SYSCTL option complete with autoconf
support and include the sys/syctl.h header when the option is
enabled to make the sysctl function available.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 Makefile  |  6 ++
 config.mak.uname  |  5 +
 configure.ac  | 23 +++
 git-compat-util.h |  3 +++
 4 files changed, 37 insertions(+)

diff --git a/Makefile b/Makefile
index 44f1dd10..5f3987fe 100644
--- a/Makefile
+++ b/Makefile
@@ -357,6 +357,8 @@ all::
 # and define it to no if you need to remove the parentheses () around the
 # constant.  The default is auto, which means to use parentheses if your
 # compiler is detected to support it.
+#
+# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
 
 GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1431,6 +1433,10 @@ ifdef HAVE_CLOCK_MONOTONIC
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
 endif
 
+ifdef HAVE_BSD_SYSCTL
+   BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
diff --git a/config.mak.uname b/config.mak.uname
index b64b63c3..f4e77cb9 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -107,6 +107,7 @@ ifeq ($(uname_S),Darwin)
COMPAT_OBJS += compat/precompose_utf8.o
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
+   HAVE_BSD_SYSCTL = YesPlease
 endif
 ifeq ($(uname_S),SunOS)
NEEDS_SOCKET = YesPlease
@@ -199,6 +200,7 @@ ifeq ($(uname_S),FreeBSD)
PYTHON_PATH = /usr/local/bin/python
HAVE_PATHS_H = YesPlease
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
+   HAVE_BSD_SYSCTL = YesPlease
 endif
 ifeq ($(uname_S),OpenBSD)
NO_STRCASESTR = YesPlease
@@ -208,6 +210,7 @@ ifeq ($(uname_S),OpenBSD)
BASIC_CFLAGS += -I/usr/local/include
BASIC_LDFLAGS += -L/usr/local/lib
HAVE_PATHS_H = YesPlease
+   HAVE_BSD_SYSCTL = YesPlease
 endif
 ifeq ($(uname_S),MirBSD)
NO_STRCASESTR = YesPlease
@@ -215,6 +218,7 @@ ifeq ($(uname_S),MirBSD)
USE_ST_TIMESPEC = YesPlease
NEEDS_LIBICONV = YesPlease
HAVE_PATHS_H = YesPlease
+   HAVE_BSD_SYSCTL = YesPlease
 endif
 ifeq ($(uname_S),NetBSD)
ifeq ($(shell expr $(uname_R) : '[01]\.'),2)
@@ -225,6 +229,7 @@ ifeq ($(uname_S),NetBSD)
USE_ST_TIMESPEC = YesPlease
NO_MKSTEMPS = YesPlease
HAVE_PATHS_H = YesPlease
+   HAVE_BSD_SYSCTL = YesPlease
 endif
 ifeq ($(uname_S),AIX)
DEFAULT_PAGER = more
diff --git a/configure.ac b/configure.ac
index 55e5a9b3..bbdde85c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1046,6 +1046,29 @@ GIT_CONF_SUBST([NO_INITGROUPS])
 #
 # Define NO_ICONV if your libc does not properly support iconv.
 
+AC_DEFUN([BSD_SYSCTL_SRC], [
+AC_LANG_PROGRAM([[
+#include stddef.h
+#include sys/types.h
+#include sys/sysctl.h
+]],[[
+int val, mib[2];
+size_t len;
+mib[0] = CTL_HW;
+mib[1] = 1;
+len = sizeof(val);
+return sysctl(mib, 2, val, len, NULL, 0) ? 1 : 0;
+]])])
+
+#
+# Define HAVE_BSD_SYSCTL=YesPlease if a BSD-compatible sysctl function is 
available.
+AC_MSG_CHECKING([for BSD sysctl])
+AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],
+   [AC_MSG_RESULT([yes])
+   HAVE_BSD_SYSCTL=YesPlease],
+   [AC_MSG_RESULT([no])
+   HAVE_BSD_SYSCTL=])
+GIT_CONF_SUBST([HAVE_BSD_SYSCTL])
 
 ## Other checks.
 # Define USE_PIC if you need the main git objects to be built with -fPIC
diff --git a/git-compat-util.h b/git-compat-util.h
index a3095be9..50691d3c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -127,6 +127,9 @@
 #else
 #include poll.h
 #endif
+#ifdef HAVE_BSD_SYSCTL
+#include sys/sysctl.h
+#endif
 
 #if defined(__MINGW32__)
 /* pull in Windows compatibility stuff */
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] thread-utils.c: detect CPU count on older BSD-like systems

2015-03-07 Thread Kyle J. McKay
Not all systems support using sysconf to detect the number
of available CPU cores.  Older BSD and BSD-derived systems
only provide the information via the sysctl function.

If HAVE_BSD_SYSCTL is defined attempt to retrieve the number
of available CPU cores using the sysctl function.

If HAVE_BSD_SYSCTL is not defined or the sysctl function
fails, we still attempt to get the information via sysconf.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 thread-utils.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/thread-utils.c b/thread-utils.c
index 97396a75..a2135e07 100644
--- a/thread-utils.c
+++ b/thread-utils.c
@@ -35,7 +35,23 @@ int online_cpus(void)
 
if (!pstat_getdynamic(psd, sizeof(psd), (size_t)1, 0))
return (int)psd.psd_proc_cnt;
-#endif
+#elif defined(HAVE_BSD_SYSCTL)  defined(HW_NCPU)
+   int mib[2];
+   size_t len;
+   int cpucount;
+
+   mib[0] = CTL_HW;
+#  ifdef HW_AVAILCPU
+   mib[1] = HW_AVAILCPU;
+   len = sizeof(cpucount);
+   if (!sysctl(mib, 2, cpucount, len, NULL, 0))
+   return cpucount;
+#  endif /* HW_AVAILCPU */
+   mib[1] = HW_NCPU;
+   len = sizeof(cpucount);
+   if (!sysctl(mib, 2, cpucount, len, NULL, 0))
+   return cpucount;
+#endif /* defined(HAVE_BSD_SYSCTL)  defined(HW_NCPU) */
 
 #ifdef _SC_NPROCESSORS_ONLN
if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN))  0)
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/4] git-credential-store: support multiple credential files

2015-03-07 Thread Paul Tan
Previously, git-credential-store only supported storing credentials in a
single file: ~/.git-credentials. In order to support the XDG base
directory specification[1], git-credential-store needs to be able to
lookup and erase credentials from multiple files, as well as to pick the
appropriate file to write to so that the credentials can be found on
subsequent lookups.

[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html

Note that some credential storage files may not be owned, readable or
writable by the user, as they may be system-wide files that are meant to
apply to every user.

Instead of a single file path, lookup_credential(), remove_credential()
and store_credential() now take a precedence-ordered string_list of
file paths. lookup_credential() expects both user-specific and
system-wide credential files to be provided to support the use case of
system administrators setting default credentials for users.
remove_credential() and store_credential() expect only the user-specific
credential files to be provided as usually the only config files that
users are allowed to edit are their own user-specific ones.

lookup_credential() will read these (user-specific and system-wide) file
paths in order until it finds the 1st matching credential and print it.
As some files may be private and thus unreadable, any file which cannot
be read will be ignored silently.

remove_credential() will erase credentials from all (user-specific)
files in the list.  This is because if credentials are only erased from
the file with the highest precedence, a matching credential may still be
found in a file further down the list. (Note that due to the lockfile
code, this requires the directory to be writable, which should be so for
user-specific config files)

store_credential() will write the credentials to the first existing
(user-specific) file in the list. If none of the files in the list
exist, store_credential() will write to the filename specified by
default_index, thus creating it. For backwards compatibility,
~/.git-credentials should be the file specified by default_index.

Helped-by: Matthieu Moy matthieu@grenoble-inp.fr
Helped-by: Junio C Hamano gits...@pobox.com
Helped-by: Jeff King p...@peff.net
Signed-off-by: Paul Tan pyoka...@gmail.com
---
 credential-store.c | 77 --
 1 file changed, 52 insertions(+), 25 deletions(-)

diff --git a/credential-store.c b/credential-store.c
index 925d3f4..3455d7a 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -6,7 +6,7 @@
 
 static struct lock_file credential_lock;
 
-static void parse_credential_file(const char *fn,
+static int parse_credential_file(const char *fn,
  struct credential *c,
  void (*match_cb)(struct credential *),
  void (*other_cb)(struct strbuf *))
@@ -14,18 +14,20 @@ static void parse_credential_file(const char *fn,
FILE *fh;
struct strbuf line = STRBUF_INIT;
struct credential entry = CREDENTIAL_INIT;
+   int found_credential = 0;
 
fh = fopen(fn, r);
if (!fh) {
-   if (errno != ENOENT)
+   if (errno != ENOENT  errno != EACCES)
die_errno(unable to open %s, fn);
-   return;
+   return found_credential;
}
 
while (strbuf_getline(line, fh, '\n') != EOF) {
credential_from_url(entry, line.buf);
if (entry.username  entry.password 
credential_match(c, entry)) {
+   found_credential = 1;
if (match_cb) {
match_cb(entry);
break;
@@ -38,6 +40,7 @@ static void parse_credential_file(const char *fn,
credential_clear(entry);
strbuf_release(line);
fclose(fh);
+   return found_credential;
 }
 
 static void print_entry(struct credential *c)
@@ -64,21 +67,10 @@ static void rewrite_credential_file(const char *fn, struct 
credential *c,
die_errno(unable to commit credential store);
 }
 
-static void store_credential(const char *fn, struct credential *c)
+static void store_credential_file(const char *fn, struct credential *c)
 {
struct strbuf buf = STRBUF_INIT;
 
-   /*
-* Sanity check that what we are storing is actually sensible.
-* In particular, we can't make a URL without a protocol field.
-* Without either a host or pathname (depending on the scheme),
-* we have no primary key. And without a username and password,
-* we are not actually storing a credential.
-*/
-   if (!c-protocol || !(c-host || c-path) ||
-   !c-username || !c-password)
-   return;
-
strbuf_addf(buf, %s://, c-protocol);
strbuf_addstr_urlencode(buf, c-username, 1);
strbuf_addch(buf, ':');
@@ -95,8 

[PATCH v2 3/4] docs/git-credential-store: document XDG file and precedence

2015-03-07 Thread Paul Tan
git-credential-store now supports an additional default credential file
at $XDG_CONFIG_HOME/git/credentials. However, ~/.git-credentials takes
precedence over it for backwards compatibility. To make the precedence
ordering explicit, add a new section FILES that lists out the credential
file paths in their order of precedence, and explains how the ordering
affects the lookup, storage and erase operations.

Also update documentation for --store to briefly explain the operations
on multiple files if the --store option is not provided.

Signed-off-by: Paul Tan pyoka...@gmail.com
---
 Documentation/git-credential-store.txt | 37 --
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-credential-store.txt 
b/Documentation/git-credential-store.txt
index bc97071..451c4fa 100644
--- a/Documentation/git-credential-store.txt
+++ b/Documentation/git-credential-store.txt
@@ -31,10 +31,43 @@ OPTIONS
 
 --file=path::
 
-   Use `path` to store credentials. The file will have its
+   Use `path` to lookup and store credentials. The file will have its
filesystem permissions set to prevent other users on the system
from reading it, but will not be encrypted or otherwise
-   protected. Defaults to `~/.git-credentials`.
+   protected. If not specified, credentials will be searched for from
+   `~/.git-credentials` and `$XDG_CONFIG_HOME/git/credentials`, and
+   credentials will be written to `~/.git-credentials` if it exists, or
+   `$XDG_CONFIG_HOME/git/credentials` if it exists and the former does
+   not. See also FILES.
+
+[[FILES]]
+FILES
+-
+
+If not set explicitly with '--file', there are two files where
+git-credential-store will search for credentials in order of precedence:
+
+~/.git-credentials::
+   User-specific credentials file.
+
+$XDG_CONFIG_HOME/git/credentials::
+   Second user-specific credentials file. If '$XDG_CONFIG_HOME' is not set
+   or empty, `$HOME/.config/git/credentials` will be used. Any credentials
+   stored in this file will not be used if `~/.git-credentials` has a
+   matching credential as well. It is a good idea not to create this file
+   if you sometimes use older versions of Git, as support for this file
+   was added fairly recently.
+
+
+For credential lookups, the files are read in the order given above, with the
+first matching credential found taking precedence over credentials found in
+files further down the list.
+
+Credential storage will per default write to the first existing file in the
+list. If none of these files exist, `~/.git-credentials` will be created and
+written to.
+
+When erasing credentials, matching credentials will be erased from all files.
 
 EXAMPLES
 
-- 
2.1.4

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


[PATCH v2 2/4] git-credential-store: support XDG_CONFIG_HOME

2015-03-07 Thread Paul Tan
Add $XDG_CONFIG_HOME/git/credentials to the default credential search
path of git-credential-store. This allows git-credential-store to
support user-specific configuration files in accordance with the XDG
base directory specification[1].

[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html

~/.git-credentials has a higher precedence than
$XDG_CONFIG_HOME/git/credentials when looking up credentials.  This
means that if any duplicate matching credentials are found in the xdg
file (due to ~/.git-credentials being updated by old versions of git or
outdated tools), they will not be used at all. This is to give the user
some leeway in switching to old versions of git while keeping the xdg
directory. This is consistent with the behavior of git-config.

However, the higher precedence of ~/.git-credentials means that as long
as ~/.git-credentials exist, all credentials will be written to the
~/.git-credentials file even if the user has an xdg file as having a
~/.git-credentials file indicates that the user wants to preserve
backwards-compatibility. This is also consistent with the behavior of
git-config.

Since the xdg file will not be used unless it actually exists, to
prevent the situation where some credentials are present in the xdg file
while some are present in the home file, users are recommended to not
create the xdg file if they require compatibility with old versions of
git or outdated tools. Note, though, that erase can be used to
explicitly erase matching credentials from all files.

Helped-by: Matthieu Moy matthieu@grenoble-inp.fr
Helped-by: Junio C Hamano gits...@pobox.com
Helped-by: Jeff King p...@peff.net
Signed-off-by: Paul Tan pyoka...@gmail.com
---
 credential-store.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/credential-store.c b/credential-store.c
index 3455d7a..7b22a3a 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -162,11 +162,16 @@ int main(int argc, char **argv)
usage_with_options(usage, options);
op = argv[0];
 
-   if (!file)
-   file = expand_user_path(~/.git-credentials);
-   if (file)
+   if (file) {
string_list_append_nodup(fns, file);
-   else
+   } else {
+   if ((file = expand_user_path(~/.git-credentials)))
+   string_list_append_nodup(fns, file);
+   home_config_paths(NULL, file, credentials);
+   if (file)
+   string_list_append_nodup(fns, file);
+   }
+   if (!fns.nr)
die(unable to set up default path; use --file);
 
if (credential_read(c, stdin)  0)
@@ -177,7 +182,7 @@ int main(int argc, char **argv)
else if (!strcmp(op, erase))
remove_credential(fns, c);
else if (!strcmp(op, store))
-   store_credential(fns, c, fns.nr - 1);
+   store_credential(fns, c, 0);
else
; /* Ignore unknown operation. */
 
-- 
2.1.4

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


[PATCH v2 0/4] git-credential-store: XDG user-specific config file support

2015-03-07 Thread Paul Tan
The previous patch series can be found at [1].

[1] http://thread.gmane.org/gmane.comp.version-control.git/264682

The changes are as follows:

* Code refactor: instead of a gigantic blob of code in main(),
  store_credential(), remove_credential() and lookup_credential() have been
  modified to take a string_list of precedence-ordered file paths. Although in
  this patch only support for XDG_CONFIG_HOME (user-specific config files) are
  implemented, this opens the door for support of XDG_CONFIG_DIRS (system-wide
  config files) to be implemented as well.

* parse_credential_file() returns the value of found_credential at all times.
  (Thanks Junio for pointing this out)

* parse_credential_file(), and thus get ignores unreadable/non-existing files
  instead of warning the user. This is done to follow the XDG base dir spec,
  which states that: if for any reason a file in a certain directory is
  unaccessible, e.g. because the directory is non-existant, the file is
  non-existant or the user is not authorized to open the file, then the
  processing of the file in that directory should be skipped.[2]

[2] http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

* store now only write to a single file instead of writing to one and erasing
  from the rest, unlike the behavior in the 1st patch, as the complexity
  introduced by implementing this behavior is probably unnecessary. If the user
  really wanted all matching credentials to be erased, the user can simply just
  issue an erase. (Thanks Matthieu, Junio and Jeff for this suggestion)

* ~/.git-credentials now has greater precedence than the xdg credentials file.
  This is to be consistent with the behavior of git-config.

* Support for $XDG_CONFIG_HOME/git/credentials has been documented in
  git-credentials-store.

The changes for the tests are as follows:

* Instead of repeating ${XDG_CONFIG_HOME:-$HOME/.config} all over
  the place, add tests that test for $HOME/.config/git/credentials (when
  XDG_CONFIG_HOME is unset) and for $XDG_CONFIG_HOME/git/credentials with a
  custom $XDG_CONFIG_HOME directory set. This is to test that the new code
  respects the $XDG_CONFIG_HOME environment variable. (Thanks Junio)

* Use test_path_is_missing to test if files exist. (Thanks Matthieu)

* All code is now within test_expect_success and will now fail if any
  error occurs in the code block through the use of . Furthermore, tests do
  not rely on previous tests passing as the credential files are overwritten in
  each test. (Thanks Matthieu and Junio for your code review)

The most current version of the patch queue is published in the xdg branch
at [3]. I try to push -f regularly.

For your feedback, please.

[3] https://github.com/pyokagan/git

Paul Tan (4):
  git-credential-store: support multiple credential files
  git-credential-store: support XDG_CONFIG_HOME
  docs/git-credential-store: document XDG file and precedence
  t0302: test credential-store support for XDG_CONFIG_HOME

 Documentation/git-credential-store.txt | 37 +-
 credential-store.c | 86 +--
 t/t0302-credential-store.sh| 92 ++
 3 files changed, 186 insertions(+), 29 deletions(-)

-- 
2.1.4

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


Re: [PATCH v2 00/10] Use a structure for object IDs.

2015-03-07 Thread Junio C Hamano
brian m. carlson sand...@crustytoothpaste.net writes:

 Certain parts of the code have to be converted before others to keep the
 patch sizes small, maintainable, and bisectable, so functions and
 structures that are used across the codebase (e.g. struct object) will
 be converted later.  Conversion has been done in a somewhat haphazard
 manner by converting modules with leaf functions and less commonly used
 structs first.

That leaf-first approach sounds very sensible.

In the medium term, I wonder if the changes can progress faster and
in a less error prone way if you first used GIT_SHA1_RAWSZ in places
that cannot be immediately converted to the struct yet.  That way,
we will be easily tell by git grep GIT_SHA1_RAWSZ how many more
places need treatment.  I do not know if that is all that useful
offhand, though.  Those places need to be touched in the second pass
to use the struct again, after the s/\[20\]/[GIT_SHA1_RAWSZ]/
first pass.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] help.c: use SHELL_PATH instead of hard-coded /bin/sh

2015-03-07 Thread Junio C Hamano
Kyle J. McKay mack...@gmail.com writes:

 If the user has set SHELL_PATH in the Makefile then we
 should respect that value and use it.

 Signed-off-by: Kyle J. McKay mack...@gmail.com
 ---
  builtin/help.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/builtin/help.c b/builtin/help.c
 index 6133fe49..2ae8a1e9 100644
 --- a/builtin/help.c
 +++ b/builtin/help.c
 @@ -171,7 +171,7 @@ static void exec_man_cmd(const char *cmd, const char 
 *page)
  {
   struct strbuf shell_cmd = STRBUF_INIT;
   strbuf_addf(shell_cmd, %s %s, cmd, page);
 - execl(/bin/sh, sh, -c, shell_cmd.buf, (char *)NULL);
 + execl(SHELL_PATH, SHELL_PATH, -c, shell_cmd.buf, (char *)NULL);

It is a common convention to make the first argument the command
name without its path, and this change breaks that convention.

Does it matter, or would it break something?  I recall that some
implementations of shell (e.g. bash) change their behaviour
depending on how they are invoked (e.g. ln -s bash /bin/sh makes
it run in posix mode) but I do not know if they do so by paying
attention to their argv[0].  There might be other fallouts I do not
think of offhand here.

I do not have an objection to what these patches want to do, though.

Thanks.

   warning(_(failed to exec '%s': %s), cmd, strerror(errno));
  }
  
 ---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [GSoC Microproject]Adding - shorthand for @{-1} in RESET command

2015-03-07 Thread Junio C Hamano
Sundararajan R dyou...@gmail.com writes:

 diff --git a/builtin/reset.c b/builtin/reset.c
 index 4c08ddc..62764d4 100644
 --- a/builtin/reset.c
 +++ b/builtin/reset.c
 @@ -203,8 +203,16 @@ static void parse_args(struct pathspec *pathspec,
*
* At this point, argv points immediately after [-opts].
*/
 -
 + int flag=0; /* 
 +  *  - may refer to filename in which case we should be 
 giving more precedence 
 +  *  to filename than equating argv[0] to @{-1} 
 +  */

Comment on a separate line.  More importantly, think if you can give
the variable a more meaningful name so that you do not have to
explain.

You are missing SPs requested by the coding guideline everywhere in
your patch.


   if (argv[0]) {
 + if (!strcmp(argv[0], -)  !argv[1])  /* - is the only 
 argument */
 + {
 + argv[0]=@{-1};
 + flag=1;
 + }
   if (!strcmp(argv[0], --)) {
   argv++; /* reset to HEAD, possibly with paths */
   } else if (argv[1]  !strcmp(argv[1], --)) {
 @@ -226,6 +234,8 @@ static void parse_args(struct pathspec *pathspec,

Around here not shown by this patch there are a few uses of argv[0],
and the most important one is

verify_non_filename(prefix, argv[0]);

just before the line below (see below).

   rev = *argv++;
   } else {
   /* Otherwise we treat this as a filename */
 + if(flag)
 + argv[0]=-;
   verify_filename(prefix, argv[0], 1);
   }
   }

By the way, do you understand the intent of the existing checks in
this codepath that uses verify_filename() and verify_non_filename()?

The idea is to allow users to write git reset X and git reset Y
Z safely in an unambiguous way.

 * X could be a commit (e.g. git reset master), to update the
   current branch to point at the same commit as 'master' and update
   the index to match.

 * X could be a pathspec (e.g. git reset hello.c), to grab the
   blob object for X out of the HEAD and put it in the index.

 * Y could be a tree-ish and Z a pathspec (e.g. git reset HEAD^
   hello.c), to grab the blob object for Z out of tree-ish Y and
   put it to the index.

 * Both Y and Z could be pathspecs (e.g. git reset hello.c
   goodbye.c), to revert the index entries for these two paths to
   what the HEAD records.

If you happen to have a file whose name is 'master', and if you are
working on your 'topic' branch, what would this do?

$ git reset master

Is this a request to revert the index entry for path 'master' from
the HEAD?  Or is it a request to update the current branch to be the
same as the 'master' branch and repopulate the index from there?

What does the existing code try to do, and how does it do it?  It
detects the ambiguity and refuses to do either, to make sure it
causes no harm.

Now, with your change, does the result still honor this when
ambiguous, stop without causing harm to the user principle?  What
happens when your user has a file whose name is - in the working
tree?  What happens when your user has a file whose name is @{-1}
in the working tree?





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


[PATCH v2 4/4] t0302: test credential-store support for XDG_CONFIG_HOME

2015-03-07 Thread Paul Tan
t0302 now tests git-credential-store's support for the XDG user-specific
configuration file $XDG_CONFIG_HOME/git/credentials. Specifically:

* Ensure that the XDG file is strictly opt-in. It should not be created
  by git at all times if it does not exist.

* On the flip side, if the XDG file exists, ~/.git-credentials should
  not be created at all times.

* If both the XDG file and ~/.git-credentials exists, then both files
  should be used for credential lookups. However, credentials should
  only be written to ~/.git-credentials.

* Credentials must be erased from both files.

* $XDG_CONFIG_HOME can be a custom directory set by the user as per the
  XDG base directory specification. Test that git-credential-store
  respects that, but defaults to ~/.config/git/credentials if it does
  not exist or is empty.

Helped-by: Matthieu Moy matthieu@grenoble-inp.fr
Helped-by: Junio C Hamano gits...@pobox.com
Signed-off-by: Paul Tan pyoka...@gmail.com
---
 t/t0302-credential-store.sh | 92 +
 1 file changed, 92 insertions(+)

diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index f61b40c..7fe832d 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -5,5 +5,97 @@ test_description='credential-store tests'
 . $TEST_DIRECTORY/lib-credential.sh
 
 helper_test store
+test_expect_success '~/.git-credentials is written to when xdg credentials 
file does not exist' '
+   test -s $HOME/.git-credentials
+'
+test_expect_success 'xdg credentials file will not be created if it does not 
exist' '
+   test_path_is_missing $HOME/.config/git/credentials
+'
+test_expect_success 'create $XDG_CONFIG_HOME/git/credentials file' '
+   test_might_fail rm $HOME/.git-credentials 
+   mkdir -p $HOME/.config/git 
+   $HOME/.config/git/credentials
+'
+helper_test store
+test_expect_success 'xdg credentials file will be written to if it exists' '
+   test -s $HOME/.config/git/credentials
+'
+test_expect_success '~/.git-credentials will not be created if xdg credentials 
file exists' '
+   test_path_is_missing $HOME/.git-credentials
+'
+test_expect_success 'set up custom XDG_CONFIG_HOME credential file' '
+   XDG_CONFIG_HOME=$HOME/xdg  export XDG_CONFIG_HOME 
+   mkdir -p $HOME/xdg/git 
+   $HOME/xdg/git/credentials 
+   $HOME/.config/git/credentials
+'
+helper_test store
+test_expect_success 'custom XDG_CONFIG_HOME credentials file will be written 
to if it exists' '
+   unset XDG_CONFIG_HOME 
+   test -s $HOME/xdg/git/credentials
+'
+test_expect_success '~/.config/git/credentials file will not be written to if 
a custom XDG_CONFIG_HOME is set' '
+   test_must_be_empty $HOME/.config/git/credentials
+'
+test_expect_success '~/.git-credentials will not be created if xdg credentials 
file exists' '
+   test_path_is_missing $HOME/.git-credentials
+'
+test_expect_success 'get: return credentials from home file if matches are 
found in both home and xdg files' '
+   mkdir -p $HOME/.config/git 
+   echo https://xdg-user:xdg-p...@example.com; 
$HOME/.config/git/credentials 
+   echo https://home-user:home-p...@example.com; 
$HOME/.git-credentials 
+   check fill store -\EOF
+   protocol=https
+   host=example.com
+   --
+   protocol=https
+   host=example.com
+   username=home-user
+   password=home-pass
+   --
+   EOF
+'
+test_expect_success 'get: return credentials from xdg file if the home files 
do not have them' '
+   mkdir -p $HOME/.config/git 
+   $HOME/.git-credentials 
+   echo https://home-user:home-p...@example.com; 
$HOME/.config/git/credentials 
+   check fill store -\EOF
+   protocol=https
+   host=example.com
+   --
+   protocol=https
+   host=example.com
+   username=home-user
+   password=home-pass
+   --
+   EOF
+'
+test_expect_success 'get: return credentials from home file if xdg files are 
unreadable' '
+   mkdir -p $HOME/.config/git 
+   echo https://xdg-user:xdg-p...@example.com; 
$HOME/.config/git/credentials 
+   echo https://home-user:home-p...@example.com; 
$HOME/.git-credentials 
+   chmod -r $HOME/.config/git/credentials 
+   check fill store -\EOF
+   protocol=https
+   host=example.com
+   --
+   protocol=https
+   host=example.com
+   username=home-user
+   password=home-pass
+   --
+   EOF
+'
+test_expect_success 'erase: erase matching credentials from both xdg and home 
files' '
+   mkdir -p $HOME/.config/git 
+   echo https://xdg-user:xdg-p...@example.com; 
$HOME/.config/git/credentials 
+   echo https://home-user:home-p...@example.com; 
$HOME/.git-credentials 
+   check reject store -\EOF
+   protocol=https
+   host=example.com
+   EOF
+   test_must_be_empty $HOME/.config/git/credentials 
+   test_must_be_empty $HOME/.git-credentials
+'
 
 test_done
-- 
2.1.4

--
To 

Re: [PATCH v3 2/3] sha1_file: implement changes for cat-file --literally -t

2015-03-07 Thread karthik nayak



On 03/07/2015 12:58 AM, Junio C Hamano wrote:

karthik nayak karthik@gmail.com writes:


... I suspect that the caller should supply a pointer to struct
object_info, i.e. something along these lines:

  struct object_info oi = { NULL };
  struct strbuf sb = STRBUF_INIT;
  enum object_type type;

  ...

  oi.typename = sb;
  sha1_object_info_literally(sha1, oi);
  if (!sb.len)
  that is an error;
  else
  use sb.buf as the name;

  strbuf_release(sb);

I thought I could get the calling function cat_one_file() to send
the address to a struct strbuf. Like this ..

struct strbuf sb = STRBUF_INIT;
length = sha1_object_info_literally(sha1, sb);
if (length  0)
die(git cat-file --literally -t %s: failed,
 obj_name);
printf(%s\n, sb.buf);
strbuf_release(sb);
return 0;

What do you think? Is this ok?


When I gave you $gmane/264420, I was actually hoping that we do not
have to have object-info-literally helper at all, and instead the
caller in cat-file that deals with -t option can become something
like this:

struct object_info oi = { NULL };
struct strbuf typename = STRBUF_INIT;
unsigned flags = LOOKUP_REPLACE_OBJECT;

 if (doing the --literally stuff)
flags |= LOOKUP_LITERALLY;

...

switch (...) {
case 't':
oi.typename = typename;
 sha1_object_info_extended(sha1, oi, flags);
if (typename.len) {
printf(%s\n, typename.buf);
return 0;
}
 break;
...

The change illustrated in $gmane/264420 is probably incomplete and
some calls from the sha1_object_info_extended() after that change
may still need to be tweaked to pay attention to LOOKUP_LITERALLY
bit (e.g. parse_sha1_header() may want to learn not to barf when
seeing an unexpected typename in the header when the caller asks to
look up literally).


I got confused with $gmane/264420 thanks for clearing that up, also I
tried implementing it as follows  :

case 't':
oi.typep = type;
oi.typename = sb;
sha1_object_info_extended(sha1, oi, flags);
if (sb.len) {
printf(%s\n, sb.buf);
strbuf_release(sb);
return 0;
} else if (type) {
printf(%s\n, typename(type));
return 0;
}
break;

This works but I need an else statement to check the type if not getting 
the type literally, which is because if not called literally the 
oi.typename is not set, which I will fix now.
Also when trying to get the type literally it does not call 
parse_sha1_header() hence we don't need to worry about it handling 
unexpected typenames.

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


Re: [PATCH 10/24] untracked cache: save to an index extension

2015-03-07 Thread Stefan Beller
On Sun, Feb 8, 2015 at 12:55 AM, Nguyễn Thái Ngọc Duy pclo...@gmail.com wrote:
 +   ouc = xmalloc(sizeof(*ouc) + len + 1);

Do we need to free `ouc` at the end of the function as well?
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] git: treat -C treat as a no-op when path is empty

2015-03-07 Thread karthik nayak


 This iteration looks sensible, except that the Subject reads
 strange.  Will queue with minor tweaks to the log message,
 and perhaps with a fix to unreadable *(*argv)[1] that was
 mentioned elsewhere.

 Thanks.

Hey could you tell me what seems strange, so I can improve on
it the next time.
Also *(*argv)[1] seems more readable to me, maybe more of a perspective?

Thanks


On 03/07/2015 07:49 AM, Eric Sunshine wrote:

On Fri, Mar 6, 2015 at 6:18 AM, Karthik Nayak karthik@gmail.com wrote:

'git -C ' unhelpfully dies with error Cannot change to '',
whereas the shell treats `cd ' as a no-op. Taking the shell's
behavior as a precedent, teach git to treat `-C ' as a no-op, as
well.

Test to check the no-op behaviour of -C path when path is
empty, written by Junio C Hamano.

Helped-by: Junio C Hamano gits...@pobox.com
Helped-by: Eric Sunchine sunsh...@sunshineco.com


s/Sunchine/Sunshine/


Signed-off-by: Karthik Nayak karthik@gmail.com


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


Re: [PATCH] daemon: use strbuf for hostname info

2015-03-07 Thread René Scharfe

Am 07.03.2015 um 02:08 schrieb Jeff King:

On Sat, Mar 07, 2015 at 01:20:22AM +0100, René Scharfe wrote:


Not a big deal, but do we want to rename sanitize_client_strbuf to
sanitize_client? It only had the unwieldy name to distinguish it from
this one.


A patch would look like this.  The result is shorter, but no win in
terms of vertical space (number of lines).


IMHO this is an improvement, though whether it is enough to merit the
code churn I dunno. So I'm in favor, but don't mind dropping it if
others disagree.


I don't think the change justifies a separate patch, but we can squash 
it in. :)


René

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


[GSoC] small project idea from my todo list.. Bundle Symbolic links

2015-03-07 Thread Philip Oakley

Hi folks,

This is one of my small/mini projects from late year that got pushed 
down my stack that may be suitable for someone on the GSoC small project 
list:


- Embed symbolic link references into the Bundle processing.

Currently git bundle gets 'confused' when there are multiple refs using 
the same HEAD ref, with only a heuristic to guess which ref should be 
allocate to HEAD. The issue is to update the 'heuristic' process to get 
it right, while still being backward compatible.


A potential solution was identified in [1], and a similar problem (where 
does HEAD point to..) was recently covered in patch [2] (and discussions 
either side) .


I'd be quite happy for a GSoC candidate/student to have a go at it, 
especially as I've let it languish! ;-)

--
Philip

--
Essentially, hide the clues as to where the Symbolic refs point to 
(other symrefs) after a null char in the line format..


Perhaps also add a 'Rev #n' after the bundle's version line as well ?

[1] 
http://thread.gmane.org/gmane.comp.version-control.git/258827/focus=259087 
(addition of symref=refs/heads/master after a \0 null at the end of the 
refs line.)
[2] 
http://thread.gmane.org/gmane.comp.version-control.git/263922/focus=264936
[3] http://thread.gmane.org/gmane.comp.version-control.git/234053 has an 
older discussion regarding the same issue ('where does HEAD point to') 
on cloning. Linked from 
http://thread.gmane.org/gmane.comp.version-control.git/258365/focus=258463


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


[PATCH v2 1/2] daemon: use strbuf for hostname info

2015-03-07 Thread René Scharfe
Convert hostname, canon_hostname, ip_address and tcp_port to strbuf.
This allows to get rid of the helpers strbuf_addstr_or_null() and STRARG
because a strbuf always represents a valid (initially empty) string.

sanitize_client() is not needed anymore and sanitize_client_strbuf()
takes its place and name.

Helped-by: Jeff King p...@peff.net
Signed-off-by: Rene Scharfe l@web.de
---
This one is the first patch + s/_strbuf// + s/_reset/_release/.

 daemon.c | 98 +++-
 1 file changed, 41 insertions(+), 57 deletions(-)

diff --git a/daemon.c b/daemon.c
index c3edd96..265c188 100644
--- a/daemon.c
+++ b/daemon.c
@@ -56,10 +56,10 @@ static const char *user_path;
 static unsigned int timeout;
 static unsigned int init_timeout;
 
-static char *hostname;
-static char *canon_hostname;
-static char *ip_address;
-static char *tcp_port;
+static struct strbuf hostname = STRBUF_INIT;
+static struct strbuf canon_hostname = STRBUF_INIT;
+static struct strbuf ip_address = STRBUF_INIT;
+static struct strbuf tcp_port = STRBUF_INIT;
 
 static int hostname_lookup_done;
 
@@ -68,13 +68,13 @@ static void lookup_hostname(void);
 static const char *get_canon_hostname(void)
 {
lookup_hostname();
-   return canon_hostname;
+   return canon_hostname.buf;
 }
 
 static const char *get_ip_address(void)
 {
lookup_hostname();
-   return ip_address;
+   return ip_address.buf;
 }
 
 static void logreport(int priority, const char *err, va_list params)
@@ -122,12 +122,6 @@ static void NORETURN daemon_die(const char *err, va_list 
params)
exit(1);
 }
 
-static void strbuf_addstr_or_null(struct strbuf *sb, const char *s)
-{
-   if (s)
-   strbuf_addstr(sb, s);
-}
-
 struct expand_path_context {
const char *directory;
 };
@@ -138,22 +132,22 @@ static size_t expand_path(struct strbuf *sb, const char 
*placeholder, void *ctx)
 
switch (placeholder[0]) {
case 'H':
-   strbuf_addstr_or_null(sb, hostname);
+   strbuf_addbuf(sb, hostname);
return 1;
case 'C':
if (placeholder[1] == 'H') {
-   strbuf_addstr_or_null(sb, get_canon_hostname());
+   strbuf_addstr(sb, get_canon_hostname());
return 2;
}
break;
case 'I':
if (placeholder[1] == 'P') {
-   strbuf_addstr_or_null(sb, get_ip_address());
+   strbuf_addstr(sb, get_ip_address());
return 2;
}
break;
case 'P':
-   strbuf_addstr_or_null(sb, tcp_port);
+   strbuf_addbuf(sb, tcp_port);
return 1;
case 'D':
strbuf_addstr(sb, context-directory);
@@ -301,16 +295,14 @@ static int run_access_hook(struct daemon_service 
*service, const char *dir, cons
char *eol;
int seen_errors = 0;
 
-#define STRARG(x) ((x) ? (x) : )
*arg++ = access_hook;
*arg++ = service-name;
*arg++ = path;
-   *arg++ = STRARG(hostname);
-   *arg++ = STRARG(get_canon_hostname());
-   *arg++ = STRARG(get_ip_address());
-   *arg++ = STRARG(tcp_port);
+   *arg++ = hostname.buf;
+   *arg++ = get_canon_hostname();
+   *arg++ = get_ip_address();
+   *arg++ = tcp_port.buf;
*arg = NULL;
-#undef STRARG
 
child.use_shell = 1;
child.argv = argv;
@@ -542,7 +534,7 @@ static void parse_host_and_port(char *hostport, char **host,
  * trailing and leading dots, which means that the client cannot escape
  * our base path via .. traversal.
  */
-static void sanitize_client_strbuf(struct strbuf *out, const char *in)
+static void sanitize_client(struct strbuf *out, const char *in)
 {
for (; *in; in++) {
if (*in == '/')
@@ -556,23 +548,14 @@ static void sanitize_client_strbuf(struct strbuf *out, 
const char *in)
strbuf_setlen(out, out-len - 1);
 }
 
-static char *sanitize_client(const char *in)
-{
-   struct strbuf out = STRBUF_INIT;
-   sanitize_client_strbuf(out, in);
-   return strbuf_detach(out, NULL);
-}
-
 /*
  * Like sanitize_client, but we also perform any canonicalization
  * to make life easier on the admin.
  */
-static char *canonicalize_client(const char *in)
+static void canonicalize_client(struct strbuf *out, const char *in)
 {
-   struct strbuf out = STRBUF_INIT;
-   sanitize_client_strbuf(out, in);
-   strbuf_tolower(out);
-   return strbuf_detach(out, NULL);
+   sanitize_client(out, in);
+   strbuf_tolower(out);
 }
 
 /*
@@ -595,11 +578,11 @@ static void parse_host_arg(char *extra_args, int buflen)
char *port;
parse_host_and_port(val, host, port);
if (port) {
-   

[PATCH v2 2/2] daemon: deglobalize hostname information

2015-03-07 Thread René Scharfe
Move the variables related to the client-supplied hostname into its own
struct, let execute() own an instance of that instead of storing the
information in global variables and pass the struct to any function that
needs to access it as a parameter.

The lifetime of the variables is easier to see this way.  Allocated
memory is released within execute().  The strbufs don't have to be reset
anymore because they are written to only once at most: parse_host_arg()
is only called once by execute() and lookup_hostname() guards against
being called twice using hostname_lookup_done.

Signed-off-by: Rene Scharfe l@web.de
---
 daemon.c | 133 +++
 1 file changed, 74 insertions(+), 59 deletions(-)

diff --git a/daemon.c b/daemon.c
index 265c188..9ee2187 100644
--- a/daemon.c
+++ b/daemon.c
@@ -43,9 +43,6 @@ static const char *base_path;
 static const char *interpolated_path;
 static int base_path_relaxed;
 
-/* Flag indicating client sent extra args. */
-static int saw_extended_args;
-
 /* If defined, ~user notation is allowed and the string is inserted
  * after ~user/.  E.g. a request to git://host/~alice/frotz would
  * go to /home/alice/pub_git/frotz with --user-path=pub_git.
@@ -56,25 +53,27 @@ static const char *user_path;
 static unsigned int timeout;
 static unsigned int init_timeout;
 
-static struct strbuf hostname = STRBUF_INIT;
-static struct strbuf canon_hostname = STRBUF_INIT;
-static struct strbuf ip_address = STRBUF_INIT;
-static struct strbuf tcp_port = STRBUF_INIT;
-
-static int hostname_lookup_done;
+struct hostinfo {
+   struct strbuf hostname;
+   struct strbuf canon_hostname;
+   struct strbuf ip_address;
+   struct strbuf tcp_port;
+   unsigned int hostname_lookup_done:1;
+   unsigned int saw_extended_args:1;
+};
 
-static void lookup_hostname(void);
+static void lookup_hostname(struct hostinfo *hi);
 
-static const char *get_canon_hostname(void)
+static const char *get_canon_hostname(struct hostinfo *hi)
 {
-   lookup_hostname();
-   return canon_hostname.buf;
+   lookup_hostname(hi);
+   return hi-canon_hostname.buf;
 }
 
-static const char *get_ip_address(void)
+static const char *get_ip_address(struct hostinfo *hi)
 {
-   lookup_hostname();
-   return ip_address.buf;
+   lookup_hostname(hi);
+   return hi-ip_address.buf;
 }
 
 static void logreport(int priority, const char *err, va_list params)
@@ -124,30 +123,32 @@ static void NORETURN daemon_die(const char *err, va_list 
params)
 
 struct expand_path_context {
const char *directory;
+   struct hostinfo *hostinfo;
 };
 
 static size_t expand_path(struct strbuf *sb, const char *placeholder, void 
*ctx)
 {
struct expand_path_context *context = ctx;
+   struct hostinfo *hi = context-hostinfo;
 
switch (placeholder[0]) {
case 'H':
-   strbuf_addbuf(sb, hostname);
+   strbuf_addbuf(sb, hi-hostname);
return 1;
case 'C':
if (placeholder[1] == 'H') {
-   strbuf_addstr(sb, get_canon_hostname());
+   strbuf_addstr(sb, get_canon_hostname(hi));
return 2;
}
break;
case 'I':
if (placeholder[1] == 'P') {
-   strbuf_addstr(sb, get_ip_address());
+   strbuf_addstr(sb, get_ip_address(hi));
return 2;
}
break;
case 'P':
-   strbuf_addbuf(sb, tcp_port);
+   strbuf_addbuf(sb, hi-tcp_port);
return 1;
case 'D':
strbuf_addstr(sb, context-directory);
@@ -156,7 +157,7 @@ static size_t expand_path(struct strbuf *sb, const char 
*placeholder, void *ctx)
return 0;
 }
 
-static const char *path_ok(const char *directory)
+static const char *path_ok(const char *directory, struct hostinfo *hi)
 {
static char rpath[PATH_MAX];
static char interp_path[PATH_MAX];
@@ -192,11 +193,12 @@ static const char *path_ok(const char *directory)
dir = rpath;
}
}
-   else if (interpolated_path  saw_extended_args) {
+   else if (interpolated_path  hi-saw_extended_args) {
struct strbuf expanded_path = STRBUF_INIT;
struct expand_path_context context;
 
context.directory = directory;
+   context.hostinfo = hi;
 
if (*dir != '/') {
/* Allow only absolute */
@@ -286,7 +288,8 @@ static int daemon_error(const char *dir, const char *msg)
 
 static const char *access_hook;
 
-static int run_access_hook(struct daemon_service *service, const char *dir, 
const char *path)
+static int run_access_hook(struct daemon_service *service, const char *dir,
+  const char *path, struct hostinfo *hi)
 {

[GSOC] Introduction

2015-03-07 Thread karthik nayak

Hello everyone!
I am Karthik Nayak from Bangalore, India. I am currently pursuing my B.E 
in Computer Science. I am very keen on contributing to Git via GSoC 
2015. I have worked on one of the micro projects[1], I like how code is 
reviewed via the mailing list, It always ensures different perspectives 
on the same code and shows how there is always room for improvement.
I have been using Git for personal work, since about two years now. The 
reason why I want to contribute to Git is because I can relate to what 
is happening in the code, since I use it regularly.
I want to work on the project of Unifying git branch -l, git tag -l, 
and git for-each-ref and have been reading up on what Junio suggested 
in a reply to Amate Yolande[2].
I also found a link to a previous discussion[3] on the same topic. Is 
there any other discussion on the same? Do you guys have any comments?


Regards
-Karthik


[1] : http://article.gmane.org/gmane.comp.version-control.git/264911
[2] : http://article.gmane.org/gmane.comp.version-control.git/264966
[3] : http://thread.gmane.org/gmane.comp.version-control.git/261479
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Bashing freelancers

2015-03-07 Thread David Kastrup
Junio C Hamano gits...@pobox.com writes:

 David Kastrup d...@gnu.org writes:

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

 David Kastrup d...@gnu.org writes:

 Good work is worth good money. Suggesting that people who are not able
 to work for free are morally inferior is not conducive for a cooperative
 work atmosphere.

 Yes, but I do not think anybody did any such thing.

 Of course, I am hoping that all the mentors are doing GSoC not for
 money but out of love of our software and our community,

 Huh.

 I did not intend any moral judgement in that statement, but after
 re-reading it, I would say that not for money would have been
 better phrased as not only for money.

Shrug.  love of our software and our community was not sufficient in
the thread started at
http://permalink.gmane.org/gmane.comp.version-control.git/255385 to
make anybody do a one-character change spelled out explicitly even after
the user, presumably a community member, begged again.  Presumably a
case of Somebody else's problem.

The reality is that developers work mostly for their own motivations,
what Linus Torvalds describes as scratching your own itch.  And not
everybody is in the situation where he is able to scratch his own itch.

Sometimes there are good scratchers whose main itch is that everybody is
of the opinion they are so excellent at scratching people's itches that
they have the moral obligation to not do anything else.

Like eating.  Or sleeping.  Or having a life.

The non-glorious part of maintaining a flea circus where you can say
jump and marvel at inhuman feats of strength is feeding time.  You
can't just hope to shake down some passing dog whenever it is
performance time: even if that works, some of your actors may be too
starved to perform well.

Well, a flea circus is probably a bad analogy when talking about
scratching one's own itches.  But it's easy to state that one wants
people to work for love when oneself is getting paid for it.

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


[PATCH] rev-list: refuse --first-parent combined with --bisect

2015-03-07 Thread Kevin Daudt
rev-list --bisect is used by git bisect, but never together with
--first-parent. Because rev-list --bisect together with --first-parent
is not handled currently, and even leads to segfaults, refuse to use
both options together.

Signed-off-by: Kevin Daudt m...@ikke.info
---
This is my first code patch, and thought this was a nice exercise.

 Documentation/rev-list-options.txt | 3 ++-
 builtin/rev-list.c | 3 +++
 t/t6000-rev-list-misc.sh   | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Documentation/rev-list-options.txt 
b/Documentation/rev-list-options.txt
index 4ed8587..05c3f6d 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -123,7 +123,8 @@ parents) and `--max-parents=-1` (negative numbers denote no 
upper limit).
because merges into a topic branch tend to be only about
adjusting to updated upstream from time to time, and
this option allows you to ignore the individual commits
-   brought in to your history by such a merge.
+   brought in to your history by such a merge. Cannot be
+   combined with --bisect.
 
 --not::
Reverses the meaning of the '{caret}' prefix (or lack thereof)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ff84a82..c271e15 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -291,6 +291,9 @@ int cmd_rev_list(int argc, const char **argv, const char 
*prefix)
if (revs.bisect)
bisect_list = 1;
 
+   if(revs.first_parent_only  revs.bisect)
+   die(_(--first-parent is incompattible with --bisect));
+
if (DIFF_OPT_TST(revs.diffopt, QUICK))
info.flags |= REV_LIST_QUIET;
for (i = 1 ; i  argc; i++) {
diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh
index 2602086..1f58b46 100755
--- a/t/t6000-rev-list-misc.sh
+++ b/t/t6000-rev-list-misc.sh
@@ -96,4 +96,8 @@ test_expect_success 'rev-list can show index objects' '
test_cmp expect actual
 '
 
+test_expect_success '--bisect and --first-parent can not be combined' '
+   test_must_fail git rev-list --bisect --first-parent HEAD
+'
+
 test_done
-- 
2.3.1.184.g97c12a8.dirty

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


Re: [PATCH] rev-list: refuse --first-parent combined with --bisect

2015-03-07 Thread Kevin Daudt
On Sat, Mar 07, 2015 at 10:31:16PM +0100, Kevin Daudt wrote:
 diff --git a/builtin/rev-list.c b/builtin/rev-list.c
 index ff84a82..c271e15 100644
 --- a/builtin/rev-list.c
 +++ b/builtin/rev-list.c
 @@ -291,6 +291,9 @@ int cmd_rev_list(int argc, const char **argv, const char 
 *prefix)
   if (revs.bisect)
   bisect_list = 1;
  
 + if(revs.first_parent_only  revs.bisect)

I should have added a space after the if.

 + die(_(--first-parent is incompattible with --bisect));
 +
   if (DIFF_OPT_TST(revs.diffopt, QUICK))
   info.flags |= REV_LIST_QUIET;
   for (i = 1 ; i  argc; i++) {

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


Re: Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread brian m. carlson

On Sat, Mar 07, 2015 at 11:26:28PM +0100, Andreas Schwab wrote:

Diego Viola diego.vi...@gmail.com writes:


I know I could git-init in a empty directory


You can also git init a non-empty directory.


I have a script to set up a new throwaway VM with my dotfiles using git.
It looks a bit like the following ($BRANCH != master):

 SSH=ssh $DEST
 
 $SSH cd; $GIT init

 git push --receive-pack=$GIT-receive-pack $DEST:~/.git $BRANCH
 $SSH 
 $GIT pull . $BRANCH
 $GIT submodule update --init
 

It relies on the ability to git init a non-empty directory.  $BRANCH can 
be master if you use the new updateInstead functionality in git 2.3.0, 
and you can use git pull from a remote location instead of the push/pull 
pair if that suits you better.

--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187


signature.asc
Description: Digital signature


Efficient parsing of `status -z` output

2015-03-07 Thread Matthew Rothenberg
I've been working on a utility that parses the output of `git status
--porcelain` as a fundamental part of its operation.

Since I would like for this tool to be as robust as possible (and
cross-platform compatibility is a goal), I am currently trying to
migrate it from parsing the output of `--porcelain` to using the
output of `-z`, to quote from the documentation:

 There is also an alternate -z format recommended for machine parsing. In
 that format, the status field is the same, but some other things change.
 First, the - is omitted from rename entries and the field order is
 reversed (e.g from - to becomes to from). Second, a NUL (ASCII 0) follows
 each filename, replacing space as a field separator and the terminating
 newline (but a space still separates the status field from the first
 filename). Third, filenames containing special characters are not
 specially formatted; no quoting or backslash-escaping is performed.

I am encountering some significant issues with using this because of
one detail.  In particular, parsing output using NUL as *both* the
entry terminator and the filename separator for entries that contain
multiple files is problematic. Because of this, one cannot know in
advance how many NULs to read from the buffer until considering an
entry to be in memory for parsing.

There are two workarounds I've considered:

 1. Reading the *entire* buffer into memory, and then using a regular
expression (yikes) to split the entries. This is something I would
obviously like to avoid for performance reasons.

 2. Read from buffer until the first NUL, parse the entry status
codes, and if the entry status code represents a status that *should*
have multiple filenames, read from buffer until a second NUL is found,
and then reparse that entry with both filenames. The issues I see with
this approach:
   a.) One has to know exactly which status code combinations will end
up with two filenames, and this list has to be exhaustive. As far as I
can tell, there is no canonical documentation for this?
   b.) It seems a bit brittle, because if the logic from the above is
wrong and we miss an extended entry or ask for one when it doesn't
exist we will leave the buffer an essentially corrupt state for future
reads.

My understanding is the goal of `-z` is to make machine parsing status
from a binary stream *more* reliable, so perhaps (likely!) I am
missing something obvious?

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


[PATCH v2 06/10] bulk-checkin.c: convert to use struct object_id

2015-03-07 Thread brian m. carlson
Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 bulk-checkin.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bulk-checkin.c b/bulk-checkin.c
index 0c4b8a7..e50f60e 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -24,7 +24,7 @@ static struct bulk_checkin_state {
 
 static void finish_bulk_checkin(struct bulk_checkin_state *state)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct strbuf packname = STRBUF_INIT;
int i;
 
@@ -36,11 +36,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state 
*state)
unlink(state-pack_tmp_name);
goto clear_exit;
} else if (state-nr_written == 1) {
-   sha1close(state-f, sha1, CSUM_FSYNC);
+   sha1close(state-f, oid.sha1, CSUM_FSYNC);
} else {
-   int fd = sha1close(state-f, sha1, 0);
-   fixup_pack_header_footer(fd, sha1, state-pack_tmp_name,
-state-nr_written, sha1,
+   int fd = sha1close(state-f, oid.sha1, 0);
+   fixup_pack_header_footer(fd, oid.sha1, state-pack_tmp_name,
+state-nr_written, oid.sha1,
 state-offset);
close(fd);
}
@@ -48,7 +48,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state 
*state)
strbuf_addf(packname, %s/pack/pack-, get_object_directory());
finish_tmp_packfile(packname, state-pack_tmp_name,
state-written, state-nr_written,
-   state-pack_idx_opts, sha1);
+   state-pack_idx_opts, oid.sha1);
for (i = 0; i  state-nr_written; i++)
free(state-written[i]);
 
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 03/10] bisect.c: convert leaf functions to use struct object_id

2015-03-07 Thread brian m. carlson
Convert some constants to GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 bisect.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/bisect.c b/bisect.c
index 8c6d843..2692d54 100644
--- a/bisect.c
+++ b/bisect.c
@@ -15,7 +15,7 @@
 static struct sha1_array good_revs;
 static struct sha1_array skipped_revs;
 
-static unsigned char *current_bad_sha1;
+static struct object_id *current_bad_oid;
 
 static const char *argv_checkout[] = {checkout, -q, NULL, --, NULL};
 static const char *argv_show_branch[] = {show-branch, NULL, NULL};
@@ -404,8 +404,8 @@ static int register_ref(const char *refname, const unsigned 
char *sha1,
int flags, void *cb_data)
 {
if (!strcmp(refname, bad)) {
-   current_bad_sha1 = xmalloc(20);
-   hashcpy(current_bad_sha1, sha1);
+   current_bad_oid = xmalloc(sizeof(*current_bad_oid));
+   hashcpy(current_bad_oid-sha1, sha1);
} else if (starts_with(refname, good-)) {
sha1_array_append(good_revs, sha1);
} else if (starts_with(refname, skip-)) {
@@ -564,7 +564,7 @@ static struct commit_list *skip_away(struct commit_list 
*list, int count)
 
for (i = 0; cur; cur = cur-next, i++) {
if (i == index) {
-   if (hashcmp(cur-item-object.sha1, current_bad_sha1))
+   if (hashcmp(cur-item-object.sha1, 
current_bad_oid-sha1))
return cur;
if (previous)
return previous;
@@ -607,7 +607,7 @@ static void bisect_rev_setup(struct rev_info *revs, const 
char *prefix,
 
/* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(rev_argv, bisect_rev_setup);
-   argv_array_pushf(rev_argv, bad_format, sha1_to_hex(current_bad_sha1));
+   argv_array_pushf(rev_argv, bad_format, 
sha1_to_hex(current_bad_oid-sha1));
for (i = 0; i  good_revs.nr; i++)
argv_array_pushf(rev_argv, good_format,
 sha1_to_hex(good_revs.sha1[i]));
@@ -628,7 +628,7 @@ static void bisect_common(struct rev_info *revs)
 }
 
 static void exit_if_skipped_commits(struct commit_list *tried,
-   const unsigned char *bad)
+   const struct object_id *bad)
 {
if (!tried)
return;
@@ -637,12 +637,12 @@ static void exit_if_skipped_commits(struct commit_list 
*tried,
   The first bad commit could be any of:\n);
print_commit_list(tried, %s\n, %s\n);
if (bad)
-   printf(%s\n, sha1_to_hex(bad));
+   printf(%s\n, oid_to_hex(bad));
printf(We cannot bisect more!\n);
exit(2);
 }
 
-static int is_expected_rev(const unsigned char *sha1)
+static int is_expected_rev(const struct object_id *oid)
 {
const char *filename = git_path(BISECT_EXPECTED_REV);
struct stat st;
@@ -658,7 +658,7 @@ static int is_expected_rev(const unsigned char *sha1)
return 0;
 
if (strbuf_getline(str, fp, '\n') != EOF)
-   res = !strcmp(str.buf, sha1_to_hex(sha1));
+   res = !strcmp(str.buf, oid_to_hex(oid));
 
strbuf_release(str);
fclose(fp);
@@ -719,7 +719,7 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
struct commit **rev = xmalloc(len * sizeof(*rev));
int i, n = 0;
 
-   rev[n++] = get_commit_reference(current_bad_sha1);
+   rev[n++] = get_commit_reference(current_bad_oid-sha1);
for (i = 0; i  good_revs.nr; i++)
rev[n++] = get_commit_reference(good_revs.sha1[i]);
*rev_nr = n;
@@ -729,8 +729,8 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
 
 static void handle_bad_merge_base(void)
 {
-   if (is_expected_rev(current_bad_sha1)) {
-   char *bad_hex = sha1_to_hex(current_bad_sha1);
+   if (is_expected_rev(current_bad_oid)) {
+   char *bad_hex = oid_to_hex(current_bad_oid);
char *good_hex = join_sha1_array_hex(good_revs, ' ');
 
fprintf(stderr, The merge base %s is bad.\n
@@ -750,7 +750,7 @@ static void handle_bad_merge_base(void)
 static void handle_skipped_merge_base(const unsigned char *mb)
 {
char *mb_hex = sha1_to_hex(mb);
-   char *bad_hex = sha1_to_hex(current_bad_sha1);
+   char *bad_hex = sha1_to_hex(current_bad_oid-sha1);
char *good_hex = join_sha1_array_hex(good_revs, ' ');
 
warning(the merge base between %s and [%s] 
@@ -781,7 +781,7 @@ static void check_merge_bases(int no_checkout)
 
for (; result; result = result-next) {
const unsigned char *mb = result-item-object.sha1;
-   if (!hashcmp(mb, current_bad_sha1)) {
+   if (!hashcmp(mb, current_bad_oid-sha1)) {
   

[PATCH v2 07/10] diff: convert struct combine_diff_path to object_id

2015-03-07 Thread brian m. carlson
Also, convert a constant to GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 combine-diff.c | 56 
 diff-lib.c | 10 +-
 diff.h |  5 +++--
 tree-diff.c| 10 +-
 4 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/combine-diff.c b/combine-diff.c
index 91edce5..ec25202 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -44,9 +44,9 @@ static struct combine_diff_path *intersect_paths(struct 
combine_diff_path *curr,
memset(p-parent, 0,
   sizeof(p-parent[0]) * num_parent);
 
-   hashcpy(p-sha1, q-queue[i]-two-sha1);
+   hashcpy(p-oid.sha1, q-queue[i]-two-sha1);
p-mode = q-queue[i]-two-mode;
-   hashcpy(p-parent[n].sha1, q-queue[i]-one-sha1);
+   hashcpy(p-parent[n].oid.sha1, q-queue[i]-one-sha1);
p-parent[n].mode = q-queue[i]-one-mode;
p-parent[n].status = q-queue[i]-status;
*tail = p;
@@ -77,7 +77,7 @@ static struct combine_diff_path *intersect_paths(struct 
combine_diff_path *curr,
continue;
}
 
-   hashcpy(p-parent[n].sha1, q-queue[i]-one-sha1);
+   hashcpy(p-parent[n].oid.sha1, q-queue[i]-one-sha1);
p-parent[n].mode = q-queue[i]-one-mode;
p-parent[n].status = q-queue[i]-status;
 
@@ -284,7 +284,7 @@ static struct lline *coalesce_lines(struct lline *base, int 
*lenbase,
return base;
 }
 
-static char *grab_blob(const unsigned char *sha1, unsigned int mode,
+static char *grab_blob(const struct object_id *oid, unsigned int mode,
   unsigned long *size, struct userdiff_driver *textconv,
   const char *path)
 {
@@ -294,20 +294,20 @@ static char *grab_blob(const unsigned char *sha1, 
unsigned int mode,
if (S_ISGITLINK(mode)) {
blob = xmalloc(100);
*size = snprintf(blob, 100,
-Subproject commit %s\n, sha1_to_hex(sha1));
-   } else if (is_null_sha1(sha1)) {
+Subproject commit %s\n, oid_to_hex(oid));
+   } else if (is_null_oid(oid)) {
/* deleted blob */
*size = 0;
return xcalloc(1, 1);
} else if (textconv) {
struct diff_filespec *df = alloc_filespec(path);
-   fill_filespec(df, sha1, 1, mode);
+   fill_filespec(df, oid-sha1, 1, mode);
*size = fill_textconv(textconv, df, blob);
free_filespec(df);
} else {
-   blob = read_sha1_file(sha1, type, size);
+   blob = read_sha1_file(oid-sha1, type, size);
if (type != OBJ_BLOB)
-   die(object '%s' is not a blob!, sha1_to_hex(sha1));
+   die(object '%s' is not a blob!, oid_to_hex(oid));
}
return blob;
 }
@@ -389,7 +389,7 @@ static void consume_line(void *state_, char *line, unsigned 
long len)
}
 }
 
-static void combine_diff(const unsigned char *parent, unsigned int mode,
+static void combine_diff(const struct object_id *parent, unsigned int mode,
 mmfile_t *result_file,
 struct sline *sline, unsigned int cnt, int n,
 int num_parent, int result_deleted,
@@ -897,7 +897,7 @@ static void show_combined_header(struct combine_diff_path 
*elem,
 int show_file_header)
 {
struct diff_options *opt = rev-diffopt;
-   int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
+   int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? GIT_SHA1_HEXSZ : 
DEFAULT_ABBREV;
const char *a_prefix = opt-a_prefix ? opt-a_prefix : a/;
const char *b_prefix = opt-b_prefix ? opt-b_prefix : b/;
const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
@@ -914,11 +914,11 @@ static void show_combined_header(struct combine_diff_path 
*elem,
 , elem-path, line_prefix, c_meta, c_reset);
printf(%s%sindex , line_prefix, c_meta);
for (i = 0; i  num_parent; i++) {
-   abb = find_unique_abbrev(elem-parent[i].sha1,
+   abb = find_unique_abbrev(elem-parent[i].oid.sha1,
 abbrev);
printf(%s%s, i ? , : , abb);
}
-   abb = find_unique_abbrev(elem-sha1, abbrev);
+   abb = find_unique_abbrev(elem-oid.sha1, abbrev);
printf(..%s%s\n, abb, c_reset);
 
if (mode_differs) {
@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, 
int num_parent,
 
/* Read the result of merge first */
if (!working_tree_file)
-   result = grab_blob(elem-sha1, 

[PATCH v2 09/10] patch-id: convert to use struct object_id

2015-03-07 Thread brian m. carlson
Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 builtin/patch-id.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 77db873..c208e7e 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,14 +1,14 @@
 #include builtin.h
 
-static void flush_current_id(int patchlen, unsigned char *id, unsigned char 
*result)
+static void flush_current_id(int patchlen, struct object_id *id, struct 
object_id *result)
 {
char name[50];
 
if (!patchlen)
return;
 
-   memcpy(name, sha1_to_hex(id), 41);
-   printf(%s %s\n, sha1_to_hex(result), name);
+   memcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);
+   printf(%s %s\n, oid_to_hex(result), name);
 }
 
 static int remove_space(char *line)
@@ -53,23 +53,23 @@ static int scan_hunk_header(const char *p, int *p_before, 
int *p_after)
return 1;
 }
 
-static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)
+static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
 {
-   unsigned char hash[20];
+   unsigned char hash[GIT_SHA1_RAWSZ];
unsigned short carry = 0;
int i;
 
git_SHA1_Final(hash, ctx);
git_SHA1_Init(ctx);
/* 20-byte sum, with carry */
-   for (i = 0; i  20; ++i) {
-   carry += result[i] + hash[i];
-   result[i] = carry;
+   for (i = 0; i  GIT_SHA1_RAWSZ; ++i) {
+   carry += result-sha1[i] + hash[i];
+   result-sha1[i] = carry;
carry = 8;
}
 }
 
-static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
+static int get_one_patchid(struct object_id *next_oid, struct object_id 
*result,
   struct strbuf *line_buf, int stable)
 {
int patchlen = 0, found_next = 0;
@@ -77,7 +77,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned 
char *result,
git_SHA_CTX ctx;
 
git_SHA1_Init(ctx);
-   hashclr(result);
+   oidclr(result);
 
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf-buf;
@@ -93,7 +93,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned 
char *result,
else if (!memcmp(line, \\ , 2)  12  strlen(line))
continue;
 
-   if (!get_sha1_hex(p, next_sha1)) {
+   if (!get_oid_hex(p, next_oid)) {
found_next = 1;
break;
}
@@ -143,7 +143,7 @@ static int get_one_patchid(unsigned char *next_sha1, 
unsigned char *result,
}
 
if (!found_next)
-   hashclr(next_sha1);
+   oidclr(next_oid);
 
flush_one_hunk(result, ctx);
 
@@ -152,15 +152,15 @@ static int get_one_patchid(unsigned char *next_sha1, 
unsigned char *result,
 
 static void generate_id_list(int stable)
 {
-   unsigned char sha1[20], n[20], result[20];
+   struct object_id oid, n, result;
int patchlen;
struct strbuf line_buf = STRBUF_INIT;
 
-   hashclr(sha1);
+   oidclr(oid);
while (!feof(stdin)) {
-   patchlen = get_one_patchid(n, result, line_buf, stable);
-   flush_current_id(patchlen, sha1, result);
-   hashcpy(sha1, n);
+   patchlen = get_one_patchid(n, result, line_buf, stable);
+   flush_current_id(patchlen, oid, result);
+   oidcpy(oid, n);
}
strbuf_release(line_buf);
 }
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 05/10] zip: use GIT_SHA1_HEXSZ for trailers

2015-03-07 Thread brian m. carlson
Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 archive-zip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/archive-zip.c b/archive-zip.c
index 4bde019..b669e50 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -427,12 +427,12 @@ static void write_zip_trailer(const unsigned char *sha1)
copy_le16(trailer.entries, zip_dir_entries);
copy_le32(trailer.size, zip_dir_offset);
copy_le32(trailer.offset, zip_offset);
-   copy_le16(trailer.comment_length, sha1 ? 40 : 0);
+   copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);
 
write_or_die(1, zip_dir, zip_dir_offset);
write_or_die(1, trailer, ZIP_DIR_TRAILER_SIZE);
if (sha1)
-   write_or_die(1, sha1_to_hex(sha1), 40);
+   write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
 }
 
 static void dos_time(time_t *time, int *dos_date, int *dos_time)
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 10/10] apply: convert threeway_stage to object_id

2015-03-07 Thread brian m. carlson
Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 builtin/apply.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 65b97ee..75c5342 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -208,7 +208,7 @@ struct patch {
struct patch *next;
 
/* three-way fallback result */
-   unsigned char threeway_stage[3][20];
+   struct object_id threeway_stage[3];
 };
 
 static void free_fragment_list(struct fragment *list)
@@ -3424,11 +3424,11 @@ static int try_threeway(struct image *image, struct 
patch *patch,
if (status) {
patch-conflicted_threeway = 1;
if (patch-is_new)
-   hashclr(patch-threeway_stage[0]);
+   hashclr(patch-threeway_stage[0].sha1);
else
-   hashcpy(patch-threeway_stage[0], pre_sha1);
-   hashcpy(patch-threeway_stage[1], our_sha1);
-   hashcpy(patch-threeway_stage[2], post_sha1);
+   hashcpy(patch-threeway_stage[0].sha1, pre_sha1);
+   hashcpy(patch-threeway_stage[1].sha1, our_sha1);
+   hashcpy(patch-threeway_stage[2].sha1, post_sha1);
fprintf(stderr, Applied patch to '%s' with conflicts.\n, 
patch-new_name);
} else {
fprintf(stderr, Applied patch to '%s' cleanly.\n, 
patch-new_name);
@@ -4184,14 +4184,14 @@ static void add_conflicted_stages_file(struct patch 
*patch)
 
remove_file_from_cache(patch-new_name);
for (stage = 1; stage  4; stage++) {
-   if (is_null_sha1(patch-threeway_stage[stage - 1]))
+   if (is_null_oid(patch-threeway_stage[stage - 1]))
continue;
ce = xcalloc(1, ce_size);
memcpy(ce-name, patch-new_name, namelen);
ce-ce_mode = create_ce_mode(mode);
ce-ce_flags = create_ce_flags(stage);
ce-ce_namelen = namelen;
-   hashcpy(ce-sha1, patch-threeway_stage[stage - 1]);
+   hashcpy(ce-sha1, patch-threeway_stage[stage - 1].sha1);
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD)  0)
die(_(unable to add cache entry for %s), 
patch-new_name);
}
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 08/10] commit: convert parts to struct object_id

2015-03-07 Thread brian m. carlson
Convert struct commit_graft and necessary local parts of commit.c.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 commit.c  | 32 
 commit.h  |  4 ++--
 log-tree.c|  2 +-
 send-pack.c   |  2 +-
 shallow.c |  8 
 upload-pack.c |  2 +-
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/commit.c b/commit.c
index a8c7577..89c207e 100644
--- a/commit.c
+++ b/commit.c
@@ -55,12 +55,12 @@ struct commit *lookup_commit(const unsigned char *sha1)
 
 struct commit *lookup_commit_reference_by_name(const char *name)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct commit *commit;
 
-   if (get_sha1_committish(name, sha1))
+   if (get_sha1_committish(name, oid.sha1))
return NULL;
-   commit = lookup_commit_reference(sha1);
+   commit = lookup_commit_reference(oid.sha1);
if (parse_commit(commit))
return NULL;
return commit;
@@ -99,7 +99,7 @@ static int commit_graft_alloc, commit_graft_nr;
 static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 {
struct commit_graft **commit_graft_table = table;
-   return commit_graft_table[index]-sha1;
+   return commit_graft_table[index]-oid.sha1;
 }
 
 static int commit_graft_pos(const unsigned char *sha1)
@@ -110,7 +110,7 @@ static int commit_graft_pos(const unsigned char *sha1)
 
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
 {
-   int pos = commit_graft_pos(graft-sha1);
+   int pos = commit_graft_pos(graft-oid.sha1);
 
if (0 = pos) {
if (ignore_dups)
@@ -148,12 +148,12 @@ struct commit_graft *read_graft_line(char *buf, int len)
i = (len + 1) / 41 - 1;
graft = xmalloc(sizeof(*graft) + 20 * i);
graft-nr_parent = i;
-   if (get_sha1_hex(buf, graft-sha1))
+   if (get_oid_hex(buf, graft-oid))
goto bad_graft_data;
for (i = 40; i  len; i += 41) {
if (buf[i] != ' ')
goto bad_graft_data;
-   if (get_sha1_hex(buf + i + 1, graft-parent[i/41]))
+   if (get_sha1_hex(buf + i + 1, graft-parent[i/41].sha1))
goto bad_graft_data;
}
return graft;
@@ -302,7 +302,7 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
 {
const char *tail = buffer;
const char *bufptr = buffer;
-   unsigned char parent[20];
+   struct object_id parent;
struct commit_list **pptr;
struct commit_graft *graft;
 
@@ -312,10 +312,10 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
tail += size;
if (tail = bufptr + 46 || memcmp(bufptr, tree , 5) || bufptr[45] != 
'\n')
return error(bogus commit object %s, 
sha1_to_hex(item-object.sha1));
-   if (get_sha1_hex(bufptr + 5, parent)  0)
+   if (get_sha1_hex(bufptr + 5, parent.sha1)  0)
return error(bad tree pointer in commit %s,
 sha1_to_hex(item-object.sha1));
-   item-tree = lookup_tree(parent);
+   item-tree = lookup_tree(parent.sha1);
bufptr += 46; /* tree  + hex sha1 + \n */
pptr = item-parents;
 
@@ -324,7 +324,7 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
struct commit *new_parent;
 
if (tail = bufptr + 48 ||
-   get_sha1_hex(bufptr + 7, parent) ||
+   get_sha1_hex(bufptr + 7, parent.sha1) ||
bufptr[47] != '\n')
return error(bad parents in commit %s, 
sha1_to_hex(item-object.sha1));
bufptr += 48;
@@ -334,7 +334,7 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
 */
if (graft  (graft-nr_parent  0 || grafts_replace_parents))
continue;
-   new_parent = lookup_commit(parent);
+   new_parent = lookup_commit(parent.sha1);
if (new_parent)
pptr = commit_list_insert(new_parent, pptr)-next;
}
@@ -342,7 +342,7 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
int i;
struct commit *new_parent;
for (i = 0; i  graft-nr_parent; i++) {
-   new_parent = lookup_commit(graft-parent[i]);
+   new_parent = lookup_commit(graft-parent[i].sha1);
if (!new_parent)
continue;
pptr = commit_list_insert(new_parent, pptr)-next;
@@ -1580,10 +1580,10 @@ struct commit *get_merge_parent(const char *name)
 {
struct object *obj;
struct commit *commit;
-   unsigned char sha1[20];
-   if (get_sha1(name, sha1))
+   

[PATCH v2 04/10] archive.c: convert to use struct object_id

2015-03-07 Thread brian m. carlson
Convert a hard-coded 20 as well.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 archive.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/archive.c b/archive.c
index 96057ed..46d9025 100644
--- a/archive.c
+++ b/archive.c
@@ -101,7 +101,7 @@ static void setup_archive_check(struct git_attr_check 
*check)
 
 struct directory {
struct directory *up;
-   unsigned char sha1[20];
+   unsigned char sha1[GIT_SHA1_RAWSZ];
int baselen, len;
unsigned mode;
int stage;
@@ -354,7 +354,7 @@ static void parse_treeish_arg(const char **argv,
time_t archive_time;
struct tree *tree;
const struct commit *commit;
-   unsigned char sha1[20];
+   struct object_id oid;
 
/* Remotes are only allowed to fetch actual refs */
if (remote  !remote_allow_unreachable) {
@@ -362,15 +362,15 @@ static void parse_treeish_arg(const char **argv,
const char *colon = strchrnul(name, ':');
int refnamelen = colon - name;
 
-   if (!dwim_ref(name, refnamelen, sha1, ref))
+   if (!dwim_ref(name, refnamelen, oid.sha1, ref))
die(no such ref: %.*s, refnamelen, name);
free(ref);
}
 
-   if (get_sha1(name, sha1))
+   if (get_sha1(name, oid.sha1))
die(Not a valid object name);
 
-   commit = lookup_commit_reference_gently(sha1, 1);
+   commit = lookup_commit_reference_gently(oid.sha1, 1);
if (commit) {
commit_sha1 = commit-object.sha1;
archive_time = commit-date;
@@ -379,21 +379,21 @@ static void parse_treeish_arg(const char **argv,
archive_time = time(NULL);
}
 
-   tree = parse_tree_indirect(sha1);
+   tree = parse_tree_indirect(oid.sha1);
if (tree == NULL)
die(not a tree object);
 
if (prefix) {
-   unsigned char tree_sha1[20];
+   struct object_id tree_oid;
unsigned int mode;
int err;
 
err = get_tree_entry(tree-object.sha1, prefix,
-tree_sha1, mode);
+tree_oid.sha1, mode);
if (err || !S_ISDIR(mode))
die(current working directory is untracked);
 
-   tree = parse_tree_indirect(tree_sha1);
+   tree = parse_tree_indirect(tree_oid.sha1);
}
ar_args-tree = tree;
ar_args-commit_sha1 = commit_sha1;
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 02/10] Define utility functions for object IDs.

2015-03-07 Thread brian m. carlson
There are several utility functions (hashcmp and friends) that are used
for comparing object IDs (SHA-1 values).  Using these functions, which
take pointers to unsigned char, with struct object_id requires tiresome
access to the sha1 member, which bloats code and violates the desired
encapsulation.  Provide wrappers around these functions for struct
object_id for neater, more maintainable code.  Use the new constants to
avoid the hard-coded 20s and 40s throughout the original functions.

These functions simply call the underlying pointer-to-unsigned-char
versions to ensure that any performance improvements will be passed
through to the new functions.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
I'm not very excited about having to put the #include in the middle of
cache.h.  The alternative, of course, is to move enum object_type up,
which I can do if necessary.  Another alternative is to simply move the
struct object_id definitions to cache.h instead of object.h, which might
be cleaner.

I'm interested in hearing opinions about the best way to go forward.

 cache.h | 37 +
 hex.c   | 16 +---
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/cache.h b/cache.h
index 761c570..f9addcc 100644
--- a/cache.h
+++ b/cache.h
@@ -368,6 +368,11 @@ static inline enum object_type object_type(unsigned int 
mode)
OBJ_BLOB;
 }
 
+/* This must go before the oid* functions, but after the declaration of enum
+ * object_type.
+ */
+#include object.h
+
 /* Double-check local_repo_env below if you add to this list. */
 #define GIT_DIR_ENVIRONMENT GIT_DIR
 #define GIT_NAMESPACE_ENVIRONMENT GIT_NAMESPACE
@@ -710,13 +715,13 @@ extern char *sha1_pack_name(const unsigned char *sha1);
 extern char *sha1_pack_index_name(const unsigned char *sha1);
 
 extern const char *find_unique_abbrev(const unsigned char *sha1, int);
-extern const unsigned char null_sha1[20];
+extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
int i;
 
-   for (i = 0; i  20; i++, sha1++, sha2++) {
+   for (i = 0; i  GIT_SHA1_RAWSZ; i++, sha1++, sha2++) {
if (*sha1 != *sha2)
return *sha1 - *sha2;
}
@@ -724,20 +729,42 @@ static inline int hashcmp(const unsigned char *sha1, 
const unsigned char *sha2)
return 0;
 }
 
+static inline int oidcmp(const struct object_id *o1, const struct object_id 
*o2)
+{
+   return hashcmp(o1-sha1, o2-sha1);
+}
+
 static inline int is_null_sha1(const unsigned char *sha1)
 {
return !hashcmp(sha1, null_sha1);
 }
 
+static inline int is_null_oid(const struct object_id *oid)
+{
+   return !hashcmp(oid-sha1, null_sha1);
+}
+
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char 
*sha_src)
 {
-   memcpy(sha_dst, sha_src, 20);
+   memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
 }
+
+static inline void oidcpy(struct object_id *dst, const struct object_id *src)
+{
+   hashcpy(dst-sha1, src-sha1);
+}
+
 static inline void hashclr(unsigned char *hash)
 {
-   memset(hash, 0, 20);
+   memset(hash, 0, GIT_SHA1_RAWSZ);
 }
 
+static inline void oidclr(struct object_id *oid)
+{
+   hashclr(oid-sha1);
+}
+
+
 #define EMPTY_TREE_SHA1_HEX \
4b825dc642cb6eb9a060e54bf8d69288fbee4904
 #define EMPTY_TREE_SHA1_BIN_LITERAL \
@@ -944,8 +971,10 @@ extern int for_each_abbrev(const char *prefix, 
each_abbrev_fn, void *);
  * null-terminated string.
  */
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
+extern int get_oid_hex(const char *hex, struct object_id *sha1);
 
 extern char *sha1_to_hex(const unsigned char *sha1);   /* static buffer 
result! */
+extern char *oid_to_hex(const struct object_id *oid);  /* same static buffer 
as sha1_to_hex */
 extern int read_ref_full(const char *refname, int resolve_flags,
 unsigned char *sha1, int *flags);
 extern int read_ref(const char *refname, unsigned char *sha1);
diff --git a/hex.c b/hex.c
index cfd9d72..7e25a88 100644
--- a/hex.c
+++ b/hex.c
@@ -38,7 +38,7 @@ const signed char hexval_table[256] = {
 int get_sha1_hex(const char *hex, unsigned char *sha1)
 {
int i;
-   for (i = 0; i  20; i++) {
+   for (i = 0; i  GIT_SHA1_RAWSZ; i++) {
unsigned int val;
/*
 * hex[1]=='\0' is caught when val is checked below,
@@ -56,15 +56,20 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
return 0;
 }
 
+int get_oid_hex(const char *hex, struct object_id *oid)
+{
+   return get_sha1_hex(hex, oid-sha1);
+}
+
 char *sha1_to_hex(const unsigned char *sha1)
 {
static int bufno;
-   static char hexbuffer[4][41];
+   static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
static const char hex[] = 0123456789abcdef;
char *buffer = hexbuffer[3  ++bufno], *buf = buffer;
int i;
 
- 

[PATCH v2 01/10] Define a structure for object IDs.

2015-03-07 Thread brian m. carlson
Many places throughout the code use unsigned char [20] to store object IDs
(SHA-1 values).  This leads to lots of hardcoded numbers throughout the
codebase.  It also leads to confusion about the purposes of a buffer.

Introduce a structure for object IDs.  This allows us to obtain the benefits
of compile-time checking for misuse.  The structure is expected to remain
the same size and have the same alignment requirements on all known
platforms, compared to the array of unsigned char, although this is not
required for correctness.

Signed-off-by: brian m. carlson sand...@crustytoothpaste.net
---
 object.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/object.h b/object.h
index 6416247..f99b502 100644
--- a/object.h
+++ b/object.h
@@ -1,6 +1,14 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ 40
+
+struct object_id {
+   unsigned char sha1[GIT_SHA1_RAWSZ];
+};
+
 struct object_list {
struct object *item;
struct object_list *next;
-- 
2.2.1.209.g41e5f3a

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


[PATCH v2 00/10] Use a structure for object IDs.

2015-03-07 Thread brian m. carlson
This is a patch series to convert some of the relevant uses of unsigned
char [20] to struct object_id.

The goal of this series to improve type-checking in the codebase and to
make it easier to move to a different hash function if the project
decides to do that.  This series does not convert all of the codebase,
but only parts.  I've dropped some of the patches from earlier (which no
longer apply) and added others.

Certain parts of the code have to be converted before others to keep the
patch sizes small, maintainable, and bisectable, so functions and
structures that are used across the codebase (e.g. struct object) will
be converted later.  Conversion has been done in a somewhat haphazard
manner by converting modules with leaf functions and less commonly used
structs first.

Since part of the goal is to ease a move to a different hash function if
the project decides to do that, I've adopted Michael Haggerty's
suggestion of using variables named oid, naming the structure member
sha1, and using GIT_SHA1_RAWSZ and GIT_SHA1_HEXSZ as the constants.

I've been holding on to this series for a long time in hopes of
converting more of the code before submitting, but realized that this
deprived others of the ability to use the new structure and required me
to rebase extremely frequently.

brian m. carlson (10):
  Define a structure for object IDs.
  Define utility functions for object IDs.
  bisect.c: convert leaf functions to use struct object_id
  archive.c: convert to use struct object_id
  zip: use GIT_SHA1_HEXSZ for trailers
  bulk-checkin.c: convert to use struct object_id
  diff: convert struct combine_diff_path to object_id
  commit: convert parts to struct object_id
  patch-id: convert to use struct object_id
  apply: convert threeway_stage to object_id

 archive-zip.c  |  4 ++--
 archive.c  | 18 +-
 bisect.c   | 40 +++---
 builtin/apply.c| 14 +++---
 builtin/patch-id.c | 34 -
 bulk-checkin.c | 12 ++--
 cache.h| 37 
 combine-diff.c | 56 +++---
 commit.c   | 32 +++
 commit.h   |  4 ++--
 diff-lib.c | 10 +-
 diff.h |  5 +++--
 hex.c  | 16 +---
 log-tree.c |  2 +-
 object.h   |  8 
 send-pack.c|  2 +-
 shallow.c  |  8 
 tree-diff.c| 10 +-
 upload-pack.c  |  2 +-
 19 files changed, 181 insertions(+), 133 deletions(-)

-- 
2.2.1.209.g41e5f3a

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


Re: Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread Diego Viola
Sorry, I wanted to say: I know I can git-clone in a empty directory
and then move the files over to $HOME.

I know I can git init in a non-empty directory. :-)

Thanks,

Diego

On Sat, Mar 7, 2015 at 7:26 PM, Andreas Schwab sch...@linux-m68k.org wrote:
 Diego Viola diego.vi...@gmail.com writes:

 I know I could git-init in a empty directory

 You can also git init a non-empty directory.

 Andreas.

 --
 Andreas Schwab, sch...@linux-m68k.org
 GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 And now for something completely different.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] reset: allow - short hand for previous commit

2015-03-07 Thread Sudhanshu Shekhar
Teach reset the same shorthand as checkout and merge. - means the
previous commit.

Signed-off-by: Sudhanshu Shekhar sudshekha...@gmail.com
---
 builtin/reset.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 4c08ddc..9f8967d 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -192,6 +192,7 @@ static void parse_args(struct pathspec *pathspec,
 {
const char *rev = HEAD;
unsigned char unused[20];
+   int substituted_minus = 0;
/*
 * Possible arguments are:
 *
@@ -205,6 +206,10 @@ static void parse_args(struct pathspec *pathspec,
 */
 
if (argv[0]) {
+   if(!strcmp(argv[0], -)) {
+   argv[0] = @{-1};
+   substituted_minus = 1;
+   }
if (!strcmp(argv[0], --)) {
argv++; /* reset to HEAD, possibly with paths */
} else if (argv[1]  !strcmp(argv[1], --)) {
@@ -225,12 +230,14 @@ static void parse_args(struct pathspec *pathspec,
verify_non_filename(prefix, argv[0]);
rev = *argv++;
} else {
+   /* We were treating - as a commit and not a file */
+   if(substituted_minus)
+   argv[0] = -;
/* Otherwise we treat this as a filename */
verify_filename(prefix, argv[0], 1);
}
}
*rev_ret = rev;
-
if (read_cache()  0)
die(_(index file corrupt));
 
-- 
2.3.1.168.g0c82976.dirty


From 21f0298c17768aaa11ff0a677cdefc8f54ac9515 Mon Sep 17 00:00:00 2001
From: Sudhanshu Shekhar sudshekha...@gmail.com
Date: Sun, 8 Mar 2015 02:13:57 +0530
Subject: [PATCH 2/2] Added test cases for reset -

Four test cases have been added

1) when user does reset - without any previous branch = Leads to error
2) when user does reset - with a previous branch  = Ensure it
behaves like @{-1}

Other two deal with the situation when we have a file named '-'. We
ignore such a file and - is always treated either as a previous branch
or a bad filename. Users who wish to reset a file named '-' should specify
it as './-'
---
 builtin/reset.c  |  4 ++--
 t/t7102-reset.sh | 62 
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 9f8967d..02f33ef 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -206,7 +206,7 @@ static void parse_args(struct pathspec *pathspec,
 */
 
if (argv[0]) {
-   if(!strcmp(argv[0], -)) {
+   if (!strcmp(argv[0], -)) {
argv[0] = @{-1};
substituted_minus = 1;
}
@@ -231,7 +231,7 @@ static void parse_args(struct pathspec *pathspec,
rev = *argv++;
} else {
/* We were treating - as a commit and not a file */
-   if(substituted_minus)
+   if (substituted_minus)
argv[0] = -;
/* Otherwise we treat this as a filename */
verify_filename(prefix, argv[0], 1);
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 98bcfe2..4b8d7f5 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -568,4 +568,66 @@ test_expect_success 'reset --mixed sets up work tree' '
test_cmp expect actual
 '
 
+cat  expect  EOF
+fatal: bad flag '-' used after filename
+EOF
+
+test_expect_success 'reset - with no previous branch' '
+   git init no_previous --quiet 
+   (
+   cd no_previous
+   ) 
+   test_must_fail git reset - 2 output 
+   test_cmp expect output
+'
+
+test_expect_success 'reset - while having file named - and no previous branch' 
'
+   git init no_previous --quiet 
+   (
+   cd no_previous 
+   touch ./-
+   ) 
+   test_must_fail git reset - 2 output 
+   test_cmp expect output
+'
+
+cat  expect  EOF
+Unstaged changes after reset:
+M  -
+M  1
+EOF
+
+test_expect_success 'reset - in the prescence of file named - with previou 
branch' '
+   git init no_previous --quiet 
+   cd no_previous 
+   touch ./- 1 
+   git add 1 - 
+   git commit -m add base files 
+   git checkout -b new_branch 
+   echo random  ./- 
+   echo wow  1 
+   git add 1 - 
+   git reset -  output 
+   test_cmp output ../expect
+'
+test_expect_success 'reset - works same as reset @{-1}' '
+   git init no_previous --quiet 
+   cd no_previous 
+   echo random  random 
+   git add random 
+   git commit -m base commit 
+   git checkout -b temp 
+   echo new-file  new-file 
+   git add new-file 
+   git commit -m added new-file 
+   git reset - 
+
+   git status  ../first 

Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread Diego Viola
Hello,

I was thinking about creating a new repository in my home dir so that I could
keep my dot files in it.

However, I found that I can't do a `git clone url:user/repo.git .` in a
non-empty directory.

Is there a possibility of implementing a -f switch to git-clone so that when I
use that, git would still clone the repo in the non-empty directory and keep the
untracked files untracked/unstaged? (just as if I copied files to the git repo).

I know I could git-init in a empty directory and then copy the .git dir to the
non-empty directory as a workaround, but I like the idea of cloning better.

My C skills aren't that great or I would have sent a patch already.

Thanks,

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


Re: Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread Andreas Schwab
Diego Viola diego.vi...@gmail.com writes:

 I know I could git-init in a empty directory

You can also git init a non-empty directory.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Delivery Status Notification (Failure)

2015-03-07 Thread Amate Yolande
Hello Junio

  Thanks for the quick review and I apologize for the poorly
constructed code. I am
new to open source and git, and that was my first time coming across
the git source
code so I hoped to submit a working patch first, with the intention of
amending it later since
I did not really understand the requirements. With your clarification
and getting my self
familiar with the git commands, I hope to submit an accurate patch.

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


[PATCH] git-instaweb: allow running in a working tree subdirectory

2015-03-07 Thread Kyle J. McKay
Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 git-instaweb.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/git-instaweb.sh b/git-instaweb.sh
index 513efa66..4c0af04f 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -20,6 +20,7 @@ start  start the web server
 restartrestart the web server
 
 
+SUBDIRECTORY_OK=Yes
 . git-sh-setup
 
 fqgitdir=$GIT_DIR
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] git: treat -C treat as a no-op when path is empty

2015-03-07 Thread karthik nayak


On 03/08/2015 10:08 AM, Eric Sunshine wrote:

On Sat, Mar 7, 2015 at 5:49 AM, karthik nayak karthik@gmail.com wrote:
 This iteration looks sensible, except that the Subject reads
 strange.  Will queue with minor tweaks to the log message,
 and perhaps with a fix to unreadable *(*argv)[1] that was
 mentioned elsewhere.

 Hey could you tell me what seems strange, so I can improve on
 it the next time.

Junio means that you somehow botched the Subject: line when you copied
the commit message I suggested into your new version of the patch.
Instead of path, you wrote treat.


Oops! I'm too anxious i guess.

 Also *(*argv)[1] seems more readable to me, maybe more of a perspective?

I also had considered suggesting (*argv)[1][0] as more readable, but
it is primarily personal taste, and I didn't want to bike-shed the
issue.


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


Re: Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread Diego Viola
Something like this is the scenario I'm talking about:

$ mkdir non-empty-dir
$ cd non-empty-dir
$ touch foo bar baz
$ git clone -f url:user/dotfiles.git .
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use git add file... to include in what will be committed)

bar
baz
foo

nothing added to commit but untracked files present (use git add to track)


On Sat, Mar 7, 2015 at 9:02 PM, Diego Viola diego.vi...@gmail.com wrote:
 Sorry, I wanted to say: I know I can git-clone in a empty directory
 and then move the files over to $HOME.

 I know I can git init in a non-empty directory. :-)

 Thanks,

 Diego

 On Sat, Mar 7, 2015 at 7:26 PM, Andreas Schwab sch...@linux-m68k.org wrote:
 Diego Viola diego.vi...@gmail.com writes:

 I know I could git-init in a empty directory

 You can also git init a non-empty directory.

 Andreas.

 --
 Andreas Schwab, sch...@linux-m68k.org
 GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 And now for something completely different.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Please consider adding a -f switch to git-clone (or something similar)

2015-03-07 Thread Kyle J. McKay

On Mar 7, 2015, at 17:53, Diego Viola wrote:

Something like this is the scenario I'm talking about:

$ mkdir non-empty-dir
$ cd non-empty-dir
$ touch foo bar baz
$ git clone -f url:user/dotfiles.git .
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
 (use git add file... to include in what will be committed)

   bar
   baz
   foo

nothing added to commit but untracked files present (use git add  
to track)


Have you considered using an alias?

git config --global alias.irfc \
  '!sh -c '\''git init  git remote add origin $1  git fetch   
git checkout ${2:-master}'\'' sh'


(You'll likely have to carefully unwrap that line above.)

Then you get

  git irfc URL [branch]

where branch defaults to master.
So your scenario would become just:



$ mkdir non-empty-dir
$ cd non-empty-dir
$ touch foo bar baz
$ git irfc url:user/dotfiles.git
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
 (use git add file... to include in what will be committed)

   bar
   baz
   foo

nothing added to commit but untracked files present (use git add to  
track)



-Kyle

P.S. irfc = init, remote, fetch, checkout.  But do make up a better  
name. :)

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


Re: [PATCH v4] git: treat -C treat as a no-op when path is empty

2015-03-07 Thread Eric Sunshine
On Sat, Mar 7, 2015 at 5:49 AM, karthik nayak karthik@gmail.com wrote:
 This iteration looks sensible, except that the Subject reads
 strange.  Will queue with minor tweaks to the log message,
 and perhaps with a fix to unreadable *(*argv)[1] that was
 mentioned elsewhere.

 Hey could you tell me what seems strange, so I can improve on
 it the next time.

Junio means that you somehow botched the Subject: line when you copied
the commit message I suggested into your new version of the patch.
Instead of path, you wrote treat.

 Also *(*argv)[1] seems more readable to me, maybe more of a perspective?

I also had considered suggesting (*argv)[1][0] as more readable, but
it is primarily personal taste, and I didn't want to bike-shed the
issue.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] help.c: use SHELL_PATH instead of hard-coded /bin/sh

2015-03-07 Thread Kyle J. McKay
If the user has set SHELL_PATH in the Makefile then we
should respect that value and use it.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 builtin/help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/help.c b/builtin/help.c
index 6133fe49..2ae8a1e9 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -171,7 +171,7 @@ static void exec_man_cmd(const char *cmd, const char *page)
 {
struct strbuf shell_cmd = STRBUF_INIT;
strbuf_addf(shell_cmd, %s %s, cmd, page);
-   execl(/bin/sh, sh, -c, shell_cmd.buf, (char *)NULL);
+   execl(SHELL_PATH, SHELL_PATH, -c, shell_cmd.buf, (char *)NULL);
warning(_(failed to exec '%s': %s), cmd, strerror(errno));
 }
 
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] git-compat-util.h: move SHELL_PATH default into header

2015-03-07 Thread Kyle J. McKay
If SHELL_PATH is not defined we use /bin/sh.  However,
run-command.c is not the only file that needs to use
the default value so move it into a common header.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 git-compat-util.h | 4 
 run-command.c | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index a3095be9..fbfd10da 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -876,4 +876,8 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
 #define USE_PARENS_AROUND_GETTEXT_N 1
 #endif
 
+#ifndef SHELL_PATH
+# define SHELL_PATH /bin/sh
+#endif
+
 #endif
diff --git a/run-command.c b/run-command.c
index 0b432cc9..3afb124c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -4,10 +4,6 @@
 #include sigchain.h
 #include argv-array.h
 
-#ifndef SHELL_PATH
-# define SHELL_PATH /bin/sh
-#endif
-
 void child_process_init(struct child_process *child)
 {
memset(child, 0, sizeof(*child));
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] git-instaweb: use @SHELL_PATH@ instead of /bin/sh

2015-03-07 Thread Kyle J. McKay
If the user has configured a value for SHELL_PATH then
be sure to use it for any generated scripts instead of
hard-coding /bin/sh.

The first line of the script is handled specially, but
the embedded #!/bin/sh line in the here document will
not be automatically updated unless it uses @SHELL_PATH@.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 git-instaweb.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-instaweb.sh b/git-instaweb.sh
index 513efa66..7b6ba2bc 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -204,7 +204,7 @@ webrick_conf () {
# actual gitweb.cgi using a shell script to force it
   wrapper=$fqgitdir/gitweb/$httpd/wrapper.sh
cat  $wrapper EOF
-#!/bin/sh
+#!@SHELL_PATH@
 # we use this shell script wrapper around the real gitweb.cgi since
 # there appears to be no other way to pass arbitrary environment variables
 # into the CGI process
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] imap-send: use cURL automatically when NO_OPENSSL defined

2015-03-07 Thread Kyle J. McKay
If both USE_CURL_FOR_IMAP_SEND and NO_OPENSSL are defined do
not force the user to add --curl to get a working git imap-send
command.

Instead automatically select --curl and warn and ignore the
--no-curl option.  And while we're in there, correct the
warning message when --curl is requested but not supported.

Signed-off-by: Kyle J. McKay mack...@gmail.com
---
 Documentation/git-imap-send.txt |  3 ++-
 imap-send.c | 17 +++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt
index 77aacf13..5d1e4c80 100644
--- a/Documentation/git-imap-send.txt
+++ b/Documentation/git-imap-send.txt
@@ -44,7 +44,8 @@ OPTIONS
 
 --no-curl::
Talk to the IMAP server using git's own IMAP routines instead of
-   using libcurl.
+   using libcurl.  Ignored if Git was built with the NO_OPENSSL option
+   set.
 
 
 CONFIGURATION
diff --git a/imap-send.c b/imap-send.c
index d69887da..37ac4aa8 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -34,8 +34,16 @@ typedef void *SSL;
 #include http.h
 #endif
 
+#if defined(USE_CURL_FOR_IMAP_SEND)  defined(NO_OPENSSL)
+/* only available option */
+#define USE_CURL_DEFAULT 1
+#else
+/* strictly opt in */
+#define USE_CURL_DEFAULT 0
+#endif
+
 static int verbosity;
-static int use_curl; /* strictly opt in */
+static int use_curl = USE_CURL_DEFAULT;
 
 static const char * const imap_send_usage[] = { git imap-send [-v] [-q] 
[--[no-]curl]  mbox, NULL };
 
@@ -1504,9 +1512,14 @@ int main(int argc, char **argv)
 
 #ifndef USE_CURL_FOR_IMAP_SEND
if (use_curl) {
-   warning(--use-curl not supported in this build);
+   warning(--curl not supported in this build);
use_curl = 0;
}
+#elif defined(NO_OPENSSL)
+   if (!use_curl) {
+   warning(--no-curl not supported in this build);
+   use_curl = 1;
+   }
 #endif
 
if (!server.port)
---
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html