Git development
 help / color / mirror / Atom feed
* [RFC][PATCH 07/10] Sparse: fix "'merge_file' not declared" warning
From: Ramsay Jones @ 2007-06-08 22:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


Add a declaration for merge_file() to a new "merge-file.h" header
file, and add the appropriate include directives.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---

There are two other (static) definitions of a merge_file() function,
one in merge-recursive.c, which could probably be renamed merge_filespec()
and one in merge-index.c, which could be renamed merge_path().
Maybe the the function in merge-file.c should be called merge_blob() ...
(and then change the file names too!)

 Makefile     |    3 ++-
 merge-file.c |    1 +
 merge-file.h |    8 ++++++++
 merge-tree.c |    3 +--
 4 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100644 merge-file.h

diff --git a/Makefile b/Makefile
index 29243c6..19b6da1 100644
--- a/Makefile
+++ b/Makefile
@@ -296,7 +296,8 @@ LIB_H = \
 	diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \
 	run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
 	tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \
-	utf8.h reflog-walk.h patch-ids.h attr.h decorate.h progress.h mailmap.h
+	utf8.h reflog-walk.h patch-ids.h attr.h decorate.h progress.h \
+	mailmap.h merge-file.h
 
 DIFF_OBJS = \
 	diff.o diff-lib.o diffcore-break.o diffcore-order.o \
diff --git a/merge-file.c b/merge-file.c
index 748d15c..7bfefe7 100644
--- a/merge-file.c
+++ b/merge-file.c
@@ -2,6 +2,7 @@
 #include "run-command.h"
 #include "xdiff-interface.h"
 #include "blob.h"
+#include "merge-file.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
diff --git a/merge-file.h b/merge-file.h
new file mode 100644
index 0000000..a503c90
--- /dev/null
+++ b/merge-file.h
@@ -0,0 +1,8 @@
+#ifndef MERGE_FILE_H
+#define MERGE_FILE_H
+
+#include "blob.h"
+
+extern void *merge_file(struct blob *, struct blob *, struct blob *, unsigned long *);
+
+#endif
diff --git a/merge-tree.c b/merge-tree.c
index 3b8d9e6..93c8f54 100644
--- a/merge-tree.c
+++ b/merge-tree.c
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "xdiff-interface.h"
 #include "blob.h"
+#include "merge-file.h"
 
 static const char merge_tree_usage[] = "git-merge-tree <base-tree> <branch1> <branch2>";
 static int resolve_directories = 1;
@@ -53,8 +54,6 @@ static const char *explanation(struct merge_list *entry)
 	return "removed in remote";
 }
 
-extern void *merge_file(struct blob *, struct blob *, struct blob *, unsigned long *);
-
 static void *result(struct merge_list *entry, unsigned long *size)
 {
 	enum object_type type;
-- 
1.5.2

^ permalink raw reply related

* [RFC][PATCH 04/10] Sparse: fix some "symbol not declared" warnings (Part 2)
From: Ramsay Jones @ 2007-06-08 22:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


The complete warning message reads something like:

    symbol 'whatever' was not declared. Should be static?

In this commit, the answer is yes; all of these symbols have
no need to be visible beyond the compilation unit, so make
them static.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 builtin-branch.c |    4 ++--
 builtin-revert.c |    6 +++---
 commit.c         |    2 +-
 daemon.c         |    2 +-
 refs.c           |    2 +-
 upload-pack.c    |    2 +-
 wt-status.c      |    2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index 7408285..b2104fe 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -55,7 +55,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
 	die("bad config variable '%s'", var);
 }
 
-int git_branch_config(const char *var, const char *value)
+static int git_branch_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "color.branch")) {
 		branch_use_color = git_config_colorbool(var, value);
@@ -72,7 +72,7 @@ int git_branch_config(const char *var, const char *value)
 	return git_default_config(var, value);
 }
 
-const char *branch_get_color(enum color_branch ix)
+static const char *branch_get_color(enum color_branch ix)
 {
 	if (branch_use_color)
 		return branch_colors[ix];
diff --git a/builtin-revert.c b/builtin-revert.c
index ea2f15b..f58d32e 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -25,7 +25,7 @@ static const char *cherry_pick_usage = "git-cherry-pick [--edit] [-n] [-r] [-x]
 
 static int edit;
 static int replay;
-enum { REVERT, CHERRY_PICK } action;
+static enum { REVERT, CHERRY_PICK } action;
 static int no_commit;
 static struct commit *commit;
 static int needed_deref;
@@ -104,7 +104,7 @@ static char *get_oneline(const char *message)
 	return result;
 }
 
-char *get_encoding(const char *message)
+static char *get_encoding(const char *message)
 {
 	const char *p = message, *eol;
 
@@ -126,7 +126,7 @@ char *get_encoding(const char *message)
 	return NULL;
 }
 
-struct lock_file msg_file;
+static struct lock_file msg_file;
 static int msg_fd;
 
 static void add_to_msg(const char *string)
diff --git a/commit.c b/commit.c
index bee066f..be0c76d 100644
--- a/commit.c
+++ b/commit.c
@@ -27,7 +27,7 @@ struct sort_node
 
 const char *commit_type = "commit";
 
-struct cmt_fmt_map {
+static struct cmt_fmt_map {
 	const char *n;
 	size_t cmp_len;
 	enum cmit_fmt v;
diff --git a/daemon.c b/daemon.c
index b79e905..64f1f34 100644
--- a/daemon.c
+++ b/daemon.c
@@ -439,7 +439,7 @@ static void parse_extra_args(struct interp *table, char *extra_args, int buflen)
 	}
 }
 
-void fill_in_extra_table_entries(struct interp *itable)
+static void fill_in_extra_table_entries(struct interp *itable)
 {
 	char *hp;
 
diff --git a/refs.c b/refs.c
index 89876bf..820e6ac 100644
--- a/refs.c
+++ b/refs.c
@@ -150,7 +150,7 @@ static struct ref_list *sort_ref_list(struct ref_list *list)
  * Future: need to be in "struct repository"
  * when doing a full libification.
  */
-struct cached_refs {
+static struct cached_refs {
 	char did_loose;
 	char did_packed;
 	struct ref_list *loose;
diff --git a/upload-pack.c b/upload-pack.c
index d3a09e7..1046ea9 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -62,7 +62,7 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 	return safe_write(fd, data, sz);
 }
 
-FILE *pack_pipe = NULL;
+static FILE *pack_pipe = NULL;
 static void show_commit(struct commit *commit)
 {
 	if (commit->object.flags & BOUNDARY)
diff --git a/wt-status.c b/wt-status.c
index a055990..fd8a877 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -197,7 +197,7 @@ static void wt_read_cache(struct wt_status *s)
 	read_cache();
 }
 
-void wt_status_print_initial(struct wt_status *s)
+static void wt_status_print_initial(struct wt_status *s)
 {
 	int i;
 	char buf[PATH_MAX];
-- 
1.5.2

^ permalink raw reply related

* [RFC][PATCH 03/10] Sparse: fix some "symbol not declared" warnings (Part 1)
From: Ramsay Jones @ 2007-06-08 22:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


The complete warning message reads something like:

    symbol 'whatever' was not declared. Should be static?

In this commit, the answer is no; the various cmd_something()
functions have been correctly declared in "builtin.h". However,
the header file has not been included in the source, which
elicits the above warning from sparse.

Also, cmd_for_each_ref(), cmd_fsck() and cmd_merge_file() required
some tweaks to their declaration, in order to conform to the
correct prototype.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 builtin-bundle.c         |    1 +
 builtin-checkout-index.c |    1 +
 builtin-fetch--tool.c    |    1 +
 builtin-for-each-ref.c   |    3 ++-
 builtin-fsck.c           |    3 ++-
 builtin-gc.c             |    1 +
 builtin-merge-base.c     |    1 +
 builtin-merge-file.c     |    7 ++++---
 builtin-pack-refs.c      |    1 +
 builtin-rerere.c         |    1 +
 builtin-runstatus.c      |    1 +
 builtin-show-ref.c       |    1 +
 12 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/builtin-bundle.c b/builtin-bundle.c
index 306ad29..375e3ef 100644
--- a/builtin-bundle.c
+++ b/builtin-bundle.c
@@ -5,6 +5,7 @@
 #include "revision.h"
 #include "list-objects.h"
 #include "run-command.h"
+#include "builtin.h"
 
 /*
  * Basic handler for bundle files to connect repositories via sneakernet.
diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c
index 8460f97..3a0c0ac 100644
--- a/builtin-checkout-index.c
+++ b/builtin-checkout-index.c
@@ -40,6 +40,7 @@
 #include "strbuf.h"
 #include "quote.h"
 #include "cache-tree.h"
+#include "builtin.h"
 
 #define CHECKOUT_ALL 4
 static int line_termination = '\n';
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index 12adb38..a1d51d0 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "commit.h"
+#include "builtin.h"
 
 #define CHUNK_SIZE 1024
 
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 2b21842..3ca77b5 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -6,6 +6,7 @@
 #include "tree.h"
 #include "blob.h"
 #include "quote.h"
+#include "builtin.h"
 
 /* Quoting styles */
 #define QUOTE_NONE 0
@@ -796,7 +797,7 @@ static struct ref_sort *default_sort(void)
 	return sort;
 }
 
-int cmd_for_each_ref(int ac, const char **av, char *prefix)
+int cmd_for_each_ref(int ac, const char **av, const char *prefix)
 {
 	int i, num_refs;
 	const char *format = NULL;
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 44ce629..776a435 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -7,6 +7,7 @@
 #include "pack.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
+#include "builtin.h"
 
 #define REACHABLE 0x0001
 #define SEEN      0x0002
@@ -607,7 +608,7 @@ static const char fsck_usage[] =
 "git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
 "[--strict] <head-sha1>*]";
 
-int cmd_fsck(int argc, char **argv, const char *prefix)
+int cmd_fsck(int argc, const char **argv, const char *prefix)
 {
 	int i, heads;
 
diff --git a/builtin-gc.c b/builtin-gc.c
index 3b1f8c2..2ca5e77 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -12,6 +12,7 @@
 
 #include "cache.h"
 #include "run-command.h"
+#include "builtin.h"
 
 #define FAILED_RUN "failed to run %s"
 
diff --git a/builtin-merge-base.c b/builtin-merge-base.c
index e35d362..f026e5a 100644
--- a/builtin-merge-base.c
+++ b/builtin-merge-base.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "commit.h"
+#include "builtin.h"
 
 static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
 {
diff --git a/builtin-merge-file.c b/builtin-merge-file.c
index 9135773..a3830c3 100644
--- a/builtin-merge-file.c
+++ b/builtin-merge-file.c
@@ -1,13 +1,14 @@
 #include "cache.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
+#include "builtin.h"
 
 static const char merge_file_usage[] =
 "git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
 
-int cmd_merge_file(int argc, char **argv, char **envp)
+int cmd_merge_file(int argc, const char **argv, const char *prefix)
 {
-	char *names[3];
+	const char *names[3];
 	mmfile_t mmfs[3];
 	mmbuffer_t result = {NULL, 0};
 	xpparam_t xpp = {XDF_NEED_MINIMAL};
@@ -47,7 +48,7 @@ int cmd_merge_file(int argc, char **argv, char **envp)
 		free(mmfs[i].ptr);
 
 	if (ret >= 0) {
-		char *filename = argv[1];
+		const char *filename = argv[1];
 		FILE *f = to_stdout ? stdout : fopen(filename, "wb");
 
 		if (!f)
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index d080e30..1a7d131 100644
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
@@ -2,6 +2,7 @@
 #include "refs.h"
 #include "object.h"
 #include "tag.h"
+#include "builtin.h"
 
 static const char builtin_pack_refs_usage[] =
 "git-pack-refs [--all] [--prune | --no-prune]";
diff --git a/builtin-rerere.c b/builtin-rerere.c
index 8c2c8bd..c4d4178 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -2,6 +2,7 @@
 #include "path-list.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
+#include "builtin.h"
 
 #include <time.h>
 
diff --git a/builtin-runstatus.c b/builtin-runstatus.c
index 4b489b1..d7b04cb 100644
--- a/builtin-runstatus.c
+++ b/builtin-runstatus.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "wt-status.h"
+#include "builtin.h"
 
 extern int wt_status_use_color;
 
diff --git a/builtin-show-ref.c b/builtin-show-ref.c
index 9463ff0..f70e9a2 100644
--- a/builtin-show-ref.c
+++ b/builtin-show-ref.c
@@ -3,6 +3,7 @@
 #include "object.h"
 #include "tag.h"
 #include "path-list.h"
+#include "builtin.h"
 
 static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<length>]] [--abbrev[=<length>]] [--tags] [--heads] [--] [pattern*] < ref-list";
 
-- 
1.5.2

^ permalink raw reply related

* [RFC][PATCH 08/10] Sparse: fix an "incorrect type in argument n" warning
From: Ramsay Jones @ 2007-06-08 22:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


In particular, the warning referred to argument 3 in a call to
accept() and alluded to the type of the actual and formal arguments
being of a different signedness. The type of the formal parameter
of accept is (socklen_t *), rather than (unsigned int *) as used
here, so make the necessary changes to use socklen_t in the
appropriate places.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 daemon.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/daemon.c b/daemon.c
index 64f1f34..9daa850 100644
--- a/daemon.c
+++ b/daemon.c
@@ -604,11 +604,11 @@ static unsigned int children_deleted;
 
 static struct child {
 	pid_t pid;
-	int addrlen;
+	socklen_t addrlen;
 	struct sockaddr_storage address;
 } live_child[MAX_CHILDREN];
 
-static void add_child(int idx, pid_t pid, struct sockaddr *addr, int addrlen)
+static void add_child(int idx, pid_t pid, struct sockaddr *addr, socklen_t addrlen)
 {
 	live_child[idx].pid = pid;
 	live_child[idx].addrlen = addrlen;
@@ -702,7 +702,7 @@ static void check_max_connections(void)
 	}
 }
 
-static void handle(int incoming, struct sockaddr *addr, int addrlen)
+static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 {
 	pid_t pid = fork();
 
@@ -917,7 +917,7 @@ static int service_loop(int socknum, int *socklist)
 		for (i = 0; i < socknum; i++) {
 			if (pfd[i].revents & POLLIN) {
 				struct sockaddr_storage ss;
-				unsigned int sslen = sizeof(ss);
+				socklen_t sslen = sizeof(ss);
 				int incoming = accept(pfd[i].fd, (struct sockaddr *)&ss, &sslen);
 				if (incoming < 0) {
 					switch (errno) {
-- 
1.5.2

^ permalink raw reply related

* [RFC][PATCH 09/10] Sparse: fix some "symbol 's' shadows an earlier one" warnings
From: Ramsay Jones @ 2007-06-08 22:25 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 builtin-apply.c         |   18 +++++++++---------
 builtin-blame.c         |    3 ++-
 builtin-diff.c          |    1 -
 builtin-fetch--tool.c   |    3 +--
 builtin-fmt-merge-msg.c |    2 +-
 builtin-for-each-ref.c  |   10 +++++-----
 builtin-fsck.c          |    7 +++----
 builtin-grep.c          |    6 +++---
 builtin-mailinfo.c      |   16 ++++++++--------
 builtin-pack-objects.c  |   10 +++++-----
 builtin-show-branch.c   |    8 +++++---
 combine-diff.c          |    2 +-
 config.c                |    4 ++--
 convert-objects.c       |   10 +++++-----
 daemon.c                |    1 -
 fetch-pack.c            |   16 ++++++++--------
 fetch.c                 |    6 +++---
 pack-check.c            |    9 ++++-----
 reflog-walk.c           |    6 +++---
 revision.c              |    4 ++--
 20 files changed, 70 insertions(+), 72 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 0399743..5700d43 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1393,7 +1393,7 @@ static const char minuses[]= "--------------------------------------------------
 
 static void show_stats(struct patch *patch)
 {
-	const char *prefix = "";
+	const char *intro = "";
 	char *name = patch->new_name;
 	char *qname = NULL;
 	int len, max, add, del, total;
@@ -1416,7 +1416,7 @@ static void show_stats(struct patch *patch)
 		max = 50;
 	if (len > max) {
 		char *slash;
-		prefix = "...";
+		intro = "...";
 		max -= 3;
 		name += len - max;
 		slash = strchr(name, '/');
@@ -1442,9 +1442,9 @@ static void show_stats(struct patch *patch)
 		del = total - add;
 	}
 	if (patch->is_binary)
-		printf(" %s%-*s |  Bin\n", prefix, len, name);
+		printf(" %s%-*s |  Bin\n", intro, len, name);
 	else
-		printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
+		printf(" %s%-*s |%5d %.*s%.*s\n", intro,
 		       len, name, patch->lines_added + patch->lines_deleted,
 		       add, pluses, del, minuses);
 	free(qname);
@@ -1771,7 +1771,7 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
 			offset = -1;
 		if (offset >= 0) {
 			int diff = newsize - oldsize;
-			unsigned long size = desc->size + diff;
+			unsigned long buf_size = desc->size + diff;
 			unsigned long alloc = desc->alloc;
 
 			/* Warn if it was necessary to reduce the number
@@ -1783,16 +1783,16 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
 					" to apply fragment at %d\n",
 					leading, trailing, pos + lines);
 
-			if (size > alloc) {
-				alloc = size + 8192;
+			if (buf_size > alloc) {
+				alloc = buf_size + 8192;
 				desc->alloc = alloc;
 				buf = xrealloc(buf, alloc);
 				desc->buffer = buf;
 			}
-			desc->size = size;
+			desc->size = buf_size;
 			memmove(buf + offset + newsize,
 				buf + offset + oldsize,
-				size - offset - newsize);
+				buf_size - offset - newsize);
 			memcpy(buf + offset, newlines, newsize);
 			offset = 0;
 
diff --git a/builtin-blame.c b/builtin-blame.c
index 35471fc..d4d11a7 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -1185,7 +1185,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
 	int i, pass;
 	struct commit *commit = origin->commit;
 	struct commit_list *parent;
-	struct origin *parent_origin[MAXPARENT], *porigin;
+	struct origin *parent_origin[MAXPARENT];
 
 	memset(parent_origin, 0, sizeof(parent_origin));
 
@@ -1201,6 +1201,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
 		     i < MAXPARENT && parent;
 		     parent = parent->next, i++) {
 			struct commit *p = parent->item;
+			struct origin *porigin;
 			int j, same;
 
 			if (parent_origin[i])
diff --git a/builtin-diff.c b/builtin-diff.c
index e00a212..6a1c116 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -226,7 +226,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	 * default to HEAD by hand.  Eek.
 	 */
 	if (!rev.pending.nr) {
-		int i;
 		for (i = 1; i < argc; i++) {
 			const char *arg = argv[i];
 			if (!strcmp(arg, "--"))
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index a1d51d0..3b2b952 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -289,7 +289,7 @@ static int fetch_native_store(FILE *fp,
 			continue;
 		if (!strcmp(buffer, "keep")) {
 			char *od = get_object_directory();
-			int len = strlen(od) + strlen(cp) + 50;
+			len = strlen(od) + strlen(cp) + 50;
 			keep = xmalloc(len);
 			sprintf(keep, "%s/pack/pack-%s.keep", od, cp);
 			continue;
@@ -476,7 +476,6 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu
 	while (1) {
 		const char *next;
 		int rreflen;
-		int i;
 
 		while (*rref && isspace(*rref))
 			rref++;
diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index 5c145d2..a8b9b5b 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -138,7 +138,7 @@ static int handle_line(char *line)
 	}
 
 	if (!strcmp(".", src) || !strcmp(src, origin)) {
-		int len = strlen(origin);
+		len = strlen(origin);
 		if (origin[0] == '\'' && origin[len - 1] == '\'') {
 			char *new_origin = xmalloc(len - 1);
 			memcpy(new_origin, origin + 1, len - 2);
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 3ca77b5..b74e5f9 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -268,17 +268,17 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
 		}
 		else if (!strcmp(name, "parent")) {
 			int num = num_parents(commit);
-			int i;
+			int j;
 			struct commit_list *parents;
 			char *s = xmalloc(42 * num);
 			v->s = s;
-			for (i = 0, parents = commit->parents;
+			for (j = 0, parents = commit->parents;
 			     parents;
-			     parents = parents->next, i = i + 42) {
+			     parents = parents->next, j = j + 42) {
 				struct commit *parent = parents->item;
-				strcpy(s+i, sha1_to_hex(parent->object.sha1));
+				strcpy(s+j, sha1_to_hex(parent->object.sha1));
 				if (parents->next)
-					s[i+40] = ' ';
+					s[j+40] = ' ';
 			}
 		}
 	}
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 776a435..2a3890e 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -669,9 +669,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 			verify_pack(p, 0);
 
 		for (p = packed_git; p; p = p->next) {
-			uint32_t i, num = p->num_objects;
-			for (i = 0; i < num; i++)
-				fsck_sha1(nth_packed_object_sha1(p, i));
+			uint32_t j, num = p->num_objects;
+			for (j = 0; j < num; j++)
+				fsck_sha1(nth_packed_object_sha1(p, j));
 		}
 	}
 
@@ -708,7 +708,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	}
 
 	if (keep_cache_objects) {
-		int i;
 		read_cache();
 		for (i = 0; i < active_nr; i++) {
 			unsigned int mode;
diff --git a/builtin-grep.c b/builtin-grep.c
index e13cb31..84e346b 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -275,10 +275,10 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 			continue;
 		name = ce->name;
 		if (name[0] == '-') {
-			int len = ce_namelen(ce);
-			name = xmalloc(len + 3);
+			int name_len = ce_namelen(ce);
+			name = xmalloc(name_len + 3);
 			memcpy(name, "./", 2);
-			memcpy(name + 2, ce->name, len + 1);
+			memcpy(name + 2, ce->name, name_len + 1);
 		}
 		argv[argc++] = name;
 		if (argc < MAXARGS && !ce_stage(ce))
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index c95e477..8df8984 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -70,14 +70,14 @@ static int bogus_from(char *line)
 
 static int handle_from(char *in_line)
 {
-	char line[1000];
+	char from_line[1000];
 	char *at;
 	char *dst;
 
-	strcpy(line, in_line);
-	at = strchr(line, '@');
+	strcpy(from_line, in_line);
+	at = strchr(from_line, '@');
 	if (!at)
-		return bogus_from(line);
+		return bogus_from(from_line);
 
 	/*
 	 * If we already have one email, don't take any confusing lines
@@ -88,7 +88,7 @@ static int handle_from(char *in_line)
 	/* Pick up the string around '@', possibly delimited with <>
 	 * pair; that is the email part.  White them out while copying.
 	 */
-	while (at > line) {
+	while (at > from_line) {
 		char c = at[-1];
 		if (isspace(c))
 			break;
@@ -116,8 +116,8 @@ static int handle_from(char *in_line)
 	 * email part, so trim from both ends, possibly removing
 	 * the () pair at the end.
 	 */
-	at = line + strlen(line);
-	while (at > line) {
+	at = from_line + strlen(from_line);
+	while (at > from_line) {
 		unsigned char c = *--at;
 		if (!isspace(c)) {
 			at[(c == ')') ? 0 : 1] = 0;
@@ -125,7 +125,7 @@ static int handle_from(char *in_line)
 		}
 	}
 
-	at = line;
+	at = from_line;
 	for (;;) {
 		unsigned char c = *at;
 		if (!c || !isspace(c)) {
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 966f843..ccf583f 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1004,17 +1004,17 @@ static void add_pbase_object(struct tree_desc *tree,
 		}
 		if (S_ISDIR(entry.mode)) {
 			struct tree_desc sub;
-			struct pbase_tree_cache *tree;
+			struct pbase_tree_cache *t;
 			const char *down = name+cmplen+1;
 			int downlen = name_cmp_len(down);
 
-			tree = pbase_tree_get(entry.sha1);
-			if (!tree)
+			t = pbase_tree_get(entry.sha1);
+			if (!t)
 				return;
-			init_tree_desc(&sub, tree->tree_data, tree->tree_size);
+			init_tree_desc(&sub, t->tree_data, t->tree_size);
 
 			add_pbase_object(&sub, down, downlen, fullname);
-			pbase_tree_put(tree);
+			pbase_tree_put(t);
 		}
 	}
 }
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index c892f1f..3ec3448 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -875,9 +875,11 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 	all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
 
 	while (seen) {
-		struct commit *commit = pop_one_commit(&seen);
-		int this_flag = commit->object.flags;
-		int is_merge_point = ((this_flag & all_revs) == all_revs);
+		int this_flag, is_merge_point;
+
+		commit = pop_one_commit(&seen);
+		this_flag = commit->object.flags;
+		is_merge_point = ((this_flag & all_revs) == all_revs);
 
 		shown_merge_point |= is_merge_point;
 
diff --git a/combine-diff.c b/combine-diff.c
index ea3ca5f..63ea310 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -699,7 +699,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 			 !fstat(fd, &st)) {
 			size_t len = xsize_t(st.st_size);
 			size_t sz = 0;
-			int is_file, i;
+			int is_file;
 
 			elem->mode = canon_mode(st.st_mode);
 			/* if symlinks don't work, assume symlink if all parents
diff --git a/config.c b/config.c
index 5754ec2..5e6a675 100644
--- a/config.c
+++ b/config.c
@@ -152,7 +152,7 @@ static int get_extended_base_var(char *name, int baselen, int c)
 	name[baselen++] = '.';
 
 	for (;;) {
-		int c = get_next_char();
+		c = get_next_char();
 		if (c == '\n')
 			return -1;
 		if (c == '"')
@@ -753,7 +753,7 @@ int git_config_set_multivar(const char* key, const char* value,
 		struct stat st;
 		char* contents;
 		size_t contents_sz, copy_begin, copy_end;
-		int i, new_line = 0;
+		int new_line = 0;
 
 		if (value_regex == NULL)
 			store.value_regex = NULL;
diff --git a/convert-objects.c b/convert-objects.c
index cefbceb..90aecc4 100644
--- a/convert-objects.c
+++ b/convert-objects.c
@@ -180,15 +180,15 @@ static unsigned long parse_oldstyle_date(const char *buf)
 				return mktime(&tm);
 			buf = next;
 		} else {
-			const char **p = timezones;
+			const char **t = timezones;
 			while (isspace(*buf))
 				buf++;
-			while (*p) {
-				if (!memcmp(buf, *p, strlen(*p))) {
-					buf += strlen(*p);
+			while (*t) {
+				if (!memcmp(buf, *t, strlen(*t))) {
+					buf += strlen(*t);
 					break;
 				}
-				p++;
+				t++;
 			}
 		}
 		fmt++;
diff --git a/daemon.c b/daemon.c
index 9daa850..c09ab5c 100644
--- a/daemon.c
+++ b/daemon.c
@@ -903,7 +903,6 @@ static int service_loop(int socknum, int *socklist)
 	signal(SIGCHLD, child_handler);
 
 	for (;;) {
-		int i;
 
 		if (poll(pfd, socknum, -1) < 0) {
 			if (errno != EINTR) {
diff --git a/fetch-pack.c b/fetch-pack.c
index 75649a6..fc1696e 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -147,7 +147,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
 {
 	int fetching;
 	int count = 0, flushes = 0, retval;
-	const unsigned char *sha1;
+	const unsigned char *rev;
 	unsigned in_vain = 0;
 	int got_continue = 0;
 
@@ -223,10 +223,10 @@ static int find_common(int fd[2], unsigned char *result_sha1,
 
 	flushes = 0;
 	retval = -1;
-	while ((sha1 = get_rev())) {
-		packet_write(fd[1], "have %s\n", sha1_to_hex(sha1));
+	while ((rev = get_rev())) {
+		packet_write(fd[1], "have %s\n", sha1_to_hex(rev));
 		if (verbose)
-			fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
+			fprintf(stderr, "have %s\n", sha1_to_hex(rev));
 		in_vain++;
 		if (!(31 & ++count)) {
 			int ack;
@@ -759,7 +759,7 @@ int main(int argc, char **argv)
 	if (!ret && depth > 0) {
 		struct cache_time mtime;
 		char *shallow = git_path("shallow");
-		int fd;
+		int lock_fd;
 
 		mtime.sec = st.st_mtime;
 #ifdef USE_NSEC
@@ -775,12 +775,12 @@ int main(int argc, char **argv)
 			  )
 			die("shallow file was changed during fetch");
 
-		fd = hold_lock_file_for_update(&lock, shallow, 1);
-		if (!write_shallow_commits(fd, 0)) {
+		lock_fd = hold_lock_file_for_update(&lock, shallow, 1);
+		if (!write_shallow_commits(lock_fd, 0)) {
 			unlink(shallow);
 			rollback_lock_file(&lock);
 		} else {
-			close(fd);
+			close(lock_fd);
 			commit_lock_file(&lock);
 		}
 	}
diff --git a/fetch.c b/fetch.c
index 8e29d31..c2742f5 100644
--- a/fetch.c
+++ b/fetch.c
@@ -47,9 +47,9 @@ static int process_tree(struct tree *tree)
 		struct object *obj = NULL;
 
 		if (S_ISDIR(entry.mode)) {
-			struct tree *tree = lookup_tree(entry.sha1);
-			if (tree)
-				obj = &tree->object;
+			struct tree *t = lookup_tree(entry.sha1);
+			if (t)
+				obj = &t->object;
 		}
 		else {
 			struct blob *blob = lookup_blob(entry.sha1);
diff --git a/pack-check.c b/pack-check.c
index d04536b..ef7179e 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -7,7 +7,7 @@ static int verify_packfile(struct packed_git *p,
 	off_t index_size = p->index_size;
 	const unsigned char *index_base = p->index_data;
 	SHA_CTX ctx;
-	unsigned char sha1[20];
+	unsigned char pack_sha1[20];
 	off_t offset = 0, pack_sig = p->pack_size - 20;
 	uint32_t nr_objects, i;
 	int err;
@@ -27,11 +27,11 @@ static int verify_packfile(struct packed_git *p,
 			remaining -= (unsigned int)(offset - pack_sig);
 		SHA1_Update(&ctx, in, remaining);
 	}
-	SHA1_Final(sha1, &ctx);
-	if (hashcmp(sha1, use_pack(p, w_curs, pack_sig, NULL)))
+	SHA1_Final(pack_sha1, &ctx);
+	if (hashcmp(pack_sha1, use_pack(p, w_curs, pack_sig, NULL)))
 		return error("Packfile %s SHA1 mismatch with itself",
 			     p->pack_name);
-	if (hashcmp(sha1, index_base + index_size - 40))
+	if (hashcmp(pack_sha1, index_base + index_size - 40))
 		return error("Packfile %s SHA1 mismatch with idx",
 			     p->pack_name);
 	unuse_pack(w_curs);
@@ -46,7 +46,6 @@ static int verify_packfile(struct packed_git *p,
 		void *data;
 		enum object_type type;
 		unsigned long size;
-		off_t offset;
 
 		sha1 = nth_packed_object_sha1(p, i);
 		if (!sha1)
diff --git a/reflog-walk.c b/reflog-walk.c
index c983858..a2c1f17 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -240,11 +240,11 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
 	commit->object.flags &= ~(ADDED | SEEN | SHOWN);
 }
 
-void show_reflog_message(struct reflog_walk_info* info, int oneline,
+void show_reflog_message(struct reflog_walk_info* winfo, int oneline,
 	int relative_date)
 {
-	if (info && info->last_commit_reflog) {
-		struct commit_reflog *commit_reflog = info->last_commit_reflog;
+	if (winfo && winfo->last_commit_reflog) {
+		struct commit_reflog *commit_reflog = winfo->last_commit_reflog;
 		struct reflog_info *info;
 
 		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
diff --git a/revision.c b/revision.c
index 1bfe80c..13b7b37 100644
--- a/revision.c
+++ b/revision.c
@@ -79,9 +79,9 @@ void mark_tree_uninteresting(struct tree *tree)
 	tree->buffer = NULL;
 }
 
-void mark_parents_uninteresting(struct commit *commit)
+void mark_parents_uninteresting(struct commit *c)
 {
-	struct commit_list *parents = commit->parents;
+	struct commit_list *parents = c->parents;
 
 	while (parents) {
 		struct commit *commit = parents->item;
-- 
1.5.2

^ permalink raw reply related

* Re: git-p4 fails when cloning a p4 depo.
From: Han-Wen Nienhuys @ 2007-06-08 23:33 UTC (permalink / raw)
  To: git; +Cc: Scott Lamb
In-Reply-To: <1621f9fa0706081504l6106c639oe57c9fd74ebd097a@mail.gmail.com>

Benjamin Sergeant escreveu:

> So are you saying that in the old days, git-p4 was importing the p4
> depo in small slices to not overkill the process memory (in case the
> depo is big) ?

no, in the "old days" git-p4 used a separate p4 invocation for each file.

-- 
 Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen

^ permalink raw reply

* [PATCH] Port git-tag.sh to C.
From: Kristian Høgsberg @ 2007-06-08 22:45 UTC (permalink / raw)
  To: git; +Cc: Kristian Høgsberg

From: Kristian Høgsberg <krh@redhat.com>

A more or less straight-forward port of git-tag.sh to C.

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---

Ok, here's an updated version that passes the test suite.  Johannes, I
leave it to you and jasam to merge the bits you find useful, but as
far as I see it, this conversion is complete, and there's enough other
shell scripts to port.  My port doesn't pass jasam's test suite, it
looks like he is expecting the -l glob to be a regexp, but the
git-tag.sh I started from used shell globs.

Anyways, it'd be nice if you or jasam could keep the list a little
more in the loop with the SoC changes, it is where most of the
development happens, after all.  What's next on your list?

cheers,
Kristian

 Makefile      |    3 +-
 builtin-tag.c |  371 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h     |    1 +
 git-tag.sh    |  183 ----------------------------
 git.c         |    1 +
 5 files changed, 375 insertions(+), 184 deletions(-)
 create mode 100644 builtin-tag.c
 delete mode 100755 git-tag.sh

diff --git a/Makefile b/Makefile
index 0f75955..bb1bed1 100644
--- a/Makefile
+++ b/Makefile
@@ -205,7 +205,7 @@ SCRIPT_SH = \
 	git-pull.sh git-rebase.sh \
 	git-repack.sh git-request-pull.sh git-reset.sh \
 	git-sh-setup.sh \
-	git-tag.sh git-verify-tag.sh \
+	git-verify-tag.sh \
 	git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
@@ -372,6 +372,7 @@ BUILTIN_OBJS = \
 	builtin-show-branch.o \
 	builtin-stripspace.o \
 	builtin-symbolic-ref.o \
+	builtin-tag.o \
 	builtin-tar-tree.o \
 	builtin-unpack-objects.o \
 	builtin-update-index.o \
diff --git a/builtin-tag.c b/builtin-tag.c
new file mode 100644
index 0000000..26035f5
--- /dev/null
+++ b/builtin-tag.c
@@ -0,0 +1,371 @@
+/*
+ * Builtin "git tag"
+ *
+ * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
+ * Based on git-tag.sh and mktag.c by Linus Torvalds.
+ */
+
+#include "cache.h"
+#include "refs.h"
+#include "commit.h"
+#include "builtin.h"
+#include "tag.h"
+#include "run-command.h"
+
+static const char builtin_tag_usage[] =
+  "git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]";
+
+static char signingkey[1000];
+
+static int launch_editor(const char *path, const char *template,
+			  char *buffer, size_t size)
+{
+	struct child_process child;
+	const char *editor;
+	const char *args[3];
+	char *eol;
+	int len, fd, blank_lines, i, j;
+
+	fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644);
+	if (fd < 0)
+		die("could not create file %s.", path);
+
+	len = strlen(template);
+	write_or_die(fd, template, len);
+	close(fd);
+
+	editor = getenv("VISUAL");
+	if (!editor)
+		editor = getenv("EDITOR");
+	if (!editor)
+		editor = "vi";
+	    
+	memset(&child, 0, sizeof(child));
+	child.argv = args;
+	args[0] = editor;
+	args[1] = path;
+	args[2] = NULL;
+
+	if (run_command(&child))
+		die("could not launch editor %s.", editor);
+
+	fd = open(path, O_RDONLY, 0644);
+	if (fd == -1)
+		die("could not read %s.", path);
+	len = read_in_full(fd, buffer, size);
+	if (len < 0)
+		die("failed to read '%s', %m", path);
+	close(fd);
+
+	blank_lines = 1;
+	for (i = 0, j = 0; i < len; i++) {
+		if (blank_lines > 0 && buffer[i] == '#') {
+			eol = strchr(buffer + i, '\n');
+			if (!eol)
+				break;
+
+			i = eol - buffer;
+			continue;
+		}
+
+		if (buffer[i] == '\n') {
+			blank_lines++;
+			if (blank_lines > 1)
+				continue;
+		} else {
+			if (blank_lines > 2)
+				buffer[j++] = '\n';
+			blank_lines = 0;
+		}
+
+		buffer[j++] = buffer[i];
+	}
+
+	if (buffer[j - 1] != '\n')
+		buffer[j++] = '\n';
+
+	unlink(path);
+
+	return j;
+}
+
+static int show_reference(const char *refname, const unsigned char *sha1,
+			  int flag, void *cb_data)
+{
+	const char *pattern = cb_data;
+
+	if (pattern == NULL || !fnmatch(pattern, refname, 0))
+		printf("%s\n", refname);
+
+	return 0;
+}
+
+static int list_tags(const char *pattern)
+{
+	for_each_tag_ref(show_reference, (void *) pattern);
+
+	return 0;
+}
+
+
+static int delete_tags(const char **argv)
+{
+	const char **p;
+	char ref[PATH_MAX];
+	int had_error = 0;
+	unsigned char sha1[20];
+
+	for (p = argv; *p; p++) {
+		if (snprintf(ref, sizeof ref, "refs/tags/%s", *p) > sizeof ref)
+			die("tag name '%s' too long.", *p);
+		if (!resolve_ref(ref, sha1, 1, NULL)) {
+			fprintf(stderr, "tag '%s' not found.\n", *p);
+			had_error = 1;
+			continue;
+		}
+
+		if (!delete_ref(ref, sha1))
+			printf("Deleted tag '%s'\n", *p);
+	}
+			
+	return had_error;
+}
+
+static int verify_tags(const char **argv)
+{
+	const char **p;
+	char ref[PATH_MAX];
+	int had_error = 0;
+	unsigned char sha1[20];
+
+	for (p = argv; *p; p++) {
+		if (snprintf(ref, sizeof ref, "refs/tags/%s", *p) > sizeof ref)
+			die("tag name '%s' too long.", *p);
+
+		if (!resolve_ref(ref, sha1, 1, NULL)) {
+			fprintf(stderr, "tag '%s' not found.\n", *p);
+			had_error = 1;
+			continue;
+		}
+
+		printf("FIXME: verify tag '%s'\n", *p);
+	}
+
+	return had_error;
+}
+
+static int do_sign(char *buffer, size_t size, size_t max)
+{
+	struct child_process gpg;
+	const char *args[5];
+	char *bracket;
+	int len;
+
+	if (signingkey[0] == '\0') {
+		strlcpy(signingkey, git_committer_info(1), sizeof signingkey);
+		bracket = strchr(signingkey, '>');
+		if (bracket)
+			bracket[1] = '\0';
+	}
+
+	memset(&gpg, 0, sizeof(gpg));
+	gpg.argv = args;
+	gpg.in = -1;
+	gpg.out = -1;
+	args[0] = "gpg";
+	args[1] = "-bsa";
+	args[2] = "-u";
+	args[3] = signingkey;
+	args[4] = NULL;
+		
+	if (start_command(&gpg))
+		die("could not run gpg.");
+
+	write_or_die(gpg.in, buffer, size);
+	close(gpg.in);
+	gpg.close_in = 0;
+	len = read_in_full(gpg.out, buffer + size, max - size);
+
+	finish_command(&gpg);
+
+	return size + len;
+}
+
+static const char tag_template[] =
+	"\n"
+	"#\n"
+	"# Write a tag message\n"
+	"#\n";
+
+static int git_tag_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "user.signingkey")) {
+		if (!value)
+			die("user.signingkey without value");
+		strlcpy(signingkey, value, sizeof signingkey);
+		return 0;
+	}
+
+	return git_default_config(var, value);
+}
+
+static void create_tag(const unsigned char *object, const char *tag,
+		       const char *message, int sign, unsigned char *result)
+{
+	enum object_type type;
+	char buffer[4096];
+	int header, body, total;
+
+	type = sha1_object_info(object, NULL);
+	if (type <= 0)
+	    die("bad object type.");
+
+	header = snprintf(buffer, sizeof buffer,
+			  "object %s\n"
+			  "type %s\n"
+			  "tag %s\n"
+			  "tagger %s\n\n",
+			  sha1_to_hex(object),
+			  typename(type),
+			  tag,
+			  git_committer_info(1));
+
+	if (message == NULL)
+		body = launch_editor(git_path("TAGMSG"), tag_template,
+				     buffer + header, sizeof buffer - header);
+	else
+		body = snprintf(buffer + header, sizeof buffer - header,
+				"%s\n", message);
+
+	if (body == 0)
+		die("no tag message?");
+
+	if (header + body > sizeof buffer)
+		die("tag message too big.");
+
+	if (sign)
+		total = do_sign(buffer, header + body, sizeof buffer);
+	else
+		total = header + body;
+
+	if (write_sha1_file(buffer, total, tag_type, result) < 0)
+		die("unable to write tag file");
+}
+
+int cmd_tag(int argc, const char **argv, const char *prefix)
+{
+	unsigned char object[20], prev[20], result[20];
+	int annotate = 0, sign = 0, force = 0, lines = 0;
+	const char *message = NULL;
+	char ref[PATH_MAX];
+	const char *object_ref, *tag;
+	int i, fd;
+	struct ref_lock *lock;
+
+	git_config(git_tag_config);
+
+	for (i = 1; i < argc; i++) {
+		const char *arg = argv[i];
+
+		if (arg[0] != '-')
+			break;
+		if (!strcmp(arg, "-a")) {
+			annotate = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-s")) {
+			annotate = 1;
+			sign = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-f")) {
+			force = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-n")) {
+			if (i + 1 == argc || *argv[i + 1] == '-')
+				/* no argument */
+				lines = 1;
+			else
+				/* FIXME, fallback to 1 on invalid integer */
+				lines = atoi(argv[i + 1]);
+			continue;
+		}
+		if (!strcmp(arg, "-m")) {
+			annotate = 1;
+			i++;
+			if  (i == argc)
+				die("option -m needs an argument.");
+			message = argv[i];
+			continue;
+		}
+		if (!strcmp(arg, "-F")) {
+			annotate = 1;
+			i++;
+			if  (i == argc)
+				die("option -F needs an argument.");
+
+			fd = open(argv[i], O_RDONLY);
+			if (fd < 0)
+				die("cannot open %s", argv[1]);
+
+			message = xmalloc(4096);
+			if (read_in_full(fd, (char *) message, 4096) < 0)
+				die("cannot read %s", argv[1]);
+			continue;
+		}
+		if (!strcmp(arg, "-u")) {
+			annotate = 1;
+			sign = 1;
+			i++;
+			if  (i == argc)
+				die("option -u needs an argument.");
+			strlcpy(signingkey, argv[i], sizeof signingkey);
+			continue;
+		}
+		if (!strcmp(arg, "-l")) {
+			return list_tags(argv[i + 1]);
+		}
+		if (!strcmp(arg, "-d")) {
+			return delete_tags(argv + i + 1);
+		}
+		if (!strcmp(arg, "-v")) {
+			return verify_tags(argv + i + 1);
+		}
+		usage(builtin_tag_usage);
+	}
+
+	if (i == argc)
+		return list_tags(NULL);
+	tag = argv[i++];
+
+	if (i < argc)
+		object_ref = argv[i];
+	else
+		object_ref = "HEAD";
+
+	if (get_sha1(object_ref, object))
+		die("Failed to resolve '%s' as a valid ref.", object_ref);
+
+	if (snprintf(ref, sizeof ref, "refs/tags/%s", tag) > sizeof ref)
+		die("tag '%s' too long.", tag);
+	if (check_ref_format(ref))
+		die("'%s' is not a valid tag name.", tag);
+	if (resolve_ref(ref, prev, 1, NULL)) {
+		if (!force)
+			die("tag '%s' already exists", tag);
+	} else {
+		hashclr(prev);
+	}
+
+	if (annotate)
+		create_tag(object, tag, message, sign, object);
+
+	lock = lock_any_ref_for_update(ref, prev, 0);
+	if (!lock)
+		die("%s: cannot lock the ref", ref);
+	if (write_ref_sha1(lock, object, NULL) < 0)
+		die("%s: cannot update the ref", ref);
+
+	return 0;
+}
diff --git a/builtin.h b/builtin.h
index 39290d1..91166e1 100644
--- a/builtin.h
+++ b/builtin.h
@@ -72,6 +72,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
+extern int cmd_tag(int argc, const char **argv, const char *prefix);
 extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_update_index(int argc, const char **argv, const char *prefix);
diff --git a/git-tag.sh b/git-tag.sh
deleted file mode 100755
index 37cee97..0000000
--- a/git-tag.sh
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2005 Linus Torvalds
-
-USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
-SUBDIRECTORY_OK='Yes'
-. git-sh-setup
-
-message_given=
-annotate=
-signed=
-force=
-message=
-username=
-list=
-verify=
-LINES=0
-while case "$#" in 0) break ;; esac
-do
-    case "$1" in
-    -a)
-	annotate=1
-	;;
-    -s)
-	annotate=1
-	signed=1
-	;;
-    -f)
-	force=1
-	;;
-    -n)
-        case $2 in
-	-*)	LINES=1 	# no argument
-		;;
-	*)	shift
-		LINES=$(expr "$1" : '\([0-9]*\)')
-		[ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
-		;;
-	esac
-	;;
-    -l)
-	list=1
-	shift
-	PATTERN="$1"	# select tags by shell pattern, not re
-	git rev-parse --symbolic --tags | sort |
-	    while read TAG
-	    do
-	        case "$TAG" in
-		*$PATTERN*) ;;
-		*)	    continue ;;
-		esac
-		[ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
-		OBJTYPE=$(git cat-file -t "$TAG")
-		case $OBJTYPE in
-		tag)	ANNOTATION=$(git cat-file tag "$TAG" |
-				       sed -e '1,/^$/d' \
-					   -e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
-			printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
-			  sed -e '2,$s/^/    /' \
-			      -e "${LINES}q"
-			;;
-		*)      echo "$TAG"
-			;;
-		esac
-	    done
-	;;
-    -m)
-    	annotate=1
-	shift
-	message="$1"
-	if test "$#" = "0"; then
-	    die "error: option -m needs an argument"
-	else
-	    message_given=1
-	fi
-	;;
-    -F)
-	annotate=1
-	shift
-	if test "$#" = "0"; then
-	    die "error: option -F needs an argument"
-	else
-	    message="$(cat "$1")"
-	    message_given=1
-	fi
-	;;
-    -u)
-	annotate=1
-	signed=1
-	shift
-	username="$1"
-	;;
-    -d)
-    	shift
-	had_error=0
-	for tag
-	do
-		cur=$(git-show-ref --verify --hash -- "refs/tags/$tag") || {
-			echo >&2 "Seriously, what tag are you talking about?"
-			had_error=1
-			continue
-		}
-		git-update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
-			had_error=1
-			continue
-		}
-		echo "Deleted tag $tag."
-	done
-	exit $had_error
-	;;
-    -v)
-	shift
-	tag_name="$1"
-	tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
-		die "Seriously, what tag are you talking about?"
-	git-verify-tag -v "$tag"
-	exit $?
-	;;
-    -*)
-        usage
-	;;
-    *)
-	break
-	;;
-    esac
-    shift
-done
-
-[ -n "$list" ] && exit 0
-
-name="$1"
-[ "$name" ] || usage
-prev=0000000000000000000000000000000000000000
-if git-show-ref --verify --quiet -- "refs/tags/$name"
-then
-    test -n "$force" || die "tag '$name' already exists"
-    prev=`git rev-parse "refs/tags/$name"`
-fi
-shift
-git-check-ref-format "tags/$name" ||
-	die "we do not like '$name' as a tag name."
-
-object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
-type=$(git-cat-file -t $object) || exit 1
-tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
-
-test -n "$username" ||
-	username=$(git-repo-config user.signingkey) ||
-	username=$(expr "z$tagger" : 'z\(.*>\)')
-
-trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
-
-if [ "$annotate" ]; then
-    if [ -z "$message_given" ]; then
-        ( echo "#"
-          echo "# Write a tag message"
-          echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
-        ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
-    else
-        printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
-    fi
-
-    grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
-    git-stripspace >"$GIT_DIR"/TAG_FINALMSG
-
-    [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
-	echo >&2 "No tag message?"
-	exit 1
-    }
-
-    ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
-	"$object" "$type" "$name" "$tagger";
-      cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
-    rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
-    if [ "$signed" ]; then
-	gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
-	cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
-	die "failed to sign the tag with GPG."
-    fi
-    object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
-fi
-
-git update-ref "refs/tags/$name" "$object" "$prev"
-
diff --git a/git.c b/git.c
index 29b55a1..c9c20fb 100644
--- a/git.c
+++ b/git.c
@@ -285,6 +285,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
+		{ "tag", cmd_tag, RUN_SETUP },
 		{ "tar-tree", cmd_tar_tree },
 		{ "unpack-objects", cmd_unpack_objects, RUN_SETUP },
 		{ "update-index", cmd_update_index, RUN_SETUP },
-- 
1.5.0.6

^ permalink raw reply related

* [PATCH] git-p4import.py: handle paths with symlinks
From: Kevin Green @ 2007-06-08 22:33 UTC (permalink / raw)
  To: git

Need to expand symlinks when checking if the p4 client is misconfigured
for the local git dir.

Signed-off-by: Kevin Green <Kevin.Green@morganstanley.com>
---
 git-p4import.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-p4import.py b/git-p4import.py
index 0f3d97b..ad15708 100644
--- a/git-p4import.py
+++ b/git-p4import.py
@@ -312,7 +312,7 @@ for o, a in opts:
         p4.authors(a)

 localdir = git.basedir()
-if p4.where()[:len(localdir)] != localdir:
+if os.path.realpath(os.path.dirname(p4.where())) != os.path.realpath(localdir):
     report(1, "**WARNING** Appears p4 client is misconfigured")
     report(1, "   for sync from %s to %s" % (p4.repopath, localdir))
     if ignore_warnings != True:
--
1.5.2.1

^ permalink raw reply related

* Re: [PATCH] Port git-tag.sh to C.
From: Matthijs Melchior @ 2007-06-08 22:39 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Kristian Høgsberg, git
In-Reply-To: <Pine.LNX.4.64.0706082249040.4059@racer.site>

Hi,

Johannes Schindelin wrote:
> Hi,
> 
> On Fri, 8 Jun 2007, Kristian Høgsberg wrote:
> 
>> A more or less straight-forward port of git-tag.sh to C.
> 
> It is somewhat unfortunate that you did not say that you were working on 
> this stuff; we have a Google Summer of Code project going on, which tries 
> to port many scripts to builtins.
> 
> As it happens, I am working with jasam on exactly the same script.
> 
> Pity,
> Dscho

Please consider the idea of showing (part of) the tag annotation with
git-tag as well.

See message archived at:
   http://permalink.gmane.org/gmane.comp.version-control.git/48962

Thanks,
	Matthijs Melchior.

^ permalink raw reply

* Re: git-p4 fails when cloning a p4 depo.
From: Simon Hausmann @ 2007-06-08 22:38 UTC (permalink / raw)
  To: Han-Wen Nienhuys; +Cc: Benjamin Sergeant, git
In-Reply-To: <1621f9fa0706081113w7bb765ebx74f03a7407b753cb@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 948 bytes --]

On Friday 08 June 2007 20:13:55 Benjamin Sergeant wrote:
> A perforce command with all the files in the repo is generated to get
> all the file content.
> Here is a patch to break it into multiple successive perforce command
> who uses 4K of parameter max, and collect the output for later.
>
> It works, but not for big depos, because the whole perforce depo
> content is stored in memory in P4Sync.run(), and it looks like mine is
> bigger than 2 Gigs, so I had to kill the process.

I'd be generally fine with splitting up the "p4 print ..." calls into chunks 
but you have a good point with the memory usage. The old approach of calling 
print per file did not have any of those limitations. Han-Wen, what do you 
think? How much of a performance improvement is the batched print?

(I didn't notice any immediate difference, but then I have a very fast 
connection to the perforce server and usually small changesets)

Simon

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply

* Re: [PATCH] Port git-tag.sh to C.
From: Carlos Rica @ 2007-06-08 22:36 UTC (permalink / raw)
  To: Kristian Høgsberg; +Cc: Johannes Schindelin, git
In-Reply-To: <1181340320.30683.30.camel@hinata.boston.redhat.com>

2007/6/9, Kristian Høgsberg <krh@redhat.com>:
> Ugh, yeah... wasted effort...  I didn't see anything about the SoC
> project on the list and I didn't pre-announce my work because I only
> spent little more than half a day...

Sorry, it should have been announced before this could happen.

> > As it happens, I am working with jasam on exactly the same script.

We were doing a conservative work to get exactly the same options
and behaviour that git-tag.sh does. The work is now almost finished,
so you could help us comparing the two versions to see how could
end with a better git-tag. It would be fantastic if we could point what
parts of my code can be enhanced with those of yours.

My test suite can also be run against the git-tag.sh code now, you
can check check your code with it. Feel free to say everything you want
about it!

Carlos

^ permalink raw reply

* [RFC][PATCH 01/10] Sparse: fix "non-ANSI function declaration" warnings
From: Ramsay Jones @ 2007-06-08 22:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 config.c          |    2 +-
 merge-recursive.c |    2 +-
 sha1_file.c       |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index 7b655fd..5754ec2 100644
--- a/config.c
+++ b/config.c
@@ -512,7 +512,7 @@ static int store_aux(const char* key, const char* value)
 	return 0;
 }
 
-static int write_error()
+static int write_error(void)
 {
 	fprintf(stderr, "Failed to write new configuration file\n");
 
diff --git a/merge-recursive.c b/merge-recursive.c
index 8f72b2c..2042004 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -127,7 +127,7 @@ static void output(int v, const char *fmt, ...)
 	va_end(args);
 }
 
-static void flush_output()
+static void flush_output(void)
 {
 	struct output_buffer *b, *n;
 	for (b = output_list; b; b = n) {
diff --git a/sha1_file.c b/sha1_file.c
index be991ed..7b77468 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -412,7 +412,7 @@ static size_t peak_pack_mapped;
 static size_t pack_mapped;
 struct packed_git *packed_git;
 
-void pack_report()
+void pack_report(void)
 {
 	fprintf(stderr,
 		"pack_report: getpagesize()            = %10" SZ_FMT "\n"
-- 
1.5.2

^ permalink raw reply related

* [RFC][PATCH 00/10] Sparse: Git's "make check" target
From: Ramsay Jones @ 2007-06-08 22:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list, Josh Triplett

Hi Junio,

Since the Git Makefile has a "check" target that uses sparse, I decided to
take a look at the sparse project to see what it was about, and what it
has to say about the git source code.

Initially, I had many problems because I am using cygwin, but I was able to
fix most of those problems. (the output from "make check" was about 16k lines
at one point!). Git also tickled a bug in sparse 0.2, which resulted in some
120+ lines of bogus warnings; that was fixed in version 0.3 (commit 0.2-15-gef25961).
As a result, sparse version 0.3 + my patches, elicits 106 lines of output
from "make check".

Naturally, I decided to "fix" the warnings produced by sparse, which resulted
in the following patch series:

[PATCH 01/10] Sparse: fix "non-ANSI function declaration" warnings
[PATCH 02/10] Sparse: fix some "using integer as NULL pointer" warnings
[PATCH 03/10] Sparse: fix some "symbol not declared" warnings (Part 1)
[PATCH 04/10] Sparse: fix some "symbol not declared" warnings (Part 2)
[PATCH 05/10] Sparse: fix some "symbol not declared" warnings (Part 3)
[PATCH 06/10] Sparse: fix "'add_head' not declared" warning
[PATCH 07/10] Sparse: fix "'merge_file' not declared" warning
[PATCH 08/10] Sparse: fix an "incorrect type in argument n" warning
[PATCH 09/10] Sparse: fix some "symbol 's' shadows an earlier one" warnings
[PATCH 10/10] Sparse: fix a "symbol 'weak_match' shadows an earlier one" warning

However, this patch series does not completely remove all warnings; the output
is reduced to:

builtin-pack-objects.c:312:31: warning: Using plain integer as NULL pointer
csum-file.c:152:22: warning: Using plain integer as NULL pointer
exec_cmd.c:7:40: error: undefined identifier 'GIT_EXEC_PATH'
git.c:209:35: error: undefined identifier 'GIT_VERSION'
http.c:203:46: error: undefined identifier 'GIT_USER_AGENT'
index-pack.c:201:25: warning: Using plain integer as NULL pointer
index-pack.c:538:26: warning: Using plain integer as NULL pointer

The three "undefined identifier 'GIT_...'" are easy to remove, I just didn't
get around to doing it (The GIT_... symbols are macros, defined in individual
make rules rather than CFLAGS, an thus not passed to sparse).

The four "Using plain integer...", whilst equally easy to remove, arguably should
not be ;-)  If you look at the code you will find they are all of the form
    x = crc32(0, Z_NULL, 0);
where the second parameter type is basically (unsigned char *) and the Z_NULL
macro is defined in the zlib header file as 0.  It could be said that this is
"idiomatic zlib usage" and should remain as written.  If you don't subscribe
to that view, then the required patch is obvious :P)

The above is one reason why this is an RFC series.  With one notable exception,
the patches do not fix a bug, add a feature or alter the program behaviour.
The only thing they do is remove sparse warnings; so you really have to believe
that this is a worthwhile thing to do, otherwise they are worthless!

[Note: As far as the NULL pointer warnings are concerned, I don't much care either
way. I just used that as an example (also note patch 02). Having said that, I
do think that the "NULL is the only one true null pointer" brigade need to
chill out a little; in fact I remember when 0 was the *only* null pointer.]

Another reason for the RFC, is that the patches are against the v1.5.2 tar-ball.
Since this was released a few weeks ago, the patches may not apply cleanly to
current git. (Yes, I really need to bite the bullet and get a broadband
connection so that I can clone the git repo.)

Also, that "one notable exception" is patch 10, which fixes a bug caused by a
"shadow" declaration.  Unfortunately, it also crashes my laptop when running
the test-suite. Yes, the machine freezes solid, with no option but to pull
the power-cord, and then the battery ... (I blush to have to admit that it
wasn't until the third time this happened that I realized that it might be
an idea not to put the battery back ... ;-))

The first nine patches all pass "make test" no problem, but patch 10 causes
totally unpredictable mayhem. The crash seems to occur randomly, on any test,
even those which can't possibly be affected by the change (when have you
heard that before...). As far as I can see, only git-http-push, git-send-pack
and git-push should be affected, which in turn means only t5400-send-pack.sh,
t5401-update-hooks.sh and t9400-git-cvsserver-server.sh.  None of those tests
have caused a crash. (actually, since I don't have cvs installed, t9400* is
not even running)

The nature of the crash has made debugging this such a nightmare that I've
just given up!  Hopefully, somebody on a system which does not grind to a
halt (ie. not using cygwin) can find the bug. (I think that cygwin may be
part of the problem here)

If the patches are whitespace damaged, please let me know and I will resend
as attachments.  (As josh noticed on the sparse list, my thunderbird
configuration was causing WS damage to the patches. I hope I have finally
fixed that, but I can't guarantee it!)

I've included a few more notes below, if you want to reproduce the
sparse output.

Hopefully someone will find this useful.

All the best,

Ramsay Jones

If you are on Linux and want to play along, then the official version 0.3
release of sparse should work for you, along with a minor change to the
Makefile thus:

--->8---
diff --git a/Makefile b/Makefile
index 19b6da1..ac3e2af 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ export TCL_PATH TCLTK_PATH
 
 # sparse is architecture-neutral, which means that we need to tell it
 # explicitly what architecture to check for. Fix this up for yours..
-SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
+SPARSE_FLAGS = -D__STDC__=1 $(shell cat .sparse_flags)
 
 
 
--->8---

where the .sparse_flags file is created with a script (gen-sparse-flags.sh)
as follows:

--->8---
#/bin/sh

rm -f /tmp/foo.h .macros; touch /tmp/foo.h

gcc -E -dM /tmp/foo.h >.macros
sed -e "s/^#define /-D'/" -e "s/ /=/" -e "s/$/'/" <.macros >.sparse_flags 

rm -f /tmp/foo.h

--->8---

Note: setting __STDC__ in the SPARSE_FLAGS should not be necessary (I thought
I needed it at one point...) but I didn't get around to removing it.

As an alternative, you could clear the SPARSE_FLAGS and change the "check" target
to call "cgcc -no-compile" in place of sparse.

BTW sparse Git repo: git://git.kernel.org/pub/scm/devel/sparse/sparse.git

^ permalink raw reply related

* Re: git-p4 fails when cloning a p4 depo.
From: Benjamin Sergeant @ 2007-06-08 22:25 UTC (permalink / raw)
  To: Scott Lamb; +Cc: git
In-Reply-To: <1621f9fa0706081504l6106c639oe57c9fd74ebd097a@mail.gmail.com>

I got my git-p4 from here BTW.
http://repo.or.cz/w/fast-export.git

On 6/8/07, Benjamin Sergeant <bsergean@gmail.com> wrote:
> On 6/8/07, Scott Lamb <slamb@slamb.org> wrote:
> > Scott Lamb wrote:
> > > No need to hardcode - from Python this is
> > > os.sysconf(os.sysconf_names['SC_ARG_MAX'])
> >
> > In fact, just os.sysconf('SC_ARG_MAX') will do.
> >
>
> magic number are lot of fun, why would you want to use the clean method :)
>
> So are you saying that in the old days, git-p4 was importing the p4
> depo in small slices to not overkill the process memory (in case the
> depo is big) ?
>
> BTW, there is the whole universe in my depot, so using -//Work/Users
> in my client specification I usually manage to have less megs of code
> on my disk after a sync.
> This way the git-p4 clone would not use too much memory. But we would
> have to change the way git-p4 works, it should be able to read a full
> client view instead of just a single perforce path.
>
> Would you give me the git command to fetch the up
> git clone <git-url> --date <the good date> ?
>
> Thanks,
> Benjamin.
>

^ permalink raw reply

* Re: [PATCH] Port git-tag.sh to C.
From: Johannes Schindelin @ 2007-06-08 22:07 UTC (permalink / raw)
  To: Kristian Høgsberg; +Cc: git
In-Reply-To: <1181340320.30683.30.camel@hinata.boston.redhat.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=utf-8, Size: 430 bytes --]

Hi,

On Fri, 8 Jun 2007, Kristian Høgsberg wrote:

> FWIW, I'm going to send an updated version of the patch that should also 
> pass the test suite.  The previous version always only creates annotated 
> tags.

As it happens, jasam also worked on a relatively extensive test script.

You might want to test it:

	http://repo.or.cz/w/git/builtin-gsoc.git

Branch is "builtin-tag", the test script is t/t7400-tag.sh.

Ciao,
Dscho


^ permalink raw reply

* Re: [PATCH] Port git-tag.sh to C.
From: Kristian Høgsberg @ 2007-06-08 22:05 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0706082249040.4059@racer.site>

On Fri, 2007-06-08 at 22:51 +0100, Johannes Schindelin wrote:
> Hi,
> 
> On Fri, 8 Jun 2007, Kristian Høgsberg wrote:
> 
> > A more or less straight-forward port of git-tag.sh to C.
> 
> It is somewhat unfortunate that you did not say that you were working on 
> this stuff; we have a Google Summer of Code project going on, which tries 
> to port many scripts to builtins.

Ugh, yeah... wasted effort...  I didn't see anything about the SoC
project on the list and I didn't pre-announce my work because I only
spent little more than half a day...

> As it happens, I am working with jasam on exactly the same script.

Hm... not sure how to resolve this.  FWIW, I'm going to send an updated
version of the patch that should also pass the test suite.  The previous
version always only creates annotated tags.

Kristian

^ permalink raw reply

* Re: git-p4 fails when cloning a p4 depo.
From: Benjamin Sergeant @ 2007-06-08 22:04 UTC (permalink / raw)
  To: Scott Lamb; +Cc: git
In-Reply-To: <4669CB75.7060009@slamb.org>

On 6/8/07, Scott Lamb <slamb@slamb.org> wrote:
> Scott Lamb wrote:
> > No need to hardcode - from Python this is
> > os.sysconf(os.sysconf_names['SC_ARG_MAX'])
>
> In fact, just os.sysconf('SC_ARG_MAX') will do.
>

magic number are lot of fun, why would you want to use the clean method :)

So are you saying that in the old days, git-p4 was importing the p4
depo in small slices to not overkill the process memory (in case the
depo is big) ?

BTW, there is the whole universe in my depot, so using -//Work/Users
in my client specification I usually manage to have less megs of code
on my disk after a sync.
This way the git-p4 clone would not use too much memory. But we would
have to change the way git-p4 works, it should be able to read a full
client view instead of just a single perforce path.

Would you give me the git command to fetch the up
git clone <git-url> --date <the good date> ?

Thanks,
Benjamin.

^ permalink raw reply

* Re: [PATCH] Port git-tag.sh to C.
From: Johannes Schindelin @ 2007-06-08 21:51 UTC (permalink / raw)
  To: Kristian Høgsberg; +Cc: git
In-Reply-To: <1181338730800-git-send-email-krh@redhat.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 376 bytes --]

Hi,

On Fri, 8 Jun 2007, Kristian Høgsberg wrote:

> A more or less straight-forward port of git-tag.sh to C.

It is somewhat unfortunate that you did not say that you were working on 
this stuff; we have a Google Summer of Code project going on, which tries 
to port many scripts to builtins.

As it happens, I am working with jasam on exactly the same script.

Pity,
Dscho

^ permalink raw reply

* [PATCH] Port git-tag.sh to C.
From: Kristian Høgsberg @ 2007-06-08 21:38 UTC (permalink / raw)
  To: git; +Cc: Kristian Høgsberg

A more or less straight-forward port of git-tag.sh to C.

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---

There's two behavioral changes here: git tag with no arguments behaves like
git branch with no arguments; it lists all tags.  The other change is
an empty line in the tag message template to make it look more like the
commit message template.

cheers,
Kristian
 

 Makefile      |    3 +-
 builtin-tag.c |  364 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h     |    1 +
 git-tag.sh    |  183 -----------------------------
 git.c         |    1 +
 5 files changed, 368 insertions(+), 184 deletions(-)
 create mode 100644 builtin-tag.c
 delete mode 100755 git-tag.sh

diff --git a/Makefile b/Makefile
index 0f75955..bb1bed1 100644
--- a/Makefile
+++ b/Makefile
@@ -205,7 +205,7 @@ SCRIPT_SH = \
 	git-pull.sh git-rebase.sh \
 	git-repack.sh git-request-pull.sh git-reset.sh \
 	git-sh-setup.sh \
-	git-tag.sh git-verify-tag.sh \
+	git-verify-tag.sh \
 	git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
@@ -372,6 +372,7 @@ BUILTIN_OBJS = \
 	builtin-show-branch.o \
 	builtin-stripspace.o \
 	builtin-symbolic-ref.o \
+	builtin-tag.o \
 	builtin-tar-tree.o \
 	builtin-unpack-objects.o \
 	builtin-update-index.o \
diff --git a/builtin-tag.c b/builtin-tag.c
new file mode 100644
index 0000000..06eafc0
--- /dev/null
+++ b/builtin-tag.c
@@ -0,0 +1,364 @@
+/*
+ * Builtin "git tag"
+ *
+ * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
+ * Based on git-tag.sh and mktag.c by Linus Torvalds.
+ */
+
+#include "cache.h"
+#include "refs.h"
+#include "commit.h"
+#include "builtin.h"
+#include "tag.h"
+#include "run-command.h"
+
+static const char builtin_tag_usage[] =
+  "git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]";
+
+static char signingkey[1000];
+
+static int launch_editor(const char *path, const char *template,
+			  char *buffer, size_t size)
+{
+	struct child_process child;
+	const char *editor;
+	const char *args[3];
+	char *eol;
+	int len, fd, blank_lines, i, j;
+
+	fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644);
+	if (fd < 0)
+		die("could not create file %s.", path);
+
+	len = strlen(template);
+	write_or_die(fd, template, len);
+	close(fd);
+
+	editor = getenv("VISUAL");
+	if (!editor)
+		editor = getenv("EDITOR");
+	if (!editor)
+		editor = "vi";
+	    
+	memset(&child, 0, sizeof(child));
+	child.argv = args;
+	args[0] = editor;
+	args[1] = path;
+	args[2] = NULL;
+
+	if (run_command(&child))
+		die("could not launch editor %s.", editor);
+
+	fd = open(path, O_RDONLY, 0644);
+	if (fd == -1)
+		die("could not read %s.", path);
+	len = read_in_full(fd, buffer, size);
+	if (len < 0)
+		die("failed to read '%s', %m", path);
+	close(fd);
+
+	blank_lines = 1;
+	for (i = 0, j = 0; i < len; i++) {
+		if (blank_lines > 0 && buffer[i] == '#') {
+			eol = strchr(buffer + i, '\n');
+			if (!eol)
+				break;
+
+			i = eol - buffer;
+			continue;
+		}
+
+		if (buffer[i] == '\n') {
+			blank_lines++;
+			if (blank_lines > 1)
+				continue;
+		} else {
+			if (blank_lines > 2)
+				buffer[j++] = '\n';
+			blank_lines = 0;
+		}
+
+		buffer[j++] = buffer[i];
+	}
+
+	if (buffer[j - 1] != '\n')
+		buffer[j++] = '\n';
+
+	unlink(path);
+
+	return j;
+}
+
+static int show_reference(const char *refname, const unsigned char *sha1,
+			  int flag, void *cb_data)
+{
+	const char *pattern = cb_data;
+
+	if (pattern == NULL || !fnmatch(pattern, refname, 0))
+		printf("%s\n", refname);
+
+	return 0;
+}
+
+static int list_tags(const char *pattern)
+{
+	for_each_tag_ref(show_reference, (void *) pattern);
+
+	return 0;
+}
+
+
+static int delete_tags(const char **argv)
+{
+	const char **p;
+	char ref[PATH_MAX];
+	int had_error = 0;
+	unsigned char sha1[20];
+
+	for (p = argv; *p; p++) {
+		if (snprintf(ref, sizeof ref, "refs/tags/%s", *p) > sizeof ref)
+			die("tag name '%s' too long.", *p);
+		if (!resolve_ref(ref, sha1, 1, NULL)) {
+			fprintf(stderr, "tag '%s' not found.\n", *p);
+			had_error = 1;
+			continue;
+		}
+
+		if (!delete_ref(ref, sha1))
+			printf("Deleted tag '%s'\n", *p);
+	}
+			
+	return had_error;
+}
+
+static int verify_tags(const char **argv)
+{
+	const char **p;
+	char ref[PATH_MAX];
+	int had_error = 0;
+	unsigned char sha1[20];
+
+	for (p = argv; *p; p++) {
+		if (snprintf(ref, sizeof ref, "refs/tags/%s", *p) > sizeof ref)
+			die("tag name '%s' too long.", *p);
+
+		if (!resolve_ref(ref, sha1, 1, NULL)) {
+			fprintf(stderr, "tag '%s' not found.\n", *p);
+			had_error = 1;
+			continue;
+		}
+
+		printf("FIXME: verify tag '%s'\n", *p);
+	}
+
+	return had_error;
+}
+
+static int do_sign(char *buffer, size_t size, size_t max)
+{
+	struct child_process gpg;
+	const char *args[5];
+	char *bracket;
+	int len;
+
+	if (signingkey[0] == '\0') {
+		strlcpy(signingkey, git_committer_info(1), sizeof signingkey);
+		bracket = strchr(signingkey, '>');
+		if (bracket)
+			bracket[1] = '\0';
+	}
+
+	memset(&gpg, 0, sizeof(gpg));
+	gpg.argv = args;
+	gpg.in = -1;
+	gpg.out = -1;
+	args[0] = "gpg";
+	args[1] = "-bsa";
+	args[2] = "-u";
+	args[3] = signingkey;
+	args[4] = NULL;
+		
+	if (start_command(&gpg))
+		die("could not run gpg.");
+
+	write_or_die(gpg.in, buffer, size);
+	close(gpg.in);
+	gpg.close_in = 0;
+	len = read_in_full(gpg.out, buffer + size, max - size);
+
+	finish_command(&gpg);
+
+	return size + len;
+}
+
+static const char tag_template[] =
+	"\n"
+	"#\n"
+	"# Write a tag message\n"
+	"#\n";
+
+int git_tag_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "user.signingkey")) {
+		if (!value)
+			die("user.signingkey without value");
+		strlcpy(signingkey, value, sizeof signingkey);
+		return 0;
+	}
+
+	return git_default_config(var, value);
+}
+
+int cmd_tag(int argc, const char **argv, const char *prefix)
+{
+	char buffer[4096];
+	unsigned char object[20], prev[20], result[20];
+	int annotate = 0, is_signed = 0, force = 0, lines = 0;
+	const char *message = NULL;
+	char ref[PATH_MAX];
+	const char *object_ref, *tag;
+	int i, body, header, total, fd;
+	enum object_type type;
+	struct ref_lock *lock;
+
+	git_config(git_tag_config);
+
+	for (i = 1; i < argc; i++) {
+		const char *arg = argv[i];
+
+		if (arg[0] != '-')
+			break;
+		if (!strcmp(arg, "-a")) {
+			annotate = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-s")) {
+			annotate = 1;
+			is_signed = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-f")) {
+			force = 1;
+			continue;
+		}
+		if (!strcmp(arg, "-n")) {
+			if (i + 1 == argc || *argv[i + 1] == '-')
+				/* no argument */
+				lines = 1;
+			else
+				/* FIXME, fallback to 1 on invalid integer */
+				lines = atoi(argv[i + 1]);
+			continue;
+		}
+		if (!strcmp(arg, "-m")) {
+			annotate = 1;
+			i++;
+			if  (i == argc)
+				die("option -m needs an argument.");
+			message = argv[i];
+			continue;
+		}
+		if (!strcmp(arg, "-F")) {
+			annotate = 1;
+			i++;
+			if  (i == argc)
+				die("option -F needs an argument.");
+
+			fd = open(argv[i], O_RDONLY);
+			if (fd < 0)
+				die("cannot open %s", argv[1]);
+
+			message = xmalloc(4096);
+			if (read_in_full(fd, (char *) message, 4096) < 0)
+				die("cannot read %s", argv[1]);
+			continue;
+		}
+		if (!strcmp(arg, "-u")) {
+			annotate = 1;
+			is_signed = 1;
+			i++;
+			if  (i == argc)
+				die("option -u needs an argument.");
+			strlcpy(signingkey, argv[i], sizeof signingkey);
+			continue;
+		}
+		if (!strcmp(arg, "-l")) {
+			return list_tags(argv[i + 1]);
+		}
+		if (!strcmp(arg, "-d")) {
+			return delete_tags(argv + i + 1);
+		}
+		if (!strcmp(arg, "-v")) {
+			return verify_tags(argv + i + 1);
+		}
+		usage(builtin_tag_usage);
+	}
+
+	if (i == argc)
+		return list_tags(NULL);
+	tag = argv[i++];
+
+	if (i < argc)
+		object_ref = argv[i];
+	else
+		object_ref = "HEAD";
+
+	if (get_sha1(object_ref, object))
+		die("Failed to resolve '%s' as a valid ref.", object_ref);
+
+	if (snprintf(ref, sizeof ref, "refs/tags/%s", tag) > sizeof ref)
+		die("tag '%s' too long.", tag);
+	if (check_ref_format(ref))
+		die("'%s' is not a valid tag name.", tag);
+	if (resolve_ref(ref, prev, 1, NULL)) {
+		if (!force)
+			die("tag '%s' already exists", tag);
+	} else {
+		hashclr(prev);
+	}
+
+	type = sha1_object_info(object, NULL);
+	if (type <= 0)
+	    die("bad object type.");
+
+	header = snprintf(buffer, sizeof buffer,
+			  "object %s\n"
+			  "type %s\n"
+			  "tag %s\n"
+			  "tagger %s\n\n",
+			  sha1_to_hex(object),
+			  typename(type),
+			  tag,
+			  git_committer_info(1));
+
+	if (annotate && message == NULL)
+		body = launch_editor(git_path("TAGMSG"), tag_template,
+				     buffer + header, sizeof buffer - header);
+	else if (annotate)
+		body = snprintf(buffer + header, sizeof buffer - header,
+				"%s\n", message);
+	else
+		body = 0;
+
+	if (annotate && body == 0)
+		die("no tag message?");
+
+	if (header + body > sizeof buffer)
+		die("tag message too big.");
+
+	if (is_signed)
+		total = do_sign(buffer, header + body, sizeof buffer);
+	else
+		total = header + body;
+
+	if (write_sha1_file(buffer, total, tag_type, result) < 0)
+		die("unable to write tag file");
+
+	lock = lock_any_ref_for_update(ref, prev, 0);
+	if (!lock)
+		die("%s: cannot lock the ref", ref);
+	if (write_ref_sha1(lock, result, NULL) < 0)
+		die("%s: cannot update the ref", ref);
+
+	return 0;
+}
diff --git a/builtin.h b/builtin.h
index 39290d1..91166e1 100644
--- a/builtin.h
+++ b/builtin.h
@@ -72,6 +72,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
+extern int cmd_tag(int argc, const char **argv, const char *prefix);
 extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_update_index(int argc, const char **argv, const char *prefix);
diff --git a/git-tag.sh b/git-tag.sh
deleted file mode 100755
index 37cee97..0000000
--- a/git-tag.sh
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2005 Linus Torvalds
-
-USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
-SUBDIRECTORY_OK='Yes'
-. git-sh-setup
-
-message_given=
-annotate=
-signed=
-force=
-message=
-username=
-list=
-verify=
-LINES=0
-while case "$#" in 0) break ;; esac
-do
-    case "$1" in
-    -a)
-	annotate=1
-	;;
-    -s)
-	annotate=1
-	signed=1
-	;;
-    -f)
-	force=1
-	;;
-    -n)
-        case $2 in
-	-*)	LINES=1 	# no argument
-		;;
-	*)	shift
-		LINES=$(expr "$1" : '\([0-9]*\)')
-		[ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
-		;;
-	esac
-	;;
-    -l)
-	list=1
-	shift
-	PATTERN="$1"	# select tags by shell pattern, not re
-	git rev-parse --symbolic --tags | sort |
-	    while read TAG
-	    do
-	        case "$TAG" in
-		*$PATTERN*) ;;
-		*)	    continue ;;
-		esac
-		[ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
-		OBJTYPE=$(git cat-file -t "$TAG")
-		case $OBJTYPE in
-		tag)	ANNOTATION=$(git cat-file tag "$TAG" |
-				       sed -e '1,/^$/d' \
-					   -e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
-			printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
-			  sed -e '2,$s/^/    /' \
-			      -e "${LINES}q"
-			;;
-		*)      echo "$TAG"
-			;;
-		esac
-	    done
-	;;
-    -m)
-    	annotate=1
-	shift
-	message="$1"
-	if test "$#" = "0"; then
-	    die "error: option -m needs an argument"
-	else
-	    message_given=1
-	fi
-	;;
-    -F)
-	annotate=1
-	shift
-	if test "$#" = "0"; then
-	    die "error: option -F needs an argument"
-	else
-	    message="$(cat "$1")"
-	    message_given=1
-	fi
-	;;
-    -u)
-	annotate=1
-	signed=1
-	shift
-	username="$1"
-	;;
-    -d)
-    	shift
-	had_error=0
-	for tag
-	do
-		cur=$(git-show-ref --verify --hash -- "refs/tags/$tag") || {
-			echo >&2 "Seriously, what tag are you talking about?"
-			had_error=1
-			continue
-		}
-		git-update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
-			had_error=1
-			continue
-		}
-		echo "Deleted tag $tag."
-	done
-	exit $had_error
-	;;
-    -v)
-	shift
-	tag_name="$1"
-	tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
-		die "Seriously, what tag are you talking about?"
-	git-verify-tag -v "$tag"
-	exit $?
-	;;
-    -*)
-        usage
-	;;
-    *)
-	break
-	;;
-    esac
-    shift
-done
-
-[ -n "$list" ] && exit 0
-
-name="$1"
-[ "$name" ] || usage
-prev=0000000000000000000000000000000000000000
-if git-show-ref --verify --quiet -- "refs/tags/$name"
-then
-    test -n "$force" || die "tag '$name' already exists"
-    prev=`git rev-parse "refs/tags/$name"`
-fi
-shift
-git-check-ref-format "tags/$name" ||
-	die "we do not like '$name' as a tag name."
-
-object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
-type=$(git-cat-file -t $object) || exit 1
-tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
-
-test -n "$username" ||
-	username=$(git-repo-config user.signingkey) ||
-	username=$(expr "z$tagger" : 'z\(.*>\)')
-
-trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
-
-if [ "$annotate" ]; then
-    if [ -z "$message_given" ]; then
-        ( echo "#"
-          echo "# Write a tag message"
-          echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
-        ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
-    else
-        printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
-    fi
-
-    grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
-    git-stripspace >"$GIT_DIR"/TAG_FINALMSG
-
-    [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
-	echo >&2 "No tag message?"
-	exit 1
-    }
-
-    ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
-	"$object" "$type" "$name" "$tagger";
-      cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
-    rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
-    if [ "$signed" ]; then
-	gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
-	cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
-	die "failed to sign the tag with GPG."
-    fi
-    object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
-fi
-
-git update-ref "refs/tags/$name" "$object" "$prev"
-
diff --git a/git.c b/git.c
index 29b55a1..c9c20fb 100644
--- a/git.c
+++ b/git.c
@@ -285,6 +285,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
+		{ "tag", cmd_tag, RUN_SETUP },
 		{ "tar-tree", cmd_tar_tree },
 		{ "unpack-objects", cmd_unpack_objects, RUN_SETUP },
 		{ "update-index", cmd_update_index, RUN_SETUP },
-- 
1.5.2.1.134.g447c2

^ permalink raw reply related

* Re: git-p4 fails when cloning a p4 depo.
From: Scott Lamb @ 2007-06-08 21:34 UTC (permalink / raw)
  To: Benjamin Sergeant; +Cc: git
In-Reply-To: <4669CAB4.5080507@slamb.org>

Scott Lamb wrote:
> No need to hardcode - from Python this is 
> os.sysconf(os.sysconf_names['SC_ARG_MAX'])

In fact, just os.sysconf('SC_ARG_MAX') will do.

^ permalink raw reply

* Re: [PATCH 1/2] filter-branch: Simplify parent computation.
From: Johannes Schindelin @ 2007-06-08 21:29 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git
In-Reply-To: <200706082328.39758.johannes.sixt@telecom.at>

Hi,

Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>

for both patches. They look obviously correct to me.

Ciao,
Dscho

^ permalink raw reply

* Re: git-p4 fails when cloning a p4 depo.
From: Scott Lamb @ 2007-06-08 21:31 UTC (permalink / raw)
  To: Benjamin Sergeant; +Cc: git
In-Reply-To: <1621f9fa0706081113w7bb765ebx74f03a7407b753cb@mail.gmail.com>

Benjamin Sergeant wrote:
> A perforce command with all the files in the repo is generated to get
> all the file content.
> Here is a patch to break it into multiple successive perforce command
> who uses 4K of parameter max, and collect the output for later.
> 
> It works, but not for big depos, because the whole perforce depo
> content is stored in memory in P4Sync.run(), and it looks like mine is
> bigger than 2 Gigs, so I had to kill the process.

Hmm. I tried git-p4 out on Sunday, and it definitely didn't do this 
then...this commit must have showed up since:

     commit 6460cf12df4556f889888b5f0b49e07040747e6f
     Author: Han-Wen Nienhuys <hanwen@google.com>
     Date:   Wed May 23 18:49:35 2007 -0300

         Read p4 files in one batch.

I believe HEAD at the time was this:

     commit 458e0545cb3dd03af9cd1a61480cbb764639043a
     Author: Simon Hausmann <simon@lst.de>
     Date:   Mon May 28 19:24:57 2007 +0200

         Fix typo in listExistingP4Branches that broke sync.

so you might try checking out an old version, and I'll go RTFM on 
reading merge history, because I can't figure out when this happened.

> 
> 
> diff --git a/git-p4 b/git-p4
> index 36fe69a..906b193 100755
> --- a/git-p4
> +++ b/git-p4
> @@ -703,9 +703,22 @@ class P4Sync(Command):
>         if not files:
>             return
> 
> -        filedata = p4CmdList('print %s' % ' '.join(['"%s#%s"' % 
> (f['path'],
> -                                                                 f['rev'])
> -                                                    for f in files]))
> +        # We cannot put all the files on the command line
> +        # OS have limitations on the max lenght of arguments
> +        # POSIX says it's 4096 bytes, default for Linux seems to be 130 K.
> +        # and all OS from the table below seems to be higher than POSIX.
> +        # See http://www.in-ulm.de/~mascheck/various/argmax/

No need to hardcode - from Python this is 
os.sysconf(os.sysconf_names['SC_ARG_MAX'])

> +        chunk = ''
> +        filedata = []
> +        for i in xrange(len(files)):
> +            f = files[i]
> +            chunk += '"%s#%s" ' % (f['path'], f['rev'])
> +            if len(chunk) > 4000 or i == len(files)-1:
> +                data = p4CmdList('print %s' % chunk)
> +                if "p4ExitCode" in data[0]:
> +                    die("Problems executing p4. Error: [%d]." %
> (data[0]['p4ExitCode']));
> +                filedata.extend(data)
> +                chunk = ''
> 
>         j = 0;
>         contents = {}
> @@ -1486,3 +1499,5 @@ def main():
> 
> if __name__ == '__main__':
>     main()
> +
> +# vim: set filetype=python sts=4 sw=4 et si :

^ permalink raw reply

* [PATCH 2/2] filter-branch: subdirectory filter needs --full-history
From: Johannes Sixt @ 2007-06-08 21:28 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin

When two branches are merged that modify a subdirectory (possibly in
different intermediate steps) such that both end up identical, then
rev-list chooses only one branch. But when we filter history, we want to
keep both branches. Therefore, we must use --full-history.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 git-filter-branch.sh     |    2 +-
 t/t7003-filter-branch.sh |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 4ef4570..2e4ccec 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -326,7 +326,7 @@ case "$filter_subdir" in
 	;;
 *)
 	git-rev-list --reverse --topo-order --default HEAD \
-		--parents "$@" -- "$filter_subdir"
+		--parents --full-history "$@" -- "$filter_subdir"
 esac > ../revs
 commits=$(cat ../revs | wc -l | tr -d " ")
 
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 292b837..0fabe49 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -78,4 +78,25 @@ test_expect_success 'subdirectory filter result looks 
okay' '
 	! git show sub:subdir
 '
 
+test_expect_success 'setup and filter history that requires --full-history' '
+	git checkout master &&
+	mkdir subdir &&
+	echo A > subdir/new &&
+	git add subdir/new &&
+	test_tick &&
+	git commit -m "subdir on master" subdir/new &&
+	git rm a &&
+	test_tick &&
+	git commit -m "again subdir on master" &&
+	git merge branch &&
+	git-filter-branch --subdirectory-filter subdir sub-master
+'
+
+test_expect_success 'subdirectory filter result looks okay' '
+	test 3 = $(git-rev-list -1 --parents sub-master | wc -w) &&
+	git show sub-master^:new &&
+	git show sub-master^2:new &&
+	! git show sub:subdir
+'
+
 test_done
-- 
1.5.2

^ permalink raw reply related

* [PATCH 1/2] filter-branch: Simplify parent computation.
From: Johannes Sixt @ 2007-06-08 21:28 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin

We can use git rev-list --parents when we list the commits to rewrite.
It is not necessary to run git rev-list --parents for each commit in the
loop.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 git-filter-branch.sh |   24 +++++++-----------------
 1 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 4990729..4ef4570 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -229,17 +229,6 @@ set_ident () {
 	echo "[ -n \"\$GIT_${uid}_NAME\" ] || export 
GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
 }
 
-# list all parent's object names for a given commit
-get_parents () {
-	case "$filter_subdir" in
-	"")
-		git-rev-list -1 --parents "$1"
-		;;
-	*)
-		git-rev-list -1 --parents "$1" -- "$filter_subdir"
-	esac | sed "s/^[0-9a-f]*//"
-}
-
 tempdir=.git-rewrite
 filter_env=
 filter_tree=
@@ -332,18 +321,19 @@ mkdir ../map # map old->new commit ids for rewriting 
parents
 
 case "$filter_subdir" in
 "")
-	git-rev-list --reverse --topo-order --default HEAD "$@"
+	git-rev-list --reverse --topo-order --default HEAD \
+		--parents "$@"
 	;;
 *)
-	git-rev-list --reverse --topo-order --default HEAD "$@" \
-		-- "$filter_subdir"
+	git-rev-list --reverse --topo-order --default HEAD \
+		--parents "$@" -- "$filter_subdir"
 esac > ../revs
 commits=$(cat ../revs | wc -l | tr -d " ")
 
 test $commits -eq 0 && die "Found nothing to rewrite"
 
 i=0
-while read commit; do
+while read commit parents; do
 	i=$(($i+1))
 	printf "\rRewriting commits... ($i/$commits)"
 
@@ -377,7 +367,7 @@ while read commit; do
 	eval "$filter_index" < /dev/null
 
 	parentstr=
-	for parent in $(get_parents $commit); do
+	for parent in $parents; do
 		for reparent in $(map "$parent"); do
 			parentstr="$parentstr -p $reparent"
 		done
@@ -398,7 +388,7 @@ while read commit; do
 		done > ../map/$commit
 done <../revs
 
-src_head=$(tail -n 1 ../revs)
+src_head=$(tail -n 1 ../revs | sed -e 's/ .*//')
 target_head=$(head -n 1 ../map/$src_head)
 case "$target_head" in
 '')
-- 
1.5.2

^ permalink raw reply related

* Re: gitk highlighting commits
From: Jan Hudec @ 2007-06-08 21:11 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: picca, git
In-Reply-To: <20070608065739.GC18521@spearce.org>

[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]

On Fri, Jun 08, 2007 at 02:57:39 -0400, Shawn O. Pearce wrote:
> picca <picca@synchrotron-soleil.Fr> wrote:
> > I am using git to follow the wine development. And I wondering if it
> > is possible to highlight all the commit since my last git pull ?
> 
> If you do it *right after* the pull, you can see those commits that
> are new to you with:
> 
> 	gitk ORIG_HEAD..
> 
> ORIG_HEAD is a special name for the commit that you had just before
> you pulled.  So you are asking gitk to show you all commits that
> are now in your current branch (implied by nothing to the right of
> the ..) that were not in your branch before the pull (ORIG_HEAD).
> That is the stuff you just pullled.
> 
> If its many days later that you want to look at this and you have
> done some things that overwrite ORIG_HEAD (git reset; git rebase;
> etc.)  then this becomes more difficult.  But you can also do by
> time:
> 
>   gitk HEAD@{2.days.ago}..

There is actually one ref which only changes in pulls (and fetches) -- the
tracking brach. Therefore:

gitk origin/master@{1}..

(or whatever you pull) is what you want.

> This shows you everything that is new *to you* in the past two days.
> Even if the changes were created months ago and just recently were
> pulled by you yesterday, they will appear in gitk, because you asked
> for *your* history over the past two days, not the project history.
> 
> These same tricks also work with git-log of course:
> 
>   git log ORIG_HEAD...
>   git log HEAD@{2.days.ago}..
> 
> You could also take a look at the manual page for git-rev-parse,
> there are some more details covered there I think.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ 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