Git development
 help / color / mirror / Atom feed
* Re: Complete http-pull; where should it go?
From: Linus Torvalds @ 2005-05-01 20:46 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Petr Baudis
In-Reply-To: <Pine.LNX.4.21.0505011544120.30848-100000@iabervon.org>



On Sun, 1 May 2005, Daniel Barkalow wrote:
> 
> Right; what I want to make programs able to do is take explicit
> references, instead of only taking the objects they reference. So you
> say heads/master or heads/linus instead of
> "198b0fb635ed8a007bac0c16eab112c5e2c7995c".

That's fine. 

This is really just an issue of havign a function that does "get_sha1()", 
and then making the things that take command line arguments use that 
one instead of "get_sha1_hex()".

Then you can have rules like:
 - if it's a hex number, take it
 - if it's a filename,  look it up
 - if ".git/refs + str is a filename, look it up.

Something like

	int get_sha1(char *str, unsigned char *result)
	{
		static char pathname[PATH_MAX];

		if (get_sha1_hex(str, result) == 0)
			return 0;
		if (get_sha1_file(str, result) == 0)
			return 0;
		snprintf(pathname, sizeof(pathname), ".git/refs/%s", str);
		if (get_sha1_file(pathname, result) == 0)
			return 0;
		...
	}

where you have

	int get_sha1_file(char *path, unsigned char *result)
	{
		char buffer[60];
		int fd = open(path, O_RDONLY);
		int len;

		if (fd < 0)
			return -1;
		len = read(fd, buffer, sizeof(buffer));
		close(fd);
		if (len < 40)
			return -1;
		return get_sha1_hex(buffer, result);
	}
			
or whatever.

The _only_ thing I want to be careful about is that all the _internal_
stuff still have to use the strict "get_sha1_hex()" function, ie we should
never _ever_ accept a tree object where the "sha1" ends up being anything
but the hex thing. So this "generalized get_sha1()" would have to be used 
only on real user input (ie argv[] array and the like).

		Linus

^ permalink raw reply

* Re: [PATCH] Really fix git-merge-one-file-script this time.
From: Junio C Hamano @ 2005-05-01 21:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505011312080.2296@ppc970.osdl.org>

>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

>> Linus, have you decided to like or dislike the behaviour of
>> git-merge-one-file-script touching the work tree in some cases
>> but not in other cases?

LT> I don't care about the _successful_ merge, since a successful merge is 
LT> basically always followed by a "git-checkout-cache -f -a" anyway (and 
LT> update-cache + remove now-stale files etc).

Let me make sure I understand you correctly before I go
further.  In the above sentence, do you mean a merge that is
_successful_ by merges that:

    (1) "git-remove-tree -m" considers them trivial;

or
    (2) in addition to (1), "git-merge-one-file-script"
        considers them trivial.  That is, only one-side changes
        or removes or adds it, or both sides adds it
        identically, or merge/diff3 merges without conflict.

Which one?

LT> Sounds sane.

LT> On the other hand, I think it would actually be easier to just make your 
LT> "magic SHA1" be just another "stage".

I am undecided on this one but having worked on the diff side, I
think the magic SHA1 of 0{40} would match better with what diff
needs to do.  It would mean "cache is stale, look in the work
tree" to them.


^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Junio C Hamano @ 2005-05-01 21:25 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Daniel Barkalow, git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505011337070.2296@ppc970.osdl.org>

>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

LT> On Sun, 1 May 2005, Daniel Barkalow wrote:
>> 
>> Right; what I want to make programs able to do is take explicit
>> references, instead of only taking the objects they reference. So you
>> say heads/master or heads/linus instead of
>> "198b0fb635ed8a007bac0c16eab112c5e2c7995c".

LT> That's fine. 

LT> This is really just an issue of havign a function that does "get_sha1()", 
LT> and then making the things that take command line arguments use that 
LT> one instead of "get_sha1_hex()".

LT> Then you can have rules like:
LT>  - if it's a hex number, take it
LT>  - if it's a filename,  look it up
LT>  - if ".git/refs + str is a filename, look it up.

LT> The _only_ thing I want to be careful about is that all the _internal_
LT> stuff still have to use the strict "get_sha1_hex()" function, ie we should
LT> never _ever_ accept a tree object where the "sha1" ends up being anything
LT> but the hex thing. So this "generalized get_sha1()" would have to be used 
LT> only on real user input (ie argv[] array and the like).

I agree with Linus.  Dan, you are welcome to lift the code from
the find-in-vicinity() function in jit-util.c in my JIT toolset,
found at http://members.cox.net/junkio/.


^ permalink raw reply

* Re: [PATCH] Really fix git-merge-one-file-script this time.
From: Junio C Hamano @ 2005-05-01 21:32 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505011312080.2296@ppc970.osdl.org>

>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

LT> In particular, I think the "apply the patch forward" (that cogito does) is
LT> as wrong with the "local modifications" as it is for the merge itself, and
LT> that a truly good merge would actually have _another_ three-way merge on
LT> the working file - the "original" is the version in our old HEAD branch,
LT> with the two branches being merged are "working copy before the merge" and
LT> "merge results".

Funny that I realize that is exactly how I've been doing my
merges with you.


^ permalink raw reply

* Re: [PATCH] Really fix git-merge-one-file-script this time.
From: Linus Torvalds @ 2005-05-01 21:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7vsm16sl0q.fsf@assigned-by-dhcp.cox.net>



On Sun, 1 May 2005, Junio C Hamano wrote:
> 
> Let me make sure I understand you correctly before I go
> further.  In the above sentence, do you mean a merge that is
> _successful_ by merges that:
> 
>     (1) "git-remove-tree -m" considers them trivial;
> 
> or
>     (2) in addition to (1), "git-merge-one-file-script"
>         considers them trivial.  That is, only one-side changes
>         or removes or adds it, or both sides adds it
>         identically, or merge/diff3 merges without conflict.

(2).

But in the more general case _any_ automated merge is the "uninteresting" 
case (except for the fact that we hope for them ;)

In other words, I want this case really designed for the situation where 
automation (_any_ kind) breaks down. 

			Linus

^ permalink raw reply

* [PATCH] Make git-prune-script a bit more careful.
From: Junio C Hamano @ 2005-05-01 21:27 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <7vwtqismpn.fsf@assigned-by-dhcp.cox.net>

As discussed on the git list, this patch makes the sample script
git-prune-script a bit more careful by keeping the objects
referenced from the current cache from being reclaimed.

At the same time it also fixes and enhances the following:

 - Optional command line parameters can specify which commit
   heads to start reachablity test from.  Earlier we had a
   hardcoded .git/HEAD.  It now defaults to the contents of
   .git/HEAD and .git/refs/*/* files.

 - It does not assume SHA1_FILE_DIRECTORY is .git/objects/ but
   uses the value from the environment if there is one.

 - It runs xargs with "-r" option to prevent it from making "rm"
   command barf if there is nothing to remove.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

git-prune-script |   32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletion(-)

# - date handling: handle "AM"/"PM" on time
# + [PATCH] Make git-prune-script a bit more careful.
--- k/git-prune-script
+++ l/git-prune-script
@@ -1,2 +1,32 @@
 #!/bin/sh
-git-fsck-cache --unreachable $(cat .git/HEAD ) | grep unreachable | cut -d' ' -f3 | sed 's:^\(..\):.git/objects/\1/:' | xargs rm
+
+tmp=.git-prune-script-$$
+trap 'rm -f $tmp-*' 0 1 2 3 15 
+
+# Defaulting to include .git/refs/*/* may be debatable from the
+# purist POV but power users can always give explicit parameters
+# to the script anyway.
+case "$#" in
+0) set x $(cat .git/HEAD .git/refs/*/*); shift ;;
+esac
+
+git-fsck-cache --unreachable "$@" |
+sed -ne 's/unreachable [^ ][^ ]* //p' |
+sort >$tmp-unreachable
+
+# This makes extra objects to be kept if the cache has an entry
+# with an unusual name like "this\n0 0123...abcdef 0 file", but
+# we are trying not to discard information and keeping extra in
+# an unusual situation would be OK.
+git-ls-files --stage |
+sed -ne 's|^[0-7][0-7]* \([0-9a-f][0-9a-f]*\) [0-3] .*|\1|p' |
+sort >$tmp-keep
+
+comm -23 $tmp-unreachable $tmp-keep |
+sed -e 's|\(..\)|\1/|' | {
+	case "$SHA1_FILE_DIRECTORY" in
+	'') cd .git/objects/ ;;
+	*) cd "$SHA1_FILE_DIRECTORY" ;;
+	esac || exit
+	xargs -r echo rm -f
+}


^ permalink raw reply

* Re: Quick command reference
From: bert hubert @ 2005-05-01 21:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: David Greaves, omb, Paul Mackerras, git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505010927040.2296@ppc970.osdl.org>

On Sun, May 01, 2005 at 09:29:23AM -0700, Linus Torvalds wrote:
> (And no, by "standard format" I do _not_ mean xml or stuff like that. I 
> mean something that is actually easy to read ;)

I've recently been very happy with AsciiDoc
http://www.methods.co.nz/asciidoc/ - it's input is as easy to read as to
write.

>From this input:
http://ds9a.nl/splitpipe/splitpipe-0.3/doc/splitpipe.1.txt

It produces this lovely page (html, man, pdf, the works):
http://ds9a.nl/splitpipe/splitpipe-0.3/doc/splitpipe.1.html

And if you are really in a wild mood, you can have it make entire websites,
like http://ds9a.nl/splitpipe

When used properly it builds tables of contents, indexes, books and whatnot.

-- 
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://netherlabs.nl              Open and Closed source services

^ permalink raw reply

* Re: Todays update (with cogito 0.8)
From: Russell King @ 2005-05-01 21:40 UTC (permalink / raw)
  To: git
In-Reply-To: <20050501092743.B7459@flint.arm.linux.org.uk>

On Sun, May 01, 2005 at 09:27:43AM +0100, Russell King wrote:
> receiving file list ... done
> client: nothing to do: perhaps you need to specify some filenames or the --recursive option?
> unable to get tags list (non-fatal)
> Tree change: a6ad57fb4b5e9d68553f4440377b99f75588fa88:e8e6993178344eb348f60f05b16d9dc30db3b9cf
> *100644->100644	blob	8da3a306d0c0c070d87048d14a033df02f40a154->48990899db0d9a9506e72fe2fa79570c3b5a306b	Makefile
> *100644->100644	blob	c397e71f938d0f79fbcbf29869fbb1d40cf09306->72b03f201eb946f97c9f419090d683ece6ea5bc1	arch/arm/common/rtctime.c
> *100644->100644	blob	68e15c36e33610d6ed0ccec61d7d7a23ebcd4fa3->3b948e8c27513f7896263a87a99123ad5394b860	arch/arm/mach-integrator/integrator_cp.c
> *100644->100644	blob	20729de2af285d62102691ef20942f7caab184af->1a844ca139e0df85e57cee2a67916aa305b1ffcb	arch/arm/mach-integrator/time.c
> *100644->100644	blob	b1575b8dc1cd3e043f78794c56df9d57e6e96afa->a45aaa115a76664bb81438455b06a6ff890886f7	arch/arm/mach-pxa/generic.c
> *100644->100644	blob	314c7146e9bf0a58c9df75c86065b4ad7598b419->04783ceb050c13d7a475a60bdb916b6eb56ffddf	arch/i386/Makefile
> *100644->100644	blob	774de8e2387193be0570a3fba681fd6dd1936816->f850fb0fb5118be47d976291ee028697fbdeb688	arch/ppc/boot/images/Makefile
> *100644->100644	blob	b0e167db6af9c68f49949d409abc747d3119842f->3c2fa5c284c04ef223c468c2df53f6c7676dc20a	arch/ppc64/kernel/signal32.c
> *100644->100644	blob	8e61be34a1d328c5a948a646504ad65629eaef62->ed867db550a9da16a690a9a122b28d33491ac6f8	drivers/char/s3c2410-rtc.c
> *100644->100644	blob	3e386fd4c5c6e627699ccd04117b712030f0f3f4->321dbe91dc14e270450216cf4cc79562d89ca225	drivers/video/amba-clcd.c
> *100644->100644	blob	4d2404305ab687c2a0eee84b3c5842ba9852965a->95483baab706baa9921eb14757c08da90970fdb5	fs/cifs/CHANGES
> *100644->100644	blob	1e8490ed694878b3bbed1e96ab792791ddf1daed->8cc881694e2911d0a2eff3ca7eb5dd5efc0503d3	fs/cifs/TODO
> *100644->100644	blob	b004fef0a42bac42e8b3490fba19df1ea233762d->741ff0c69f37f44154247020649b4104afff0cda	fs/cifs/cifssmb.c
> *100644->100644	blob	d31c1a71f781ccc7c189e3bff9dc1ee4ee282188->1ab353e235955eee63e43a3a030d0b8b4b719a2b	include/asm-arm/arch-integrator/cm.h
> *100644->100644	blob	aa7e16b2e2255fbcc0f5aef2cf72c241daf2f81b->370dfe77589d2abd9d8a963772fc79072feba5c0	include/asm-arm/rtc.h
> 
> Applying changes...
> Fast-forwarding a6ad57fb4b5e9d68553f4440377b99f75588fa88 -> e8e6993178344eb348f60f05b16d9dc30db3b9cf
> 	on top of a6ad57fb4b5e9d68553f4440377b99f75588fa88...
> The next patch would create the file arch/ia64/sn/include/pci/pcibus_provider_defs.h,
> which already exists!  Skipping patch.
> 1 out of 1 hunk ignored -- saving rejects to file arch/ia64/sn/include/pci/pcibus_provider_defs.h.rej
> The next patch would create the file arch/ia64/sn/include/pci/pcidev.h,
> which already exists!  Skipping patch.
> 1 out of 1 hunk ignored -- saving rejects to file arch/ia64/sn/include/pci/pcidev.h.rej

Ok.  Some further information.

I ran cg-diff, which said that these two files were new, and not part
of the kernel tree anymore.  So I removed them.  cg-diff was then happy.

I've just done another update, and they've magically reappeared again.

strings -a .git/index | grep arch/ia64/sn/include/pci/pcidev.h

shows they exist.  After running read-tree $(tree-id) and
update-cache --refresh I think everything's fine again - these files
have certainly gone from the index file.

So it seems that merging in cogito-0.8 isn't working correctly - known
problem or new problem?

-- 
Russell King


^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Daniel Barkalow @ 2005-05-01 21:25 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505011337070.2296@ppc970.osdl.org>

On Sun, 1 May 2005, Linus Torvalds wrote:

> On Sun, 1 May 2005, Daniel Barkalow wrote:
> > 
> > Right; what I want to make programs able to do is take explicit
> > references, instead of only taking the objects they reference. So you
> > say heads/master or heads/linus instead of
> > "198b0fb635ed8a007bac0c16eab112c5e2c7995c".
> 
> That's fine. 
> 
> This is really just an issue of havign a function that does "get_sha1()", 
> and then making the things that take command line arguments use that 
> one instead of "get_sha1_hex()".

I added a get_ref_sha1() that just does the .git/refs/ case; I think that
most things that want to accept various forms will also want to know what
form they got and do something with it, so get_sha1() isn't a big win.

The biggest thing so far is actually writing the references when the user
has specified where to write them, and I wanted to restrict that to a
target of the right format.

> The _only_ thing I want to be careful about is that all the _internal_
> stuff still have to use the strict "get_sha1_hex()" function, ie we should
> never _ever_ accept a tree object where the "sha1" ends up being anything
> but the hex thing. So this "generalized get_sha1()" would have to be used 
> only on real user input (ie argv[] array and the like).

Agreed.

	-Daniel
*This .sig left intentionally blank*


^ permalink raw reply

* [PATCH] Make git-update-cache --refresh fail if update/merge needed.
From: Junio C Hamano @ 2005-05-01 21:29 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505010916510.2296@ppc970.osdl.org>

Scripts may find it useful if they do not have to parse the
output from the command but just can rely on its exit status.

Earlier both Linus and myself thought this would be necessary to
make git-prune-script safer but it turns out that the issue was
somewhere else and not related to what this patch addresses.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

update-cache.c |   15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)

# - date handling: handle "AM"/"PM" on time
# + [PATCH] Make git-prune-script a bit more careful.
--- k/update-cache.c
+++ l/update-cache.c
@@ -212,15 +212,17 @@ static struct cache_entry *refresh_entry
 	return updated;
 }
 
-static void refresh_cache(void)
+static int refresh_cache(void)
 {
 	int i;
+	int has_errors = 0;
 
 	for (i = 0; i < active_nr; i++) {
 		struct cache_entry *ce, *new;
 		ce = active_cache[i];
 		if (ce_stage(ce)) {
 			printf("%s: needs merge\n", ce->name);
+			has_errors = 1;
 			while ((i < active_nr) &&
 			       ! strcmp(active_cache[i]->name, ce->name))
 				i++;
@@ -230,12 +232,15 @@ static void refresh_cache(void)
 
 		new = refresh_entry(ce);
 		if (IS_ERR(new)) {
-			if (!(not_new && PTR_ERR(new) == -ENOENT))
+			if (!(not_new && PTR_ERR(new) == -ENOENT)) {
 				printf("%s: needs update\n", ce->name);
+				has_errors = 1;
+			}
 			continue;
 		}
 		active_cache[i] = new;
 	}
+	return has_errors;
 }
 
 /*
@@ -307,7 +312,7 @@ static void remove_lock_file_on_signal(i
 
 int main(int argc, char **argv)
 {
-	int i, newfd, entries;
+	int i, newfd, entries, has_errors = 0;
 	int allow_options = 1;
 	static char lockfile[MAXPATHLEN+1];
 	const char *indexfile = get_index_file();
@@ -343,7 +348,7 @@ int main(int argc, char **argv)
 				continue;
 			}
 			if (!strcmp(path, "--refresh")) {
-				refresh_cache();
+				has_errors |= refresh_cache();
 				continue;
 			}
 			if (!strcmp(path, "--cacheinfo")) {
@@ -369,5 +374,5 @@ int main(int argc, char **argv)
 		die("Unable to write new cachefile");
 
 	lockfile_name = NULL;
-	return 0;
+	return has_errors;
 }


^ permalink raw reply

* [0/2] Complete http-pull
From: Daniel Barkalow @ 2005-05-01 21:49 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This series enables http-pull to do everything renecessary to bring your
local repository up to date with respect to a remote repository by HTTP.

 1: Library support for files in refs
 2: Fetch refs over the network and write them locally

	-Daniel
*This .sig left intentionally blank*



^ permalink raw reply

* [1/2] Library support for refs/
From: Daniel Barkalow @ 2005-05-01 21:52 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.21.0505011746230.30848-100000@iabervon.org>

This includes three things: in init, create .git/refs/; a function to read
a refs file; and a function to write a refs file.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Index: Makefile
===================================================================
--- bab2f51e8218b023728539c7841ee7613ebd36e8/Makefile  (mode:100644 sha1:a3028efd80a4165ade03158361e0224fb46364f5)
+++ f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/Makefile  (mode:100644 sha1:e43a1db55962c771cc934227213d6520939bd0ce)
@@ -29,9 +29,10 @@
 	install $(PROG) $(SCRIPTS) $(HOME)/bin/
 
 LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \
-	 tag.o date.o
+	 tag.o date.o refs.o
+
 LIB_FILE=libgit.a
-LIB_H=cache.h object.h blob.h tree.h commit.h tag.h
+LIB_H=cache.h object.h blob.h tree.h commit.h tag.h refs.h
 
 LIB_H += strbuf.h
 LIB_OBJS += strbuf.o
Index: cache.h
===================================================================
--- bab2f51e8218b023728539c7841ee7613ebd36e8/cache.h  (mode:100644 sha1:af6345820f3f8c533868394059b2d3b189e6b422)
+++ f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/cache.h  (mode:100644 sha1:42a08f57c5b7a7cd013ab3e99f3965014068b787)
@@ -100,6 +100,11 @@
 
 #define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)
 
+#define REF_ENVIRONMENT "REF_FILE_DIRECTORY"
+#define DEFAULT_REF_ENVIRONMENT ".git/refs"
+
+#define get_refs_directory() (getenv(REF_ENVIRONMENT) ? : DEFAULT_REF_ENVIRONMENT)
+
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
 #define DEFAULT_INDEX_ENVIRONMENT ".git/index"
 
Index: init-db.c
===================================================================
--- bab2f51e8218b023728539c7841ee7613ebd36e8/init-db.c  (mode:100644 sha1:83f95e8b926f4fd28e0db0ccfc4f040d4172ee8a)
+++ f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/init-db.c  (mode:100644 sha1:6bed5a6abdfd7da152ed13b825376c2d2f8820c4)
@@ -38,6 +38,7 @@
 	memcpy(path, sha1_dir, len);
 
 	safe_create_dir(sha1_dir);
+	safe_create_dir(get_refs_directory());
 	for (i = 0; i < 256; i++) {
 		sprintf(path+len, "/%02x", i);
 		safe_create_dir(path);
Index: refs.c
===================================================================
--- /dev/null  (tree:bab2f51e8218b023728539c7841ee7613ebd36e8)
+++ f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/refs.c  (mode:100644 sha1:9ba5696c15d8597236e1f5b7a4dbd609045efc81)
@@ -0,0 +1,139 @@
+#include "refs.h"
+#include "cache.h"
+
+#include <errno.h>
+
+static char *split_ref_file_name(const char *dir, const char *name)
+{
+	char *base = get_refs_directory();
+	int baselen = strlen(base);
+	int dirlen = strlen(dir);
+	int namelen = strlen(name);
+	char *ret;
+	if (dir[0] == '.')
+		return NULL;
+	if (strchr(dir, '/'))
+		return NULL;
+	if (strchr(name, '/'))
+		return NULL;
+	ret = xmalloc(baselen + 3 + dirlen + namelen);
+	strcpy(ret, base);
+	ret[baselen] = '/';
+	strcpy(ret + baselen + 1, dir);
+	ret[baselen + 1 + dirlen] = '/';
+	strcpy(ret + baselen + 2 + dirlen, name);
+	ret[baselen + 2 + dirlen + namelen] = '\0';
+	return ret;
+}
+
+static char *ref_file_name(const char *ref)
+{
+	char *base = get_refs_directory();
+	int baselen = strlen(base);
+	int reflen = strlen(ref);
+	char *ret;
+	char *check;
+	if (ref[0] == '.')
+		return NULL;
+	check = strchr(ref, '/');
+	if (!check)
+		return NULL;
+	if (strchr(check + 1, '/'))
+		return NULL;
+	ret = xmalloc(baselen + 2 + reflen);
+	strcpy(ret, base);
+	ret[baselen] = '/';
+	strcpy(ret + baselen + 1, ref);
+	ret[baselen + 1 + reflen] = '\0';
+	return ret;
+}
+
+static int read_ref_file(char *filename, unsigned char *sha1) {
+	int fd = open(filename, O_RDONLY);
+	char hex[41];
+	if (fd < 0) {
+		return error("Couldn't open %s\n", filename);
+	}
+	if ((read(fd, hex, 41) < 41) ||
+	    (hex[40] != '\n') ||
+	    get_sha1_hex(hex, sha1)) {
+		error("Couldn't read a hash from %s\n", filename);
+		close(fd);
+		return -1;
+	}
+	close(fd);
+	return 0;
+}
+
+int get_split_ref_sha1(const char *dir, const char *name, unsigned char *sha1)
+{
+	char *filename = split_ref_file_name(dir, name);
+	int retval;
+	if (!filename)
+		return -1;
+	retval = read_ref_file(filename, sha1);
+	free(filename);
+	return retval;
+}
+
+int get_ref_sha1(const char *ref, unsigned char *sha1)
+{
+	char *filename = ref_file_name(ref);
+	int retval;
+	if (!filename)
+		return -1;
+	retval = read_ref_file(filename, sha1);
+	free(filename);
+	return retval;
+}
+
+int write_split_ref_sha1(const char *dir, const char *name,
+			 unsigned char *sha1)
+{
+	char *filename = split_ref_file_name(dir, name);
+	char *hex = sha1_to_hex(sha1);
+	char term = '\n';
+	int fd;
+	if (!filename)
+		return -1;
+	unlink(filename);
+	fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+	if (fd < 0 && errno == ENOENT) {
+		char *dirname = split_ref_file_name(dir, "");
+		mkdir(dirname, 0755);
+		free(dirname);
+		fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+	}
+	if (fd < 0) {
+		error("Couldn't open for writing %s: %s\n", filename,
+		      strerror(errno));
+		free(filename);
+		return -1;
+	}
+	if (write(fd, hex, 40) < 40 ||
+	    write(fd, &term, 1) < 1) {
+		error("Couldn't write %s\n", filename);
+		free(filename);
+		close(fd);
+		return -1;
+	}
+	close(fd);
+	return 0;
+	
+}
+
+int split_ref(char **dir, char **name, const char *ref)
+{
+	char *middle = strchr(ref, '/');
+	if (ref[0] == '.')
+		return -1;
+	if (!middle)
+		return -1;
+	if (strchr(middle + 1, '/'))
+		return -1;
+	*dir = xmalloc(middle - ref + 1);
+	*name = strdup(middle + 1);
+	(*dir)[middle - ref] = '\0';
+	memcpy(*dir, ref, middle - ref);
+	return 0;
+}
Index: refs.h
===================================================================
--- /dev/null  (tree:bab2f51e8218b023728539c7841ee7613ebd36e8)
+++ f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/refs.h  (mode:100644 sha1:9ef6ed7563f70273aef6574a01d5626fee28345a)
@@ -0,0 +1,20 @@
+#ifndef REFS_H
+#define REFS_H
+
+/** Reads the refs file specified into sha1 **/
+extern int get_split_ref_sha1(const char *dir, const char *name,
+			      unsigned char *sha1);
+
+/** Reads the refs file specified into sha1 **/
+extern int get_ref_sha1(const char *ref, unsigned char *sha1);
+
+/** Writes sha1 into the refs file specified **/
+extern int write_split_ref_sha1(const char *dir, const char *name, 
+				unsigned char *sha1);
+
+/** Sets dir and name to the directory and name parts of ref, in new
+ * storage. 
+ **/
+extern int split_ref(char **dir, char **name, const char *ref);
+
+#endif /* REFS_H */


^ permalink raw reply

* [2/2] Complete http-pull
From: Daniel Barkalow @ 2005-05-01 21:56 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.21.0505011746230.30848-100000@iabervon.org>

This adds support for fetching a reference from the remote repository and
for writing to a local reference file (with the -w option). It also makes
rpull aware that it lacks this capability.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Index: http-pull.c
===================================================================
--- f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/http-pull.c  (mode:100644 sha1:d877c4abe3ff7766d858bfeac5c9a0eaf1385b65)
+++ 6bae8854157f3f8b29f9afee2c54434334f899e4/http-pull.c  (mode:100644 sha1:9a52c08f51d8e9f96c4704f84f8d0d15637fe397)
@@ -7,6 +7,8 @@
 #include <errno.h>
 #include <stdio.h>
 
+#include "refs.h"
+
 #include "pull.h"
 
 #include <curl/curl.h>
@@ -45,6 +47,23 @@
 	return size;
 }
 
+struct buffer
+{
+	size_t posn;
+	size_t size;
+	void *buffer;
+};
+
+static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,
+			    struct buffer *buffer) {
+	size_t size = eltsize * nmemb;
+	if (size > buffer->size - buffer->posn)
+		size = buffer->size - buffer->posn;
+	memcpy(buffer->buffer + buffer->posn, ptr, size);
+	buffer->posn += size;
+	return size;
+}
+
 int fetch(unsigned char *sha1)
 {
 	char *hex = sha1_to_hex(sha1);
@@ -103,6 +122,40 @@
 	return 0;
 }
 
+int fetch_ref(char *dir, char *name, unsigned char *sha1)
+{
+	char *url, *posn;
+	char hex[42];
+	struct buffer buffer;
+	buffer.size = 41;
+	buffer.posn = 0;
+	buffer.buffer = hex;
+	hex[41] = '\0';
+	
+	curl_easy_setopt(curl, CURLOPT_FILE, &buffer);
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
+
+	url = xmalloc(strlen(base) + 7 + strlen(dir) + strlen(name));
+	strcpy(url, base);
+	posn = url + strlen(base);
+	strcpy(posn, "refs/");
+	posn += 5;
+	strcpy(posn, dir);
+	posn += strlen(dir);
+	*(posn++) = '/';
+	strcpy(posn, name);
+
+	curl_easy_setopt(curl, CURLOPT_URL, url);
+
+	if (curl_easy_perform(curl))
+		return error("Couldn't get %s for %s/%s\n", url,
+			     dir, name);
+
+	hex[40] = '\0';
+	get_sha1_hex(hex, sha1);
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	char *commit_id;
@@ -118,6 +171,10 @@
 			get_all = 1;
 			get_tree = 1;
 			get_history = 1;
+		} else if (argv[arg][1] == 'w') {
+			char *write_ref = argv[arg + 1];
+			split_ref(&write_ref_dir, &write_ref_name, write_ref);
+			arg++;
 		}
 		arg++;
 	}
Index: pull.c
===================================================================
--- f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/pull.c  (mode:100644 sha1:90d2d41ed2c56580f72f020bc93c3e1b8a3befa5)
+++ 6bae8854157f3f8b29f9afee2c54434334f899e4/pull.c  (mode:100644 sha1:89f11906f67ea9b36e1d4d85fa87f0e9b7d08d65)
@@ -3,6 +3,12 @@
 #include "cache.h"
 #include "commit.h"
 #include "tree.h"
+#include "tag.h"
+
+#include "refs.h"
+
+char *write_ref_dir = NULL;
+char *write_ref_name = NULL;
 
 int get_tree = 0;
 int get_history = 0;
@@ -61,15 +67,53 @@
 	return 0;
 }
 
+static int process_tag(unsigned char *sha1)
+{
+	return 0;
+}
+
+static int process_unknown(unsigned char *sha1)
+{
+	struct object *obj;
+	if (fetch(sha1))
+		return -1;
+	obj = parse_object(sha1);
+	if (obj->type == commit_type)
+		return process_commit(sha1);
+	else if (obj->type == tag_type)
+		return process_tag(sha1);
+	return error("Cannot pull a %s object", obj->type);
+}
+
+static int interpret_target(char *target, unsigned char *sha1)
+{
+	char *dir, *name;
+	if (!get_sha1_hex(target, sha1))
+		return 0;
+	if (!split_ref(&dir, &name, target)) {
+		if (!fetch_ref(dir, name, sha1)) {
+			return 0;
+		}
+	}
+	return -1;
+}
+
 int pull(char *target)
 {
 	int retval;
 	unsigned char sha1[20];
-	retval = get_sha1_hex(target, sha1);
+	retval = interpret_target(target, sha1);
+	if (retval) {
+		return error("Could not interpret %s as something to pull",
+			     target);
+	}
+	retval = fetch(sha1);
 	if (retval)
 		return retval;
-	retval = fetch(sha1);
+	retval = process_unknown(sha1);
 	if (retval)
 		return retval;
-	return process_commit(sha1);
+	if (write_ref_dir && write_ref_name)
+		write_split_ref_sha1(write_ref_dir, write_ref_name, sha1);
+	return 0;
 }
Index: pull.h
===================================================================
--- f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/pull.h  (mode:100644 sha1:314bc7e95ab1a73634f6a96a8a3782fda91ea261)
+++ 6bae8854157f3f8b29f9afee2c54434334f899e4/pull.h  (mode:100644 sha1:5df0ff6001ad4129dcd8b2af7c927bade8c413d2)
@@ -4,6 +4,12 @@
 /** To be provided by the particular implementation. **/
 extern int fetch(unsigned char *sha1);
 
+extern int fetch_ref(char *dir, char *name, unsigned char *sha1);
+
+/** Ref filename to write target to. **/
+extern char *write_ref_dir;
+extern char *write_ref_name;
+
 /** Set to fetch the target tree. */
 extern int get_tree;
 
Index: rpull.c
===================================================================
--- f0d6a3af54a5ec8dd588fb8e501e38f6252eda19/rpull.c  (mode:100644 sha1:6624440d5ad24854e1bd1a8dff628427581198e0)
+++ 6bae8854157f3f8b29f9afee2c54434334f899e4/rpull.c  (mode:100644 sha1:a1c1be18195d40a152f86ed35886364dbc806d80)
@@ -20,6 +20,11 @@
 	return write_sha1_from_fd(sha1, fd_in);
 }
 
+int fetch_ref(char *name, char *dir, unsigned char *sha1)
+{
+	return -1;
+}
+
 int main(int argc, char **argv)
 {
 	char *commit_id;


^ permalink raw reply

* Re: Quick command reference
From: David Greaves @ 2005-05-01 22:11 UTC (permalink / raw)
  To: bert hubert; +Cc: Linus Torvalds, omb, Paul Mackerras, git, Petr Baudis
In-Reply-To: <20050501211808.GA6900@outpost.ds9a.nl>

bert hubert wrote:

>I've recently been very happy with AsciiDoc
>http://www.methods.co.nz/asciidoc/ - it's input is as easy to read as to
>write.
>  
>
sold


^ permalink raw reply

* Re: Quick command reference
From: Linus Torvalds @ 2005-05-01 22:45 UTC (permalink / raw)
  To: bert hubert; +Cc: David Greaves, omb, Paul Mackerras, git, Petr Baudis
In-Reply-To: <20050501211808.GA6900@outpost.ds9a.nl>



On Sun, 1 May 2005, bert hubert wrote:
> 
> I've recently been very happy with AsciiDoc
> http://www.methods.co.nz/asciidoc/ - it's input is as easy to read as to
> write.

I have to agree. I don't much like most markup languages, but this one 
actually seems to truly _be_ readable even in its plain source format.

		Linus

^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Linus Torvalds @ 2005-05-01 23:23 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Petr Baudis
In-Reply-To: <Pine.LNX.4.21.0505011656270.30848-100000@iabervon.org>



On Sun, 1 May 2005, Daniel Barkalow wrote:
> 
> I added a get_ref_sha1() that just does the .git/refs/ case; I think that
> most things that want to accept various forms will also want to know what
> form they got and do something with it, so get_sha1() isn't a big win.

I really really disagree.

For example, take something like "git-diff-cache". I think it's a big
bonus if you can just write

	git-diff-cache HEAD

and it will pick up the sha1 ID from .git/HEAD. 

In general, I think a "get_sha1()" that tries as many user-friendly things 
as possible is good for the command line. Within reason. I really don't 
like the "try to autocomplete a partial sha1" thing, but I wouldn't at all 
mind having various helpers like

	git-diff-tree HEAD.p1 HEAD

where the ".p1" would just make it look up the first parent of the thing 
in HEAD (which in turn would mean "look up the sha1 from the .git/HEAD 
file".

Many of these are really easy to do, and I think most people would tend to 
prefer having the choice.

		Linus

^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Linus Torvalds @ 2005-05-01 23:48 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505011616230.22864@ppc970.osdl.org>



On Sun, 1 May 2005, Linus Torvalds wrote:
> 
> For example, take something like "git-diff-cache". I think it's a big
> bonus if you can just write
> 
> 	git-diff-cache HEAD
> 
> and it will pick up the sha1 ID from .git/HEAD. 

Ok, I just committed this. Almost all commands that take SHA1 strings from 
the command line can now use the shortened format. 

Right now it only does the "filename" version, and it tries to append 
".git/" to it if it doesn't work, so you can do

	git-diff-cache HEAD

or something like that if you want to. Where ".git/HEAD" would also have
worked, or ".git/refs/heads/master" (or just "refs/heads/master").

For example, if you have a refs/tags directory which has been populated 
with files that point to the tags, you can do

	git-diff-tree -p refs/tags/v2.6.12-rc3 HEAD

and it will do exactly what you'd expect it to do.

I didn't do the ".p1" for parent thing. It would be easy to add, I just 
haven't decided on a nice syntax for it (I'd like something that is nice 
and doesn't need quoting, but the ".p1" seems a bit _too_ ugly).

			Linus

^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Daniel Barkalow @ 2005-05-01 23:46 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505011616230.22864@ppc970.osdl.org>

On Sun, 1 May 2005, Linus Torvalds wrote:

> On Sun, 1 May 2005, Daniel Barkalow wrote:
> > 
> > I added a get_ref_sha1() that just does the .git/refs/ case; I think that
> > most things that want to accept various forms will also want to know what
> > form they got and do something with it, so get_sha1() isn't a big win.
> 
> I really really disagree.
> 
> For example, take something like "git-diff-cache". I think it's a big
> bonus if you can just write
> 
> 	git-diff-cache HEAD
> 
> and it will pick up the sha1 ID from .git/HEAD. 

True, but with -p, you'd probably want to give lines like

--- HEAD/Makefile
+++ (cache)/Makefile

when it's not just hex (and "linus/Makefile" for heads/linus, not
"heads/linus/Makefile", which would break things). I think it's generally
best to call each of the things in the list to try and not only use the
first one that understands, but also do program-specific special things
depending on which one that was.

> In general, I think a "get_sha1()" that tries as many user-friendly things 
> as possible is good for the command line. Within reason. I really don't 
> like the "try to autocomplete a partial sha1" thing, but I wouldn't at all 
> mind having various helpers like
> 
> 	git-diff-tree HEAD.p1 HEAD
> 
> where the ".p1" would just make it look up the first parent of the thing 
> in HEAD (which in turn would mean "look up the sha1 from the .git/HEAD 
> file".

Maybe :p1, to use characters that aren't frequently in filenames?

> Many of these are really easy to do, and I think most people would tend to 
> prefer having the choice.

I agree with that, but I'm not sure how useful having one function that
just looks up the sha1 without further reporting is. In any case, it's an
easy addition, and it's plausible that similar functions would work for
any similar information needed.

	-Daniel
*This .sig left intentionally blank*


^ permalink raw reply

* [PATCH] Add --help to cogito 0.8
From: Alexander Beyn @ 2005-05-02  0:00 UTC (permalink / raw)
  To: git

This patch adds -h and --help to all the cg- commands. It also moves the
detailed help printing from cg-help into cg-Xlib.

I created it because I could never remember if cg-log or cg-diff requires 
the -r before the revs.

Alexander


Index: cg-Xlib
===================================================================
--- c3aa1e6b53cc59d5fbe261f3f859584904ae3a63/cg-Xlib  (mode:100755 sha1:940d27851019940d20d2a6b141977d1c9a5debc0)
+++ d8f4221f90207b6c472dd4a2de0bf5e4d131f745/cg-Xlib  (mode:100755 sha1:09668c5c9a02ff9df9957ce656db3358c8c1ca7f)
@@ -33,6 +33,17 @@
 	$(which mktemp) $dirarg $prefix"$1"
 }
 
+print_help () {
+	which "cg-$1" >/dev/null 2>&1 || exit 1
+	cat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'
+	exit
+}
+
+for option in "$@"; do
+	if [ "$option" = "-h" -o "$option" = "--help" ]; then
+		print_help ${_cg_cmd##cg-}
+	fi
+done
 
 # Compatibility hacks:
 # 2005-04-26
Index: cg-help
===================================================================
--- c3aa1e6b53cc59d5fbe261f3f859584904ae3a63/cg-help  (mode:100755 sha1:d16446c005c4698f408bf651afd718d95f5a9cfe)
+++ d8f4221f90207b6c472dd4a2de0bf5e4d131f745/cg-help  (mode:100755 sha1:0ea78197b1c255540a35bd389c48f9a67431e556)
@@ -10,9 +10,7 @@
 
 if [ "$1" ]; then
 	cmd=$(echo "$1" | sed 's/^cg-//')
-	which "cg-$cmd" >/dev/null 2>&1 || exit 1
-	cat $(which cg-$cmd) | sed -n '3,/^$/s/^# *//p'
-	exit
+	print_help $cmd
 fi

^ permalink raw reply

* cg-log -r?
From: Petr Baudis @ 2005-05-02  0:04 UTC (permalink / raw)
  To: Alexander Beyn; +Cc: git
In-Reply-To: <20050502000019.GA1644@fatelectrons.org>

Dear diary, on Mon, May 02, 2005 at 02:00:19AM CEST, I got a letter
where Alexander Beyn <malex-git@fatelectrons.org> told me that...
> I created it because I could never remember if cg-log or cg-diff requires 
> the -r before the revs.

Actually, would you people hate me / Cogito / Richard Stallman if I
added -r to cg-log and cg-mkpatch, for the sake of consistency?
Extending cg-log to work on individual files would be then obvious.


P.S.: Yes, I'm back and hope to catch with the rest of you during tomorrow.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply

* Re: Quick command reference
From: Randy.Dunlap @ 2005-05-02  0:09 UTC (permalink / raw)
  To: bert hubert; +Cc: torvalds, david, omb, paulus, git, pasky
In-Reply-To: <20050501211808.GA6900@outpost.ds9a.nl>

On Sun, 1 May 2005 23:18:08 +0200 bert hubert wrote:

| On Sun, May 01, 2005 at 09:29:23AM -0700, Linus Torvalds wrote:
| > (And no, by "standard format" I do _not_ mean xml or stuff like that. I 
| > mean something that is actually easy to read ;)
| 
| I've recently been very happy with AsciiDoc
| http://www.methods.co.nz/asciidoc/ - it's input is as easy to read as to
| write.
| 
| >From this input:
| http://ds9a.nl/splitpipe/splitpipe-0.3/doc/splitpipe.1.txt
| 
| It produces this lovely page (html, man, pdf, the works):
| http://ds9a.nl/splitpipe/splitpipe-0.3/doc/splitpipe.1.html
| 
| And if you are really in a wild mood, you can have it make entire websites,
| like http://ds9a.nl/splitpipe
| 
| When used properly it builds tables of contents, indexes, books and whatnot.

AsciiDoc is already agreed upon, but here's another one that
I have used:  Markdown:
  http://daringfireball.net/projects/markdown/

---
~Randy

^ permalink raw reply

* Re: Complete http-pull; where should it go?
From: Junio C Hamano @ 2005-05-02  0:09 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Daniel Barkalow, git, Petr Baudis
In-Reply-To: <Pine.LNX.4.58.0505011638370.22864@ppc970.osdl.org>

>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

LT> I didn't do the ".p1" for parent thing. It would be easy to add, I just 
LT> haven't decided on a nice syntax for it (I'd like something that is nice 
LT> and doesn't need quoting, but the ".p1" seems a bit _too_ ugly).

Shameless plug but could you take a look at how my JIT does it,
at <http://members.cox.net/junkio/JITNotes.txt>, especially
scroll down to near the bottom "Syntax to naming a snapshot or a
commit" section?

I still think this kind of thing belongs to Porcelain not
Plumbing, though.


^ permalink raw reply

* [PATCH] Do not call fetch() when we have it.
From: Junio C Hamano @ 2005-05-02  0:10 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

Currently pull() calls fetch() without checking whether we have
the wanted object but all of the existing fetch()
implementations perform this check and return success
themselves.  This patch moves the check to the caller.

I will be sending a trivial git-local-pull which depends on
this in the next message.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

http-pull.c |    4 ----
pull.c      |   17 ++++++++++++-----
rpull.c     |    2 --
3 files changed, 12 insertions(+), 11 deletions(-)

# - date handling: handle "AM"/"PM" on time
# + working-tree
--- k/http-pull.c
+++ l/http-pull.c
@@ -53,10 +53,6 @@ int fetch(unsigned char *sha1)
 	char *url;
 	char *posn;
 
-	if (has_sha1_file(sha1)) {
-		return 0;
-	}
-
 	local = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
 
 	if (local < 0)
--- k/pull.c
+++ l/pull.c
@@ -8,6 +8,13 @@ int get_tree = 0;
 int get_history = 0;
 int get_all = 0;
 
+static int make_sure_we_have_it(unsigned char *sha1)
+{
+	if (has_sha1_file(sha1))
+		return 0;
+	return fetch(sha1);	
+}
+
 static int process_tree(unsigned char *sha1)
 {
 	struct tree *tree = lookup_tree(sha1);
@@ -17,7 +24,7 @@ static int process_tree(unsigned char *s
 		return -1;
 
 	for (entries = tree->entries; entries; entries = entries->next) {
-		if (fetch(entries->item.tree->object.sha1))
+		if (make_sure_we_have_it(entries->item.tree->object.sha1))
 			return -1;
 		if (entries->directory) {
 			if (process_tree(entries->item.tree->object.sha1))
@@ -31,14 +38,14 @@ static int process_commit(unsigned char 
 {
 	struct commit *obj = lookup_commit(sha1);
 
-	if (fetch(sha1))
+	if (make_sure_we_have_it(sha1))
 		return -1;
 
 	if (parse_commit(obj))
 		return -1;
 
 	if (get_tree) {
-		if (fetch(obj->tree->object.sha1))
+		if (make_sure_we_have_it(obj->tree->object.sha1))
 			return -1;
 		if (process_tree(obj->tree->object.sha1))
 			return -1;
@@ -50,7 +57,7 @@ static int process_commit(unsigned char 
 		for (; parents; parents = parents->next) {
 			if (has_sha1_file(parents->item->object.sha1))
 				continue;
-			if (fetch(parents->item->object.sha1)) {
+			if (make_sure_we_have_it(parents->item->object.sha1)) {
 				/* The server might not have it, and
 				 * we don't mind. 
 				 */
@@ -70,7 +77,7 @@ int pull(char *target)
 	retval = get_sha1_hex(target, sha1);
 	if (retval)
 		return retval;
-	retval = fetch(sha1);
+	retval = make_sure_we_have_it(sha1);
 	if (retval)
 		return retval;
 	return process_commit(sha1);
--- k/rpull.c
+++ l/rpull.c
@@ -14,8 +14,6 @@ static int fd_out;
 
 int fetch(unsigned char *sha1)
 {
-	if (has_sha1_file(sha1))
-		return 0;
 	write(fd_out, sha1, 20);
 	return write_sha1_from_fd(sha1, fd_in);
 }


^ permalink raw reply

* [PATCH] Add git-local-pull.
From: Junio C Hamano @ 2005-05-02  0:11 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This adds the git-local-pull command as a smaller brother of
http-pull and rpull.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

Makefile     |    3 +
local-pull.c |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 1 deletion(-)

# - [PATCH] Do not pollute work tree in git-merge-one-file-script
# + [PATCH] Add local pull.
--- k/Makefile
+++ l/Makefile
@@ -21,7 +21,7 @@ PROG=   git-update-cache git-diff-files 
 	git-check-files git-ls-tree git-merge-base git-merge-cache \
 	git-unpack-file git-export git-diff-cache git-convert-cache \
 	git-http-pull git-rpush git-rpull git-rev-list git-mktag \
-	git-diff-tree-helper git-tar-tree git-write-blob
+	git-diff-tree-helper git-tar-tree git-write-blob git-local-pull
 
 all: $(PROG)
 
@@ -87,6 +87,7 @@ git-export: export.c
 git-diff-cache: diff-cache.c
 git-convert-cache: convert-cache.c
 git-http-pull: http-pull.c pull.c
+git-local-pull: local-pull.c pull.c
 git-rpush: rsh.c
 git-rpull: rsh.c pull.c
 git-rev-list: rev-list.c
# - date handling: handle "AM"/"PM" on time
# + [PATCH] Add local pull.
Created: local-pull.c (mode:100644)
--- /dev/null
+++ l/local-pull.c
@@ -0,0 +1,110 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "cache.h"
+#include "commit.h"
+#include <errno.h>
+#include <stdio.h>
+#include "pull.h"
+
+static int use_link = 0;
+static int use_symlink = 0;
+static int verbose = 0;
+
+static char *path;
+
+static void say(const char *fmt, const char *hex) {
+	if (verbose)
+		fprintf(stderr, fmt, hex);
+}
+
+int fetch(unsigned char *sha1)
+{
+	static int object_name_start = -1;
+	static char filename[PATH_MAX];
+	char *hex = sha1_to_hex(sha1);
+	const char *dest_filename = sha1_file_name(sha1);
+	int ifd, ofd, status;
+	struct stat st;
+	void *map;
+
+	if (object_name_start < 0) {
+		strcpy(filename, path); /* e.g. git.git */
+		strcat(filename, "/objects/");
+		object_name_start = strlen(filename);
+	}
+	filename[object_name_start+0] = hex[0];
+	filename[object_name_start+1] = hex[1];
+	filename[object_name_start+2] = '/';
+	strcpy(filename + object_name_start + 3, hex + 2);
+	if (use_link && !link(filename, dest_filename)) {
+		say("Hardlinked %s.\n", hex);
+		return 0;
+	}
+	if (use_symlink && !symlink(filename, dest_filename)) {
+		say("Symlinked %s.\n", hex);
+		return 0;
+	}
+	ifd = open(filename, O_RDONLY);
+	if (ifd < 0 || fstat(ifd, &st) < 0) {
+		close(ifd);
+		fprintf(stderr, "Cannot open %s\n", filename);
+		return -1;
+	}
+	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
+	close(ifd);
+	if (-1 == (int)(long)map) {
+		fprintf(stderr, "Cannot mmap %s\n", filename);
+		return -1;
+	}
+	ofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+	status = ((ofd < 0) || (write(ofd, map, st.st_size) != st.st_size));
+	munmap(map, st.st_size);
+	close(ofd);
+	if (status)
+		fprintf(stderr, "Cannot write %s (%ld bytes)\n",
+			dest_filename, st.st_size);
+	else
+		say("Copied %s.\n", hex);
+	return status;
+}
+
+static const char *local_pull_usage = 
+"git-local-pull [-c] [-t] [-a] [-l] [-s] [-v] commit-id path";
+
+int main(int argc, char **argv)
+{
+	char *commit_id;
+	int arg = 1;
+
+	while (arg < argc && argv[arg][0] == '-') {
+		if (argv[arg][1] == 't')
+			get_tree = 1;
+		else if (argv[arg][1] == 'c')
+			get_history = 1;
+		else if (argv[arg][1] == 'a') {
+			get_all = 1;
+			get_tree = 1;
+			get_history = 1;
+		}
+		else if (argv[arg][1] == 'l')
+			use_link = 1;
+		else if (argv[arg][1] == 's')
+			use_symlink = 1;
+		else if (argv[arg][1] == 'v')
+			verbose = 1;
+		else
+			usage(local_pull_usage);
+		arg++;
+	}
+	if (argc < arg + 2)
+		usage(local_pull_usage);
+	commit_id = argv[arg];
+	path = argv[arg + 1];
+
+	if (pull(commit_id))
+		return 1;
+
+	return 0;
+}


^ permalink raw reply

* Re: cg-log -r?
From: Alexander Beyn @ 2005-05-02  0:16 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git
In-Reply-To: <20050502000447.GF974@pasky.ji.cz>

On Mon, May 02, 2005 at 02:04:47AM +0200, Petr Baudis wrote:
> Dear diary, on Mon, May 02, 2005 at 02:00:19AM CEST, I got a letter
> where Alexander Beyn <malex-git@fatelectrons.org> told me that...
> > I created it because I could never remember if cg-log or cg-diff requires 
> > the -r before the revs.
> 
> Actually, would you people hate me / Cogito / Richard Stallman if I
> added -r to cg-log and cg-mkpatch, for the sake of consistency?
> Extending cg-log to work on individual files would be then obvious.
> 

I'd welcome this change, but I still like the ubiquitous -h and --help
on all the commands

Alexander

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox