Re: [PATCH v3 09/28] shallow.c: extend setup_*_shallow() to accept extra shallow points

2013-11-25 Thread Junio C Hamano
Nguyễn Thái Ngọc Duy  pclo...@gmail.com writes:

 Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
 ---
  commit.h  |  8 +---
  fetch-pack.c  |  5 +++--
  shallow.c | 20 +++-
  upload-pack.c |  2 +-
  4 files changed, 24 insertions(+), 11 deletions(-)

 diff --git a/commit.h b/commit.h
 index e1fd587..3af4699 100644
 --- a/commit.h
 +++ b/commit.h
 @@ -203,10 +203,12 @@ extern struct commit_list *get_shallow_commits(struct 
 object_array *heads,
   int depth, int shallow_flag, int not_shallow_flag);
  extern void check_shallow_file_for_update(void);
  extern void set_alternate_shallow_file(const char *path);
 -extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
 +extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
 +  const struct extra_have_objects *extra);

Confusing.

Sounds as if you got the extra .have and storing them in the
.git/shallow file (which of course would not make much sense), which
is not what is going on.

Also it is unclear how the sanity check the previous step seems to
make and the new list of shallow commit names this patch adds to
existing functions are designed to interact. I think the whole
design needs a better explanation of the flow at the higher level.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 09/28] shallow.c: extend setup_*_shallow() to accept extra shallow points

2013-11-24 Thread Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
---
 commit.h  |  8 +---
 fetch-pack.c  |  5 +++--
 shallow.c | 20 +++-
 upload-pack.c |  2 +-
 4 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/commit.h b/commit.h
index e1fd587..3af4699 100644
--- a/commit.h
+++ b/commit.h
@@ -203,10 +203,12 @@ extern struct commit_list *get_shallow_commits(struct 
object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
 extern void check_shallow_file_for_update(void);
 extern void set_alternate_shallow_file(const char *path);
-extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
+extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
+const struct extra_have_objects *extra);
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
-   const char **alternate_shallow_file);
-extern char *setup_temporary_shallow(void);
+   const char **alternate_shallow_file,
+   const struct extra_have_objects *extra);
+extern char *setup_temporary_shallow(const struct extra_have_objects *extra);
 extern void advertise_shallow_grafts(int);
 extern void remove_reachable_shallow_points(struct extra_have_objects *out,
const struct extra_have_objects 
*in);
diff --git a/fetch-pack.c b/fetch-pack.c
index 1042448..0e7483e 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -311,7 +311,7 @@ static int find_common(struct fetch_pack_args *args,
}
 
if (is_repository_shallow())
-   write_shallow_commits(req_buf, 1);
+   write_shallow_commits(req_buf, 1, NULL);
if (args-depth  0)
packet_buf_write(req_buf, deepen %d, args-depth);
packet_buf_flush(req_buf);
@@ -850,7 +850,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args 
*args,
if (args-stateless_rpc)
packet_flush(fd[1]);
if (args-depth  0)
-   setup_alternate_shallow(shallow_lock, alternate_shallow_file);
+   setup_alternate_shallow(shallow_lock, alternate_shallow_file,
+   NULL);
else
alternate_shallow_file = NULL;
if (get_pack(args, fd, pack_lockfile))
diff --git a/shallow.c b/shallow.c
index c92a1dc..2ec0c8c 100644
--- a/shallow.c
+++ b/shallow.c
@@ -169,22 +169,31 @@ static int write_one_shallow(const struct commit_graft 
*graft, void *cb_data)
return 0;
 }
 
-int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
+ const struct extra_have_objects *extra)
 {
struct write_shallow_data data;
+   int i;
data.out = out;
data.use_pack_protocol = use_pack_protocol;
data.count = 0;
for_each_commit_graft(write_one_shallow, data);
+   if (!extra)
+   return data.count;
+   for (i = 0; i  extra-nr; i++) {
+   strbuf_addstr(out, sha1_to_hex(extra-array[i]));
+   strbuf_addch(out, '\n');
+   data.count++;
+   }
return data.count;
 }
 
-char *setup_temporary_shallow(void)
+char *setup_temporary_shallow(const struct extra_have_objects *extra)
 {
struct strbuf sb = STRBUF_INIT;
int fd;
 
-   if (write_shallow_commits(sb, 0)) {
+   if (write_shallow_commits(sb, 0, extra)) {
struct strbuf path = STRBUF_INIT;
strbuf_addstr(path, git_path(shallow_XX));
fd = xmkstemp(path.buf);
@@ -203,7 +212,8 @@ char *setup_temporary_shallow(void)
 }
 
 void setup_alternate_shallow(struct lock_file *shallow_lock,
-const char **alternate_shallow_file)
+const char **alternate_shallow_file,
+const struct extra_have_objects *extra)
 {
struct strbuf sb = STRBUF_INIT;
int fd;
@@ -211,7 +221,7 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
check_shallow_file_for_update();
fd = hold_lock_file_for_update(shallow_lock, git_path(shallow),
   LOCK_DIE_ON_ERROR);
-   if (write_shallow_commits(sb, 0)) {
+   if (write_shallow_commits(sb, 0, extra)) {
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno(failed to write to %s,
  shallow_lock-filename);
diff --git a/upload-pack.c b/upload-pack.c
index 38b2a29..f082f06 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -84,7 +84,7 @@ static void create_pack_file(void)
char *shallow_file = NULL;
 
if (shallow_nr) {
-   shallow_file = setup_temporary_shallow();
+   shallow_file = setup_temporary_shallow(NULL);